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

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

Issue 159783002: Re-optimize faster after making a pretenuring decision. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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') | test/cctest/test-deoptimization.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "runtime-profiler.h" 7 #include "runtime-profiler.h"
8 8
9 #include "assembler.h" 9 #include "assembler.h"
10 #include "bootstrapper.h" 10 #include "bootstrapper.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 static const int kMaxSizeEarlyOpt = 50 static const int kMaxSizeEarlyOpt =
51 5 * FullCodeGenerator::kCodeSizeMultiplier; 51 5 * FullCodeGenerator::kCodeSizeMultiplier;
52 52
53 53
54 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) 54 RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
55 : isolate_(isolate), 55 : isolate_(isolate),
56 any_ic_changed_(false) { 56 any_ic_changed_(false) {
57 } 57 }
58 58
59 59
60 static void GetICCounts(Code* shared_code,
61 int* ic_with_type_info_count,
62 int* ic_total_count,
63 int* percentage) {
64 *ic_total_count = 0;
65 *ic_with_type_info_count = 0;
66 Object* raw_info = shared_code->type_feedback_info();
67 if (raw_info->IsTypeFeedbackInfo()) {
68 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info);
69 *ic_with_type_info_count = info->ic_with_type_info_count();
70 *ic_total_count = info->ic_total_count();
71 }
72 *percentage = *ic_total_count > 0
73 ? 100 * *ic_with_type_info_count / *ic_total_count
74 : 100;
75 }
76
77
78 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
79 ASSERT(function->IsOptimizable());
80
81 if (FLAG_trace_opt && function->PassesFilter(FLAG_hydrogen_filter)) {
82 PrintF("[marking ");
83 function->ShortPrint();
84 PrintF(" for recompilation, reason: %s", reason);
85 if (FLAG_type_info_threshold > 0) {
86 int typeinfo, total, percentage;
87 GetICCounts(function->shared()->code(), &typeinfo, &total, &percentage);
88 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, percentage);
89 }
90 PrintF("]\n");
91 }
92
93
94 if (isolate_->concurrent_recompilation_enabled() &&
95 !isolate_->bootstrapper()->IsActive()) {
96 if (isolate_->concurrent_osr_enabled() &&
97 isolate_->optimizing_compiler_thread()->IsQueuedForOSR(function)) {
98 // Do not attempt regular recompilation if we already queued this for OSR.
99 // TODO(yangguo): This is necessary so that we don't install optimized
100 // code on a function that is already optimized, since OSR and regular
101 // recompilation race. This goes away as soon as OSR becomes one-shot.
102 return;
103 }
104 ASSERT(!function->IsInOptimizationQueue());
105 function->MarkForConcurrentOptimization();
106 } else {
107 // The next call to the function will trigger optimization.
108 function->MarkForOptimization();
109 }
110 }
111
112
113 void RuntimeProfiler::AttemptOnStackReplacement(JSFunction* function) { 60 void RuntimeProfiler::AttemptOnStackReplacement(JSFunction* function) {
114 // See AlwaysFullCompiler (in compiler.cc) comment on why we need 61 // See AlwaysFullCompiler (in compiler.cc) comment on why we need
115 // Debug::has_break_points(). 62 // Debug::has_break_points().
116 if (!FLAG_use_osr || 63 if (!FLAG_use_osr ||
117 isolate_->DebuggerHasBreakPoints() || 64 isolate_->DebuggerHasBreakPoints() ||
118 function->IsBuiltin()) { 65 function->IsBuiltin()) {
119 return; 66 return;
120 } 67 }
121 68
122 SharedFunctionInfo* shared = function->shared(); 69 SharedFunctionInfo* shared = function->shared();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 176 }
230 } 177 }
231 continue; 178 continue;
232 } 179 }
233 if (!function->IsOptimizable()) continue; 180 if (!function->IsOptimizable()) continue;
234 181
235 int ticks = shared_code->profiler_ticks(); 182 int ticks = shared_code->profiler_ticks();
236 183
237 if (ticks >= kProfilerTicksBeforeOptimization) { 184 if (ticks >= kProfilerTicksBeforeOptimization) {
238 int typeinfo, total, percentage; 185 int typeinfo, total, percentage;
239 GetICCounts(shared_code, &typeinfo, &total, &percentage); 186 shared_code->GetICCounts(&typeinfo, &total, &percentage);
240 if (percentage >= FLAG_type_info_threshold) { 187 if (percentage >= FLAG_type_info_threshold) {
241 // If this particular function hasn't had any ICs patched for enough 188 // If this particular function hasn't had any ICs patched for enough
242 // ticks, optimize it now. 189 // ticks, optimize it now.
243 Optimize(function, "hot and stable"); 190 Compiler::Optimize(function, "hot and stable");
244 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { 191 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
245 Optimize(function, "not much type info but very hot"); 192 Compiler::Optimize(function, "not much type info but very hot");
246 } else { 193 } else {
247 shared_code->set_profiler_ticks(ticks + 1); 194 shared_code->set_profiler_ticks(ticks + 1);
248 if (FLAG_trace_opt_verbose) { 195 if (FLAG_trace_opt_verbose) {
249 PrintF("[not yet optimizing "); 196 PrintF("[not yet optimizing ");
250 function->PrintName(); 197 function->PrintName();
251 PrintF(", not enough type info: %d/%d (%d%%)]\n", 198 PrintF(", not enough type info: %d/%d (%d%%)]\n",
252 typeinfo, total, percentage); 199 typeinfo, total, percentage);
253 } 200 }
254 } 201 }
255 } else if (!any_ic_changed_ && 202 } else if (!any_ic_changed_ &&
256 shared_code->instruction_size() < kMaxSizeEarlyOpt) { 203 shared_code->instruction_size() < kMaxSizeEarlyOpt) {
257 // If no IC was patched since the last tick and this function is very 204 // If no IC was patched since the last tick and this function is very
258 // small, optimistically optimize it now. 205 // small, optimistically optimize it now.
259 Optimize(function, "small function"); 206 Compiler::Optimize(function, "small function");
260 } else { 207 } else {
261 shared_code->set_profiler_ticks(ticks + 1); 208 shared_code->set_profiler_ticks(ticks + 1);
262 } 209 }
263 } 210 }
264 any_ic_changed_ = false; 211 any_ic_changed_ = false;
265 } 212 }
266 213
267 214
268 } } // namespace v8::internal 215 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime-profiler.h ('k') | test/cctest/test-deoptimization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698