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

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

Issue 1906823002: Move of the type feedback vector to the closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 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
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 "src/runtime-profiler.h" 5 #include "src/runtime-profiler.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/ast/scopeinfo.h" 8 #include "src/ast/scopeinfo.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // the very first time it is seen on the stack. 46 // the very first time it is seen on the stack.
47 static const int kMaxSizeEarlyOpt = 47 static const int kMaxSizeEarlyOpt =
48 5 * FullCodeGenerator::kCodeSizeMultiplier; 48 5 * FullCodeGenerator::kCodeSizeMultiplier;
49 49
50 50
51 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) 51 RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
52 : isolate_(isolate), 52 : isolate_(isolate),
53 any_ic_changed_(false) { 53 any_ic_changed_(false) {
54 } 54 }
55 55
56 56 static void GetICCounts(JSFunction* function, int* ic_with_type_info_count,
57 static void GetICCounts(SharedFunctionInfo* shared, 57 int* ic_generic_count, int* ic_total_count,
58 int* ic_with_type_info_count, int* ic_generic_count, 58 int* type_info_percentage, int* generic_percentage) {
59 int* ic_total_count, int* type_info_percentage,
60 int* generic_percentage) {
61 *ic_total_count = 0; 59 *ic_total_count = 0;
62 *ic_generic_count = 0; 60 *ic_generic_count = 0;
63 *ic_with_type_info_count = 0; 61 *ic_with_type_info_count = 0;
64 if (shared->code()->kind() == Code::FUNCTION) { 62 if (function->code()->kind() == Code::FUNCTION) {
65 Code* shared_code = shared->code(); 63 Code* shared_code = function->shared()->code();
66 Object* raw_info = shared_code->type_feedback_info(); 64 Object* raw_info = shared_code->type_feedback_info();
67 if (raw_info->IsTypeFeedbackInfo()) { 65 if (raw_info->IsTypeFeedbackInfo()) {
68 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); 66 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info);
69 *ic_with_type_info_count = info->ic_with_type_info_count(); 67 *ic_with_type_info_count = info->ic_with_type_info_count();
70 *ic_generic_count = info->ic_generic_count(); 68 *ic_generic_count = info->ic_generic_count();
71 *ic_total_count = info->ic_total_count(); 69 *ic_total_count = info->ic_total_count();
72 } 70 }
73 } 71 }
74 72
75 // Harvest vector-ics as well 73 // Harvest vector-ics as well
76 TypeFeedbackVector* vector = shared->feedback_vector(); 74 TypeFeedbackVector* vector = function->feedback_vector();
77 int with = 0, gen = 0; 75 int with = 0, gen = 0;
78 vector->ComputeCounts(&with, &gen); 76 vector->ComputeCounts(&with, &gen);
79 *ic_with_type_info_count += with; 77 *ic_with_type_info_count += with;
80 *ic_generic_count += gen; 78 *ic_generic_count += gen;
81 79
82 if (*ic_total_count > 0) { 80 if (*ic_total_count > 0) {
83 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; 81 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count;
84 *generic_percentage = 100 * *ic_generic_count / *ic_total_count; 82 *generic_percentage = 100 * *ic_generic_count / *ic_total_count;
85 } else { 83 } else {
86 *type_info_percentage = 100; // Compared against lower bound. 84 *type_info_percentage = 100; // Compared against lower bound.
87 *generic_percentage = 0; // Compared against upper bound. 85 *generic_percentage = 0; // Compared against upper bound.
88 } 86 }
89 } 87 }
90 88
91 89
92 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { 90 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
93 if (FLAG_trace_opt && 91 if (FLAG_trace_opt &&
94 function->shared()->PassesFilter(FLAG_hydrogen_filter)) { 92 function->shared()->PassesFilter(FLAG_hydrogen_filter)) {
95 PrintF("[marking "); 93 PrintF("[marking ");
96 function->ShortPrint(); 94 function->ShortPrint();
97 PrintF(" for recompilation, reason: %s", reason); 95 PrintF(" for recompilation, reason: %s", reason);
98 if (FLAG_type_info_threshold > 0) { 96 if (FLAG_type_info_threshold > 0) {
99 int typeinfo, generic, total, type_percentage, generic_percentage; 97 int typeinfo, generic, total, type_percentage, generic_percentage;
100 GetICCounts(function->shared(), &typeinfo, &generic, &total, 98 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage,
101 &type_percentage, &generic_percentage); 99 &generic_percentage);
102 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, 100 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total,
103 type_percentage); 101 type_percentage);
104 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); 102 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage);
105 } 103 }
106 PrintF("]\n"); 104 PrintF("]\n");
107 } 105 }
108 106
109 if (function->shared()->HasBytecodeArray()) { 107 if (function->shared()->HasBytecodeArray()) {
110 function->MarkForBaseline(); 108 function->MarkForBaseline();
111 } else { 109 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 194 }
197 } 195 }
198 return; 196 return;
199 } 197 }
200 if (function->IsOptimized()) return; 198 if (function->IsOptimized()) return;
201 199
202 int ticks = shared_code->profiler_ticks(); 200 int ticks = shared_code->profiler_ticks();
203 201
204 if (ticks >= kProfilerTicksBeforeOptimization) { 202 if (ticks >= kProfilerTicksBeforeOptimization) {
205 int typeinfo, generic, total, type_percentage, generic_percentage; 203 int typeinfo, generic, total, type_percentage, generic_percentage;
206 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, 204 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage,
207 &generic_percentage); 205 &generic_percentage);
208 if (type_percentage >= FLAG_type_info_threshold && 206 if (type_percentage >= FLAG_type_info_threshold &&
209 generic_percentage <= FLAG_generic_ic_threshold) { 207 generic_percentage <= FLAG_generic_ic_threshold) {
210 // If this particular function hasn't had any ICs patched for enough 208 // If this particular function hasn't had any ICs patched for enough
211 // ticks, optimize it now. 209 // ticks, optimize it now.
212 Optimize(function, "hot and stable"); 210 Optimize(function, "hot and stable");
213 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { 211 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
214 Optimize(function, "not much type info but very hot"); 212 Optimize(function, "not much type info but very hot");
215 } else { 213 } else {
216 shared_code->set_profiler_ticks(ticks + 1); 214 shared_code->set_profiler_ticks(ticks + 1);
217 if (FLAG_trace_opt_verbose) { 215 if (FLAG_trace_opt_verbose) {
218 PrintF("[not yet optimizing "); 216 PrintF("[not yet optimizing ");
219 function->PrintName(); 217 function->PrintName();
220 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, 218 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total,
221 type_percentage); 219 type_percentage);
222 } 220 }
223 } 221 }
224 } else if (!any_ic_changed_ && 222 } else if (!any_ic_changed_ &&
225 shared_code->instruction_size() < kMaxSizeEarlyOpt) { 223 shared_code->instruction_size() < kMaxSizeEarlyOpt) {
226 // If no IC was patched since the last tick and this function is very 224 // If no IC was patched since the last tick and this function is very
227 // small, optimistically optimize it now. 225 // small, optimistically optimize it now.
228 int typeinfo, generic, total, type_percentage, generic_percentage; 226 int typeinfo, generic, total, type_percentage, generic_percentage;
229 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, 227 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage,
230 &generic_percentage); 228 &generic_percentage);
231 if (type_percentage >= FLAG_type_info_threshold && 229 if (type_percentage >= FLAG_type_info_threshold &&
232 generic_percentage <= FLAG_generic_ic_threshold) { 230 generic_percentage <= FLAG_generic_ic_threshold) {
233 Optimize(function, "small function"); 231 Optimize(function, "small function");
234 } else { 232 } else {
235 shared_code->set_profiler_ticks(ticks + 1); 233 shared_code->set_profiler_ticks(ticks + 1);
236 } 234 }
237 } else { 235 } else {
238 shared_code->set_profiler_ticks(ticks + 1); 236 shared_code->set_profiler_ticks(ticks + 1);
239 } 237 }
(...skipping 30 matching lines...) Expand all
270 shared->TryReenableOptimization(); 268 shared->TryReenableOptimization();
271 } 269 }
272 } 270 }
273 return; 271 return;
274 } 272 }
275 273
276 if (function->IsOptimized()) return; 274 if (function->IsOptimized()) return;
277 275
278 if (ticks >= kProfilerTicksBeforeOptimization) { 276 if (ticks >= kProfilerTicksBeforeOptimization) {
279 int typeinfo, generic, total, type_percentage, generic_percentage; 277 int typeinfo, generic, total, type_percentage, generic_percentage;
280 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, 278 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage,
281 &generic_percentage); 279 &generic_percentage);
282 if (type_percentage >= FLAG_type_info_threshold && 280 if (type_percentage >= FLAG_type_info_threshold &&
283 generic_percentage <= FLAG_generic_ic_threshold) { 281 generic_percentage <= FLAG_generic_ic_threshold) {
284 // If this particular function hasn't had any ICs patched for enough 282 // If this particular function hasn't had any ICs patched for enough
285 // ticks, optimize it now. 283 // ticks, optimize it now.
286 Optimize(function, "hot and stable"); 284 Optimize(function, "hot and stable");
287 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { 285 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
288 Optimize(function, "not much type info but very hot"); 286 Optimize(function, "not much type info but very hot");
289 } else { 287 } else {
290 if (FLAG_trace_opt_verbose) { 288 if (FLAG_trace_opt_verbose) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } else { 328 } else {
331 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); 329 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized());
332 } 330 }
333 } 331 }
334 any_ic_changed_ = false; 332 any_ic_changed_ = false;
335 } 333 }
336 334
337 335
338 } // namespace internal 336 } // namespace internal
339 } // namespace v8 337 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698