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 class HydrogenCodeStub; | 39 class HydrogenCodeStub; |
40 | 40 |
41 // ParseRestriction is used to restrict the set of valid statements in a | 41 // ParseRestriction is used to restrict the set of valid statements in a |
42 // unit of compilation. Restriction violations cause a syntax error. | 42 // unit of compilation. Restriction violations cause a syntax error. |
43 enum ParseRestriction { | 43 enum ParseRestriction { |
44 NO_PARSE_RESTRICTION, // All expressions are allowed. | 44 NO_PARSE_RESTRICTION, // All expressions are allowed. |
45 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. | 45 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. |
46 }; | 46 }; |
47 | 47 |
| 48 enum CachedDataMode { |
| 49 NO_CACHED_DATA, |
| 50 CONSUME_CACHED_DATA, |
| 51 PRODUCE_CACHED_DATA |
| 52 }; |
| 53 |
48 struct OffsetRange { | 54 struct OffsetRange { |
49 OffsetRange(int from, int to) : from(from), to(to) {} | 55 OffsetRange(int from, int to) : from(from), to(to) {} |
50 int from; | 56 int from; |
51 int to; | 57 int to; |
52 }; | 58 }; |
53 | 59 |
54 // CompilationInfo encapsulates some information known at compile time. It | 60 // CompilationInfo encapsulates some information known at compile time. It |
55 // is constructed based on the resources available at compile-time. | 61 // is constructed based on the resources available at compile-time. |
56 class CompilationInfo { | 62 class CompilationInfo { |
57 public: | 63 public: |
(...skipping 12 matching lines...) Expand all Loading... |
70 bool is_in_loop() const { return IsInLoop::decode(flags_); } | 76 bool is_in_loop() const { return IsInLoop::decode(flags_); } |
71 FunctionLiteral* function() const { return function_; } | 77 FunctionLiteral* function() const { return function_; } |
72 Scope* scope() const { return scope_; } | 78 Scope* scope() const { return scope_; } |
73 Scope* global_scope() const { return global_scope_; } | 79 Scope* global_scope() const { return global_scope_; } |
74 Handle<Code> code() const { return code_; } | 80 Handle<Code> code() const { return code_; } |
75 Handle<JSFunction> closure() const { return closure_; } | 81 Handle<JSFunction> closure() const { return closure_; } |
76 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 82 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
77 Handle<Script> script() const { return script_; } | 83 Handle<Script> script() const { return script_; } |
78 HydrogenCodeStub* code_stub() const {return code_stub_; } | 84 HydrogenCodeStub* code_stub() const {return code_stub_; } |
79 v8::Extension* extension() const { return extension_; } | 85 v8::Extension* extension() const { return extension_; } |
80 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 86 ScriptDataImpl** cached_data() const { return cached_data_; } |
| 87 CachedDataMode cached_data_mode() const { |
| 88 return cached_data_mode_; |
| 89 } |
81 Handle<Context> context() const { return context_; } | 90 Handle<Context> context() const { return context_; } |
82 BailoutId osr_ast_id() const { return osr_ast_id_; } | 91 BailoutId osr_ast_id() const { return osr_ast_id_; } |
83 Handle<Code> unoptimized_code() const { return unoptimized_code_; } | 92 Handle<Code> unoptimized_code() const { return unoptimized_code_; } |
84 int opt_count() const { return opt_count_; } | 93 int opt_count() const { return opt_count_; } |
85 int num_parameters() const; | 94 int num_parameters() const; |
86 int num_heap_slots() const; | 95 int num_heap_slots() const; |
87 Code::Flags flags() const; | 96 Code::Flags flags() const; |
88 | 97 |
89 void MarkAsEval() { | 98 void MarkAsEval() { |
90 ASSERT(!is_lazy()); | 99 ASSERT(!is_lazy()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void PrepareForCompilation(Scope* scope); | 182 void PrepareForCompilation(Scope* scope); |
174 void SetGlobalScope(Scope* global_scope) { | 183 void SetGlobalScope(Scope* global_scope) { |
175 ASSERT(global_scope_ == NULL); | 184 ASSERT(global_scope_ == NULL); |
176 global_scope_ = global_scope; | 185 global_scope_ = global_scope; |
177 } | 186 } |
178 void SetCode(Handle<Code> code) { code_ = code; } | 187 void SetCode(Handle<Code> code) { code_ = code; } |
179 void SetExtension(v8::Extension* extension) { | 188 void SetExtension(v8::Extension* extension) { |
180 ASSERT(!is_lazy()); | 189 ASSERT(!is_lazy()); |
181 extension_ = extension; | 190 extension_ = extension; |
182 } | 191 } |
183 void SetPreParseData(ScriptDataImpl* pre_parse_data) { | 192 void SetCachedData(ScriptDataImpl** cached_data, |
184 ASSERT(!is_lazy()); | 193 CachedDataMode cached_data_mode) { |
185 pre_parse_data_ = pre_parse_data; | 194 cached_data_mode_ = cached_data_mode; |
| 195 if (cached_data_mode == NO_CACHED_DATA) { |
| 196 cached_data_ = NULL; |
| 197 } else { |
| 198 ASSERT(!is_lazy()); |
| 199 cached_data_ = cached_data; |
| 200 } |
186 } | 201 } |
187 void SetContext(Handle<Context> context) { | 202 void SetContext(Handle<Context> context) { |
188 context_ = context; | 203 context_ = context; |
189 } | 204 } |
190 | 205 |
191 void MarkCompilingForDebugging() { | 206 void MarkCompilingForDebugging() { |
192 flags_ |= IsCompilingForDebugging::encode(true); | 207 flags_ |= IsCompilingForDebugging::encode(true); |
193 } | 208 } |
194 bool IsCompilingForDebugging() { | 209 bool IsCompilingForDebugging() { |
195 return IsCompilingForDebugging::decode(flags_); | 210 return IsCompilingForDebugging::decode(flags_); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // The compiled code. | 405 // The compiled code. |
391 Handle<Code> code_; | 406 Handle<Code> code_; |
392 | 407 |
393 // Possible initial inputs to the compilation process. | 408 // Possible initial inputs to the compilation process. |
394 Handle<JSFunction> closure_; | 409 Handle<JSFunction> closure_; |
395 Handle<SharedFunctionInfo> shared_info_; | 410 Handle<SharedFunctionInfo> shared_info_; |
396 Handle<Script> script_; | 411 Handle<Script> script_; |
397 | 412 |
398 // Fields possibly needed for eager compilation, NULL by default. | 413 // Fields possibly needed for eager compilation, NULL by default. |
399 v8::Extension* extension_; | 414 v8::Extension* extension_; |
400 ScriptDataImpl* pre_parse_data_; | 415 ScriptDataImpl** cached_data_; |
| 416 CachedDataMode cached_data_mode_; |
401 | 417 |
402 // The context of the caller for eval code, and the global context for a | 418 // The context of the caller for eval code, and the global context for a |
403 // global script. Will be a null handle otherwise. | 419 // global script. Will be a null handle otherwise. |
404 Handle<Context> context_; | 420 Handle<Context> context_; |
405 | 421 |
406 // Compilation mode flag and whether deoptimization is allowed. | 422 // Compilation mode flag and whether deoptimization is allowed. |
407 Mode mode_; | 423 Mode mode_; |
408 BailoutId osr_ast_id_; | 424 BailoutId osr_ast_id_; |
409 // The unoptimized code we patched for OSR may not be the shared code | 425 // The unoptimized code we patched for OSR may not be the shared code |
410 // afterwards, since we may need to compile it again to include deoptimization | 426 // afterwards, since we may need to compile it again to include deoptimization |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 #endif | 626 #endif |
611 | 627 |
612 // Compile a String source within a context for eval. | 628 // Compile a String source within a context for eval. |
613 static Handle<JSFunction> GetFunctionFromEval(Handle<String> source, | 629 static Handle<JSFunction> GetFunctionFromEval(Handle<String> source, |
614 Handle<Context> context, | 630 Handle<Context> context, |
615 StrictMode strict_mode, | 631 StrictMode strict_mode, |
616 ParseRestriction restriction, | 632 ParseRestriction restriction, |
617 int scope_position); | 633 int scope_position); |
618 | 634 |
619 // Compile a String source within a context. | 635 // Compile a String source within a context. |
620 static Handle<SharedFunctionInfo> CompileScript(Handle<String> source, | 636 static Handle<SharedFunctionInfo> CompileScript( |
621 Handle<Object> script_name, | 637 Handle<String> source, |
622 int line_offset, | 638 Handle<Object> script_name, |
623 int column_offset, | 639 int line_offset, |
624 bool is_shared_cross_origin, | 640 int column_offset, |
625 Handle<Context> context, | 641 bool is_shared_cross_origin, |
626 v8::Extension* extension, | 642 Handle<Context> context, |
627 ScriptDataImpl* pre_data, | 643 v8::Extension* extension, |
628 NativesFlag is_natives_code); | 644 ScriptDataImpl** cached_data, |
| 645 CachedDataMode cached_data_mode, |
| 646 NativesFlag is_natives_code); |
629 | 647 |
630 // Create a shared function info object (the code may be lazily compiled). | 648 // Create a shared function info object (the code may be lazily compiled). |
631 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 649 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
632 Handle<Script> script); | 650 Handle<Script> script); |
633 | 651 |
634 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 652 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
635 | 653 |
636 // Generate and return optimized code or start a concurrent optimization job. | 654 // Generate and return optimized code or start a concurrent optimization job. |
637 // In the latter case, return the InOptimizationQueue builtin. On failure, | 655 // In the latter case, return the InOptimizationQueue builtin. On failure, |
638 // return the empty handle. | 656 // return the empty handle. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 unsigned info_zone_start_allocation_size_; | 690 unsigned info_zone_start_allocation_size_; |
673 ElapsedTimer timer_; | 691 ElapsedTimer timer_; |
674 | 692 |
675 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); | 693 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); |
676 }; | 694 }; |
677 | 695 |
678 | 696 |
679 } } // namespace v8::internal | 697 } } // namespace v8::internal |
680 | 698 |
681 #endif // V8_COMPILER_H_ | 699 #endif // V8_COMPILER_H_ |
OLD | NEW |