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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 : isolate_(script->GetIsolate()), | 55 : isolate_(script->GetIsolate()), |
56 flags_(LanguageModeField::encode(CLASSIC_MODE)), | 56 flags_(LanguageModeField::encode(CLASSIC_MODE)), |
57 function_(NULL), | 57 function_(NULL), |
58 scope_(NULL), | 58 scope_(NULL), |
59 global_scope_(NULL), | 59 global_scope_(NULL), |
| 60 code_stub_(NULL), |
60 script_(script), | 61 script_(script), |
61 extension_(NULL), | 62 extension_(NULL), |
62 pre_parse_data_(NULL), | 63 pre_parse_data_(NULL), |
63 osr_ast_id_(BailoutId::None()), | 64 osr_ast_id_(BailoutId::None()), |
64 zone_(zone), | 65 zone_(zone), |
65 deferred_handles_(NULL) { | 66 deferred_handles_(NULL) { |
66 Initialize(BASE); | 67 Initialize(BASE); |
67 } | 68 } |
68 | 69 |
69 | 70 |
70 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 71 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
71 Zone* zone) | 72 Zone* zone) |
72 : isolate_(shared_info->GetIsolate()), | 73 : isolate_(shared_info->GetIsolate()), |
73 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 74 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
74 IsLazy::encode(true)), | 75 IsLazy::encode(true)), |
75 function_(NULL), | 76 function_(NULL), |
76 scope_(NULL), | 77 scope_(NULL), |
77 global_scope_(NULL), | 78 global_scope_(NULL), |
| 79 code_stub_(NULL), |
78 shared_info_(shared_info), | 80 shared_info_(shared_info), |
79 script_(Handle<Script>(Script::cast(shared_info->script()))), | 81 script_(Handle<Script>(Script::cast(shared_info->script()))), |
80 extension_(NULL), | 82 extension_(NULL), |
81 pre_parse_data_(NULL), | 83 pre_parse_data_(NULL), |
82 osr_ast_id_(BailoutId::None()), | 84 osr_ast_id_(BailoutId::None()), |
83 zone_(zone), | 85 zone_(zone), |
84 deferred_handles_(NULL) { | 86 deferred_handles_(NULL) { |
85 Initialize(BASE); | 87 Initialize(BASE); |
86 } | 88 } |
87 | 89 |
88 | 90 |
89 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) | 91 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
90 : isolate_(closure->GetIsolate()), | 92 : isolate_(closure->GetIsolate()), |
91 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 93 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
92 IsLazy::encode(true)), | 94 IsLazy::encode(true)), |
93 function_(NULL), | 95 function_(NULL), |
94 scope_(NULL), | 96 scope_(NULL), |
95 global_scope_(NULL), | 97 global_scope_(NULL), |
| 98 code_stub_(NULL), |
96 closure_(closure), | 99 closure_(closure), |
97 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 100 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
98 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 101 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
99 extension_(NULL), | 102 extension_(NULL), |
100 pre_parse_data_(NULL), | 103 pre_parse_data_(NULL), |
101 context_(closure->context()), | 104 context_(closure->context()), |
102 osr_ast_id_(BailoutId::None()), | 105 osr_ast_id_(BailoutId::None()), |
103 zone_(zone), | 106 zone_(zone), |
104 deferred_handles_(NULL) { | 107 deferred_handles_(NULL) { |
105 Initialize(BASE); | 108 Initialize(BASE); |
106 } | 109 } |
107 | 110 |
108 | 111 |
| 112 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
| 113 Isolate* isolate, Zone* zone) |
| 114 : isolate_(isolate), |
| 115 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 116 IsLazy::encode(true)), |
| 117 function_(NULL), |
| 118 scope_(NULL), |
| 119 global_scope_(NULL), |
| 120 code_stub_(stub), |
| 121 extension_(NULL), |
| 122 pre_parse_data_(NULL), |
| 123 osr_ast_id_(BailoutId::None()), |
| 124 zone_(zone), |
| 125 deferred_handles_(NULL) { |
| 126 Initialize(STUB); |
| 127 } |
| 128 |
| 129 |
109 CompilationInfo::~CompilationInfo() { | 130 CompilationInfo::~CompilationInfo() { |
110 delete deferred_handles_; | 131 delete deferred_handles_; |
111 } | 132 } |
112 | 133 |
113 | 134 |
| 135 int CompilationInfo::num_parameters() const { |
| 136 if (IsStub()) { |
| 137 return 0; |
| 138 } else { |
| 139 return scope()->num_parameters(); |
| 140 } |
| 141 } |
| 142 |
| 143 |
| 144 int CompilationInfo::num_heap_slots() const { |
| 145 if (IsStub()) { |
| 146 return 0; |
| 147 } else { |
| 148 return scope()->num_heap_slots(); |
| 149 } |
| 150 } |
| 151 |
| 152 |
| 153 Code::Flags CompilationInfo::flags() const { |
| 154 if (IsStub()) { |
| 155 return Code::ComputeFlags(Code::COMPILED_STUB); |
| 156 } else { |
| 157 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); |
| 158 } |
| 159 } |
| 160 |
| 161 |
114 // Disable optimization for the rest of the compilation pipeline. | 162 // Disable optimization for the rest of the compilation pipeline. |
115 void CompilationInfo::DisableOptimization() { | 163 void CompilationInfo::DisableOptimization() { |
116 bool is_optimizable_closure = | 164 bool is_optimizable_closure = |
117 FLAG_optimize_closures && | 165 FLAG_optimize_closures && |
118 closure_.is_null() && | 166 closure_.is_null() && |
119 !scope_->HasTrivialOuterContext() && | 167 !scope_->HasTrivialOuterContext() && |
120 !scope_->outer_scope_calls_non_strict_eval() && | 168 !scope_->outer_scope_calls_non_strict_eval() && |
121 !scope_->inside_with(); | 169 !scope_->inside_with(); |
122 SetMode(is_optimizable_closure ? BASE : NONOPT); | 170 SetMode(is_optimizable_closure ? BASE : NONOPT); |
123 } | 171 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // optimizations. When using the always_opt flag we disregard the | 362 // optimizations. When using the always_opt flag we disregard the |
315 // optimizable marker in the code object and optimize anyway. This | 363 // optimizable marker in the code object and optimize anyway. This |
316 // is safe as long as the unoptimized code has deoptimization | 364 // is safe as long as the unoptimized code has deoptimization |
317 // support. | 365 // support. |
318 ASSERT(FLAG_always_opt || code->optimizable()); | 366 ASSERT(FLAG_always_opt || code->optimizable()); |
319 ASSERT(info()->shared_info()->has_deoptimization_support()); | 367 ASSERT(info()->shared_info()->has_deoptimization_support()); |
320 | 368 |
321 if (FLAG_trace_hydrogen) { | 369 if (FLAG_trace_hydrogen) { |
322 PrintF("-----------------------------------------------------------\n"); | 370 PrintF("-----------------------------------------------------------\n"); |
323 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 371 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
324 HTracer::Instance()->TraceCompilation(info()->function()); | 372 HTracer::Instance()->TraceCompilation(info()); |
325 } | 373 } |
326 Handle<Context> native_context( | 374 Handle<Context> native_context( |
327 info()->closure()->context()->native_context()); | 375 info()->closure()->context()->native_context()); |
328 oracle_ = new(info()->zone()) TypeFeedbackOracle( | 376 oracle_ = new(info()->zone()) TypeFeedbackOracle( |
329 code, native_context, info()->isolate(), info()->zone()); | 377 code, native_context, info()->isolate(), info()->zone()); |
330 graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_); | 378 graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_); |
331 | 379 |
332 Timer t(this, &time_taken_to_create_graph_); | 380 Timer t(this, &time_taken_to_create_graph_); |
333 graph_ = graph_builder_->CreateGraph(); | 381 graph_ = graph_builder_->CreateGraph(); |
334 | 382 |
335 if (info()->isolate()->has_pending_exception()) { | 383 if (info()->isolate()->has_pending_exception()) { |
336 info()->SetCode(Handle<Code>::null()); | 384 info()->SetCode(Handle<Code>::null()); |
337 return SetLastStatus(FAILED); | 385 return SetLastStatus(FAILED); |
338 } | 386 } |
339 | 387 |
340 // The function being compiled may have bailed out due to an inline | 388 // 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... |
373 return SetLastStatus(SUCCEEDED); | 421 return SetLastStatus(SUCCEEDED); |
374 } | 422 } |
375 | 423 |
376 | 424 |
377 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { | 425 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { |
378 ASSERT(last_status() == SUCCEEDED); | 426 ASSERT(last_status() == SUCCEEDED); |
379 { // Scope for timer. | 427 { // Scope for timer. |
380 Timer timer(this, &time_taken_to_codegen_); | 428 Timer timer(this, &time_taken_to_codegen_); |
381 ASSERT(chunk_ != NULL); | 429 ASSERT(chunk_ != NULL); |
382 ASSERT(graph_ != NULL); | 430 ASSERT(graph_ != NULL); |
383 Handle<Code> optimized_code = chunk_->Codegen(); | 431 Handle<Code> optimized_code = chunk_->Codegen(Code::OPTIMIZED_FUNCTION); |
384 if (optimized_code.is_null()) { | 432 if (optimized_code.is_null()) { |
385 info()->set_bailout_reason("code generation failed"); | 433 info()->set_bailout_reason("code generation failed"); |
386 return AbortOptimization(); | 434 return AbortOptimization(); |
387 } | 435 } |
388 info()->SetCode(optimized_code); | 436 info()->SetCode(optimized_code); |
389 } | 437 } |
390 RecordOptimizationStats(); | 438 RecordOptimizationStats(); |
391 return SetLastStatus(SUCCEEDED); | 439 return SetLastStatus(SUCCEEDED); |
392 } | 440 } |
393 | 441 |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 } | 1122 } |
1075 } | 1123 } |
1076 | 1124 |
1077 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1125 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
1078 Handle<Script>(info->script()), | 1126 Handle<Script>(info->script()), |
1079 Handle<Code>(info->code()), | 1127 Handle<Code>(info->code()), |
1080 info)); | 1128 info)); |
1081 } | 1129 } |
1082 | 1130 |
1083 } } // namespace v8::internal | 1131 } } // namespace v8::internal |
OLD | NEW |