Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/compilation-info.h" | 5 #include "src/compilation-info.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/debug/debug.h" | 10 #include "src/debug/debug.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 Context* CompilationInfo::native_context() const { | 208 Context* CompilationInfo::native_context() const { |
| 209 return has_native_context() ? closure()->native_context() : nullptr; | 209 return has_native_context() ? closure()->native_context() : nullptr; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool CompilationInfo::has_global_object() const { return has_native_context(); } | 212 bool CompilationInfo::has_global_object() const { return has_native_context(); } |
| 213 | 213 |
| 214 JSGlobalObject* CompilationInfo::global_object() const { | 214 JSGlobalObject* CompilationInfo::global_object() const { |
| 215 return has_global_object() ? native_context()->global_object() : nullptr; | 215 return has_global_object() ? native_context()->global_object() : nullptr; |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool CompilationInfo::AssignSourceIdToInlining(int inlining_id, | |
| 219 int* source_id) { | |
| 220 if (inlining_id == SourcePosition::kNotInlined) { | |
| 221 // This is a function that is being compiled. Always dump its source. | |
| 222 *source_id = -1; | |
|
Tobias Tebbi
2016/12/15 16:22:01
Is -1 here InlinedFunctionHolder::kSourceNotDumped
| |
| 223 return true; | |
| 224 } | |
| 225 | |
| 226 InlinedFunctionHolder* inl = &inlined_functions_[inlining_id]; | |
| 227 DCHECK_EQ(InlinedFunctionHolder::kSourceNotDumped, inl->source_id); | |
| 228 | |
| 229 // Search for the same function among inlined once and use its source id. | |
| 230 // If its the first time we are inlining this particular function the | |
| 231 // assign a new source id to it and request the source dump. | |
| 232 int max_source_id = InlinedFunctionHolder::kSourceNotDumped; | |
| 233 for (InlinedFunctionHolder& h : inlined_functions_) { | |
| 234 max_source_id = std::max(h.source_id, max_source_id); | |
| 235 if (h.shared_info.is_identical_to(inl->shared_info) && | |
| 236 h.source_id != InlinedFunctionHolder::kSourceNotDumped) { | |
| 237 inl->source_id = *source_id = h.source_id; | |
| 238 return false; | |
| 239 } | |
| 240 } | |
| 241 inl->source_id = *source_id = (max_source_id + 1); | |
| 242 return true; | |
| 243 } | |
| 244 | |
| 245 void CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | |
| 246 SourcePosition position, | |
| 247 int inlining_id) { | |
| 248 if (!FLAG_hydrogen_track_positions) { | |
| 249 return; | |
| 250 } | |
| 251 | |
| 252 int source_id = InlinedFunctionHolder::kSourceNotDumped; | |
| 253 if (AssignSourceIdToInlining(inlining_id, &source_id) && | |
| 254 !shared->script()->IsUndefined(isolate())) { | |
| 255 Handle<Script> script(Script::cast(shared->script()), isolate()); | |
| 256 | |
| 257 if (!script->source()->IsUndefined(isolate())) { | |
| 258 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | |
| 259 Object* source_name = script->name(); | |
| 260 OFStream os(tracing_scope.file()); | |
| 261 os << "--- FUNCTION SOURCE ("; | |
| 262 if (source_name->IsString()) { | |
| 263 os << String::cast(source_name)->ToCString().get() << ":"; | |
| 264 } | |
| 265 os << shared->DebugName()->ToCString().get() << ") id{"; | |
| 266 os << optimization_id() << "," << source_id << "} start{"; | |
| 267 os << shared->start_position() << "} ---\n"; | |
| 268 { | |
| 269 DisallowHeapAllocation no_allocation; | |
| 270 int start = shared->start_position(); | |
| 271 int len = shared->end_position() - start; | |
| 272 String::SubStringRange source(String::cast(script->source()), start, | |
| 273 len); | |
| 274 for (const auto& c : source) { | |
| 275 os << AsReversiblyEscapedUC16(c); | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 os << "\n--- END ---\n"; | |
| 280 } | |
| 281 } | |
| 282 | |
| 283 if (inlining_id != SourcePosition::kNotInlined) { | |
| 284 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | |
| 285 OFStream os(tracing_scope.file()); | |
| 286 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" | |
| 287 << optimization_id() << "," << source_id << "} AS " << inlining_id | |
| 288 << " AT "; | |
| 289 if (position.IsKnown()) { | |
| 290 os << "<" << position.InliningId() << ":" << position.ScriptOffset() | |
| 291 << ">"; | |
| 292 } else { | |
| 293 os << "<?>"; | |
| 294 } | |
| 295 os << std::endl; | |
| 296 } | |
| 297 } | |
| 298 | |
| 218 void CompilationInfo::SetOptimizing() { | 299 void CompilationInfo::SetOptimizing() { |
| 219 DCHECK(has_shared_info()); | 300 DCHECK(has_shared_info()); |
| 220 SetMode(OPTIMIZE); | 301 SetMode(OPTIMIZE); |
| 221 optimization_id_ = isolate()->NextOptimizationId(); | 302 optimization_id_ = isolate()->NextOptimizationId(); |
| 222 code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); | 303 code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); |
| 304 TraceInlinedFunction(shared_info(), SourcePosition::Unknown(), | |
| 305 SourcePosition::kNotInlined); | |
| 223 } | 306 } |
| 224 | 307 |
| 225 int CompilationInfo::AddInlinedFunction( | 308 int CompilationInfo::AddInlinedFunction( |
| 226 Handle<SharedFunctionInfo> inlined_function, SourcePosition pos) { | 309 Handle<SharedFunctionInfo> inlined_function, SourcePosition pos) { |
| 227 int id = static_cast<int>(inlined_functions_.size()); | 310 int id = static_cast<int>(inlined_functions_.size()); |
| 228 inlined_functions_.push_back(InlinedFunctionHolder( | 311 inlined_functions_.push_back(InlinedFunctionHolder( |
| 229 inlined_function, handle(inlined_function->code()), pos)); | 312 inlined_function, handle(inlined_function->code()), pos)); |
| 313 TraceInlinedFunction(inlined_function, pos, id); | |
| 230 return id; | 314 return id; |
| 231 } | 315 } |
| 232 | 316 |
| 233 Code::Kind CompilationInfo::output_code_kind() const { | 317 Code::Kind CompilationInfo::output_code_kind() const { |
| 234 return Code::ExtractKindFromFlags(code_flags_); | 318 return Code::ExtractKindFromFlags(code_flags_); |
| 235 } | 319 } |
| 236 | 320 |
| 237 } // namespace internal | 321 } // namespace internal |
| 238 } // namespace v8 | 322 } // namespace v8 |
| OLD | NEW |