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/zone.h" | 10 #include "src/zone.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 StrictMode strict_mode() const { | 100 StrictMode strict_mode() const { |
101 return GetFlag(kStrictMode) ? STRICT : SLOPPY; | 101 return GetFlag(kStrictMode) ? STRICT : SLOPPY; |
102 } | 102 } |
103 FunctionLiteral* function() const { return function_; } | 103 FunctionLiteral* function() const { return function_; } |
104 Scope* scope() const { return scope_; } | 104 Scope* scope() const { return scope_; } |
105 Scope* global_scope() const { return global_scope_; } | 105 Scope* global_scope() const { return global_scope_; } |
106 Handle<Code> code() const { return code_; } | 106 Handle<Code> code() const { return code_; } |
107 Handle<JSFunction> closure() const { return closure_; } | 107 Handle<JSFunction> closure() const { return closure_; } |
108 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 108 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
109 Handle<Script> script() const { return script_; } | 109 Handle<Script> script() const { return script_; } |
110 void set_script(Handle<Script> script) { script_ = script; } | |
111 HydrogenCodeStub* code_stub() const {return code_stub_; } | 110 HydrogenCodeStub* code_stub() const {return code_stub_; } |
112 v8::Extension* extension() const { return extension_; } | 111 v8::Extension* extension() const { return extension_; } |
113 ScriptData** cached_data() const { return cached_data_; } | 112 ScriptData** cached_data() const { return cached_data_; } |
114 ScriptCompiler::CompileOptions compile_options() const { | 113 ScriptCompiler::CompileOptions compile_options() const { |
115 return compile_options_; | 114 return compile_options_; |
116 } | 115 } |
117 ScriptCompiler::ExternalSourceStream* source_stream() const { | |
118 return source_stream_; | |
119 } | |
120 ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const { | |
121 return source_stream_encoding_; | |
122 } | |
123 Handle<Context> context() const { return context_; } | 116 Handle<Context> context() const { return context_; } |
124 BailoutId osr_ast_id() const { return osr_ast_id_; } | 117 BailoutId osr_ast_id() const { return osr_ast_id_; } |
125 Handle<Code> unoptimized_code() const { return unoptimized_code_; } | 118 Handle<Code> unoptimized_code() const { return unoptimized_code_; } |
126 int opt_count() const { return opt_count_; } | 119 int opt_count() const { return opt_count_; } |
127 int num_parameters() const; | 120 int num_parameters() const; |
128 int num_heap_slots() const; | 121 int num_heap_slots() const; |
129 Code::Flags flags() const; | 122 Code::Flags flags() const; |
130 | 123 |
131 void MarkAsEval() { | 124 void MarkAsEval() { |
132 DCHECK(!is_lazy()); | 125 DCHECK(!is_lazy()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 AstNode::IdGen* ast_node_id_gen() { return &ast_node_id_gen_; } | 371 AstNode::IdGen* ast_node_id_gen() { return &ast_node_id_gen_; } |
379 | 372 |
380 protected: | 373 protected: |
381 CompilationInfo(Handle<Script> script, | 374 CompilationInfo(Handle<Script> script, |
382 Zone* zone); | 375 Zone* zone); |
383 CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 376 CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
384 Zone* zone); | 377 Zone* zone); |
385 CompilationInfo(HydrogenCodeStub* stub, | 378 CompilationInfo(HydrogenCodeStub* stub, |
386 Isolate* isolate, | 379 Isolate* isolate, |
387 Zone* zone); | 380 Zone* zone); |
388 CompilationInfo(ScriptCompiler::ExternalSourceStream* source_stream, | |
389 ScriptCompiler::StreamedSource::Encoding encoding, | |
390 Isolate* isolate, Zone* zone); | |
391 | |
392 | 381 |
393 private: | 382 private: |
394 Isolate* isolate_; | 383 Isolate* isolate_; |
395 | 384 |
396 // Compilation mode. | 385 // Compilation mode. |
397 // BASE is generated by the full codegen, optionally prepared for bailouts. | 386 // BASE is generated by the full codegen, optionally prepared for bailouts. |
398 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 387 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
399 // NONOPT is generated by the full codegen and is not prepared for | 388 // NONOPT is generated by the full codegen and is not prepared for |
400 // recompilation/bailouts. These functions are never recompiled. | 389 // recompilation/bailouts. These functions are never recompiled. |
401 enum Mode { | 390 enum Mode { |
(...skipping 29 matching lines...) Expand all Loading... |
431 Scope* global_scope_; | 420 Scope* global_scope_; |
432 // For compiled stubs, the stub object | 421 // For compiled stubs, the stub object |
433 HydrogenCodeStub* code_stub_; | 422 HydrogenCodeStub* code_stub_; |
434 // The compiled code. | 423 // The compiled code. |
435 Handle<Code> code_; | 424 Handle<Code> code_; |
436 | 425 |
437 // Possible initial inputs to the compilation process. | 426 // Possible initial inputs to the compilation process. |
438 Handle<JSFunction> closure_; | 427 Handle<JSFunction> closure_; |
439 Handle<SharedFunctionInfo> shared_info_; | 428 Handle<SharedFunctionInfo> shared_info_; |
440 Handle<Script> script_; | 429 Handle<Script> script_; |
441 ScriptCompiler::ExternalSourceStream* source_stream_; // Not owned. | |
442 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; | |
443 | 430 |
444 // Fields possibly needed for eager compilation, NULL by default. | 431 // Fields possibly needed for eager compilation, NULL by default. |
445 v8::Extension* extension_; | 432 v8::Extension* extension_; |
446 ScriptData** cached_data_; | 433 ScriptData** cached_data_; |
447 ScriptCompiler::CompileOptions compile_options_; | 434 ScriptCompiler::CompileOptions compile_options_; |
448 | 435 |
449 // The context of the caller for eval code, and the global context for a | 436 // The context of the caller for eval code, and the global context for a |
450 // global script. Will be a null handle otherwise. | 437 // global script. Will be a null handle otherwise. |
451 Handle<Context> context_; | 438 Handle<Context> context_; |
452 | 439 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 zone_(script->GetIsolate()) {} | 501 zone_(script->GetIsolate()) {} |
515 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | 502 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
516 : CompilationInfo(shared_info, &zone_), | 503 : CompilationInfo(shared_info, &zone_), |
517 zone_(shared_info->GetIsolate()) {} | 504 zone_(shared_info->GetIsolate()) {} |
518 explicit CompilationInfoWithZone(Handle<JSFunction> closure) | 505 explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
519 : CompilationInfo(closure, &zone_), | 506 : CompilationInfo(closure, &zone_), |
520 zone_(closure->GetIsolate()) {} | 507 zone_(closure->GetIsolate()) {} |
521 CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) | 508 CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) |
522 : CompilationInfo(stub, isolate, &zone_), | 509 : CompilationInfo(stub, isolate, &zone_), |
523 zone_(isolate) {} | 510 zone_(isolate) {} |
524 CompilationInfoWithZone(ScriptCompiler::ExternalSourceStream* stream, | |
525 ScriptCompiler::StreamedSource::Encoding encoding, | |
526 Isolate* isolate) | |
527 : CompilationInfo(stream, encoding, isolate, &zone_), zone_(isolate) {} | |
528 | 511 |
529 // Virtual destructor because a CompilationInfoWithZone has to exit the | 512 // Virtual destructor because a CompilationInfoWithZone has to exit the |
530 // zone scope and get rid of dependent maps even when the destructor is | 513 // zone scope and get rid of dependent maps even when the destructor is |
531 // called when cast as a CompilationInfo. | 514 // called when cast as a CompilationInfo. |
532 virtual ~CompilationInfoWithZone() { | 515 virtual ~CompilationInfoWithZone() { |
533 RollbackDependencies(); | 516 RollbackDependencies(); |
534 } | 517 } |
535 | 518 |
536 private: | 519 private: |
537 Zone zone_; | 520 Zone zone_; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 int scope_position); | 660 int scope_position); |
678 | 661 |
679 // Compile a String source within a context. | 662 // Compile a String source within a context. |
680 static Handle<SharedFunctionInfo> CompileScript( | 663 static Handle<SharedFunctionInfo> CompileScript( |
681 Handle<String> source, Handle<Object> script_name, int line_offset, | 664 Handle<String> source, Handle<Object> script_name, int line_offset, |
682 int column_offset, bool is_shared_cross_origin, Handle<Context> context, | 665 int column_offset, bool is_shared_cross_origin, Handle<Context> context, |
683 v8::Extension* extension, ScriptData** cached_data, | 666 v8::Extension* extension, ScriptData** cached_data, |
684 ScriptCompiler::CompileOptions compile_options, | 667 ScriptCompiler::CompileOptions compile_options, |
685 NativesFlag is_natives_code); | 668 NativesFlag is_natives_code); |
686 | 669 |
687 static Handle<SharedFunctionInfo> CompileStreamedScript(CompilationInfo* info, | |
688 int source_length); | |
689 | |
690 // Create a shared function info object (the code may be lazily compiled). | 670 // Create a shared function info object (the code may be lazily compiled). |
691 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 671 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
692 Handle<Script> script, | 672 Handle<Script> script, |
693 CompilationInfo* outer); | 673 CompilationInfo* outer); |
694 | 674 |
695 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 675 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
696 | 676 |
697 // Generate and return optimized code or start a concurrent optimization job. | 677 // Generate and return optimized code or start a concurrent optimization job. |
698 // In the latter case, return the InOptimizationQueue builtin. On failure, | 678 // In the latter case, return the InOptimizationQueue builtin. On failure, |
699 // return the empty handle. | 679 // return the empty handle. |
700 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( | 680 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( |
701 Handle<JSFunction> function, | 681 Handle<JSFunction> function, |
702 Handle<Code> current_code, | 682 Handle<Code> current_code, |
703 ConcurrencyMode mode, | 683 ConcurrencyMode mode, |
704 BailoutId osr_ast_id = BailoutId::None()); | 684 BailoutId osr_ast_id = BailoutId::None()); |
705 | 685 |
706 // Generate and return code from previously queued optimization job. | 686 // Generate and return code from previously queued optimization job. |
707 // On failure, return the empty handle. | 687 // On failure, return the empty handle. |
708 static Handle<Code> GetConcurrentlyOptimizedCode(OptimizedCompileJob* job); | 688 static Handle<Code> GetConcurrentlyOptimizedCode(OptimizedCompileJob* job); |
709 | 689 |
710 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 690 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
711 CompilationInfo* info, | 691 CompilationInfo* info, |
712 Handle<SharedFunctionInfo> shared); | 692 Handle<SharedFunctionInfo> shared); |
713 | |
714 static bool DebuggerWantsEagerCompilation( | |
715 CompilationInfo* info, bool allow_lazy_without_ctx = false); | |
716 }; | 693 }; |
717 | 694 |
718 | 695 |
719 class CompilationPhase BASE_EMBEDDED { | 696 class CompilationPhase BASE_EMBEDDED { |
720 public: | 697 public: |
721 CompilationPhase(const char* name, CompilationInfo* info); | 698 CompilationPhase(const char* name, CompilationInfo* info); |
722 ~CompilationPhase(); | 699 ~CompilationPhase(); |
723 | 700 |
724 protected: | 701 protected: |
725 bool ShouldProduceTraceOutput() const; | 702 bool ShouldProduceTraceOutput() const; |
726 | 703 |
727 const char* name() const { return name_; } | 704 const char* name() const { return name_; } |
728 CompilationInfo* info() const { return info_; } | 705 CompilationInfo* info() const { return info_; } |
729 Isolate* isolate() const { return info()->isolate(); } | 706 Isolate* isolate() const { return info()->isolate(); } |
730 Zone* zone() { return &zone_; } | 707 Zone* zone() { return &zone_; } |
731 | 708 |
732 private: | 709 private: |
733 const char* name_; | 710 const char* name_; |
734 CompilationInfo* info_; | 711 CompilationInfo* info_; |
735 Zone zone_; | 712 Zone zone_; |
736 unsigned info_zone_start_allocation_size_; | 713 unsigned info_zone_start_allocation_size_; |
737 base::ElapsedTimer timer_; | 714 base::ElapsedTimer timer_; |
738 | 715 |
739 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); | 716 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); |
740 }; | 717 }; |
741 | 718 |
742 } } // namespace v8::internal | 719 } } // namespace v8::internal |
743 | 720 |
744 #endif // V8_COMPILER_H_ | 721 #endif // V8_COMPILER_H_ |
OLD | NEW |