| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 isolate_ = isolate; | 111 isolate_ = isolate; |
| 112 zone_ = zone; | 112 zone_ = zone; |
| 113 deferred_handles_ = NULL; | 113 deferred_handles_ = NULL; |
| 114 code_stub_ = NULL; | 114 code_stub_ = NULL; |
| 115 prologue_offset_ = Code::kPrologueOffsetNotSet; | 115 prologue_offset_ = Code::kPrologueOffsetNotSet; |
| 116 opt_count_ = has_shared_info() ? shared_info()->opt_count() : 0; | 116 opt_count_ = has_shared_info() ? shared_info()->opt_count() : 0; |
| 117 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() | 117 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
| 118 ? new List<OffsetRange>(2) : NULL; | 118 ? new List<OffsetRange>(2) : NULL; |
| 119 if (FLAG_hydrogen_track_positions) { | 119 if (FLAG_hydrogen_track_positions) { |
| 120 inlined_function_infos_ = new std::vector<InlinedFunctionInfo>(); | 120 inlined_function_infos_ = new std::vector<InlinedFunctionInfo>(); |
| 121 track_positions_ = true; |
| 121 } else { | 122 } else { |
| 122 inlined_function_infos_ = NULL; | 123 inlined_function_infos_ = NULL; |
| 124 track_positions_ = false; |
| 123 } | 125 } |
| 124 | 126 |
| 125 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 127 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
| 126 dependencies_[i] = NULL; | 128 dependencies_[i] = NULL; |
| 127 } | 129 } |
| 128 if (mode == STUB) { | 130 if (mode == STUB) { |
| 129 mode_ = STUB; | 131 mode_ = STUB; |
| 130 return; | 132 return; |
| 131 } | 133 } |
| 132 mode_ = mode; | 134 mode_ = mode; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 271 |
| 270 | 272 |
| 271 bool CompilationInfo::is_simple_parameter_list() { | 273 bool CompilationInfo::is_simple_parameter_list() { |
| 272 return scope()->is_simple_parameter_list(); | 274 return scope()->is_simple_parameter_list(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 | 277 |
| 276 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | 278 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
| 277 SourcePosition position, | 279 SourcePosition position, |
| 278 int parent_id) { | 280 int parent_id) { |
| 279 DCHECK(FLAG_hydrogen_track_positions); | 281 DCHECK(track_positions_); |
| 280 DCHECK(inlined_function_infos_); | 282 DCHECK(inlined_function_infos_); |
| 281 | 283 |
| 282 int inline_id = static_cast<int>(inlined_function_infos_->size()); | 284 int inline_id = static_cast<int>(inlined_function_infos_->size()); |
| 283 InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId, | 285 InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId, |
| 284 shared->start_position()); | 286 shared->start_position()); |
| 285 if (!shared->script()->IsUndefined()) { | 287 if (!shared->script()->IsUndefined()) { |
| 286 Handle<Script> script(Script::cast(shared->script())); | 288 Handle<Script> script(Script::cast(shared->script())); |
| 287 info.script_id = script->id()->value(); | 289 info.script_id = script->id()->value(); |
| 288 | 290 |
| 289 if (!script->source()->IsUndefined()) { | 291 if (FLAG_hydrogen_track_positions && !script->source()->IsUndefined()) { |
| 290 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 292 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
| 291 OFStream os(tracing_scope.file()); | 293 OFStream os(tracing_scope.file()); |
| 292 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get() | 294 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get() |
| 293 << ") id{" << optimization_id() << "," << inline_id << "} ---\n"; | 295 << ") id{" << optimization_id() << "," << inline_id << "} ---\n"; |
| 294 { | 296 { |
| 295 DisallowHeapAllocation no_allocation; | 297 DisallowHeapAllocation no_allocation; |
| 296 int start = shared->start_position(); | 298 int start = shared->start_position(); |
| 297 int len = shared->end_position() - start; | 299 int len = shared->end_position() - start; |
| 298 String::SubStringRange source(String::cast(script->source()), start, | 300 String::SubStringRange source(String::cast(script->source()), start, |
| 299 len); | 301 len); |
| 300 for (const auto& c : source) { | 302 for (const auto& c : source) { |
| 301 os << AsReversiblyEscapedUC16(c); | 303 os << AsReversiblyEscapedUC16(c); |
| 302 } | 304 } |
| 303 } | 305 } |
| 304 | 306 |
| 305 os << "\n--- END ---\n"; | 307 os << "\n--- END ---\n"; |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 | 310 |
| 309 inlined_function_infos_->push_back(info); | 311 inlined_function_infos_->push_back(info); |
| 310 | 312 |
| 311 if (inline_id != 0) { | 313 if (FLAG_hydrogen_track_positions && inline_id != 0) { |
| 312 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 314 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
| 313 OFStream os(tracing_scope.file()); | 315 OFStream os(tracing_scope.file()); |
| 314 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" | 316 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" |
| 315 << optimization_id() << "," << inline_id << "} AS " << inline_id | 317 << optimization_id() << "," << inline_id << "} AS " << inline_id |
| 316 << " AT " << position << std::endl; | 318 << " AT " << position << std::endl; |
| 317 } | 319 } |
| 318 | 320 |
| 319 return inline_id; | 321 return inline_id; |
| 320 } | 322 } |
| 321 | 323 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // Type-check the function. | 475 // Type-check the function. |
| 474 AstTyper::Run(info()); | 476 AstTyper::Run(info()); |
| 475 | 477 |
| 476 // Optimization could have been disabled by the parser. Note that this check | 478 // Optimization could have been disabled by the parser. Note that this check |
| 477 // is only needed because the Hydrogen graph builder is missing some bailouts. | 479 // is only needed because the Hydrogen graph builder is missing some bailouts. |
| 478 if (info()->shared_info()->optimization_disabled()) { | 480 if (info()->shared_info()->optimization_disabled()) { |
| 479 return AbortOptimization( | 481 return AbortOptimization( |
| 480 info()->shared_info()->disable_optimization_reason()); | 482 info()->shared_info()->disable_optimization_reason()); |
| 481 } | 483 } |
| 482 | 484 |
| 483 graph_builder_ = (FLAG_hydrogen_track_positions || FLAG_trace_ic) | 485 graph_builder_ = (info()->is_tracking_positions() || FLAG_trace_ic) |
| 484 ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info()) | 486 ? new (info()->zone()) |
| 485 : new(info()->zone()) HOptimizedGraphBuilder(info()); | 487 HOptimizedGraphBuilderWithPositions(info()) |
| 488 : new (info()->zone()) HOptimizedGraphBuilder(info()); |
| 486 | 489 |
| 487 Timer t(this, &time_taken_to_create_graph_); | 490 Timer t(this, &time_taken_to_create_graph_); |
| 488 // TODO(titzer): ParseInfo::this_has_uses is only used by Crankshaft. Move. | 491 // TODO(titzer): ParseInfo::this_has_uses is only used by Crankshaft. Move. |
| 489 info()->parse_info()->set_this_has_uses(false); | 492 info()->parse_info()->set_this_has_uses(false); |
| 490 graph_ = graph_builder_->CreateGraph(); | 493 graph_ = graph_builder_->CreateGraph(); |
| 491 | 494 |
| 492 if (isolate()->has_pending_exception()) { | 495 if (isolate()->has_pending_exception()) { |
| 493 return SetLastStatus(FAILED); | 496 return SetLastStatus(FAILED); |
| 494 } | 497 } |
| 495 | 498 |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 parse_info_ = nullptr; | 1597 parse_info_ = nullptr; |
| 1595 } | 1598 } |
| 1596 | 1599 |
| 1597 #if DEBUG | 1600 #if DEBUG |
| 1598 void CompilationInfo::PrintAstForTesting() { | 1601 void CompilationInfo::PrintAstForTesting() { |
| 1599 PrintF("--- Source from AST ---\n%s\n", | 1602 PrintF("--- Source from AST ---\n%s\n", |
| 1600 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1603 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1601 } | 1604 } |
| 1602 #endif | 1605 #endif |
| 1603 } } // namespace v8::internal | 1606 } } // namespace v8::internal |
| OLD | NEW |