OLD | NEW |
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 Loading... |
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; | |
72 // If a function does not have enough type info (according to | 68 // If a function does not have enough type info (according to |
73 // FLAG_type_info_threshold), but has seen a huge number of ticks, | 69 // FLAG_type_info_threshold), but has seen a huge number of ticks, |
74 // optimize it as it is. | 70 // optimize it as it is. |
75 static const int kTicksWhenNotEnoughTypeInfo = 100; | 71 static const int kTicksWhenNotEnoughTypeInfo = 100; |
76 // We only have one byte to store the number of ticks. | 72 // We only have one byte to store the number of ticks. |
77 STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256); | |
78 STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256); | |
79 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); | 73 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); |
80 | 74 |
81 // Maximum size in bytes of generated code for a function to be optimized | 75 // Maximum size in bytes of generated code for a function to be optimized |
82 // the very first time it is seen on the stack. | 76 // the very first time it is seen on the stack. |
83 static const int kMaxSizeEarlyOpt = 500; | 77 static const int kMaxSizeEarlyOpt = 500; |
84 | 78 |
85 | 79 |
86 Atomic32 RuntimeProfiler::state_ = 0; | 80 Atomic32 RuntimeProfiler::state_ = 0; |
87 | 81 |
88 // TODO(isolates): Clean up the semaphore when it is no longer required. | 82 // TODO(isolates): Clean up the semaphore when it is no longer required. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // modify and reset the ticks until next adjustment. | 256 // modify and reset the ticks until next adjustment. |
263 if (sampler_threshold_ > kSamplerThresholdMin) { | 257 if (sampler_threshold_ > kSamplerThresholdMin) { |
264 sampler_threshold_ -= kSamplerThresholdDelta; | 258 sampler_threshold_ -= kSamplerThresholdDelta; |
265 sampler_ticks_until_threshold_adjustment_ = | 259 sampler_ticks_until_threshold_adjustment_ = |
266 kSamplerTicksBetweenThresholdAdjustment; | 260 kSamplerTicksBetweenThresholdAdjustment; |
267 } | 261 } |
268 } | 262 } |
269 } | 263 } |
270 } | 264 } |
271 | 265 |
272 SharedFunctionInfo* shared = function->shared(); | 266 Code* shared_code = function->shared()->code(); |
273 Code* shared_code = shared->code(); | |
274 if (shared_code->kind() != Code::FUNCTION) continue; | 267 if (shared_code->kind() != Code::FUNCTION) continue; |
275 | 268 |
276 if (function->IsMarkedForLazyRecompilation()) { | 269 if (function->IsMarkedForLazyRecompilation()) { |
277 int nesting = shared_code->allow_osr_at_loop_nesting_level(); | 270 int nesting = shared_code->allow_osr_at_loop_nesting_level(); |
278 if (nesting == 0) AttemptOnStackReplacement(function); | 271 if (nesting == 0) AttemptOnStackReplacement(function); |
279 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); | 272 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); |
280 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting); | 273 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting); |
281 } | 274 } |
282 | 275 |
| 276 // Do not record non-optimizable functions. |
| 277 if (!function->IsOptimizable()) continue; |
| 278 if (function->shared()->optimization_disabled()) continue; |
| 279 |
283 // Only record top-level code on top of the execution stack and | 280 // Only record top-level code on top of the execution stack and |
284 // avoid optimizing excessively large scripts since top-level code | 281 // avoid optimizing excessively large scripts since top-level code |
285 // will be executed only once. | 282 // will be executed only once. |
286 const int kMaxToplevelSourceSize = 10 * 1024; | 283 const int kMaxToplevelSourceSize = 10 * 1024; |
287 if (shared->is_toplevel() && | 284 if (function->shared()->is_toplevel() |
288 (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) { | 285 && (frame_count > 1 |
| 286 || function->shared()->SourceSize() > kMaxToplevelSourceSize)) { |
289 continue; | 287 continue; |
290 } | 288 } |
291 | 289 |
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 | |
309 if (FLAG_watch_ic_patching) { | 290 if (FLAG_watch_ic_patching) { |
310 int ticks = shared_code->profiler_ticks(); | 291 int ticks = shared_code->profiler_ticks(); |
311 | 292 |
312 if (ticks >= kProfilerTicksBeforeOptimization) { | 293 if (ticks >= kProfilerTicksBeforeOptimization) { |
313 int typeinfo, total, percentage; | 294 int typeinfo, total, percentage; |
314 GetICCounts(function, &typeinfo, &total, &percentage); | 295 GetICCounts(function, &typeinfo, &total, &percentage); |
315 if (percentage >= FLAG_type_info_threshold) { | 296 if (percentage >= FLAG_type_info_threshold) { |
316 // If this particular function hasn't had any ICs patched for enough | 297 // If this particular function hasn't had any ICs patched for enough |
317 // ticks, optimize it now. | 298 // ticks, optimize it now. |
318 Optimize(function, "hot and stable"); | 299 Optimize(function, "hot and stable"); |
319 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { | 300 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { |
320 Optimize(function, "not much type info but very hot"); | 301 Optimize(function, "not much type info but very hot"); |
321 } else { | 302 } else { |
322 shared_code->set_profiler_ticks(ticks + 1); | 303 shared_code->set_profiler_ticks(ticks + 1); |
323 if (FLAG_trace_opt_verbose) { | 304 if (FLAG_trace_opt_verbose) { |
324 PrintF("[not yet optimizing "); | 305 PrintF("[not yet optimizing "); |
325 function->PrintName(); | 306 function->PrintName(); |
326 PrintF(", not enough type info: %d/%d (%d%%)]\n", | 307 PrintF(", not enough type info: %d/%d (%d%%)]\n", |
327 typeinfo, total, percentage); | 308 typeinfo, total, percentage); |
328 } | 309 } |
329 } | 310 } |
330 } else if (!any_ic_changed_ && | 311 } else if (!any_ic_changed_ && |
331 shared_code->instruction_size() < kMaxSizeEarlyOpt) { | 312 shared_code->instruction_size() < kMaxSizeEarlyOpt) { |
332 // If no IC was patched since the last tick and this function is very | 313 // If no IC was patched since the last tick and this function is very |
333 // small, optimistically optimize it now. | 314 // small, optimistically optimize it now. |
334 Optimize(function, "small function"); | 315 Optimize(function, "small function"); |
335 } else { | 316 } else { |
336 shared_code->set_profiler_ticks(ticks + 1); | 317 shared_code->set_profiler_ticks(ticks + 1); |
337 } | 318 } |
338 } else { // !FLAG_watch_ic_patching | 319 } else { // !FLAG_watch_ic_patching |
339 samples[sample_count++] = function; | 320 samples[sample_count++] = function; |
340 | 321 |
341 int function_size = shared->SourceSize(); | 322 int function_size = function->shared()->SourceSize(); |
342 int threshold_size_factor = (function_size > kSizeLimit) | 323 int threshold_size_factor = (function_size > kSizeLimit) |
343 ? sampler_threshold_size_factor_ | 324 ? sampler_threshold_size_factor_ |
344 : 1; | 325 : 1; |
345 | 326 |
346 int threshold = sampler_threshold_ * threshold_size_factor; | 327 int threshold = sampler_threshold_ * threshold_size_factor; |
347 | 328 |
348 if (LookupSample(function) >= threshold) { | 329 if (LookupSample(function) >= threshold) { |
349 Optimize(function, "sampler window lookup"); | 330 Optimize(function, "sampler window lookup"); |
350 } | 331 } |
351 } | 332 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 464 |
484 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { | 465 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { |
485 if (!RuntimeProfiler::IsSomeIsolateInJS()) { | 466 if (!RuntimeProfiler::IsSomeIsolateInJS()) { |
486 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); | 467 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); |
487 } | 468 } |
488 return false; | 469 return false; |
489 } | 470 } |
490 | 471 |
491 | 472 |
492 } } // namespace v8::internal | 473 } } // namespace v8::internal |
OLD | NEW |