Chromium Code Reviews| 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/runtime-profiler.h" | 5 #include "src/runtime-profiler.h" |
| 6 | 6 |
| 7 #include "src/assembler.h" | 7 #include "src/assembler.h" |
| 8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } | 106 } |
| 107 PrintF("]\n"); | 107 PrintF("]\n"); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { | 111 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { |
| 112 TraceRecompile(function, reason, "optimized"); | 112 TraceRecompile(function, reason, "optimized"); |
| 113 | 113 |
| 114 // TODO(4280): Fix this to check function is compiled to baseline once we | 114 // TODO(4280): Fix this to check function is compiled to baseline once we |
| 115 // have a standard way to check that. For now, if baseline code doesn't have | 115 // have a standard way to check that. For now, if baseline code doesn't have |
| 116 // a bytecode array. | 116 // a bytecode array. |
|
Michael Starzinger
2016/07/19 16:00:07
nit: The TODO applied to the assertion I think, le
rmcilroy
2016/07/20 21:48:40
Done.
| |
| 117 DCHECK(!function->shared()->HasBytecodeArray()); | |
| 118 function->AttemptConcurrentOptimization(); | 117 function->AttemptConcurrentOptimization(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void RuntimeProfiler::Baseline(JSFunction* function, const char* reason) { | 120 void RuntimeProfiler::Baseline(JSFunction* function, const char* reason) { |
| 122 TraceRecompile(function, reason, "baseline"); | 121 TraceRecompile(function, reason, "baseline"); |
| 123 | 122 |
| 124 // TODO(4280): Fix this to check function is compiled for the interpreter | 123 // TODO(4280): Fix this to check function is compiled for the interpreter |
| 125 // once we have a standard way to check that. For now function will only | 124 // once we have a standard way to check that. For now function will only |
| 126 // have a bytecode array if compiled for the interpreter. | 125 // have a bytecode array if compiled for the interpreter. |
| 127 DCHECK(function->shared()->HasBytecodeArray()); | 126 DCHECK(function->shared()->HasBytecodeArray()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 generic_percentage <= FLAG_generic_ic_threshold) { | 245 generic_percentage <= FLAG_generic_ic_threshold) { |
| 247 Optimize(function, "small function"); | 246 Optimize(function, "small function"); |
| 248 } else { | 247 } else { |
| 249 shared_code->set_profiler_ticks(ticks + 1); | 248 shared_code->set_profiler_ticks(ticks + 1); |
| 250 } | 249 } |
| 251 } else { | 250 } else { |
| 252 shared_code->set_profiler_ticks(ticks + 1); | 251 shared_code->set_profiler_ticks(ticks + 1); |
| 253 } | 252 } |
| 254 } | 253 } |
| 255 | 254 |
| 256 void RuntimeProfiler::MaybeOptimizeIgnition(JSFunction* function) { | 255 void RuntimeProfiler::MaybeBaselineIgnition(JSFunction* function) { |
| 257 if (function->IsInOptimizationQueue()) return; | 256 if (function->IsInOptimizationQueue()) return; |
| 258 | 257 |
| 259 SharedFunctionInfo* shared = function->shared(); | 258 SharedFunctionInfo* shared = function->shared(); |
| 260 int ticks = shared->profiler_ticks(); | 259 int ticks = shared->profiler_ticks(); |
| 261 | 260 |
| 262 // TODO(rmcilroy): Also ensure we only OSR top-level code if it is smaller | 261 // TODO(rmcilroy): Also ensure we only OSR top-level code if it is smaller |
| 263 // than kMaxToplevelSourceSize. | 262 // than kMaxToplevelSourceSize. |
| 264 // TODO(rmcilroy): Consider whether we should optimize small functions when | |
| 265 // they are first seen on the stack (e.g., kMaxSizeEarlyOpt). | |
| 266 | 263 |
| 267 if (function->IsMarkedForBaseline() || function->IsMarkedForOptimization() || | 264 if (function->IsMarkedForBaseline() || function->IsMarkedForOptimization() || |
| 268 function->IsMarkedForConcurrentOptimization() || | 265 function->IsMarkedForConcurrentOptimization() || |
| 269 function->IsOptimized()) { | 266 function->IsOptimized()) { |
| 270 // TODO(rmcilroy): Support OSR in these cases. | 267 // TODO(rmcilroy): Support OSR in these cases. |
| 271 return; | 268 return; |
| 272 } | 269 } |
| 273 | 270 |
| 274 if (shared->optimization_disabled() && | 271 if (shared->optimization_disabled() && |
| 275 shared->disable_optimization_reason() == kOptimizationDisabledForTest) { | 272 shared->disable_optimization_reason() == kOptimizationDisabledForTest) { |
| 276 // Don't baseline functions which have been marked by NeverOptimizeFunction | 273 // Don't baseline functions which have been marked by NeverOptimizeFunction |
| 277 // in a test. | 274 // in a test. |
| 278 return; | 275 return; |
| 279 } | 276 } |
| 280 | 277 |
| 281 if (ticks >= kProfilerTicksBeforeBaseline) { | 278 if (ticks >= kProfilerTicksBeforeBaseline) { |
| 282 Baseline(function, "hot enough for baseline"); | 279 Baseline(function, "hot enough for baseline"); |
| 283 } | 280 } |
| 284 } | 281 } |
| 285 | 282 |
| 283 void RuntimeProfiler::MaybeOptimizeIgnition(JSFunction* function) { | |
| 284 if (function->IsInOptimizationQueue()) return; | |
| 285 | |
| 286 SharedFunctionInfo* shared = function->shared(); | |
| 287 int ticks = shared->profiler_ticks(); | |
| 288 | |
| 289 // TODO(rmcilroy): Also ensure we only OSR top-level code if it is smaller | |
| 290 // than kMaxToplevelSourceSize. | |
| 291 if (function->IsMarkedForBaseline() || function->IsMarkedForOptimization() || | |
| 292 function->IsMarkedForConcurrentOptimization() || | |
| 293 function->IsOptimized()) { | |
| 294 // TODO(rmcilroy): Support OSR in these cases. | |
| 295 return; | |
| 296 } | |
| 297 | |
| 298 if (shared->optimization_disabled()) { | |
| 299 if (shared->deopt_count() >= FLAG_max_opt_count) { | |
| 300 // If optimization was disabled due to many deoptimizations, | |
| 301 // then check if the function is hot and try to reenable optimization. | |
| 302 if (ticks >= kProfilerTicksBeforeReenablingOptimization) { | |
| 303 shared->set_profiler_ticks(0); | |
| 304 shared->TryReenableOptimization(); | |
| 305 } | |
| 306 } | |
| 307 return; | |
| 308 } | |
| 309 if (function->IsOptimized()) return; | |
| 310 | |
| 311 if (ticks >= kProfilerTicksBeforeOptimization) { | |
| 312 int typeinfo, generic, total, type_percentage, generic_percentage; | |
| 313 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, | |
| 314 &generic_percentage); | |
| 315 if (type_percentage >= FLAG_type_info_threshold && | |
| 316 generic_percentage <= FLAG_generic_ic_threshold) { | |
| 317 // If this particular function hasn't had any ICs patched for enough | |
| 318 // ticks, optimize it now. | |
| 319 Optimize(function, "hot and stable"); | |
| 320 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { | |
| 321 Optimize(function, "not much type info but very hot"); | |
| 322 } else { | |
| 323 if (FLAG_trace_opt_verbose) { | |
| 324 PrintF("[not yet optimizing "); | |
| 325 function->PrintName(); | |
| 326 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, | |
| 327 type_percentage); | |
| 328 } | |
| 329 } | |
| 330 } | |
| 331 // TODO(rmcilroy): Consider whether we should optimize small functions when | |
| 332 // they are first seen on the stack (e.g., kMaxSizeEarlyOpt). | |
| 333 } | |
| 334 | |
| 286 void RuntimeProfiler::MarkCandidatesForOptimization() { | 335 void RuntimeProfiler::MarkCandidatesForOptimization() { |
| 287 HandleScope scope(isolate_); | 336 HandleScope scope(isolate_); |
| 288 | 337 |
| 289 if (!isolate_->use_crankshaft()) return; | 338 if (!isolate_->use_crankshaft()) return; |
| 290 | 339 |
| 291 DisallowHeapAllocation no_gc; | 340 DisallowHeapAllocation no_gc; |
| 292 | 341 |
| 293 // Run through the JavaScript frames and collect them. If we already | 342 // Run through the JavaScript frames and collect them. If we already |
| 294 // have a sample of the function, we mark it for optimizations | 343 // have a sample of the function, we mark it for optimizations |
| 295 // (eagerly or lazily). | 344 // (eagerly or lazily). |
| 296 int frame_count = 0; | 345 int frame_count = 0; |
| 297 int frame_count_limit = FLAG_frame_count; | 346 int frame_count_limit = FLAG_frame_count; |
| 298 for (JavaScriptFrameIterator it(isolate_); | 347 for (JavaScriptFrameIterator it(isolate_); |
| 299 frame_count++ < frame_count_limit && !it.done(); | 348 frame_count++ < frame_count_limit && !it.done(); |
| 300 it.Advance()) { | 349 it.Advance()) { |
| 301 JavaScriptFrame* frame = it.frame(); | 350 JavaScriptFrame* frame = it.frame(); |
| 302 JSFunction* function = frame->function(); | 351 JSFunction* function = frame->function(); |
| 303 | 352 |
| 304 List<JSFunction*> functions(4); | 353 List<JSFunction*> functions(4); |
| 305 frame->GetFunctions(&functions); | 354 frame->GetFunctions(&functions); |
| 306 for (int i = functions.length(); --i >= 0; ) { | 355 for (int i = functions.length(); --i >= 0; ) { |
| 307 SharedFunctionInfo* shared_function_info = functions[i]->shared(); | 356 SharedFunctionInfo* shared_function_info = functions[i]->shared(); |
| 308 int ticks = shared_function_info->profiler_ticks(); | 357 int ticks = shared_function_info->profiler_ticks(); |
| 309 if (ticks < Smi::kMaxValue) { | 358 if (ticks < Smi::kMaxValue) { |
| 310 shared_function_info->set_profiler_ticks(ticks + 1); | 359 shared_function_info->set_profiler_ticks(ticks + 1); |
| 311 } | 360 } |
| 312 } | 361 } |
| 313 | 362 |
| 363 Compiler::CompilationTier next_tier = | |
| 364 Compiler::NextCompilationTier(function); | |
| 314 if (frame->is_interpreted()) { | 365 if (frame->is_interpreted()) { |
| 315 DCHECK(!frame->is_optimized()); | 366 if (next_tier == Compiler::BASELINE) { |
| 316 MaybeOptimizeIgnition(function); | 367 DCHECK(!frame->is_optimized()); |
| 368 MaybeBaselineIgnition(function); | |
| 369 } else { | |
| 370 DCHECK_EQ(next_tier, Compiler::OPTIMIZED); | |
| 371 MaybeOptimizeIgnition(function); | |
| 372 } | |
| 317 } else { | 373 } else { |
| 374 DCHECK_EQ(next_tier, Compiler::OPTIMIZED); | |
| 318 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); | 375 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); |
| 319 } | 376 } |
| 320 } | 377 } |
| 321 any_ic_changed_ = false; | 378 any_ic_changed_ = false; |
| 322 } | 379 } |
| 323 | 380 |
| 324 | 381 |
| 325 } // namespace internal | 382 } // namespace internal |
| 326 } // namespace v8 | 383 } // namespace v8 |
| OLD | NEW |