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

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

Issue 17162002: Version 3.19.17. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 7 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/runtime-profiler.h ('k') | src/sampler.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 static const int kProfilerTicksBeforeReenablingOptimization = 250; 73 static const int kProfilerTicksBeforeReenablingOptimization = 250;
74 // If a function does not have enough type info (according to 74 // If a function does not have enough type info (according to
75 // FLAG_type_info_threshold), but has seen a huge number of ticks, 75 // FLAG_type_info_threshold), but has seen a huge number of ticks,
76 // optimize it as it is. 76 // optimize it as it is.
77 static const int kTicksWhenNotEnoughTypeInfo = 100; 77 static const int kTicksWhenNotEnoughTypeInfo = 100;
78 // We only have one byte to store the number of ticks. 78 // We only have one byte to store the number of ticks.
79 STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256); 79 STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256);
80 STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256); 80 STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256);
81 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); 81 STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256);
82 82
83 // Maximum size in bytes of generate code for a function to allow OSR.
84 static const int kOSRCodeSizeAllowanceBase =
85 100 * FullCodeGenerator::kCodeSizeMultiplier;
86
87 static const int kOSRCodeSizeAllowancePerTick =
88 3 * FullCodeGenerator::kCodeSizeMultiplier;
89 83
90 // Maximum size in bytes of generated code for a function to be optimized 84 // Maximum size in bytes of generated code for a function to be optimized
91 // the very first time it is seen on the stack. 85 // the very first time it is seen on the stack.
92 static const int kMaxSizeEarlyOpt = 86 static const int kMaxSizeEarlyOpt =
93 5 * FullCodeGenerator::kCodeSizeMultiplier; 87 5 * FullCodeGenerator::kBackEdgeDistanceUnit;
94 88
95 89
96 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) 90 RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
97 : isolate_(isolate), 91 : isolate_(isolate),
98 sampler_threshold_(kSamplerThresholdInit), 92 sampler_threshold_(kSamplerThresholdInit),
99 sampler_threshold_size_factor_(kSamplerThresholdSizeFactorInit), 93 sampler_threshold_size_factor_(kSamplerThresholdSizeFactorInit),
100 sampler_ticks_until_threshold_adjustment_( 94 sampler_ticks_until_threshold_adjustment_(
101 kSamplerTicksBetweenThresholdAdjustment), 95 kSamplerTicksBetweenThresholdAdjustment),
102 sampler_window_position_(0), 96 sampler_window_position_(0),
103 any_ic_changed_(false), 97 any_ic_changed_(false),
104 code_generated_(false) { 98 code_generated_(false) {
105 ClearSampleBuffer(); 99 ClearSampleBuffer();
106 } 100 }
107 101
108 102
109 static void GetICCounts(Code* shared_code, 103 static void GetICCounts(JSFunction* function,
110 int* ic_with_type_info_count, 104 int* ic_with_type_info_count,
111 int* ic_total_count, 105 int* ic_total_count,
112 int* percentage) { 106 int* percentage) {
113 *ic_total_count = 0; 107 *ic_total_count = 0;
114 *ic_with_type_info_count = 0; 108 *ic_with_type_info_count = 0;
115 Object* raw_info = shared_code->type_feedback_info(); 109 Object* raw_info =
110 function->shared()->code()->type_feedback_info();
116 if (raw_info->IsTypeFeedbackInfo()) { 111 if (raw_info->IsTypeFeedbackInfo()) {
117 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); 112 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info);
118 *ic_with_type_info_count = info->ic_with_type_info_count(); 113 *ic_with_type_info_count = info->ic_with_type_info_count();
119 *ic_total_count = info->ic_total_count(); 114 *ic_total_count = info->ic_total_count();
120 } 115 }
121 *percentage = *ic_total_count > 0 116 *percentage = *ic_total_count > 0
122 ? 100 * *ic_with_type_info_count / *ic_total_count 117 ? 100 * *ic_with_type_info_count / *ic_total_count
123 : 100; 118 : 100;
124 } 119 }
125 120
126 121
127 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { 122 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
128 ASSERT(function->IsOptimizable()); 123 ASSERT(function->IsOptimizable());
129 124
130 if (FLAG_trace_opt && function->PassesHydrogenFilter()) { 125 if (FLAG_trace_opt && function->PassesHydrogenFilter()) {
131 PrintF("[marking "); 126 PrintF("[marking ");
132 function->ShortPrint(); 127 function->ShortPrint();
133 PrintF(" for recompilation, reason: %s", reason); 128 PrintF(" for recompilation, reason: %s", reason);
134 if (FLAG_type_info_threshold > 0) { 129 if (FLAG_type_info_threshold > 0) {
135 int typeinfo, total, percentage; 130 int typeinfo, total, percentage;
136 GetICCounts(function->shared()->code(), &typeinfo, &total, &percentage); 131 GetICCounts(function, &typeinfo, &total, &percentage);
137 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, percentage); 132 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, percentage);
138 } 133 }
139 PrintF("]\n"); 134 PrintF("]\n");
140 } 135 }
141 136
142 if (FLAG_parallel_recompilation && !isolate_->bootstrapper()->IsActive()) { 137 if (FLAG_parallel_recompilation && !isolate_->bootstrapper()->IsActive()) {
143 ASSERT(!function->IsMarkedForInstallingRecompiledCode()); 138 ASSERT(!function->IsMarkedForInstallingRecompiledCode());
144 ASSERT(!function->IsInRecompileQueue()); 139 ASSERT(!function->IsInRecompileQueue());
145 function->MarkForParallelRecompilation(); 140 function->MarkForParallelRecompilation();
146 } else { 141 } else {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 267
273 if (shared_code->kind() != Code::FUNCTION) continue; 268 if (shared_code->kind() != Code::FUNCTION) continue;
274 if (function->IsInRecompileQueue()) continue; 269 if (function->IsInRecompileQueue()) continue;
275 270
276 // Attempt OSR if we are still running unoptimized code even though the 271 // Attempt OSR if we are still running unoptimized code even though the
277 // the function has long been marked or even already been optimized. 272 // the function has long been marked or even already been optimized.
278 if (!frame->is_optimized() && 273 if (!frame->is_optimized() &&
279 (function->IsMarkedForLazyRecompilation() || 274 (function->IsMarkedForLazyRecompilation() ||
280 function->IsMarkedForParallelRecompilation() || 275 function->IsMarkedForParallelRecompilation() ||
281 function->IsOptimized())) { 276 function->IsOptimized())) {
282 int ticks = shared_code->profiler_ticks(); 277 int nesting = shared_code->allow_osr_at_loop_nesting_level();
283 int allowance = kOSRCodeSizeAllowanceBase + 278 if (nesting < Code::kMaxLoopNestingMarker) {
284 ticks * kOSRCodeSizeAllowancePerTick; 279 int new_nesting = nesting + 1;
285 if (shared_code->CodeSize() > allowance) { 280 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
286 if (ticks < 255) shared_code->set_profiler_ticks(ticks + 1); 281 AttemptOnStackReplacement(function);
287 } else {
288 int nesting = shared_code->allow_osr_at_loop_nesting_level();
289 if (nesting < Code::kMaxLoopNestingMarker) {
290 int new_nesting = nesting + 1;
291 shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
292 AttemptOnStackReplacement(function);
293 }
294 } 282 }
295 continue;
296 } 283 }
297 284
298 // 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
299 // avoid optimizing excessively large scripts since top-level code 286 // avoid optimizing excessively large scripts since top-level code
300 // will be executed only once. 287 // will be executed only once.
301 const int kMaxToplevelSourceSize = 10 * 1024; 288 const int kMaxToplevelSourceSize = 10 * 1024;
302 if (shared->is_toplevel() && 289 if (shared->is_toplevel() &&
303 (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) { 290 (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) {
304 continue; 291 continue;
305 } 292 }
(...skipping 13 matching lines...) Expand all
319 } 306 }
320 continue; 307 continue;
321 } 308 }
322 if (!function->IsOptimizable()) continue; 309 if (!function->IsOptimizable()) continue;
323 310
324 if (FLAG_watch_ic_patching) { 311 if (FLAG_watch_ic_patching) {
325 int ticks = shared_code->profiler_ticks(); 312 int ticks = shared_code->profiler_ticks();
326 313
327 if (ticks >= kProfilerTicksBeforeOptimization) { 314 if (ticks >= kProfilerTicksBeforeOptimization) {
328 int typeinfo, total, percentage; 315 int typeinfo, total, percentage;
329 GetICCounts(shared_code, &typeinfo, &total, &percentage); 316 GetICCounts(function, &typeinfo, &total, &percentage);
330 if (percentage >= FLAG_type_info_threshold) { 317 if (percentage >= FLAG_type_info_threshold) {
331 // If this particular function hasn't had any ICs patched for enough 318 // If this particular function hasn't had any ICs patched for enough
332 // ticks, optimize it now. 319 // ticks, optimize it now.
333 Optimize(function, "hot and stable"); 320 Optimize(function, "hot and stable");
334 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { 321 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
335 Optimize(function, "not much type info but very hot"); 322 Optimize(function, "not much type info but very hot");
336 } else { 323 } else {
337 shared_code->set_profiler_ticks(ticks + 1); 324 shared_code->set_profiler_ticks(ticks + 1);
338 if (FLAG_trace_opt_verbose) { 325 if (FLAG_trace_opt_verbose) {
339 PrintF("[not yet optimizing "); 326 PrintF("[not yet optimizing ");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 420
434 421
435 void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) { 422 void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) {
436 for (int i = 0; i < kSamplerWindowSize; i++) { 423 for (int i = 0; i < kSamplerWindowSize; i++) {
437 visitor->VisitPointer(&sampler_window_[i]); 424 visitor->VisitPointer(&sampler_window_[i]);
438 } 425 }
439 } 426 }
440 427
441 428
442 } } // namespace v8::internal 429 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime-profiler.h ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698