OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_H_ | 5 #ifndef V8_COMPILER_H_ |
6 #define V8_COMPILER_H_ | 6 #define V8_COMPILER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/bailout-reason.h" |
10 #include "src/zone.h" | 11 #include "src/zone.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 class AstValueFactory; | 16 class AstValueFactory; |
16 class HydrogenCodeStub; | 17 class HydrogenCodeStub; |
17 | 18 |
18 // ParseRestriction is used to restrict the set of valid statements in a | 19 // ParseRestriction is used to restrict the set of valid statements in a |
19 // unit of compilation. Restriction violations cause a syntax error. | 20 // unit of compilation. Restriction violations cause a syntax error. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 kSavesCallerDoubles = 1 << 8, | 76 kSavesCallerDoubles = 1 << 8, |
76 kRequiresFrame = 1 << 9, | 77 kRequiresFrame = 1 << 9, |
77 kMustNotHaveEagerFrame = 1 << 10, | 78 kMustNotHaveEagerFrame = 1 << 10, |
78 kDeoptimizationSupport = 1 << 11, | 79 kDeoptimizationSupport = 1 << 11, |
79 kDebug = 1 << 12, | 80 kDebug = 1 << 12, |
80 kCompilingForDebugging = 1 << 13, | 81 kCompilingForDebugging = 1 << 13, |
81 kParseRestriction = 1 << 14, | 82 kParseRestriction = 1 << 14, |
82 kSerializing = 1 << 15, | 83 kSerializing = 1 << 15, |
83 kContextSpecializing = 1 << 16, | 84 kContextSpecializing = 1 << 16, |
84 kInliningEnabled = 1 << 17, | 85 kInliningEnabled = 1 << 17, |
85 kTypingEnabled = 1 << 18 | 86 kTypingEnabled = 1 << 18, |
| 87 kDisableFutureOptimization = 1 << 19, |
| 88 kAbortedDueToDependency = 1 << 20 |
86 }; | 89 }; |
87 | 90 |
88 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 91 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
89 CompilationInfo(Isolate* isolate, Zone* zone); | 92 CompilationInfo(Isolate* isolate, Zone* zone); |
90 virtual ~CompilationInfo(); | 93 virtual ~CompilationInfo(); |
91 | 94 |
92 Isolate* isolate() const { | 95 Isolate* isolate() const { |
93 return isolate_; | 96 return isolate_; |
94 } | 97 } |
95 Zone* zone() { return zone_; } | 98 Zone* zone() { return zone_; } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 void RollbackDependencies(); | 315 void RollbackDependencies(); |
313 | 316 |
314 void SaveHandles() { | 317 void SaveHandles() { |
315 SaveHandle(&closure_); | 318 SaveHandle(&closure_); |
316 SaveHandle(&shared_info_); | 319 SaveHandle(&shared_info_); |
317 SaveHandle(&context_); | 320 SaveHandle(&context_); |
318 SaveHandle(&script_); | 321 SaveHandle(&script_); |
319 SaveHandle(&unoptimized_code_); | 322 SaveHandle(&unoptimized_code_); |
320 } | 323 } |
321 | 324 |
| 325 void AbortOptimization(BailoutReason reason) { |
| 326 if (bailout_reason_ != kNoReason) bailout_reason_ = reason; |
| 327 SetFlag(kDisableFutureOptimization); |
| 328 } |
| 329 |
| 330 void RetryOptimization(BailoutReason reason) { |
| 331 if (bailout_reason_ != kNoReason) bailout_reason_ = reason; |
| 332 } |
| 333 |
322 BailoutReason bailout_reason() const { return bailout_reason_; } | 334 BailoutReason bailout_reason() const { return bailout_reason_; } |
323 void set_bailout_reason(BailoutReason reason) { bailout_reason_ = reason; } | |
324 | 335 |
325 int prologue_offset() const { | 336 int prologue_offset() const { |
326 DCHECK_NE(Code::kPrologueOffsetNotSet, prologue_offset_); | 337 DCHECK_NE(Code::kPrologueOffsetNotSet, prologue_offset_); |
327 return prologue_offset_; | 338 return prologue_offset_; |
328 } | 339 } |
329 | 340 |
330 void set_prologue_offset(int prologue_offset) { | 341 void set_prologue_offset(int prologue_offset) { |
331 DCHECK_EQ(Code::kPrologueOffsetNotSet, prologue_offset_); | 342 DCHECK_EQ(Code::kPrologueOffsetNotSet, prologue_offset_); |
332 prologue_offset_ = prologue_offset; | 343 prologue_offset_ = prologue_offset; |
333 } | 344 } |
(...skipping 14 matching lines...) Expand all Loading... |
348 Handle<Foreign> object_wrapper() { | 359 Handle<Foreign> object_wrapper() { |
349 if (object_wrapper_.is_null()) { | 360 if (object_wrapper_.is_null()) { |
350 object_wrapper_ = | 361 object_wrapper_ = |
351 isolate()->factory()->NewForeign(reinterpret_cast<Address>(this)); | 362 isolate()->factory()->NewForeign(reinterpret_cast<Address>(this)); |
352 } | 363 } |
353 return object_wrapper_; | 364 return object_wrapper_; |
354 } | 365 } |
355 | 366 |
356 void AbortDueToDependencyChange() { | 367 void AbortDueToDependencyChange() { |
357 DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate())); | 368 DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate())); |
358 abort_due_to_dependency_ = true; | 369 SetFlag(kAbortedDueToDependency); |
359 } | 370 } |
360 | 371 |
361 bool HasAbortedDueToDependencyChange() { | 372 bool HasAbortedDueToDependencyChange() const { |
362 DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate())); | 373 DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate())); |
363 return abort_due_to_dependency_; | 374 return GetFlag(kAbortedDueToDependency); |
364 } | 375 } |
365 | 376 |
366 bool HasSameOsrEntry(Handle<JSFunction> function, BailoutId osr_ast_id) { | 377 bool HasSameOsrEntry(Handle<JSFunction> function, BailoutId osr_ast_id) { |
367 return osr_ast_id_ == osr_ast_id && function.is_identical_to(closure_); | 378 return osr_ast_id_ == osr_ast_id && function.is_identical_to(closure_); |
368 } | 379 } |
369 | 380 |
370 int optimization_id() const { return optimization_id_; } | 381 int optimization_id() const { return optimization_id_; } |
371 | 382 |
372 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 383 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
373 void SetAstValueFactory(AstValueFactory* ast_value_factory, | 384 void SetAstValueFactory(AstValueFactory* ast_value_factory, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 Handle<TypeFeedbackVector> feedback_vector_; | 466 Handle<TypeFeedbackVector> feedback_vector_; |
456 | 467 |
457 // Compilation mode flag and whether deoptimization is allowed. | 468 // Compilation mode flag and whether deoptimization is allowed. |
458 Mode mode_; | 469 Mode mode_; |
459 BailoutId osr_ast_id_; | 470 BailoutId osr_ast_id_; |
460 // The unoptimized code we patched for OSR may not be the shared code | 471 // The unoptimized code we patched for OSR may not be the shared code |
461 // afterwards, since we may need to compile it again to include deoptimization | 472 // afterwards, since we may need to compile it again to include deoptimization |
462 // data. Keep track which code we patched. | 473 // data. Keep track which code we patched. |
463 Handle<Code> unoptimized_code_; | 474 Handle<Code> unoptimized_code_; |
464 | 475 |
465 // Flag whether compilation needs to be aborted due to dependency change. | |
466 bool abort_due_to_dependency_; | |
467 | |
468 // The zone from which the compilation pipeline working on this | 476 // The zone from which the compilation pipeline working on this |
469 // CompilationInfo allocates. | 477 // CompilationInfo allocates. |
470 Zone* zone_; | 478 Zone* zone_; |
471 | 479 |
472 DeferredHandles* deferred_handles_; | 480 DeferredHandles* deferred_handles_; |
473 | 481 |
474 ZoneList<Handle<HeapObject> >* dependencies_[DependentCode::kGroupCount]; | 482 ZoneList<Handle<HeapObject> >* dependencies_[DependentCode::kGroupCount]; |
475 | 483 |
476 template<typename T> | 484 template<typename T> |
477 void SaveHandle(Handle<T> *object) { | 485 void SaveHandle(Handle<T> *object) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 }; | 589 }; |
582 | 590 |
583 MUST_USE_RESULT Status CreateGraph(); | 591 MUST_USE_RESULT Status CreateGraph(); |
584 MUST_USE_RESULT Status OptimizeGraph(); | 592 MUST_USE_RESULT Status OptimizeGraph(); |
585 MUST_USE_RESULT Status GenerateCode(); | 593 MUST_USE_RESULT Status GenerateCode(); |
586 | 594 |
587 Status last_status() const { return last_status_; } | 595 Status last_status() const { return last_status_; } |
588 CompilationInfo* info() const { return info_; } | 596 CompilationInfo* info() const { return info_; } |
589 Isolate* isolate() const { return info()->isolate(); } | 597 Isolate* isolate() const { return info()->isolate(); } |
590 | 598 |
591 MUST_USE_RESULT Status AbortOptimization( | 599 Status RetryOptimization(BailoutReason reason) { |
592 BailoutReason reason = kNoReason) { | 600 info_->RetryOptimization(reason); |
593 if (reason != kNoReason) info_->set_bailout_reason(reason); | |
594 return SetLastStatus(BAILED_OUT); | 601 return SetLastStatus(BAILED_OUT); |
595 } | 602 } |
596 | 603 |
597 MUST_USE_RESULT Status AbortAndDisableOptimization( | 604 Status AbortOptimization(BailoutReason reason) { |
598 BailoutReason reason = kNoReason) { | 605 info_->AbortOptimization(reason); |
599 if (reason != kNoReason) info_->set_bailout_reason(reason); | |
600 // Reference to shared function info does not change between phases. | |
601 AllowDeferredHandleDereference allow_handle_dereference; | |
602 info_->shared_info()->DisableOptimization(info_->bailout_reason()); | |
603 return SetLastStatus(BAILED_OUT); | 606 return SetLastStatus(BAILED_OUT); |
604 } | 607 } |
605 | 608 |
606 void WaitForInstall() { | 609 void WaitForInstall() { |
607 DCHECK(info_->is_osr()); | 610 DCHECK(info_->is_osr()); |
608 awaiting_install_ = true; | 611 awaiting_install_ = true; |
609 } | 612 } |
610 | 613 |
611 bool IsWaitingForInstall() { return awaiting_install_; } | 614 bool IsWaitingForInstall() { return awaiting_install_; } |
612 | 615 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 Zone zone_; | 740 Zone zone_; |
738 unsigned info_zone_start_allocation_size_; | 741 unsigned info_zone_start_allocation_size_; |
739 base::ElapsedTimer timer_; | 742 base::ElapsedTimer timer_; |
740 | 743 |
741 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); | 744 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); |
742 }; | 745 }; |
743 | 746 |
744 } } // namespace v8::internal | 747 } } // namespace v8::internal |
745 | 748 |
746 #endif // V8_COMPILER_H_ | 749 #endif // V8_COMPILER_H_ |
OLD | NEW |