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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "vm-state-inl.h" | 48 #include "vm-state-inl.h" |
49 | 49 |
50 namespace v8 { | 50 namespace v8 { |
51 namespace internal { | 51 namespace internal { |
52 | 52 |
53 | 53 |
54 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) | 54 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) |
55 : flags_(LanguageModeField::encode(CLASSIC_MODE)), | 55 : flags_(LanguageModeField::encode(CLASSIC_MODE)), |
56 script_(script), | 56 script_(script), |
57 osr_ast_id_(BailoutId::None()) { | 57 osr_ast_id_(BailoutId::None()) { |
58 Initialize(zone); | 58 Initialize(script->GetIsolate(), BASE, zone); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 62 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
63 Zone* zone) | 63 Zone* zone) |
64 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 64 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
65 shared_info_(shared_info), | 65 shared_info_(shared_info), |
66 script_(Handle<Script>(Script::cast(shared_info->script()))), | 66 script_(Handle<Script>(Script::cast(shared_info->script()))), |
67 osr_ast_id_(BailoutId::None()) { | 67 osr_ast_id_(BailoutId::None()) { |
68 Initialize(zone); | 68 Initialize(script_->GetIsolate(), BASE, zone); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) | 72 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
73 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 73 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
74 closure_(closure), | 74 closure_(closure), |
75 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 75 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
76 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 76 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
77 context_(closure->context()), | 77 context_(closure->context()), |
78 osr_ast_id_(BailoutId::None()) { | 78 osr_ast_id_(BailoutId::None()) { |
79 Initialize(zone); | 79 Initialize(script_->GetIsolate(), BASE, zone); |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 void CompilationInfo::Initialize(Zone* zone) { | 83 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
84 isolate_ = script_->GetIsolate(); | 84 Isolate* isolate, Zone* zone) |
| 85 : flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 86 IsLazy::encode(true)), |
| 87 osr_ast_id_(BailoutId::None()) { |
| 88 Initialize(isolate, STUB, zone); |
| 89 code_stub_ = stub; |
| 90 } |
| 91 |
| 92 |
| 93 void CompilationInfo::Initialize(Isolate* isolate, Mode mode, Zone* zone) { |
| 94 isolate_ = isolate; |
85 function_ = NULL; | 95 function_ = NULL; |
86 scope_ = NULL; | 96 scope_ = NULL; |
87 global_scope_ = NULL; | 97 global_scope_ = NULL; |
88 extension_ = NULL; | 98 extension_ = NULL; |
89 pre_parse_data_ = NULL; | 99 pre_parse_data_ = NULL; |
90 zone_ = zone; | 100 zone_ = zone; |
91 deferred_handles_ = NULL; | 101 deferred_handles_ = NULL; |
| 102 code_stub_ = NULL; |
92 prologue_offset_ = kPrologueOffsetNotSet; | 103 prologue_offset_ = kPrologueOffsetNotSet; |
93 mode_ = V8::UseCrankshaft() ? BASE : NONOPT; | 104 if (mode == STUB) { |
| 105 mode_ = STUB; |
| 106 return; |
| 107 } |
| 108 mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
94 if (script_->type()->value() == Script::TYPE_NATIVE) { | 109 if (script_->type()->value() == Script::TYPE_NATIVE) { |
95 MarkAsNative(); | 110 MarkAsNative(); |
96 } | 111 } |
97 if (!shared_info_.is_null()) { | 112 if (!shared_info_.is_null()) { |
98 ASSERT(language_mode() == CLASSIC_MODE); | 113 ASSERT(language_mode() == CLASSIC_MODE); |
99 SetLanguageMode(shared_info_->language_mode()); | 114 SetLanguageMode(shared_info_->language_mode()); |
100 } | 115 } |
101 set_bailout_reason("unknown"); | 116 set_bailout_reason("unknown"); |
102 } | 117 } |
103 | 118 |
104 | 119 |
105 CompilationInfo::~CompilationInfo() { | 120 CompilationInfo::~CompilationInfo() { |
106 delete deferred_handles_; | 121 delete deferred_handles_; |
107 } | 122 } |
108 | 123 |
109 | 124 |
| 125 int CompilationInfo::num_parameters() const { |
| 126 if (IsStub()) { |
| 127 return 0; |
| 128 } else { |
| 129 return scope()->num_parameters(); |
| 130 } |
| 131 } |
| 132 |
| 133 |
| 134 int CompilationInfo::num_heap_slots() const { |
| 135 if (IsStub()) { |
| 136 return 0; |
| 137 } else { |
| 138 return scope()->num_heap_slots(); |
| 139 } |
| 140 } |
| 141 |
| 142 |
| 143 Code::Flags CompilationInfo::flags() const { |
| 144 if (IsStub()) { |
| 145 return Code::ComputeFlags(Code::COMPILED_STUB); |
| 146 } else { |
| 147 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); |
| 148 } |
| 149 } |
| 150 |
| 151 |
110 // Disable optimization for the rest of the compilation pipeline. | 152 // Disable optimization for the rest of the compilation pipeline. |
111 void CompilationInfo::DisableOptimization() { | 153 void CompilationInfo::DisableOptimization() { |
112 bool is_optimizable_closure = | 154 bool is_optimizable_closure = |
113 FLAG_optimize_closures && | 155 FLAG_optimize_closures && |
114 closure_.is_null() && | 156 closure_.is_null() && |
115 !scope_->HasTrivialOuterContext() && | 157 !scope_->HasTrivialOuterContext() && |
116 !scope_->outer_scope_calls_non_strict_eval() && | 158 !scope_->outer_scope_calls_non_strict_eval() && |
117 !scope_->inside_with(); | 159 !scope_->inside_with(); |
118 SetMode(is_optimizable_closure ? BASE : NONOPT); | 160 SetMode(is_optimizable_closure ? BASE : NONOPT); |
119 } | 161 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // optimizations. When using the always_opt flag we disregard the | 352 // optimizations. When using the always_opt flag we disregard the |
311 // optimizable marker in the code object and optimize anyway. This | 353 // optimizable marker in the code object and optimize anyway. This |
312 // is safe as long as the unoptimized code has deoptimization | 354 // is safe as long as the unoptimized code has deoptimization |
313 // support. | 355 // support. |
314 ASSERT(FLAG_always_opt || code->optimizable()); | 356 ASSERT(FLAG_always_opt || code->optimizable()); |
315 ASSERT(info()->shared_info()->has_deoptimization_support()); | 357 ASSERT(info()->shared_info()->has_deoptimization_support()); |
316 | 358 |
317 if (FLAG_trace_hydrogen) { | 359 if (FLAG_trace_hydrogen) { |
318 PrintF("-----------------------------------------------------------\n"); | 360 PrintF("-----------------------------------------------------------\n"); |
319 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 361 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
320 HTracer::Instance()->TraceCompilation(info()->function()); | 362 HTracer::Instance()->TraceCompilation(info()); |
321 } | 363 } |
322 Handle<Context> native_context( | 364 Handle<Context> native_context( |
323 info()->closure()->context()->native_context()); | 365 info()->closure()->context()->native_context()); |
324 oracle_ = new(info()->zone()) TypeFeedbackOracle( | 366 oracle_ = new(info()->zone()) TypeFeedbackOracle( |
325 code, native_context, info()->isolate(), info()->zone()); | 367 code, native_context, info()->isolate(), info()->zone()); |
326 graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_); | 368 graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_); |
327 | 369 |
328 Timer t(this, &time_taken_to_create_graph_); | 370 Timer t(this, &time_taken_to_create_graph_); |
329 graph_ = graph_builder_->CreateGraph(); | 371 graph_ = graph_builder_->CreateGraph(); |
330 | 372 |
331 if (info()->isolate()->has_pending_exception()) { | 373 if (info()->isolate()->has_pending_exception()) { |
332 info()->SetCode(Handle<Code>::null()); | 374 info()->SetCode(Handle<Code>::null()); |
333 return SetLastStatus(FAILED); | 375 return SetLastStatus(FAILED); |
334 } | 376 } |
335 | 377 |
336 // The function being compiled may have bailed out due to an inline | 378 // The function being compiled may have bailed out due to an inline |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return SetLastStatus(SUCCEEDED); | 411 return SetLastStatus(SUCCEEDED); |
370 } | 412 } |
371 | 413 |
372 | 414 |
373 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { | 415 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { |
374 ASSERT(last_status() == SUCCEEDED); | 416 ASSERT(last_status() == SUCCEEDED); |
375 { // Scope for timer. | 417 { // Scope for timer. |
376 Timer timer(this, &time_taken_to_codegen_); | 418 Timer timer(this, &time_taken_to_codegen_); |
377 ASSERT(chunk_ != NULL); | 419 ASSERT(chunk_ != NULL); |
378 ASSERT(graph_ != NULL); | 420 ASSERT(graph_ != NULL); |
379 Handle<Code> optimized_code = chunk_->Codegen(); | 421 Handle<Code> optimized_code = chunk_->Codegen(Code::OPTIMIZED_FUNCTION); |
380 if (optimized_code.is_null()) { | 422 if (optimized_code.is_null()) { |
381 info()->set_bailout_reason("code generation failed"); | 423 info()->set_bailout_reason("code generation failed"); |
382 return AbortOptimization(); | 424 return AbortOptimization(); |
383 } | 425 } |
384 info()->SetCode(optimized_code); | 426 info()->SetCode(optimized_code); |
385 } | 427 } |
386 RecordOptimizationStats(); | 428 RecordOptimizationStats(); |
387 return SetLastStatus(SUCCEEDED); | 429 return SetLastStatus(SUCCEEDED); |
388 } | 430 } |
389 | 431 |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 } | 1112 } |
1071 } | 1113 } |
1072 | 1114 |
1073 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1115 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
1074 Handle<Script>(info->script()), | 1116 Handle<Script>(info->script()), |
1075 Handle<Code>(info->code()), | 1117 Handle<Code>(info->code()), |
1076 info)); | 1118 info)); |
1077 } | 1119 } |
1078 | 1120 |
1079 } } // namespace v8::internal | 1121 } } // namespace v8::internal |
OLD | NEW |