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

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

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

Powered by Google App Engine
This is Rietveld 408576698