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