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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 struct OffsetRange { | 50 struct OffsetRange { |
51 OffsetRange(int from, int to) : from(from), to(to) {} | 51 OffsetRange(int from, int to) : from(from), to(to) {} |
52 int from; | 52 int from; |
53 int to; | 53 int to; |
54 }; | 54 }; |
55 | 55 |
56 // CompilationInfo encapsulates some information known at compile time. It | 56 // CompilationInfo encapsulates some information known at compile time. It |
57 // is constructed based on the resources available at compile-time. | 57 // is constructed based on the resources available at compile-time. |
58 class CompilationInfo { | 58 class CompilationInfo { |
59 public: | 59 public: |
60 CompilationInfo(Handle<Script> script, Zone* zone); | |
61 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | |
62 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 60 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
63 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone); | 61 virtual ~CompilationInfo(); |
64 | |
65 ~CompilationInfo(); | |
66 | 62 |
67 Isolate* isolate() { | 63 Isolate* isolate() { |
68 ASSERT(Isolate::Current() == isolate_); | 64 ASSERT(Isolate::Current() == isolate_); |
69 return isolate_; | 65 return isolate_; |
70 } | 66 } |
71 Zone* zone() { return zone_; } | 67 Zone* zone() { return zone_; } |
72 bool is_lazy() const { return IsLazy::decode(flags_); } | 68 bool is_lazy() const { return IsLazy::decode(flags_); } |
73 bool is_eval() const { return IsEval::decode(flags_); } | 69 bool is_eval() const { return IsEval::decode(flags_); } |
74 bool is_global() const { return IsGlobal::decode(flags_); } | 70 bool is_global() const { return IsGlobal::decode(flags_); } |
75 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } | 71 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 232 |
237 // Disable all optimization attempts of this info for the rest of the | 233 // Disable all optimization attempts of this info for the rest of the |
238 // current compilation pipeline. | 234 // current compilation pipeline. |
239 void AbortOptimization(); | 235 void AbortOptimization(); |
240 | 236 |
241 void set_deferred_handles(DeferredHandles* deferred_handles) { | 237 void set_deferred_handles(DeferredHandles* deferred_handles) { |
242 ASSERT(deferred_handles_ == NULL); | 238 ASSERT(deferred_handles_ == NULL); |
243 deferred_handles_ = deferred_handles; | 239 deferred_handles_ = deferred_handles; |
244 } | 240 } |
245 | 241 |
| 242 ZoneList<Handle<Map> >* dependent_maps(DependentCode::DependencyGroup group) { |
| 243 if (dependent_maps_[group] == NULL) { |
| 244 dependent_maps_[group] = new(zone_) ZoneList<Handle<Map> >(2, zone_); |
| 245 } |
| 246 return dependent_maps_[group]; |
| 247 } |
| 248 |
| 249 void CommitDependentMaps(Handle<Code> code); |
| 250 |
| 251 void RollbackDependentMaps(); |
| 252 |
246 void SaveHandles() { | 253 void SaveHandles() { |
247 SaveHandle(&closure_); | 254 SaveHandle(&closure_); |
248 SaveHandle(&shared_info_); | 255 SaveHandle(&shared_info_); |
249 SaveHandle(&context_); | 256 SaveHandle(&context_); |
250 SaveHandle(&script_); | 257 SaveHandle(&script_); |
251 } | 258 } |
252 | 259 |
253 const char* bailout_reason() const { return bailout_reason_; } | 260 const char* bailout_reason() const { return bailout_reason_; } |
254 void set_bailout_reason(const char* reason) { bailout_reason_ = reason; } | 261 void set_bailout_reason(const char* reason) { bailout_reason_ = reason; } |
255 | 262 |
(...skipping 13 matching lines...) Expand all Loading... |
269 inline void AddNoFrameRange(int from, int to) { | 276 inline void AddNoFrameRange(int from, int to) { |
270 if (no_frame_ranges_) no_frame_ranges_->Add(OffsetRange(from, to)); | 277 if (no_frame_ranges_) no_frame_ranges_->Add(OffsetRange(from, to)); |
271 } | 278 } |
272 | 279 |
273 List<OffsetRange>* ReleaseNoFrameRanges() { | 280 List<OffsetRange>* ReleaseNoFrameRanges() { |
274 List<OffsetRange>* result = no_frame_ranges_; | 281 List<OffsetRange>* result = no_frame_ranges_; |
275 no_frame_ranges_ = NULL; | 282 no_frame_ranges_ = NULL; |
276 return result; | 283 return result; |
277 } | 284 } |
278 | 285 |
| 286 Handle<Foreign> object_wrapper() { |
| 287 if (object_wrapper_.is_null()) { |
| 288 object_wrapper_ = |
| 289 isolate()->factory()->NewForeign(reinterpret_cast<Address>(this)); |
| 290 } |
| 291 return object_wrapper_; |
| 292 } |
| 293 |
| 294 void AbortDueToDependentMap() { |
| 295 mode_ = DEPENDENT_MAP_ABORT; |
| 296 } |
| 297 |
| 298 bool HasAbortedDueToDependentMap() { |
| 299 return mode_ == DEPENDENT_MAP_ABORT; |
| 300 } |
| 301 |
| 302 protected: |
| 303 CompilationInfo(Handle<Script> script, Zone* zone); |
| 304 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
| 305 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone); |
279 | 306 |
280 private: | 307 private: |
281 Isolate* isolate_; | 308 Isolate* isolate_; |
282 | 309 |
283 // Compilation mode. | 310 // Compilation mode. |
284 // BASE is generated by the full codegen, optionally prepared for bailouts. | 311 // BASE is generated by the full codegen, optionally prepared for bailouts. |
285 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 312 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
286 // NONOPT is generated by the full codegen and is not prepared for | 313 // NONOPT is generated by the full codegen and is not prepared for |
287 // recompilation/bailouts. These functions are never recompiled. | 314 // recompilation/bailouts. These functions are never recompiled. |
288 enum Mode { | 315 enum Mode { |
289 BASE, | 316 BASE, |
290 OPTIMIZE, | 317 OPTIMIZE, |
291 NONOPT, | 318 NONOPT, |
292 STUB | 319 STUB, |
| 320 DEPENDENT_MAP_ABORT |
293 }; | 321 }; |
294 | 322 |
295 void Initialize(Isolate* isolate, Mode mode, Zone* zone); | 323 void Initialize(Isolate* isolate, Mode mode, Zone* zone); |
296 | 324 |
297 void SetMode(Mode mode) { | 325 void SetMode(Mode mode) { |
298 ASSERT(V8::UseCrankshaft()); | 326 ASSERT(V8::UseCrankshaft()); |
299 mode_ = mode; | 327 mode_ = mode; |
300 } | 328 } |
301 | 329 |
302 // Flags using template class BitField<type, start, length>. All are | 330 // Flags using template class BitField<type, start, length>. All are |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Compilation mode flag and whether deoptimization is allowed. | 390 // Compilation mode flag and whether deoptimization is allowed. |
363 Mode mode_; | 391 Mode mode_; |
364 BailoutId osr_ast_id_; | 392 BailoutId osr_ast_id_; |
365 | 393 |
366 // The zone from which the compilation pipeline working on this | 394 // The zone from which the compilation pipeline working on this |
367 // CompilationInfo allocates. | 395 // CompilationInfo allocates. |
368 Zone* zone_; | 396 Zone* zone_; |
369 | 397 |
370 DeferredHandles* deferred_handles_; | 398 DeferredHandles* deferred_handles_; |
371 | 399 |
| 400 ZoneList<Handle<Map> >* dependent_maps_[DependentCode::kGroupCount]; |
| 401 |
372 template<typename T> | 402 template<typename T> |
373 void SaveHandle(Handle<T> *object) { | 403 void SaveHandle(Handle<T> *object) { |
374 if (!object->is_null()) { | 404 if (!object->is_null()) { |
375 Handle<T> handle(*(*object)); | 405 Handle<T> handle(*(*object)); |
376 *object = handle; | 406 *object = handle; |
377 } | 407 } |
378 } | 408 } |
379 | 409 |
380 const char* bailout_reason_; | 410 const char* bailout_reason_; |
381 | 411 |
382 int prologue_offset_; | 412 int prologue_offset_; |
383 | 413 |
384 List<OffsetRange>* no_frame_ranges_; | 414 List<OffsetRange>* no_frame_ranges_; |
385 | 415 |
386 // A copy of shared_info()->opt_count() to avoid handle deref | 416 // A copy of shared_info()->opt_count() to avoid handle deref |
387 // during graph optimization. | 417 // during graph optimization. |
388 int opt_count_; | 418 int opt_count_; |
389 | 419 |
| 420 Handle<Foreign> object_wrapper_; |
| 421 |
390 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 422 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
391 }; | 423 }; |
392 | 424 |
393 | 425 |
394 // Exactly like a CompilationInfo, except also creates and enters a | 426 // Exactly like a CompilationInfo, except also creates and enters a |
395 // Zone on construction and deallocates it on exit. | 427 // Zone on construction and deallocates it on exit. |
396 class CompilationInfoWithZone: public CompilationInfo { | 428 class CompilationInfoWithZone: public CompilationInfo { |
397 public: | 429 public: |
398 explicit CompilationInfoWithZone(Handle<Script> script) | 430 explicit CompilationInfoWithZone(Handle<Script> script) |
399 : CompilationInfo(script, &zone_), | 431 : CompilationInfo(script, &zone_), |
400 zone_(script->GetIsolate()), | 432 zone_(script->GetIsolate()), |
401 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 433 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
402 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | 434 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
403 : CompilationInfo(shared_info, &zone_), | 435 : CompilationInfo(shared_info, &zone_), |
404 zone_(shared_info->GetIsolate()), | 436 zone_(shared_info->GetIsolate()), |
405 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 437 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
406 explicit CompilationInfoWithZone(Handle<JSFunction> closure) | 438 explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
407 : CompilationInfo(closure, &zone_), | 439 : CompilationInfo(closure, &zone_), |
408 zone_(closure->GetIsolate()), | 440 zone_(closure->GetIsolate()), |
409 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 441 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
410 explicit CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) | 442 CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) |
411 : CompilationInfo(stub, isolate, &zone_), | 443 : CompilationInfo(stub, isolate, &zone_), |
412 zone_(isolate), | 444 zone_(isolate), |
413 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 445 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
414 | 446 |
| 447 // Virtual destructor because a CompilationInfoWithZone has to exit the |
| 448 // zone scope and get rid of dependent maps even when the destructor is |
| 449 // called when cast as a CompilationInfo. |
| 450 virtual ~CompilationInfoWithZone() { |
| 451 RollbackDependentMaps(); |
| 452 } |
| 453 |
415 private: | 454 private: |
416 Zone zone_; | 455 Zone zone_; |
417 ZoneScope zone_scope_; | 456 ZoneScope zone_scope_; |
418 }; | 457 }; |
419 | 458 |
420 | 459 |
421 // A wrapper around a CompilationInfo that detaches the Handles from | 460 // A wrapper around a CompilationInfo that detaches the Handles from |
422 // the underlying DeferredHandleScope and stores them in info_ on | 461 // the underlying DeferredHandleScope and stores them in info_ on |
423 // destruction. | 462 // destruction. |
424 class CompilationHandleScope BASE_EMBEDDED { | 463 class CompilationHandleScope BASE_EMBEDDED { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 613 |
575 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 614 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
576 CompilationInfo* info, | 615 CompilationInfo* info, |
577 Handle<SharedFunctionInfo> shared); | 616 Handle<SharedFunctionInfo> shared); |
578 }; | 617 }; |
579 | 618 |
580 | 619 |
581 } } // namespace v8::internal | 620 } } // namespace v8::internal |
582 | 621 |
583 #endif // V8_COMPILER_H_ | 622 #endif // V8_COMPILER_H_ |
OLD | NEW |