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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 class ScriptDataImpl; | 38 class ScriptDataImpl; |
39 | 39 |
40 // CompilationInfo encapsulates some information known at compile time. It | 40 // CompilationInfo encapsulates some information known at compile time. It |
41 // is constructed based on the resources available at compile-time. | 41 // is constructed based on the resources available at compile-time. |
42 class CompilationInfo { | 42 class CompilationInfo { |
43 public: | 43 public: |
44 CompilationInfo(Handle<Script> script, Zone* zone); | 44 CompilationInfo(Handle<Script> script, Zone* zone); |
45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | 45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
| 47 CompilationInfo(Isolate* isolate, Zone* zone); |
47 | 48 |
48 virtual ~CompilationInfo(); | 49 virtual ~CompilationInfo(); |
49 | 50 |
50 Isolate* isolate() { | 51 Isolate* isolate() { |
51 ASSERT(Isolate::Current() == isolate_); | 52 ASSERT(Isolate::Current() == isolate_); |
52 return isolate_; | 53 return isolate_; |
53 } | 54 } |
54 Zone* zone() { | 55 Zone* zone() { |
55 return zone_; | 56 return zone_; |
56 } | 57 } |
(...skipping 10 matching lines...) Expand all Loading... |
67 Scope* scope() const { return scope_; } | 68 Scope* scope() const { return scope_; } |
68 Scope* global_scope() const { return global_scope_; } | 69 Scope* global_scope() const { return global_scope_; } |
69 Handle<Code> code() const { return code_; } | 70 Handle<Code> code() const { return code_; } |
70 Handle<JSFunction> closure() const { return closure_; } | 71 Handle<JSFunction> closure() const { return closure_; } |
71 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 72 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
72 Handle<Script> script() const { return script_; } | 73 Handle<Script> script() const { return script_; } |
73 v8::Extension* extension() const { return extension_; } | 74 v8::Extension* extension() const { return extension_; } |
74 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 75 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
75 Handle<Context> context() const { return context_; } | 76 Handle<Context> context() const { return context_; } |
76 BailoutId osr_ast_id() const { return osr_ast_id_; } | 77 BailoutId osr_ast_id() const { return osr_ast_id_; } |
| 78 int num_parameters() const; |
| 79 int num_heap_slots() const; |
| 80 Code::Flags flags() const; |
77 | 81 |
78 void MarkAsEval() { | 82 void MarkAsEval() { |
79 ASSERT(!is_lazy()); | 83 ASSERT(!is_lazy()); |
80 flags_ |= IsEval::encode(true); | 84 flags_ |= IsEval::encode(true); |
81 } | 85 } |
82 void MarkAsGlobal() { | 86 void MarkAsGlobal() { |
83 ASSERT(!is_lazy()); | 87 ASSERT(!is_lazy()); |
84 flags_ |= IsGlobal::encode(true); | 88 flags_ |= IsGlobal::encode(true); |
85 } | 89 } |
86 void SetLanguageMode(LanguageMode language_mode) { | 90 void SetLanguageMode(LanguageMode language_mode) { |
87 ASSERT(this->language_mode() == CLASSIC_MODE || | 91 ASSERT(this->language_mode() == CLASSIC_MODE || |
88 this->language_mode() == language_mode || | 92 this->language_mode() == language_mode || |
89 language_mode == EXTENDED_MODE); | 93 language_mode == EXTENDED_MODE); |
90 flags_ = LanguageModeField::update(flags_, language_mode); | 94 flags_ = LanguageModeField::update(flags_, language_mode); |
91 } | 95 } |
92 void MarkAsInLoop() { | 96 void MarkAsInLoop() { |
93 ASSERT(is_lazy()); | 97 ASSERT(is_lazy()); |
94 flags_ |= IsInLoop::encode(true); | 98 flags_ |= IsInLoop::encode(true); |
95 } | 99 } |
96 void MarkAsNative() { | 100 void MarkAsNative() { |
97 flags_ |= IsNative::encode(true); | 101 flags_ |= IsNative::encode(true); |
98 } | 102 } |
| 103 |
99 bool is_native() const { | 104 bool is_native() const { |
100 return IsNative::decode(flags_); | 105 return IsNative::decode(flags_); |
101 } | 106 } |
| 107 |
| 108 bool is_calling() const { |
| 109 return is_deferred_calling() || is_non_deferred_calling(); |
| 110 } |
| 111 |
| 112 void MarkAsDeferredCalling() { |
| 113 flags_ |= IsDeferredCalling::encode(true); |
| 114 } |
| 115 |
| 116 bool is_deferred_calling() const { |
| 117 return IsDeferredCalling::decode(flags_); |
| 118 } |
| 119 |
| 120 void MarkAsNonDeferredCalling() { |
| 121 flags_ |= IsNonDeferredCalling::encode(true); |
| 122 } |
| 123 |
| 124 bool is_non_deferred_calling() const { |
| 125 return IsNonDeferredCalling::decode(flags_); |
| 126 } |
| 127 |
102 void SetFunction(FunctionLiteral* literal) { | 128 void SetFunction(FunctionLiteral* literal) { |
103 ASSERT(function_ == NULL); | 129 ASSERT(function_ == NULL); |
104 function_ = literal; | 130 function_ = literal; |
105 } | 131 } |
106 void SetScope(Scope* scope) { | 132 void SetScope(Scope* scope) { |
107 ASSERT(scope_ == NULL); | 133 ASSERT(scope_ == NULL); |
108 scope_ = scope; | 134 scope_ = scope; |
109 } | 135 } |
110 void SetGlobalScope(Scope* global_scope) { | 136 void SetGlobalScope(Scope* global_scope) { |
111 ASSERT(global_scope_ == NULL); | 137 ASSERT(global_scope_ == NULL); |
(...skipping 30 matching lines...) Expand all Loading... |
142 (closure()->context()->global_object() != NULL); | 168 (closure()->context()->global_object() != NULL); |
143 } | 169 } |
144 | 170 |
145 GlobalObject* global_object() const { | 171 GlobalObject* global_object() const { |
146 return has_global_object() ? closure()->context()->global_object() : NULL; | 172 return has_global_object() ? closure()->context()->global_object() : NULL; |
147 } | 173 } |
148 | 174 |
149 // Accessors for the different compilation modes. | 175 // Accessors for the different compilation modes. |
150 bool IsOptimizing() const { return mode_ == OPTIMIZE; } | 176 bool IsOptimizing() const { return mode_ == OPTIMIZE; } |
151 bool IsOptimizable() const { return mode_ == BASE; } | 177 bool IsOptimizable() const { return mode_ == BASE; } |
| 178 bool IsStub() const { return mode_ == STUB; } |
152 void SetOptimizing(BailoutId osr_ast_id) { | 179 void SetOptimizing(BailoutId osr_ast_id) { |
153 SetMode(OPTIMIZE); | 180 SetMode(OPTIMIZE); |
154 osr_ast_id_ = osr_ast_id; | 181 osr_ast_id_ = osr_ast_id; |
155 } | 182 } |
156 void DisableOptimization(); | 183 void DisableOptimization(); |
157 | 184 |
158 // Deoptimization support. | 185 // Deoptimization support. |
159 bool HasDeoptimizationSupport() const { | 186 bool HasDeoptimizationSupport() const { |
160 return SupportsDeoptimization::decode(flags_); | 187 return SupportsDeoptimization::decode(flags_); |
161 } | 188 } |
(...skipping 28 matching lines...) Expand all Loading... |
190 Isolate* isolate_; | 217 Isolate* isolate_; |
191 | 218 |
192 // Compilation mode. | 219 // Compilation mode. |
193 // BASE is generated by the full codegen, optionally prepared for bailouts. | 220 // BASE is generated by the full codegen, optionally prepared for bailouts. |
194 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 221 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
195 // NONOPT is generated by the full codegen and is not prepared for | 222 // NONOPT is generated by the full codegen and is not prepared for |
196 // recompilation/bailouts. These functions are never recompiled. | 223 // recompilation/bailouts. These functions are never recompiled. |
197 enum Mode { | 224 enum Mode { |
198 BASE, | 225 BASE, |
199 OPTIMIZE, | 226 OPTIMIZE, |
200 NONOPT | 227 NONOPT, |
| 228 STUB |
201 }; | 229 }; |
202 | 230 |
203 void Initialize(Mode mode) { | 231 void Initialize(Mode mode) { |
| 232 if (mode == STUB) { |
| 233 mode_ = STUB; |
| 234 return; |
| 235 } |
204 mode_ = V8::UseCrankshaft() ? mode : NONOPT; | 236 mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
205 ASSERT(!script_.is_null()); | 237 ASSERT(!script_.is_null()); |
206 if (script_->type()->value() == Script::TYPE_NATIVE) { | 238 if (script_->type()->value() == Script::TYPE_NATIVE) { |
207 MarkAsNative(); | 239 MarkAsNative(); |
208 } | 240 } |
209 if (!shared_info_.is_null()) { | 241 if (!shared_info_.is_null()) { |
210 ASSERT(language_mode() == CLASSIC_MODE); | 242 ASSERT(language_mode() == CLASSIC_MODE); |
211 SetLanguageMode(shared_info_->language_mode()); | 243 SetLanguageMode(shared_info_->language_mode()); |
212 } | 244 } |
213 set_bailout_reason("unknown"); | 245 set_bailout_reason("unknown"); |
(...skipping 16 matching lines...) Expand all Loading... |
230 class IsInLoop: public BitField<bool, 3, 1> {}; | 262 class IsInLoop: public BitField<bool, 3, 1> {}; |
231 // Strict mode - used in eager compilation. | 263 // Strict mode - used in eager compilation. |
232 class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; | 264 class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
233 // Is this a function from our natives. | 265 // Is this a function from our natives. |
234 class IsNative: public BitField<bool, 6, 1> {}; | 266 class IsNative: public BitField<bool, 6, 1> {}; |
235 // Is this code being compiled with support for deoptimization.. | 267 // Is this code being compiled with support for deoptimization.. |
236 class SupportsDeoptimization: public BitField<bool, 7, 1> {}; | 268 class SupportsDeoptimization: public BitField<bool, 7, 1> {}; |
237 // If compiling for debugging produce just full code matching the | 269 // If compiling for debugging produce just full code matching the |
238 // initial mode setting. | 270 // initial mode setting. |
239 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; | 271 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; |
| 272 // If the compiled code contains calls that require building a frame |
| 273 class IsCalling: public BitField<bool, 9, 1> {}; |
| 274 // If the compiled code contains calls that require building a frame |
| 275 class IsDeferredCalling: public BitField<bool, 10, 1> {}; |
| 276 // If the compiled code contains calls that require building a frame |
| 277 class IsNonDeferredCalling: public BitField<bool, 11, 1> {}; |
240 | 278 |
241 | 279 |
242 unsigned flags_; | 280 unsigned flags_; |
243 | 281 |
244 // Fields filled in by the compilation pipeline. | 282 // Fields filled in by the compilation pipeline. |
245 // AST filled in by the parser. | 283 // AST filled in by the parser. |
246 FunctionLiteral* function_; | 284 FunctionLiteral* function_; |
247 // The scope of the function literal as a convenience. Set to indicate | 285 // The scope of the function literal as a convenience. Set to indicate |
248 // that scopes have been analyzed. | 286 // that scopes have been analyzed. |
249 Scope* scope_; | 287 Scope* scope_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 zone_(script->GetIsolate()), | 336 zone_(script->GetIsolate()), |
299 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 337 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
300 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | 338 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
301 : CompilationInfo(shared_info, &zone_), | 339 : CompilationInfo(shared_info, &zone_), |
302 zone_(shared_info->GetIsolate()), | 340 zone_(shared_info->GetIsolate()), |
303 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 341 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
304 explicit CompilationInfoWithZone(Handle<JSFunction> closure) | 342 explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
305 : CompilationInfo(closure, &zone_), | 343 : CompilationInfo(closure, &zone_), |
306 zone_(closure->GetIsolate()), | 344 zone_(closure->GetIsolate()), |
307 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 345 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 346 explicit CompilationInfoWithZone(Isolate* isolate) |
| 347 : CompilationInfo(isolate, &zone_), |
| 348 zone_(isolate), |
| 349 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
308 | 350 |
309 private: | 351 private: |
310 Zone zone_; | 352 Zone zone_; |
311 ZoneScope zone_scope_; | 353 ZoneScope zone_scope_; |
312 }; | 354 }; |
313 | 355 |
314 | 356 |
315 // A wrapper around a CompilationInfo that detaches the Handles from | 357 // A wrapper around a CompilationInfo that detaches the Handles from |
316 // the underlying DeferredHandleScope and stores them in info_ on | 358 // the underlying DeferredHandleScope and stores them in info_ on |
317 // destruction. | 359 // destruction. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 510 |
469 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 511 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
470 CompilationInfo* info, | 512 CompilationInfo* info, |
471 Handle<SharedFunctionInfo> shared); | 513 Handle<SharedFunctionInfo> shared); |
472 }; | 514 }; |
473 | 515 |
474 | 516 |
475 } } // namespace v8::internal | 517 } } // namespace v8::internal |
476 | 518 |
477 #endif // V8_COMPILER_H_ | 519 #endif // V8_COMPILER_H_ |
OLD | NEW |