| 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 20 matching lines...) Expand all Loading... |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "ast.h" | 32 #include "ast.h" |
| 33 #include "zone.h" | 33 #include "zone.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 static const int kPrologueOffsetNotSet = -1; | 38 static const int kPrologueOffsetNotSet = -1; |
| 39 | 39 |
| 40 class ScriptDataImpl; | 40 class ScriptDataImpl; |
| 41 class HydrogenCodeStub; | |
| 42 | 41 |
| 43 // CompilationInfo encapsulates some information known at compile time. It | 42 // CompilationInfo encapsulates some information known at compile time. It |
| 44 // is constructed based on the resources available at compile-time. | 43 // is constructed based on the resources available at compile-time. |
| 45 class CompilationInfo { | 44 class CompilationInfo { |
| 46 public: | 45 public: |
| 47 CompilationInfo(Handle<Script> script, Zone* zone); | 46 CompilationInfo(Handle<Script> script, Zone* zone); |
| 48 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | 47 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
| 49 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 48 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
| 50 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone); | |
| 51 | 49 |
| 52 virtual ~CompilationInfo(); | 50 virtual ~CompilationInfo(); |
| 53 | 51 |
| 54 Isolate* isolate() { | 52 Isolate* isolate() { |
| 55 ASSERT(Isolate::Current() == isolate_); | 53 ASSERT(Isolate::Current() == isolate_); |
| 56 return isolate_; | 54 return isolate_; |
| 57 } | 55 } |
| 58 Zone* zone() { | 56 Zone* zone() { |
| 59 return zone_; | 57 return zone_; |
| 60 } | 58 } |
| 61 bool is_lazy() const { return IsLazy::decode(flags_); } | 59 bool is_lazy() const { return IsLazy::decode(flags_); } |
| 62 bool is_eval() const { return IsEval::decode(flags_); } | 60 bool is_eval() const { return IsEval::decode(flags_); } |
| 63 bool is_global() const { return IsGlobal::decode(flags_); } | 61 bool is_global() const { return IsGlobal::decode(flags_); } |
| 64 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } | 62 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } |
| 65 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; } | 63 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; } |
| 66 LanguageMode language_mode() const { | 64 LanguageMode language_mode() const { |
| 67 return LanguageModeField::decode(flags_); | 65 return LanguageModeField::decode(flags_); |
| 68 } | 66 } |
| 69 bool is_in_loop() const { return IsInLoop::decode(flags_); } | 67 bool is_in_loop() const { return IsInLoop::decode(flags_); } |
| 70 FunctionLiteral* function() const { return function_; } | 68 FunctionLiteral* function() const { return function_; } |
| 71 Scope* scope() const { return scope_; } | 69 Scope* scope() const { return scope_; } |
| 72 Scope* global_scope() const { return global_scope_; } | 70 Scope* global_scope() const { return global_scope_; } |
| 73 Handle<Code> code() const { return code_; } | 71 Handle<Code> code() const { return code_; } |
| 74 Handle<JSFunction> closure() const { return closure_; } | 72 Handle<JSFunction> closure() const { return closure_; } |
| 75 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 73 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
| 76 Handle<Script> script() const { return script_; } | 74 Handle<Script> script() const { return script_; } |
| 77 HydrogenCodeStub* code_stub() {return code_stub_; } | |
| 78 v8::Extension* extension() const { return extension_; } | 75 v8::Extension* extension() const { return extension_; } |
| 79 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 76 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
| 80 Handle<Context> context() const { return context_; } | 77 Handle<Context> context() const { return context_; } |
| 81 BailoutId osr_ast_id() const { return osr_ast_id_; } | 78 BailoutId osr_ast_id() const { return osr_ast_id_; } |
| 82 int num_parameters() const; | |
| 83 int num_heap_slots() const; | |
| 84 Code::Flags flags() const; | |
| 85 | 79 |
| 86 void MarkAsEval() { | 80 void MarkAsEval() { |
| 87 ASSERT(!is_lazy()); | 81 ASSERT(!is_lazy()); |
| 88 flags_ |= IsEval::encode(true); | 82 flags_ |= IsEval::encode(true); |
| 89 } | 83 } |
| 90 void MarkAsGlobal() { | 84 void MarkAsGlobal() { |
| 91 ASSERT(!is_lazy()); | 85 ASSERT(!is_lazy()); |
| 92 flags_ |= IsGlobal::encode(true); | 86 flags_ |= IsGlobal::encode(true); |
| 93 } | 87 } |
| 94 void SetLanguageMode(LanguageMode language_mode) { | 88 void SetLanguageMode(LanguageMode language_mode) { |
| 95 ASSERT(this->language_mode() == CLASSIC_MODE || | 89 ASSERT(this->language_mode() == CLASSIC_MODE || |
| 96 this->language_mode() == language_mode || | 90 this->language_mode() == language_mode || |
| 97 language_mode == EXTENDED_MODE); | 91 language_mode == EXTENDED_MODE); |
| 98 flags_ = LanguageModeField::update(flags_, language_mode); | 92 flags_ = LanguageModeField::update(flags_, language_mode); |
| 99 } | 93 } |
| 100 void MarkAsInLoop() { | 94 void MarkAsInLoop() { |
| 101 ASSERT(is_lazy()); | 95 ASSERT(is_lazy()); |
| 102 flags_ |= IsInLoop::encode(true); | 96 flags_ |= IsInLoop::encode(true); |
| 103 } | 97 } |
| 104 void MarkAsNative() { | 98 void MarkAsNative() { |
| 105 flags_ |= IsNative::encode(true); | 99 flags_ |= IsNative::encode(true); |
| 106 } | 100 } |
| 107 | |
| 108 bool is_native() const { | 101 bool is_native() const { |
| 109 return IsNative::decode(flags_); | 102 return IsNative::decode(flags_); |
| 110 } | 103 } |
| 111 | |
| 112 bool is_calling() const { | |
| 113 return is_deferred_calling() || is_non_deferred_calling(); | |
| 114 } | |
| 115 | |
| 116 void MarkAsDeferredCalling() { | |
| 117 flags_ |= IsDeferredCalling::encode(true); | |
| 118 } | |
| 119 | |
| 120 bool is_deferred_calling() const { | |
| 121 return IsDeferredCalling::decode(flags_); | |
| 122 } | |
| 123 | |
| 124 void MarkAsNonDeferredCalling() { | |
| 125 flags_ |= IsNonDeferredCalling::encode(true); | |
| 126 } | |
| 127 | |
| 128 bool is_non_deferred_calling() const { | |
| 129 return IsNonDeferredCalling::decode(flags_); | |
| 130 } | |
| 131 | |
| 132 void SetFunction(FunctionLiteral* literal) { | 104 void SetFunction(FunctionLiteral* literal) { |
| 133 ASSERT(function_ == NULL); | 105 ASSERT(function_ == NULL); |
| 134 function_ = literal; | 106 function_ = literal; |
| 135 } | 107 } |
| 136 void SetScope(Scope* scope) { | 108 void SetScope(Scope* scope) { |
| 137 ASSERT(scope_ == NULL); | 109 ASSERT(scope_ == NULL); |
| 138 scope_ = scope; | 110 scope_ = scope; |
| 139 } | 111 } |
| 140 void SetGlobalScope(Scope* global_scope) { | 112 void SetGlobalScope(Scope* global_scope) { |
| 141 ASSERT(global_scope_ == NULL); | 113 ASSERT(global_scope_ == NULL); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 172 (closure()->context()->global_object() != NULL); | 144 (closure()->context()->global_object() != NULL); |
| 173 } | 145 } |
| 174 | 146 |
| 175 GlobalObject* global_object() const { | 147 GlobalObject* global_object() const { |
| 176 return has_global_object() ? closure()->context()->global_object() : NULL; | 148 return has_global_object() ? closure()->context()->global_object() : NULL; |
| 177 } | 149 } |
| 178 | 150 |
| 179 // Accessors for the different compilation modes. | 151 // Accessors for the different compilation modes. |
| 180 bool IsOptimizing() const { return mode_ == OPTIMIZE; } | 152 bool IsOptimizing() const { return mode_ == OPTIMIZE; } |
| 181 bool IsOptimizable() const { return mode_ == BASE; } | 153 bool IsOptimizable() const { return mode_ == BASE; } |
| 182 bool IsStub() const { return mode_ == STUB; } | |
| 183 void SetOptimizing(BailoutId osr_ast_id) { | 154 void SetOptimizing(BailoutId osr_ast_id) { |
| 184 SetMode(OPTIMIZE); | 155 SetMode(OPTIMIZE); |
| 185 osr_ast_id_ = osr_ast_id; | 156 osr_ast_id_ = osr_ast_id; |
| 186 } | 157 } |
| 187 void DisableOptimization(); | 158 void DisableOptimization(); |
| 188 | 159 |
| 189 // Deoptimization support. | 160 // Deoptimization support. |
| 190 bool HasDeoptimizationSupport() const { | 161 bool HasDeoptimizationSupport() const { |
| 191 return SupportsDeoptimization::decode(flags_); | 162 return SupportsDeoptimization::decode(flags_); |
| 192 } | 163 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 Isolate* isolate_; | 202 Isolate* isolate_; |
| 232 | 203 |
| 233 // Compilation mode. | 204 // Compilation mode. |
| 234 // BASE is generated by the full codegen, optionally prepared for bailouts. | 205 // BASE is generated by the full codegen, optionally prepared for bailouts. |
| 235 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 206 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
| 236 // NONOPT is generated by the full codegen and is not prepared for | 207 // NONOPT is generated by the full codegen and is not prepared for |
| 237 // recompilation/bailouts. These functions are never recompiled. | 208 // recompilation/bailouts. These functions are never recompiled. |
| 238 enum Mode { | 209 enum Mode { |
| 239 BASE, | 210 BASE, |
| 240 OPTIMIZE, | 211 OPTIMIZE, |
| 241 NONOPT, | 212 NONOPT |
| 242 STUB | |
| 243 }; | 213 }; |
| 244 | 214 |
| 245 void Initialize(Isolate* isolate, Mode mode, Zone* zone); | 215 void Initialize(Zone* zone); |
| 246 | 216 |
| 247 void SetMode(Mode mode) { | 217 void SetMode(Mode mode) { |
| 248 ASSERT(V8::UseCrankshaft()); | 218 ASSERT(V8::UseCrankshaft()); |
| 249 mode_ = mode; | 219 mode_ = mode; |
| 250 } | 220 } |
| 251 | 221 |
| 252 // Flags using template class BitField<type, start, length>. All are | 222 // Flags using template class BitField<type, start, length>. All are |
| 253 // false by default. | 223 // false by default. |
| 254 // | 224 // |
| 255 // Compilation is either eager or lazy. | 225 // Compilation is either eager or lazy. |
| 256 class IsLazy: public BitField<bool, 0, 1> {}; | 226 class IsLazy: public BitField<bool, 0, 1> {}; |
| 257 // Flags that can be set for eager compilation. | 227 // Flags that can be set for eager compilation. |
| 258 class IsEval: public BitField<bool, 1, 1> {}; | 228 class IsEval: public BitField<bool, 1, 1> {}; |
| 259 class IsGlobal: public BitField<bool, 2, 1> {}; | 229 class IsGlobal: public BitField<bool, 2, 1> {}; |
| 260 // Flags that can be set for lazy compilation. | 230 // Flags that can be set for lazy compilation. |
| 261 class IsInLoop: public BitField<bool, 3, 1> {}; | 231 class IsInLoop: public BitField<bool, 3, 1> {}; |
| 262 // Strict mode - used in eager compilation. | 232 // Strict mode - used in eager compilation. |
| 263 class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; | 233 class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
| 264 // Is this a function from our natives. | 234 // Is this a function from our natives. |
| 265 class IsNative: public BitField<bool, 6, 1> {}; | 235 class IsNative: public BitField<bool, 6, 1> {}; |
| 266 // Is this code being compiled with support for deoptimization.. | 236 // Is this code being compiled with support for deoptimization.. |
| 267 class SupportsDeoptimization: public BitField<bool, 7, 1> {}; | 237 class SupportsDeoptimization: public BitField<bool, 7, 1> {}; |
| 268 // If compiling for debugging produce just full code matching the | 238 // If compiling for debugging produce just full code matching the |
| 269 // initial mode setting. | 239 // initial mode setting. |
| 270 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; | 240 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; |
| 271 // If the compiled code contains calls that require building a frame | |
| 272 class IsCalling: public BitField<bool, 9, 1> {}; | |
| 273 // If the compiled code contains calls that require building a frame | |
| 274 class IsDeferredCalling: public BitField<bool, 10, 1> {}; | |
| 275 // If the compiled code contains calls that require building a frame | |
| 276 class IsNonDeferredCalling: public BitField<bool, 11, 1> {}; | |
| 277 | 241 |
| 278 | 242 |
| 279 unsigned flags_; | 243 unsigned flags_; |
| 280 | 244 |
| 281 // Fields filled in by the compilation pipeline. | 245 // Fields filled in by the compilation pipeline. |
| 282 // AST filled in by the parser. | 246 // AST filled in by the parser. |
| 283 FunctionLiteral* function_; | 247 FunctionLiteral* function_; |
| 284 // The scope of the function literal as a convenience. Set to indicate | 248 // The scope of the function literal as a convenience. Set to indicate |
| 285 // that scopes have been analyzed. | 249 // that scopes have been analyzed. |
| 286 Scope* scope_; | 250 Scope* scope_; |
| 287 // The global scope provided as a convenience. | 251 // The global scope provided as a convenience. |
| 288 Scope* global_scope_; | 252 Scope* global_scope_; |
| 289 // For compiled stubs, the stub object | |
| 290 HydrogenCodeStub* code_stub_; | |
| 291 // The compiled code. | 253 // The compiled code. |
| 292 Handle<Code> code_; | 254 Handle<Code> code_; |
| 293 | 255 |
| 294 // Possible initial inputs to the compilation process. | 256 // Possible initial inputs to the compilation process. |
| 295 Handle<JSFunction> closure_; | 257 Handle<JSFunction> closure_; |
| 296 Handle<SharedFunctionInfo> shared_info_; | 258 Handle<SharedFunctionInfo> shared_info_; |
| 297 Handle<Script> script_; | 259 Handle<Script> script_; |
| 298 | 260 |
| 299 // Fields possibly needed for eager compilation, NULL by default. | 261 // Fields possibly needed for eager compilation, NULL by default. |
| 300 v8::Extension* extension_; | 262 v8::Extension* extension_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 zone_(script->GetIsolate()), | 303 zone_(script->GetIsolate()), |
| 342 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 304 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 343 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | 305 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
| 344 : CompilationInfo(shared_info, &zone_), | 306 : CompilationInfo(shared_info, &zone_), |
| 345 zone_(shared_info->GetIsolate()), | 307 zone_(shared_info->GetIsolate()), |
| 346 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 308 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 347 explicit CompilationInfoWithZone(Handle<JSFunction> closure) | 309 explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
| 348 : CompilationInfo(closure, &zone_), | 310 : CompilationInfo(closure, &zone_), |
| 349 zone_(closure->GetIsolate()), | 311 zone_(closure->GetIsolate()), |
| 350 zone_scope_(&zone_, DELETE_ON_EXIT) {} | 312 zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 351 explicit CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) | |
| 352 : CompilationInfo(stub, isolate, &zone_), | |
| 353 zone_(isolate), | |
| 354 zone_scope_(&zone_, DELETE_ON_EXIT) {} | |
| 355 | 313 |
| 356 private: | 314 private: |
| 357 Zone zone_; | 315 Zone zone_; |
| 358 ZoneScope zone_scope_; | 316 ZoneScope zone_scope_; |
| 359 }; | 317 }; |
| 360 | 318 |
| 361 | 319 |
| 362 // A wrapper around a CompilationInfo that detaches the Handles from | 320 // A wrapper around a CompilationInfo that detaches the Handles from |
| 363 // the underlying DeferredHandleScope and stores them in info_ on | 321 // the underlying DeferredHandleScope and stores them in info_ on |
| 364 // destruction. | 322 // destruction. |
| 365 class CompilationHandleScope BASE_EMBEDDED { | 323 class CompilationHandleScope BASE_EMBEDDED { |
| 366 public: | 324 public: |
| 367 explicit CompilationHandleScope(CompilationInfo* info) | 325 explicit CompilationHandleScope(CompilationInfo* info) |
| 368 : deferred_(info->isolate()), info_(info) {} | 326 : deferred_(info->isolate()), info_(info) {} |
| 369 ~CompilationHandleScope() { | 327 ~CompilationHandleScope() { |
| 370 info_->set_deferred_handles(deferred_.Detach()); | 328 info_->set_deferred_handles(deferred_.Detach()); |
| 371 } | 329 } |
| 372 | 330 |
| 373 private: | 331 private: |
| 374 DeferredHandleScope deferred_; | 332 DeferredHandleScope deferred_; |
| 375 CompilationInfo* info_; | 333 CompilationInfo* info_; |
| 376 }; | 334 }; |
| 377 | 335 |
| 378 | 336 |
| 379 class HGraph; | 337 class HGraph; |
| 380 class HOptimizedGraphBuilder; | 338 class HGraphBuilder; |
| 381 class LChunk; | 339 class LChunk; |
| 382 | 340 |
| 383 // A helper class that calls the three compilation phases in | 341 // A helper class that calls the three compilation phases in |
| 384 // Crankshaft and keeps track of its state. The three phases | 342 // Crankshaft and keeps track of its state. The three phases |
| 385 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either | 343 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either |
| 386 // fail, bail-out to the full code generator or succeed. Apart from | 344 // fail, bail-out to the full code generator or succeed. Apart from |
| 387 // their return value, the status of the phase last run can be checked | 345 // their return value, the status of the phase last run can be checked |
| 388 // using last_status(). | 346 // using last_status(). |
| 389 class OptimizingCompiler: public ZoneObject { | 347 class OptimizingCompiler: public ZoneObject { |
| 390 public: | 348 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 412 | 370 |
| 413 MUST_USE_RESULT Status AbortOptimization() { | 371 MUST_USE_RESULT Status AbortOptimization() { |
| 414 info_->AbortOptimization(); | 372 info_->AbortOptimization(); |
| 415 info_->shared_info()->DisableOptimization(info_->bailout_reason()); | 373 info_->shared_info()->DisableOptimization(info_->bailout_reason()); |
| 416 return SetLastStatus(BAILED_OUT); | 374 return SetLastStatus(BAILED_OUT); |
| 417 } | 375 } |
| 418 | 376 |
| 419 private: | 377 private: |
| 420 CompilationInfo* info_; | 378 CompilationInfo* info_; |
| 421 TypeFeedbackOracle* oracle_; | 379 TypeFeedbackOracle* oracle_; |
| 422 HOptimizedGraphBuilder* graph_builder_; | 380 HGraphBuilder* graph_builder_; |
| 423 HGraph* graph_; | 381 HGraph* graph_; |
| 424 LChunk* chunk_; | 382 LChunk* chunk_; |
| 425 int64_t time_taken_to_create_graph_; | 383 int64_t time_taken_to_create_graph_; |
| 426 int64_t time_taken_to_optimize_; | 384 int64_t time_taken_to_optimize_; |
| 427 int64_t time_taken_to_codegen_; | 385 int64_t time_taken_to_codegen_; |
| 428 Status last_status_; | 386 Status last_status_; |
| 429 | 387 |
| 430 MUST_USE_RESULT Status SetLastStatus(Status status) { | 388 MUST_USE_RESULT Status SetLastStatus(Status status) { |
| 431 last_status_ = status; | 389 last_status_ = status; |
| 432 return last_status_; | 390 return last_status_; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 473 |
| 516 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 474 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 517 CompilationInfo* info, | 475 CompilationInfo* info, |
| 518 Handle<SharedFunctionInfo> shared); | 476 Handle<SharedFunctionInfo> shared); |
| 519 }; | 477 }; |
| 520 | 478 |
| 521 | 479 |
| 522 } } // namespace v8::internal | 480 } } // namespace v8::internal |
| 523 | 481 |
| 524 #endif // V8_COMPILER_H_ | 482 #endif // V8_COMPILER_H_ |
| OLD | NEW |