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

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

Issue 10534063: Reland r11425 "Re-enable optimization for hot functions that have optimization disabled due to many… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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
81
75 // Maximum size in bytes of generated code for a function to be optimized 82 // Maximum size in bytes of generated code for a function to be optimized
76 // the very first time it is seen on the stack. 83 // the very first time it is seen on the stack.
77 static const int kMaxSizeEarlyOpt = 500; 84 static const int kMaxSizeEarlyOpt = 500;
78 85
79 86
80 Atomic32 RuntimeProfiler::state_ = 0; 87 Atomic32 RuntimeProfiler::state_ = 0;
81 88
82 // TODO(isolates): Clean up the semaphore when it is no longer required. 89 // TODO(isolates): Clean up the semaphore when it is no longer required.
83 static LazySemaphore<0>::type semaphore = LAZY_SEMAPHORE_INITIALIZER; 90 static LazySemaphore<0>::type semaphore = LAZY_SEMAPHORE_INITIALIZER;
84 91
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // modify and reset the ticks until next adjustment. 263 // modify and reset the ticks until next adjustment.
257 if (sampler_threshold_ > kSamplerThresholdMin) { 264 if (sampler_threshold_ > kSamplerThresholdMin) {
258 sampler_threshold_ -= kSamplerThresholdDelta; 265 sampler_threshold_ -= kSamplerThresholdDelta;
259 sampler_ticks_until_threshold_adjustment_ = 266 sampler_ticks_until_threshold_adjustment_ =
260 kSamplerTicksBetweenThresholdAdjustment; 267 kSamplerTicksBetweenThresholdAdjustment;
261 } 268 }
262 } 269 }
263 } 270 }
264 } 271 }
265 272
266 Code* shared_code = function->shared()->code(); 273 SharedFunctionInfo* shared = function->shared();
274 Code* shared_code = shared->code();
275
267 if (shared_code->kind() != Code::FUNCTION) continue; 276 if (shared_code->kind() != Code::FUNCTION) continue;
268 277
269 if (function->IsMarkedForLazyRecompilation()) { 278 if (function->IsMarkedForLazyRecompilation()) {
270 int nesting = shared_code->allow_osr_at_loop_nesting_level(); 279 int nesting = shared_code->allow_osr_at_loop_nesting_level();
271 if (nesting == 0) AttemptOnStackReplacement(function); 280 if (nesting == 0) AttemptOnStackReplacement(function);
272 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); 281 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker);
273 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting); 282 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
274 } 283 }
275 284
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 285 // Only record top-level code on top of the execution stack and
281 // avoid optimizing excessively large scripts since top-level code 286 // avoid optimizing excessively large scripts since top-level code
282 // will be executed only once. 287 // will be executed only once.
283 const int kMaxToplevelSourceSize = 10 * 1024; 288 const int kMaxToplevelSourceSize = 10 * 1024;
284 if (function->shared()->is_toplevel() 289 if (shared->is_toplevel() &&
285 && (frame_count > 1 290 (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) {
286 || function->shared()->SourceSize() > kMaxToplevelSourceSize)) {
287 continue; 291 continue;
288 } 292 }
289 293
294 // Do not record non-optimizable functions.
295 if (shared->optimization_disabled()) {
296 if (shared->deopt_count() >= Compiler::kDefaultMaxOptCount) {
297 // If optimization was disabled due to many deoptimizations,
298 // then check if the function is hot and try to reenable optimization.
299 int ticks = shared_code->profiler_ticks();
300 if (ticks >= kProfilerTicksBeforeReenablingOptimization) {
301 shared_code->set_profiler_ticks(0);
302 shared->TryReenableOptimization();
303 } else {
304 shared_code->set_profiler_ticks(ticks + 1);
305 }
306 }
307 continue;
308 }
309 if (!function->IsOptimizable()) continue;
310
311
312
290 if (FLAG_watch_ic_patching) { 313 if (FLAG_watch_ic_patching) {
291 int ticks = shared_code->profiler_ticks(); 314 int ticks = shared_code->profiler_ticks();
292 315
293 if (ticks >= kProfilerTicksBeforeOptimization) { 316 if (ticks >= kProfilerTicksBeforeOptimization) {
294 int typeinfo, total, percentage; 317 int typeinfo, total, percentage;
295 GetICCounts(function, &typeinfo, &total, &percentage); 318 GetICCounts(function, &typeinfo, &total, &percentage);
296 if (percentage >= FLAG_type_info_threshold) { 319 if (percentage >= FLAG_type_info_threshold) {
297 // If this particular function hasn't had any ICs patched for enough 320 // If this particular function hasn't had any ICs patched for enough
298 // ticks, optimize it now. 321 // ticks, optimize it now.
299 Optimize(function, "hot and stable"); 322 Optimize(function, "hot and stable");
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 487
465 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { 488 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
466 if (!RuntimeProfiler::IsSomeIsolateInJS()) { 489 if (!RuntimeProfiler::IsSomeIsolateInJS()) {
467 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); 490 return RuntimeProfiler::WaitForSomeIsolateToEnterJS();
468 } 491 }
469 return false; 492 return false;
470 } 493 }
471 494
472 495
473 } } // namespace v8::internal 496 } } // 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