| OLD | NEW |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // the very first time it is seen on the stack. | 49 // the very first time it is seen on the stack. |
| 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 static void GetICCounts(JSFunction* function, int* ic_with_type_info_count, |
| 60 static void GetICCounts(SharedFunctionInfo* shared, | 60 int* ic_generic_count, int* ic_total_count, |
| 61 int* ic_with_type_info_count, int* ic_generic_count, | 61 int* type_info_percentage, int* generic_percentage) { |
| 62 int* ic_total_count, int* type_info_percentage, | |
| 63 int* generic_percentage) { | |
| 64 *ic_total_count = 0; | 62 *ic_total_count = 0; |
| 65 *ic_generic_count = 0; | 63 *ic_generic_count = 0; |
| 66 *ic_with_type_info_count = 0; | 64 *ic_with_type_info_count = 0; |
| 67 if (shared->code()->kind() == Code::FUNCTION) { | 65 if (function->code()->kind() == Code::FUNCTION) { |
| 68 Code* shared_code = shared->code(); | 66 Code* shared_code = function->shared()->code(); |
| 69 Object* raw_info = shared_code->type_feedback_info(); | 67 Object* raw_info = shared_code->type_feedback_info(); |
| 70 if (raw_info->IsTypeFeedbackInfo()) { | 68 if (raw_info->IsTypeFeedbackInfo()) { |
| 71 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); | 69 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); |
| 72 *ic_with_type_info_count = info->ic_with_type_info_count(); | 70 *ic_with_type_info_count = info->ic_with_type_info_count(); |
| 73 *ic_generic_count = info->ic_generic_count(); | 71 *ic_generic_count = info->ic_generic_count(); |
| 74 *ic_total_count = info->ic_total_count(); | 72 *ic_total_count = info->ic_total_count(); |
| 75 } | 73 } |
| 76 } | 74 } |
| 77 | 75 |
| 78 // Harvest vector-ics as well | 76 // Harvest vector-ics as well |
| 79 TypeFeedbackVector* vector = shared->feedback_vector(); | 77 TypeFeedbackVector* vector = function->feedback_vector(); |
| 80 int with = 0, gen = 0; | 78 int with = 0, gen = 0; |
| 81 vector->ComputeCounts(&with, &gen); | 79 vector->ComputeCounts(&with, &gen); |
| 82 *ic_with_type_info_count += with; | 80 *ic_with_type_info_count += with; |
| 83 *ic_generic_count += gen; | 81 *ic_generic_count += gen; |
| 84 | 82 |
| 85 if (*ic_total_count > 0) { | 83 if (*ic_total_count > 0) { |
| 86 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; | 84 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; |
| 87 *generic_percentage = 100 * *ic_generic_count / *ic_total_count; | 85 *generic_percentage = 100 * *ic_generic_count / *ic_total_count; |
| 88 } else { | 86 } else { |
| 89 *type_info_percentage = 100; // Compared against lower bound. | 87 *type_info_percentage = 100; // Compared against lower bound. |
| 90 *generic_percentage = 0; // Compared against upper bound. | 88 *generic_percentage = 0; // Compared against upper bound. |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 | 91 |
| 94 static void TraceRecompile(JSFunction* function, const char* reason, | 92 static void TraceRecompile(JSFunction* function, const char* reason, |
| 95 const char* type) { | 93 const char* type) { |
| 96 if (FLAG_trace_opt && | 94 if (FLAG_trace_opt && |
| 97 function->shared()->PassesFilter(FLAG_hydrogen_filter)) { | 95 function->shared()->PassesFilter(FLAG_hydrogen_filter)) { |
| 98 PrintF("[marking "); | 96 PrintF("[marking "); |
| 99 function->ShortPrint(); | 97 function->ShortPrint(); |
| 100 PrintF(" for %s recompilation, reason: %s", type, reason); | 98 PrintF(" for %s recompilation, reason: %s", type, reason); |
| 101 if (FLAG_type_info_threshold > 0) { | 99 if (FLAG_type_info_threshold > 0) { |
| 102 int typeinfo, generic, total, type_percentage, generic_percentage; | 100 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 103 GetICCounts(function->shared(), &typeinfo, &generic, &total, | 101 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
| 104 &type_percentage, &generic_percentage); | 102 &generic_percentage); |
| 105 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, | 103 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, |
| 106 type_percentage); | 104 type_percentage); |
| 107 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); | 105 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); |
| 108 } | 106 } |
| 109 PrintF("]\n"); | 107 PrintF("]\n"); |
| 110 } | 108 } |
| 111 } | 109 } |
| 112 | 110 |
| 113 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { | 111 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { |
| 114 TraceRecompile(function, reason, "optimized"); | 112 TraceRecompile(function, reason, "optimized"); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 210 } |
| 213 } | 211 } |
| 214 return; | 212 return; |
| 215 } | 213 } |
| 216 if (function->IsOptimized()) return; | 214 if (function->IsOptimized()) return; |
| 217 | 215 |
| 218 int ticks = shared_code->profiler_ticks(); | 216 int ticks = shared_code->profiler_ticks(); |
| 219 | 217 |
| 220 if (ticks >= kProfilerTicksBeforeOptimization) { | 218 if (ticks >= kProfilerTicksBeforeOptimization) { |
| 221 int typeinfo, generic, total, type_percentage, generic_percentage; | 219 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 222 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, | 220 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
| 223 &generic_percentage); | 221 &generic_percentage); |
| 224 if (type_percentage >= FLAG_type_info_threshold && | 222 if (type_percentage >= FLAG_type_info_threshold && |
| 225 generic_percentage <= FLAG_generic_ic_threshold) { | 223 generic_percentage <= FLAG_generic_ic_threshold) { |
| 226 // If this particular function hasn't had any ICs patched for enough | 224 // If this particular function hasn't had any ICs patched for enough |
| 227 // ticks, optimize it now. | 225 // ticks, optimize it now. |
| 228 Optimize(function, "hot and stable"); | 226 Optimize(function, "hot and stable"); |
| 229 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { | 227 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { |
| 230 Optimize(function, "not much type info but very hot"); | 228 Optimize(function, "not much type info but very hot"); |
| 231 } else { | 229 } else { |
| 232 shared_code->set_profiler_ticks(ticks + 1); | 230 shared_code->set_profiler_ticks(ticks + 1); |
| 233 if (FLAG_trace_opt_verbose) { | 231 if (FLAG_trace_opt_verbose) { |
| 234 PrintF("[not yet optimizing "); | 232 PrintF("[not yet optimizing "); |
| 235 function->PrintName(); | 233 function->PrintName(); |
| 236 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, | 234 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, |
| 237 type_percentage); | 235 type_percentage); |
| 238 } | 236 } |
| 239 } | 237 } |
| 240 } else if (!any_ic_changed_ && | 238 } else if (!any_ic_changed_ && |
| 241 shared_code->instruction_size() < kMaxSizeEarlyOpt) { | 239 shared_code->instruction_size() < kMaxSizeEarlyOpt) { |
| 242 // If no IC was patched since the last tick and this function is very | 240 // If no IC was patched since the last tick and this function is very |
| 243 // small, optimistically optimize it now. | 241 // small, optimistically optimize it now. |
| 244 int typeinfo, generic, total, type_percentage, generic_percentage; | 242 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 245 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, | 243 GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
| 246 &generic_percentage); | 244 &generic_percentage); |
| 247 if (type_percentage >= FLAG_type_info_threshold && | 245 if (type_percentage >= FLAG_type_info_threshold && |
| 248 generic_percentage <= FLAG_generic_ic_threshold) { | 246 generic_percentage <= FLAG_generic_ic_threshold) { |
| 249 Optimize(function, "small function"); | 247 Optimize(function, "small function"); |
| 250 } else { | 248 } else { |
| 251 shared_code->set_profiler_ticks(ticks + 1); | 249 shared_code->set_profiler_ticks(ticks + 1); |
| 252 } | 250 } |
| 253 } else { | 251 } else { |
| 254 shared_code->set_profiler_ticks(ticks + 1); | 252 shared_code->set_profiler_ticks(ticks + 1); |
| 255 } | 253 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } else { | 317 } else { |
| 320 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); | 318 MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); |
| 321 } | 319 } |
| 322 } | 320 } |
| 323 any_ic_changed_ = false; | 321 any_ic_changed_ = false; |
| 324 } | 322 } |
| 325 | 323 |
| 326 | 324 |
| 327 } // namespace internal | 325 } // namespace internal |
| 328 } // namespace v8 | 326 } // namespace v8 |
| OLD | NEW |