Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime-profiler.cc

Issue 10202007: Re-enable optimization for hot functions that have optimization disabled due to many deopts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix 64-bit compile error Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 static const int kSamplerThresholdSizeFactorInit = 3; 59 static const int kSamplerThresholdSizeFactorInit = 3;
60 60
61 static const int kSizeLimit = 1500; 61 static const int kSizeLimit = 1500;
62 62
63 // Constants for counter based profiler. 63 // Constants for counter based profiler.
64 64
65 // Number of times a function has to be seen on the stack before it is 65 // Number of times a function has to be seen on the stack before it is
66 // optimized. 66 // optimized.
67 static const int kProfilerTicksBeforeOptimization = 2; 67 static const int kProfilerTicksBeforeOptimization = 2;
68 // If the function optimization was disabled due to high deoptimization count,
69 // but the function is hot and has been seen on the stack this number of times,
70 // then we try to reenable optimization for this function.
71 static const int kProfilerTicksBeforeReenablingOptimization = 250;
68 // If a function does not have enough type info (according to 72 // If a function does not have enough type info (according to
69 // FLAG_type_info_threshold), but has seen a huge number of ticks, 73 // FLAG_type_info_threshold), but has seen a huge number of ticks,
70 // optimize it as it is. 74 // optimize it as it is.
71 static const int kTicksWhenNotEnoughTypeInfo = 100; 75 static const int kTicksWhenNotEnoughTypeInfo = 100;
72 // We only have one byte to store the number of ticks. 76 // We only have one byte to store the number of ticks.
77 STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256);
78 STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256);
73 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); 79 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256);
74 80
75 // Maximum size in bytes of generated code for a function to be optimized 81 // Maximum size in bytes of generated code for a function to be optimized
76 // the very first time it is seen on the stack. 82 // the very first time it is seen on the stack.
77 static const int kMaxSizeEarlyOpt = 500; 83 static const int kMaxSizeEarlyOpt = 500;
78 84
79 85
80 Atomic32 RuntimeProfiler::state_ = 0; 86 Atomic32 RuntimeProfiler::state_ = 0;
81 87
82 // TODO(isolates): Clean up the semaphore when it is no longer required. 88 // TODO(isolates): Clean up the semaphore when it is no longer required.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // modify and reset the ticks until next adjustment. 262 // modify and reset the ticks until next adjustment.
257 if (sampler_threshold_ > kSamplerThresholdMin) { 263 if (sampler_threshold_ > kSamplerThresholdMin) {
258 sampler_threshold_ -= kSamplerThresholdDelta; 264 sampler_threshold_ -= kSamplerThresholdDelta;
259 sampler_ticks_until_threshold_adjustment_ = 265 sampler_ticks_until_threshold_adjustment_ =
260 kSamplerTicksBetweenThresholdAdjustment; 266 kSamplerTicksBetweenThresholdAdjustment;
261 } 267 }
262 } 268 }
263 } 269 }
264 } 270 }
265 271
266 Code* shared_code = function->shared()->code(); 272 SharedFunctionInfo* shared = function->shared();
273 Code* shared_code = shared->code();
267 if (shared_code->kind() != Code::FUNCTION) continue; 274 if (shared_code->kind() != Code::FUNCTION) continue;
268 275
269 if (function->IsMarkedForLazyRecompilation()) { 276 if (function->IsMarkedForLazyRecompilation()) {
270 int nesting = shared_code->allow_osr_at_loop_nesting_level(); 277 int nesting = shared_code->allow_osr_at_loop_nesting_level();
271 if (nesting == 0) AttemptOnStackReplacement(function); 278 if (nesting == 0) AttemptOnStackReplacement(function);
272 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); 279 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker);
273 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting); 280 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
274 } 281 }
275 282
276 // Do not record non-optimizable functions.
277 if (!function->IsOptimizable()) continue;
278 if (function->shared()->optimization_disabled()) continue;
279
280 // Only record top-level code on top of the execution stack and 283 // Only record top-level code on top of the execution stack and
281 // avoid optimizing excessively large scripts since top-level code 284 // avoid optimizing excessively large scripts since top-level code
282 // will be executed only once. 285 // will be executed only once.
283 const int kMaxToplevelSourceSize = 10 * 1024; 286 const int kMaxToplevelSourceSize = 10 * 1024;
284 if (function->shared()->is_toplevel() 287 if (shared->is_toplevel() &&
285 && (frame_count > 1 288 (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) {
286 || function->shared()->SourceSize() > kMaxToplevelSourceSize)) {
287 continue; 289 continue;
288 } 290 }
289 291
292 // Do not record non-optimizable functions.
293 if (shared->optimization_disabled()) {
294 if (shared->opt_count() >= Compiler::kDefaultMaxOptCount) {
295 // If optimization was disabled due to many deoptimizations,
296 // then check if the function is hot and try to reenable optimization.
297 int ticks = shared_code->profiler_ticks();
298 if (ticks >= kProfilerTicksBeforeReenablingOptimization) {
299 shared_code->set_profiler_ticks(0);
300 shared->TryReenableOptimization();
301 } else {
302 shared_code->set_profiler_ticks(ticks + 1);
303 }
304 }
305 continue;
306 }
307 if (!function->IsOptimizable()) continue;
308
290 if (FLAG_watch_ic_patching) { 309 if (FLAG_watch_ic_patching) {
291 int ticks = shared_code->profiler_ticks(); 310 int ticks = shared_code->profiler_ticks();
292 311
293 if (ticks >= kProfilerTicksBeforeOptimization) { 312 if (ticks >= kProfilerTicksBeforeOptimization) {
294 int typeinfo, total, percentage; 313 int typeinfo, total, percentage;
295 GetICCounts(function, &typeinfo, &total, &percentage); 314 GetICCounts(function, &typeinfo, &total, &percentage);
296 if (percentage >= FLAG_type_info_threshold) { 315 if (percentage >= FLAG_type_info_threshold) {
297 // If this particular function hasn't had any ICs patched for enough 316 // If this particular function hasn't had any ICs patched for enough
298 // ticks, optimize it now. 317 // ticks, optimize it now.
299 Optimize(function, "hot and stable"); 318 Optimize(function, "hot and stable");
300 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { 319 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
301 Optimize(function, "not much type info but very hot"); 320 Optimize(function, "not much type info but very hot");
302 } else { 321 } else {
303 shared_code->set_profiler_ticks(ticks + 1); 322 shared_code->set_profiler_ticks(ticks + 1);
304 if (FLAG_trace_opt_verbose) { 323 if (FLAG_trace_opt_verbose) {
305 PrintF("[not yet optimizing "); 324 PrintF("[not yet optimizing ");
306 function->PrintName(); 325 function->PrintName();
307 PrintF(", not enough type info: %d/%d (%d%%)]\n", 326 PrintF(", not enough type info: %d/%d (%d%%)]\n",
308 typeinfo, total, percentage); 327 typeinfo, total, percentage);
309 } 328 }
310 } 329 }
311 } else if (!any_ic_changed_ && 330 } else if (!any_ic_changed_ &&
312 shared_code->instruction_size() < kMaxSizeEarlyOpt) { 331 shared_code->instruction_size() < kMaxSizeEarlyOpt) {
313 // If no IC was patched since the last tick and this function is very 332 // If no IC was patched since the last tick and this function is very
314 // small, optimistically optimize it now. 333 // small, optimistically optimize it now.
315 Optimize(function, "small function"); 334 Optimize(function, "small function");
316 } else { 335 } else {
317 shared_code->set_profiler_ticks(ticks + 1); 336 shared_code->set_profiler_ticks(ticks + 1);
318 } 337 }
319 } else { // !FLAG_watch_ic_patching 338 } else { // !FLAG_watch_ic_patching
320 samples[sample_count++] = function; 339 samples[sample_count++] = function;
321 340
322 int function_size = function->shared()->SourceSize(); 341 int function_size = shared->SourceSize();
323 int threshold_size_factor = (function_size > kSizeLimit) 342 int threshold_size_factor = (function_size > kSizeLimit)
324 ? sampler_threshold_size_factor_ 343 ? sampler_threshold_size_factor_
325 : 1; 344 : 1;
326 345
327 int threshold = sampler_threshold_ * threshold_size_factor; 346 int threshold = sampler_threshold_ * threshold_size_factor;
328 347
329 if (LookupSample(function) >= threshold) { 348 if (LookupSample(function) >= threshold) {
330 Optimize(function, "sampler window lookup"); 349 Optimize(function, "sampler window lookup");
331 } 350 }
332 } 351 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 483
465 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { 484 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
466 if (!RuntimeProfiler::IsSomeIsolateInJS()) { 485 if (!RuntimeProfiler::IsSomeIsolateInJS()) {
467 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); 486 return RuntimeProfiler::WaitForSomeIsolateToEnterJS();
468 } 487 }
469 return false; 488 return false;
470 } 489 }
471 490
472 491
473 } } // namespace v8::internal 492 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698