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