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/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 : parse_info_(parse_info), | 116 : parse_info_(parse_info), |
117 isolate_(isolate), | 117 isolate_(isolate), |
118 flags_(0), | 118 flags_(0), |
119 code_stub_(code_stub), | 119 code_stub_(code_stub), |
120 mode_(mode), | 120 mode_(mode), |
121 osr_ast_id_(BailoutId::None()), | 121 osr_ast_id_(BailoutId::None()), |
122 zone_(zone), | 122 zone_(zone), |
123 deferred_handles_(nullptr), | 123 deferred_handles_(nullptr), |
124 bailout_reason_(kNoReason), | 124 bailout_reason_(kNoReason), |
125 prologue_offset_(Code::kPrologueOffsetNotSet), | 125 prologue_offset_(Code::kPrologueOffsetNotSet), |
126 no_frame_ranges_(isolate->cpu_profiler()->is_profiling() | 126 no_frame_ranges_(nullptr), |
127 ? new List<OffsetRange>(2) | 127 inlined_function_infos_(nullptr), |
128 : nullptr), | |
129 track_positions_(FLAG_hydrogen_track_positions), | 128 track_positions_(FLAG_hydrogen_track_positions), |
130 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), | 129 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), |
131 parameter_count_(0), | 130 parameter_count_(0), |
132 optimization_id_(-1), | 131 optimization_id_(-1), |
133 aborted_due_to_dependency_change_(false), | 132 aborted_due_to_dependency_change_(false), |
134 osr_expr_stack_height_(0) { | 133 osr_expr_stack_height_(0) { |
135 std::fill_n(dependencies_, DependentCode::kGroupCount, nullptr); | 134 std::fill_n(dependencies_, DependentCode::kGroupCount, nullptr); |
| 135 if (isolate->cpu_profiler()->is_profiling()) { |
| 136 no_frame_ranges_ = new List<OffsetRange>(2); |
| 137 track_positions_ = true; |
| 138 } |
| 139 if (track_positions_) { |
| 140 inlined_function_infos_ = new std::vector<InlinedFunctionInfo>(); |
| 141 } |
136 } | 142 } |
137 | 143 |
138 | 144 |
139 CompilationInfo::~CompilationInfo() { | 145 CompilationInfo::~CompilationInfo() { |
140 DisableFutureOptimization(); | 146 DisableFutureOptimization(); |
141 delete deferred_handles_; | 147 delete deferred_handles_; |
142 delete no_frame_ranges_; | 148 delete no_frame_ranges_; |
| 149 delete inlined_function_infos_; |
143 #ifdef DEBUG | 150 #ifdef DEBUG |
144 // Check that no dependent maps have been added or added dependent maps have | 151 // Check that no dependent maps have been added or added dependent maps have |
145 // been rolled back or committed. | 152 // been rolled back or committed. |
146 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 153 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
147 DCHECK(!dependencies_[i]); | 154 DCHECK(!dependencies_[i]); |
148 } | 155 } |
149 #endif // DEBUG | 156 #endif // DEBUG |
150 } | 157 } |
151 | 158 |
152 | 159 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 bool CompilationInfo::is_simple_parameter_list() { | 245 bool CompilationInfo::is_simple_parameter_list() { |
239 return scope()->is_simple_parameter_list(); | 246 return scope()->is_simple_parameter_list(); |
240 } | 247 } |
241 | 248 |
242 | 249 |
243 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | 250 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
244 SourcePosition position, | 251 SourcePosition position, |
245 int parent_id) { | 252 int parent_id) { |
246 DCHECK(track_positions_); | 253 DCHECK(track_positions_); |
247 | 254 |
248 int inline_id = static_cast<int>(inlined_function_infos_.size()); | 255 int inline_id = static_cast<int>(inlined_function_infos_->size()); |
249 InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId, | 256 InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId, |
250 shared->start_position()); | 257 shared->start_position()); |
251 if (!shared->script()->IsUndefined()) { | 258 if (!shared->script()->IsUndefined()) { |
252 Handle<Script> script(Script::cast(shared->script())); | 259 Handle<Script> script(Script::cast(shared->script())); |
253 info.script_id = script->id()->value(); | 260 info.script_id = script->id()->value(); |
254 | 261 |
255 if (FLAG_hydrogen_track_positions && !script->source()->IsUndefined()) { | 262 if (FLAG_hydrogen_track_positions && !script->source()->IsUndefined()) { |
256 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 263 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
257 OFStream os(tracing_scope.file()); | 264 OFStream os(tracing_scope.file()); |
258 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get() | 265 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get() |
259 << ") id{" << optimization_id() << "," << inline_id << "} ---\n"; | 266 << ") id{" << optimization_id() << "," << inline_id << "} ---\n"; |
260 { | 267 { |
261 DisallowHeapAllocation no_allocation; | 268 DisallowHeapAllocation no_allocation; |
262 int start = shared->start_position(); | 269 int start = shared->start_position(); |
263 int len = shared->end_position() - start; | 270 int len = shared->end_position() - start; |
264 String::SubStringRange source(String::cast(script->source()), start, | 271 String::SubStringRange source(String::cast(script->source()), start, |
265 len); | 272 len); |
266 for (const auto& c : source) { | 273 for (const auto& c : source) { |
267 os << AsReversiblyEscapedUC16(c); | 274 os << AsReversiblyEscapedUC16(c); |
268 } | 275 } |
269 } | 276 } |
270 | |
271 os << "\n--- END ---\n"; | 277 os << "\n--- END ---\n"; |
272 } | 278 } |
273 } | 279 } |
274 | 280 |
275 inlined_function_infos_.push_back(info); | 281 inlined_function_infos_->push_back(info); |
276 | 282 |
277 if (FLAG_hydrogen_track_positions && inline_id != 0) { | 283 if (FLAG_hydrogen_track_positions && inline_id != 0) { |
278 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 284 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
279 OFStream os(tracing_scope.file()); | 285 OFStream os(tracing_scope.file()); |
280 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" | 286 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" |
281 << optimization_id() << "," << inline_id << "} AS " << inline_id | 287 << optimization_id() << "," << inline_id << "} AS " << inline_id |
282 << " AT " << position << std::endl; | 288 << " AT " << position << std::endl; |
283 } | 289 } |
284 | 290 |
285 return inline_id; | 291 return inline_id; |
286 } | 292 } |
287 | 293 |
288 | 294 |
289 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { | 295 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { |
290 if (!track_positions_ || IsStub()) return; | 296 if (!track_positions_ || IsStub()) return; |
291 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size()); | 297 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_->size()); |
292 inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); | 298 inlined_function_infos_->at(inlining_id) |
| 299 .deopt_pc_offsets.push_back(pc_offset); |
293 } | 300 } |
294 | 301 |
295 | 302 |
296 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 303 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
297 public: | 304 public: |
298 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) | 305 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) |
299 : HOptimizedGraphBuilder(info) { | 306 : HOptimizedGraphBuilder(info) { |
300 } | 307 } |
301 | 308 |
302 #define DEF_VISIT(type) \ | 309 #define DEF_VISIT(type) \ |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 parse_info_ = nullptr; | 1572 parse_info_ = nullptr; |
1566 } | 1573 } |
1567 | 1574 |
1568 #if DEBUG | 1575 #if DEBUG |
1569 void CompilationInfo::PrintAstForTesting() { | 1576 void CompilationInfo::PrintAstForTesting() { |
1570 PrintF("--- Source from AST ---\n%s\n", | 1577 PrintF("--- Source from AST ---\n%s\n", |
1571 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1578 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1572 } | 1579 } |
1573 #endif | 1580 #endif |
1574 } } // namespace v8::internal | 1581 } } // namespace v8::internal |
OLD | NEW |