OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 27 matching lines...) Expand all Loading... |
38 class ScriptDataImpl; | 38 class ScriptDataImpl; |
39 | 39 |
40 // CompilationInfo encapsulates some information known at compile time. It | 40 // CompilationInfo encapsulates some information known at compile time. It |
41 // is constructed based on the resources available at compile-time. | 41 // is constructed based on the resources available at compile-time. |
42 class CompilationInfo BASE_EMBEDDED { | 42 class CompilationInfo BASE_EMBEDDED { |
43 public: | 43 public: |
44 CompilationInfo(Handle<Script> script, Zone* zone); | 44 CompilationInfo(Handle<Script> script, Zone* zone); |
45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | 45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
47 | 47 |
48 ~CompilationInfo(); | |
49 | |
50 Isolate* isolate() { | 48 Isolate* isolate() { |
51 ASSERT(Isolate::Current() == isolate_); | 49 ASSERT(Isolate::Current() == isolate_); |
52 return isolate_; | 50 return isolate_; |
53 } | 51 } |
54 Zone* zone() { | 52 Zone* zone() { |
55 return zone_; | 53 return zone_; |
56 } | 54 } |
57 bool is_lazy() const { return IsLazy::decode(flags_); } | 55 bool is_lazy() const { return IsLazy::decode(flags_); } |
58 bool is_eval() const { return IsEval::decode(flags_); } | 56 bool is_eval() const { return IsEval::decode(flags_); } |
59 bool is_global() const { return IsGlobal::decode(flags_); } | 57 bool is_global() const { return IsGlobal::decode(flags_); } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 flags_ |= SupportsDeoptimization::encode(true); | 166 flags_ |= SupportsDeoptimization::encode(true); |
169 } | 167 } |
170 | 168 |
171 // Determines whether or not to insert a self-optimization header. | 169 // Determines whether or not to insert a self-optimization header. |
172 bool ShouldSelfOptimize(); | 170 bool ShouldSelfOptimize(); |
173 | 171 |
174 // Disable all optimization attempts of this info for the rest of the | 172 // Disable all optimization attempts of this info for the rest of the |
175 // current compilation pipeline. | 173 // current compilation pipeline. |
176 void AbortOptimization(); | 174 void AbortOptimization(); |
177 | 175 |
178 void set_deferred_handles(DeferredHandles* deferred_handles) { | |
179 ASSERT(deferred_handles_ == NULL); | |
180 deferred_handles_ = deferred_handles; | |
181 } | |
182 | |
183 private: | 176 private: |
184 Isolate* isolate_; | 177 Isolate* isolate_; |
185 | 178 |
186 // Compilation mode. | 179 // Compilation mode. |
187 // BASE is generated by the full codegen, optionally prepared for bailouts. | 180 // BASE is generated by the full codegen, optionally prepared for bailouts. |
188 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 181 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
189 // NONOPT is generated by the full codegen and is not prepared for | 182 // NONOPT is generated by the full codegen and is not prepared for |
190 // recompilation/bailouts. These functions are never recompiled. | 183 // recompilation/bailouts. These functions are never recompiled. |
191 enum Mode { | 184 enum Mode { |
192 BASE, | 185 BASE, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 Handle<Context> calling_context_; | 252 Handle<Context> calling_context_; |
260 | 253 |
261 // Compilation mode flag and whether deoptimization is allowed. | 254 // Compilation mode flag and whether deoptimization is allowed. |
262 Mode mode_; | 255 Mode mode_; |
263 int osr_ast_id_; | 256 int osr_ast_id_; |
264 | 257 |
265 // The zone from which the compilation pipeline working on this | 258 // The zone from which the compilation pipeline working on this |
266 // CompilationInfo allocates. | 259 // CompilationInfo allocates. |
267 Zone* zone_; | 260 Zone* zone_; |
268 | 261 |
269 DeferredHandles* deferred_handles_; | |
270 | |
271 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 262 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
272 }; | 263 }; |
273 | 264 |
274 | 265 |
275 // Exactly like a CompilationInfo, except also creates and enters a | 266 // Exactly like a CompilationInfo, except also creates and enters a |
276 // Zone on construction and deallocates it on exit. | 267 // Zone on construction and deallocates it on exit. |
277 class CompilationInfoWithZone: public CompilationInfo { | 268 class CompilationInfoWithZone: public CompilationInfo { |
278 public: | 269 public: |
279 explicit CompilationInfoWithZone(Handle<Script> script) | 270 explicit CompilationInfoWithZone(Handle<Script> script) |
280 : CompilationInfo(script, &zone_), | 271 : CompilationInfo(script, &zone_), |
281 zone_(script->GetIsolate()), | 272 zone_(script->GetIsolate()), |
282 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 273 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
283 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | 274 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
284 : CompilationInfo(shared_info, &zone_), | 275 : CompilationInfo(shared_info, &zone_), |
285 zone_(shared_info->GetIsolate()), | 276 zone_(shared_info->GetIsolate()), |
286 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 277 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
287 explicit CompilationInfoWithZone(Handle<JSFunction> closure) | 278 explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
288 : CompilationInfo(closure, &zone_), | 279 : CompilationInfo(closure, &zone_), |
289 zone_(closure->GetIsolate()), | 280 zone_(closure->GetIsolate()), |
290 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 281 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
291 | 282 |
292 private: | 283 private: |
293 Zone zone_; | 284 Zone zone_; |
294 ZoneScope zone_scope_; | 285 ZoneScope zone_scope_; |
295 }; | 286 }; |
296 | 287 |
297 | 288 |
298 // A wrapper around a CompilationInfo that detaches the Handles from | |
299 // the underlying DeferredHandleScope and stores them in info_ on | |
300 // destruction. | |
301 class CompilationHandleScope BASE_EMBEDDED { | |
302 public: | |
303 explicit CompilationHandleScope(CompilationInfo* info) | |
304 : deferred_(info->isolate()), info_(info) {} | |
305 ~CompilationHandleScope() { | |
306 info_->set_deferred_handles(deferred_.Detach()); | |
307 } | |
308 | |
309 private: | |
310 DeferredHandleScope deferred_; | |
311 CompilationInfo* info_; | |
312 }; | |
313 | |
314 | |
315 // The V8 compiler | 289 // The V8 compiler |
316 // | 290 // |
317 // General strategy: Source code is translated into an anonymous function w/o | 291 // General strategy: Source code is translated into an anonymous function w/o |
318 // parameters which then can be executed. If the source code contains other | 292 // parameters which then can be executed. If the source code contains other |
319 // functions, they will be compiled and allocated as part of the compilation | 293 // functions, they will be compiled and allocated as part of the compilation |
320 // of the source code. | 294 // of the source code. |
321 | 295 |
322 // Please note this interface returns shared function infos. This means you | 296 // Please note this interface returns shared function infos. This means you |
323 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | 297 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
324 // real function with a context. | 298 // real function with a context. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 350 |
377 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 351 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
378 CompilationInfo* info, | 352 CompilationInfo* info, |
379 Handle<SharedFunctionInfo> shared); | 353 Handle<SharedFunctionInfo> shared); |
380 }; | 354 }; |
381 | 355 |
382 | 356 |
383 } } // namespace v8::internal | 357 } } // namespace v8::internal |
384 | 358 |
385 #endif // V8_COMPILER_H_ | 359 #endif // V8_COMPILER_H_ |
OLD | NEW |