| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/runtime-profiler.h" | 7 #include "src/runtime-profiler.h" |
| 8 | 8 |
| 9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, int* ic_with_type_info_count, | 60 static void GetICCounts(SharedFunctionInfo* shared, |
| 61 int* ic_generic_count, int* ic_total_count, | 61 int* ic_with_type_info_count, int* ic_generic_count, |
| 62 int* type_info_percentage, int* generic_percentage) { | 62 int* ic_total_count, int* type_info_percentage, |
| 63 int* generic_percentage) { |
| 64 Code* shared_code = shared->code(); |
| 63 *ic_total_count = 0; | 65 *ic_total_count = 0; |
| 64 *ic_generic_count = 0; | 66 *ic_generic_count = 0; |
| 65 *ic_with_type_info_count = 0; | 67 *ic_with_type_info_count = 0; |
| 66 Object* raw_info = shared_code->type_feedback_info(); | 68 Object* raw_info = shared_code->type_feedback_info(); |
| 67 if (raw_info->IsTypeFeedbackInfo()) { | 69 if (raw_info->IsTypeFeedbackInfo()) { |
| 68 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); | 70 TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); |
| 69 *ic_with_type_info_count = info->ic_with_type_info_count(); | 71 *ic_with_type_info_count = info->ic_with_type_info_count(); |
| 70 *ic_generic_count = info->ic_generic_count(); | 72 *ic_generic_count = info->ic_generic_count(); |
| 71 *ic_total_count = info->ic_total_count(); | 73 *ic_total_count = info->ic_total_count(); |
| 72 } | 74 } |
| 75 |
| 76 // Harvest vector-ics as well |
| 77 TypeFeedbackVector* vector = shared->feedback_vector(); |
| 78 *ic_with_type_info_count += vector->ic_with_type_info_count(); |
| 79 *ic_generic_count += vector->ic_generic_count(); |
| 80 |
| 73 if (*ic_total_count > 0) { | 81 if (*ic_total_count > 0) { |
| 74 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; | 82 *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; |
| 75 *generic_percentage = 100 * *ic_generic_count / *ic_total_count; | 83 *generic_percentage = 100 * *ic_generic_count / *ic_total_count; |
| 76 } else { | 84 } else { |
| 77 *type_info_percentage = 100; // Compared against lower bound. | 85 *type_info_percentage = 100; // Compared against lower bound. |
| 78 *generic_percentage = 0; // Compared against upper bound. | 86 *generic_percentage = 0; // Compared against upper bound. |
| 79 } | 87 } |
| 80 } | 88 } |
| 81 | 89 |
| 82 | 90 |
| 83 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { | 91 void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { |
| 84 DCHECK(function->IsOptimizable()); | 92 DCHECK(function->IsOptimizable()); |
| 85 | 93 |
| 86 if (FLAG_trace_opt && function->PassesFilter(FLAG_hydrogen_filter)) { | 94 if (FLAG_trace_opt && function->PassesFilter(FLAG_hydrogen_filter)) { |
| 87 PrintF("[marking "); | 95 PrintF("[marking "); |
| 88 function->ShortPrint(); | 96 function->ShortPrint(); |
| 89 PrintF(" for recompilation, reason: %s", reason); | 97 PrintF(" for recompilation, reason: %s", reason); |
| 90 if (FLAG_type_info_threshold > 0) { | 98 if (FLAG_type_info_threshold > 0) { |
| 91 int typeinfo, generic, total, type_percentage, generic_percentage; | 99 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 92 GetICCounts(function->shared()->code(), &typeinfo, &generic, &total, | 100 GetICCounts(function->shared(), &typeinfo, &generic, &total, |
| 93 &type_percentage, &generic_percentage); | 101 &type_percentage, &generic_percentage); |
| 94 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, | 102 PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, |
| 95 type_percentage); | 103 type_percentage); |
| 96 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); | 104 PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); |
| 97 } | 105 } |
| 98 PrintF("]\n"); | 106 PrintF("]\n"); |
| 99 } | 107 } |
| 100 | 108 |
| 101 | 109 |
| 102 if (isolate_->concurrent_recompilation_enabled() && | 110 if (isolate_->concurrent_recompilation_enabled() && |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 237 } |
| 230 } | 238 } |
| 231 continue; | 239 continue; |
| 232 } | 240 } |
| 233 if (!function->IsOptimizable()) continue; | 241 if (!function->IsOptimizable()) continue; |
| 234 | 242 |
| 235 int ticks = shared_code->profiler_ticks(); | 243 int ticks = shared_code->profiler_ticks(); |
| 236 | 244 |
| 237 if (ticks >= kProfilerTicksBeforeOptimization) { | 245 if (ticks >= kProfilerTicksBeforeOptimization) { |
| 238 int typeinfo, generic, total, type_percentage, generic_percentage; | 246 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 239 GetICCounts(shared_code, &typeinfo, &generic, &total, &type_percentage, | 247 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, |
| 240 &generic_percentage); | 248 &generic_percentage); |
| 241 if (type_percentage >= FLAG_type_info_threshold && | 249 if (type_percentage >= FLAG_type_info_threshold && |
| 242 generic_percentage <= FLAG_generic_ic_threshold) { | 250 generic_percentage <= FLAG_generic_ic_threshold) { |
| 243 // If this particular function hasn't had any ICs patched for enough | 251 // If this particular function hasn't had any ICs patched for enough |
| 244 // ticks, optimize it now. | 252 // ticks, optimize it now. |
| 245 Optimize(function, "hot and stable"); | 253 Optimize(function, "hot and stable"); |
| 246 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { | 254 } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { |
| 247 Optimize(function, "not much type info but very hot"); | 255 Optimize(function, "not much type info but very hot"); |
| 248 } else { | 256 } else { |
| 249 shared_code->set_profiler_ticks(ticks + 1); | 257 shared_code->set_profiler_ticks(ticks + 1); |
| 250 if (FLAG_trace_opt_verbose) { | 258 if (FLAG_trace_opt_verbose) { |
| 251 PrintF("[not yet optimizing "); | 259 PrintF("[not yet optimizing "); |
| 252 function->PrintName(); | 260 function->PrintName(); |
| 253 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, | 261 PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, |
| 254 type_percentage); | 262 type_percentage); |
| 255 } | 263 } |
| 256 } | 264 } |
| 257 } else if (!any_ic_changed_ && | 265 } else if (!any_ic_changed_ && |
| 258 shared_code->instruction_size() < kMaxSizeEarlyOpt) { | 266 shared_code->instruction_size() < kMaxSizeEarlyOpt) { |
| 259 // If no IC was patched since the last tick and this function is very | 267 // If no IC was patched since the last tick and this function is very |
| 260 // small, optimistically optimize it now. | 268 // small, optimistically optimize it now. |
| 261 int typeinfo, generic, total, type_percentage, generic_percentage; | 269 int typeinfo, generic, total, type_percentage, generic_percentage; |
| 262 GetICCounts(shared_code, &typeinfo, &generic, &total, &type_percentage, | 270 GetICCounts(shared, &typeinfo, &generic, &total, &type_percentage, |
| 263 &generic_percentage); | 271 &generic_percentage); |
| 264 if (type_percentage >= FLAG_type_info_threshold && | 272 if (type_percentage >= FLAG_type_info_threshold && |
| 265 generic_percentage <= FLAG_generic_ic_threshold) { | 273 generic_percentage <= FLAG_generic_ic_threshold) { |
| 266 Optimize(function, "small function"); | 274 Optimize(function, "small function"); |
| 267 } else { | 275 } else { |
| 268 shared_code->set_profiler_ticks(ticks + 1); | 276 shared_code->set_profiler_ticks(ticks + 1); |
| 269 } | 277 } |
| 270 } else { | 278 } else { |
| 271 shared_code->set_profiler_ticks(ticks + 1); | 279 shared_code->set_profiler_ticks(ticks + 1); |
| 272 } | 280 } |
| 273 } | 281 } |
| 274 any_ic_changed_ = false; | 282 any_ic_changed_ = false; |
| 275 } | 283 } |
| 276 | 284 |
| 277 | 285 |
| 278 } } // namespace v8::internal | 286 } } // namespace v8::internal |
| OLD | NEW |