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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
11 #include "src/bailout-reason.h" | 11 #include "src/bailout-reason.h" |
12 #include "src/compilation-dependencies.h" | 12 #include "src/compilation-dependencies.h" |
13 #include "src/contexts.h" | 13 #include "src/contexts.h" |
14 #include "src/frames.h" | 14 #include "src/frames.h" |
15 #include "src/isolate.h" | 15 #include "src/isolate.h" |
16 #include "src/objects-inl.h" | |
17 #include "src/source-position-table.h" | 16 #include "src/source-position-table.h" |
18 #include "src/source-position.h" | 17 #include "src/source-position.h" |
19 #include "src/zone.h" | 18 #include "src/zone.h" |
20 | 19 |
21 namespace v8 { | 20 namespace v8 { |
22 namespace internal { | 21 namespace internal { |
23 | 22 |
24 // Forward declarations. | 23 // Forward declarations. |
25 class CompilationInfo; | 24 class CompilationInfo; |
26 class CompilationJob; | 25 class CompilationJob; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 329 |
331 void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) { | 330 void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) { |
332 bytecode_array_ = bytecode_array; | 331 bytecode_array_ = bytecode_array; |
333 } | 332 } |
334 | 333 |
335 bool ShouldTrapOnDeopt() const { | 334 bool ShouldTrapOnDeopt() const { |
336 return (FLAG_trap_on_deopt && IsOptimizing()) || | 335 return (FLAG_trap_on_deopt && IsOptimizing()) || |
337 (FLAG_trap_on_stub_deopt && IsStub()); | 336 (FLAG_trap_on_stub_deopt && IsStub()); |
338 } | 337 } |
339 | 338 |
340 bool has_native_context() const { | 339 bool has_native_context() const; |
341 return !closure().is_null() && (closure()->native_context() != nullptr); | 340 Context* native_context() const; |
342 } | |
343 | 341 |
344 Context* native_context() const { | 342 bool has_global_object() const; |
345 return has_native_context() ? closure()->native_context() : nullptr; | 343 JSGlobalObject* global_object() const; |
346 } | |
347 | |
348 bool has_global_object() const { return has_native_context(); } | |
349 | |
350 JSGlobalObject* global_object() const { | |
351 return has_global_object() ? native_context()->global_object() : nullptr; | |
352 } | |
353 | 344 |
354 // Accessors for the different compilation modes. | 345 // Accessors for the different compilation modes. |
355 bool IsOptimizing() const { return mode_ == OPTIMIZE; } | 346 bool IsOptimizing() const { return mode_ == OPTIMIZE; } |
356 bool IsStub() const { return mode_ == STUB; } | 347 bool IsStub() const { return mode_ == STUB; } |
357 void SetOptimizing() { | 348 void SetOptimizing() { |
358 DCHECK(has_shared_info()); | 349 DCHECK(has_shared_info()); |
359 SetMode(OPTIMIZE); | 350 SetMode(OPTIMIZE); |
360 optimization_id_ = isolate()->NextOptimizationId(); | 351 optimization_id_ = isolate()->NextOptimizationId(); |
361 code_flags_ = | 352 code_flags_ = |
362 Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); | 353 Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); |
(...skipping 17 matching lines...) Expand all Loading... |
380 bool ExpectsJSReceiverAsReceiver(); | 371 bool ExpectsJSReceiverAsReceiver(); |
381 | 372 |
382 // Determines whether or not to insert a self-optimization header. | 373 // Determines whether or not to insert a self-optimization header. |
383 bool ShouldSelfOptimize(); | 374 bool ShouldSelfOptimize(); |
384 | 375 |
385 void set_deferred_handles(DeferredHandles* deferred_handles) { | 376 void set_deferred_handles(DeferredHandles* deferred_handles) { |
386 DCHECK(deferred_handles_ == NULL); | 377 DCHECK(deferred_handles_ == NULL); |
387 deferred_handles_ = deferred_handles; | 378 deferred_handles_ = deferred_handles; |
388 } | 379 } |
389 | 380 |
390 void ReopenHandlesInNewHandleScope() { | 381 void ReopenHandlesInNewHandleScope(); |
391 closure_ = Handle<JSFunction>(*closure_); | |
392 } | |
393 | 382 |
394 void AbortOptimization(BailoutReason reason) { | 383 void AbortOptimization(BailoutReason reason) { |
395 DCHECK(reason != kNoReason); | 384 DCHECK(reason != kNoReason); |
396 if (bailout_reason_ == kNoReason) bailout_reason_ = reason; | 385 if (bailout_reason_ == kNoReason) bailout_reason_ = reason; |
397 SetFlag(kDisableFutureOptimization); | 386 SetFlag(kDisableFutureOptimization); |
398 } | 387 } |
399 | 388 |
400 void RetryOptimization(BailoutReason reason) { | 389 void RetryOptimization(BailoutReason reason) { |
401 DCHECK(reason != kNoReason); | 390 DCHECK(reason != kNoReason); |
402 if (GetFlag(kDisableFutureOptimization)) return; | 391 if (GetFlag(kDisableFutureOptimization)) return; |
(...skipping 25 matching lines...) Expand all Loading... |
428 bool has_simple_parameters(); | 417 bool has_simple_parameters(); |
429 | 418 |
430 struct InlinedFunctionHolder { | 419 struct InlinedFunctionHolder { |
431 Handle<SharedFunctionInfo> shared_info; | 420 Handle<SharedFunctionInfo> shared_info; |
432 | 421 |
433 // Root that holds the unoptimized code of the inlined function alive | 422 // Root that holds the unoptimized code of the inlined function alive |
434 // (and out of reach of code flushing) until we finish compilation. | 423 // (and out of reach of code flushing) until we finish compilation. |
435 // Do not remove. | 424 // Do not remove. |
436 Handle<Code> inlined_code_object_root; | 425 Handle<Code> inlined_code_object_root; |
437 | 426 |
438 explicit InlinedFunctionHolder( | 427 InlinedFunctionHolder(Handle<SharedFunctionInfo> inlined_shared_info, |
439 Handle<SharedFunctionInfo> inlined_shared_info) | 428 Handle<Code> inlined_code_object_root) |
440 : shared_info(inlined_shared_info), | 429 : shared_info(inlined_shared_info), |
441 inlined_code_object_root(inlined_shared_info->code()) {} | 430 inlined_code_object_root(inlined_code_object_root) {} |
442 }; | 431 }; |
443 | 432 |
444 typedef std::vector<InlinedFunctionHolder> InlinedFunctionList; | 433 typedef std::vector<InlinedFunctionHolder> InlinedFunctionList; |
445 InlinedFunctionList const& inlined_functions() const { | 434 InlinedFunctionList const& inlined_functions() const { |
446 return inlined_functions_; | 435 return inlined_functions_; |
447 } | 436 } |
448 | 437 |
449 void AddInlinedFunction(Handle<SharedFunctionInfo> inlined_function) { | 438 void AddInlinedFunction(Handle<SharedFunctionInfo> inlined_function); |
450 inlined_functions_.push_back(InlinedFunctionHolder(inlined_function)); | |
451 } | |
452 | 439 |
453 std::unique_ptr<char[]> GetDebugName() const; | 440 std::unique_ptr<char[]> GetDebugName() const; |
454 | 441 |
455 Code::Kind output_code_kind() const { | 442 Code::Kind output_code_kind() const; |
456 return Code::ExtractKindFromFlags(code_flags_); | |
457 } | |
458 | 443 |
459 StackFrame::Type GetOutputStackFrameType() const; | 444 StackFrame::Type GetOutputStackFrameType() const; |
460 | 445 |
461 int GetDeclareGlobalsFlags() const; | 446 int GetDeclareGlobalsFlags() const; |
462 | 447 |
463 SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const; | 448 SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const; |
464 | 449 |
465 private: | 450 private: |
466 // Compilation mode. | 451 // Compilation mode. |
467 // BASE is generated by the full codegen, optionally prepared for bailouts. | 452 // BASE is generated by the full codegen, optionally prepared for bailouts. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 state_ = State::kFailed; | 621 state_ = State::kFailed; |
637 } | 622 } |
638 return status; | 623 return status; |
639 } | 624 } |
640 }; | 625 }; |
641 | 626 |
642 } // namespace internal | 627 } // namespace internal |
643 } // namespace v8 | 628 } // namespace v8 |
644 | 629 |
645 #endif // V8_COMPILER_H_ | 630 #endif // V8_COMPILER_H_ |
OLD | NEW |