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

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

Issue 9866030: Move profiler_ticks to Code object, don't walk the stack when patching ICs (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 8 years, 9 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/runtime.cc ('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 a function does not have enough type info (according to
69 // FLAG_type_info_threshold), but has seen a huge number of ticks,
70 // optimize it as it is.
71 static const int kTicksWhenNotEnoughTypeInfo = 100;
72 // We only have one byte to store the number of ticks.
73 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256);
68 74
69 // 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
70 // the very first time it is seen on the stack. 76 // the very first time it is seen on the stack.
71 static const int kMaxSizeEarlyOpt = 500; 77 static const int kMaxSizeEarlyOpt = 500;
72 78
73 79
74 Atomic32 RuntimeProfiler::state_ = 0; 80 Atomic32 RuntimeProfiler::state_ = 0;
75 81
76 // 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.
77 static LazySemaphore<0>::type semaphore = LAZY_SEMAPHORE_INITIALIZER; 83 static LazySemaphore<0>::type semaphore = LAZY_SEMAPHORE_INITIALIZER;
(...skipping 20 matching lines...) Expand all
98 void RuntimeProfiler::GlobalSetup() { 104 void RuntimeProfiler::GlobalSetup() {
99 ASSERT(!has_been_globally_set_up_); 105 ASSERT(!has_been_globally_set_up_);
100 enabled_ = V8::UseCrankshaft() && FLAG_opt; 106 enabled_ = V8::UseCrankshaft() && FLAG_opt;
101 #ifdef DEBUG 107 #ifdef DEBUG
102 has_been_globally_set_up_ = true; 108 has_been_globally_set_up_ = true;
103 #endif 109 #endif
104 } 110 }
105 111
106 112
107 static void GetICCounts(JSFunction* function, 113 static void GetICCounts(JSFunction* function,
108 int* ic_with_typeinfo_count, 114 int* ic_with_type_info_count,
109 int* ic_total_count, 115 int* ic_total_count,
110 int* percentage) { 116 int* percentage) {
111 *ic_total_count = 0; 117 *ic_total_count = 0;
112 *ic_with_typeinfo_count = 0; 118 *ic_with_type_info_count = 0;
113 Object* raw_info = 119 Object* raw_info =
114 function->shared()->code()->type_feedback_info(); 120 function->shared()->code()->type_feedback_info();
115 if (raw_info->IsTypeFeedbackInfo()) { 121 if (raw_info->IsTypeFeedbackInfo()) {
116 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); 122 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info);
117 *ic_with_typeinfo_count = info->ic_with_typeinfo_count(); 123 *ic_with_type_info_count = info->ic_with_type_info_count();
118 *ic_total_count = info->ic_total_count(); 124 *ic_total_count = info->ic_total_count();
119 } 125 }
120 *percentage = *ic_total_count > 0 126 *percentage = *ic_total_count > 0
121 ? 100 * *ic_with_typeinfo_count / *ic_total_count 127 ? 100 * *ic_with_type_info_count / *ic_total_count
122 : 100; 128 : 100;
123 } 129 }
124 130
125 131
126 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { 132 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
127 ASSERT(function->IsOptimizable()); 133 ASSERT(function->IsOptimizable());
128 if (FLAG_trace_opt) { 134 if (FLAG_trace_opt) {
129 PrintF("[marking "); 135 PrintF("[marking ");
130 function->PrintName(); 136 function->PrintName();
131 PrintF(" 0x%" V8PRIxPTR, reinterpret_cast<intptr_t>(function->address())); 137 PrintF(" 0x%" V8PRIxPTR, reinterpret_cast<intptr_t>(function->address()));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // modify and reset the ticks until next adjustment. 260 // modify and reset the ticks until next adjustment.
255 if (sampler_threshold_ > kSamplerThresholdMin) { 261 if (sampler_threshold_ > kSamplerThresholdMin) {
256 sampler_threshold_ -= kSamplerThresholdDelta; 262 sampler_threshold_ -= kSamplerThresholdDelta;
257 sampler_ticks_until_threshold_adjustment_ = 263 sampler_ticks_until_threshold_adjustment_ =
258 kSamplerTicksBetweenThresholdAdjustment; 264 kSamplerTicksBetweenThresholdAdjustment;
259 } 265 }
260 } 266 }
261 } 267 }
262 } 268 }
263 269
264 if (function->IsMarkedForLazyRecompilation() && 270 Code* shared_code = function->shared()->code();
265 function->shared()->code()->kind() == Code::FUNCTION) { 271 if (shared_code->kind() != Code::FUNCTION) continue;
266 Code* unoptimized = function->shared()->code(); 272
267 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); 273 if (function->IsMarkedForLazyRecompilation()) {
274 int nesting = shared_code->allow_osr_at_loop_nesting_level();
268 if (nesting == 0) AttemptOnStackReplacement(function); 275 if (nesting == 0) AttemptOnStackReplacement(function);
269 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); 276 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker);
270 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); 277 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
271 } 278 }
272 279
273 // Do not record non-optimizable functions. 280 // Do not record non-optimizable functions.
274 if (!function->IsOptimizable()) continue; 281 if (!function->IsOptimizable()) continue;
275 if (function->shared()->optimization_disabled()) continue; 282 if (function->shared()->optimization_disabled()) continue;
276 283
277 // Only record top-level code on top of the execution stack and 284 // Only record top-level code on top of the execution stack and
278 // avoid optimizing excessively large scripts since top-level code 285 // avoid optimizing excessively large scripts since top-level code
279 // will be executed only once. 286 // will be executed only once.
280 const int kMaxToplevelSourceSize = 10 * 1024; 287 const int kMaxToplevelSourceSize = 10 * 1024;
281 if (function->shared()->is_toplevel() 288 if (function->shared()->is_toplevel()
282 && (frame_count > 1 289 && (frame_count > 1
283 || function->shared()->SourceSize() > kMaxToplevelSourceSize)) { 290 || function->shared()->SourceSize() > kMaxToplevelSourceSize)) {
284 continue; 291 continue;
285 } 292 }
286 293
287 if (FLAG_watch_ic_patching) { 294 if (FLAG_watch_ic_patching) {
288 int ticks = function->shared()->profiler_ticks(); 295 int ticks = shared_code->profiler_ticks();
289 296
290 if (ticks >= kProfilerTicksBeforeOptimization) { 297 if (ticks >= kProfilerTicksBeforeOptimization) {
291 int typeinfo, total, percentage; 298 int typeinfo, total, percentage;
292 GetICCounts(function, &typeinfo, &total, &percentage); 299 GetICCounts(function, &typeinfo, &total, &percentage);
293 if (percentage >= FLAG_type_info_threshold) { 300 if (percentage >= FLAG_type_info_threshold) {
294 // If this particular function hasn't had any ICs patched for enough 301 // If this particular function hasn't had any ICs patched for enough
295 // ticks, optimize it now. 302 // ticks, optimize it now.
296 Optimize(function, "hot and stable"); 303 Optimize(function, "hot and stable");
297 } else if (ticks >= 100) { 304 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
298 // If this function does not have enough type info, but has
299 // seen a huge number of ticks, optimize it as it is.
300 Optimize(function, "not much type info but very hot"); 305 Optimize(function, "not much type info but very hot");
301 } else { 306 } else {
302 function->shared()->set_profiler_ticks(ticks + 1); 307 shared_code->set_profiler_ticks(ticks + 1);
303 if (FLAG_trace_opt_verbose) { 308 if (FLAG_trace_opt_verbose) {
304 PrintF("[not yet optimizing "); 309 PrintF("[not yet optimizing ");
305 function->PrintName(); 310 function->PrintName();
306 PrintF(", not enough type info: %d/%d (%d%%)]\n", 311 PrintF(", not enough type info: %d/%d (%d%%)]\n",
307 typeinfo, total, percentage); 312 typeinfo, total, percentage);
308 } 313 }
309 } 314 }
310 } else if (!any_ic_changed_ && 315 } else if (!any_ic_changed_ &&
311 function->shared()->code()->instruction_size() < kMaxSizeEarlyOpt) { 316 shared_code->instruction_size() < kMaxSizeEarlyOpt) {
312 // If no IC was patched since the last tick and this function is very 317 // If no IC was patched since the last tick and this function is very
313 // small, optimistically optimize it now. 318 // small, optimistically optimize it now.
314 Optimize(function, "small function"); 319 Optimize(function, "small function");
315 } else if (!code_generated_ && 320 } else if (!code_generated_ &&
316 !any_ic_changed_ && 321 !any_ic_changed_ &&
317 total_code_generated_ > 0 && 322 total_code_generated_ > 0 &&
318 total_code_generated_ < 2000) { 323 total_code_generated_ < 2000) {
319 // If no code was generated and no IC was patched since the last tick, 324 // If no code was generated and no IC was patched since the last tick,
320 // but a little code has already been generated since last Reset(), 325 // but a little code has already been generated since last Reset(),
321 // then type info might already be stable and we can optimize now. 326 // then type info might already be stable and we can optimize now.
322 Optimize(function, "stable on startup"); 327 Optimize(function, "stable on startup");
323 } else { 328 } else {
324 function->shared()->set_profiler_ticks(ticks + 1); 329 shared_code->set_profiler_ticks(ticks + 1);
325 } 330 }
326 } else { // !FLAG_watch_ic_patching 331 } else { // !FLAG_watch_ic_patching
327 samples[sample_count++] = function; 332 samples[sample_count++] = function;
328 333
329 int function_size = function->shared()->SourceSize(); 334 int function_size = function->shared()->SourceSize();
330 int threshold_size_factor = (function_size > kSizeLimit) 335 int threshold_size_factor = (function_size > kSizeLimit)
331 ? sampler_threshold_size_factor_ 336 ? sampler_threshold_size_factor_
332 : 1; 337 : 1;
333 338
334 int threshold = sampler_threshold_ * threshold_size_factor; 339 int threshold = sampler_threshold_ * threshold_size_factor;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 483
479 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { 484 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
480 if (!RuntimeProfiler::IsSomeIsolateInJS()) { 485 if (!RuntimeProfiler::IsSomeIsolateInJS()) {
481 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); 486 return RuntimeProfiler::WaitForSomeIsolateToEnterJS();
482 } 487 }
483 return false; 488 return false;
484 } 489 }
485 490
486 491
487 } } // namespace v8::internal 492 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698