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