Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/runtime-profiler.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/assembler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "src/ast/scopeinfo.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/base/platform/platform.h" |
| 10 | #include "src/bootstrapper.h" |
| 11 | #include "src/code-stubs.h" |
| 12 | #include "src/compilation-cache.h" |
| 13 | #include "src/execution.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 14 | #include "src/frames-inl.h" |
| 15 | #include "src/full-codegen/full-codegen.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | #include "src/global-handles.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 17 | |
| 18 | namespace v8 { |
| 19 | namespace internal { |
| 20 | |
| 21 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 22 | // Number of times a function has to be seen on the stack before it is |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 23 | // compiled for baseline. |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 24 | static const int kProfilerTicksBeforeBaseline = 1; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 25 | // Number of times a function has to be seen on the stack before it is |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 26 | // optimized. |
| 27 | static const int kProfilerTicksBeforeOptimization = 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | // If the function optimization was disabled due to high deoptimization count, |
| 29 | // but the function is hot and has been seen on the stack this number of times, |
| 30 | // then we try to reenable optimization for this function. |
| 31 | static const int kProfilerTicksBeforeReenablingOptimization = 250; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 32 | // If a function does not have enough type info (according to |
| 33 | // FLAG_type_info_threshold), but has seen a huge number of ticks, |
| 34 | // optimize it as it is. |
| 35 | static const int kTicksWhenNotEnoughTypeInfo = 100; |
| 36 | // We only have one byte to store the number of ticks. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256); |
| 38 | STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256); |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 39 | STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 40 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | // Maximum size in bytes of generate code for a function to allow OSR. |
| 42 | static const int kOSRCodeSizeAllowanceBase = |
| 43 | 100 * FullCodeGenerator::kCodeSizeMultiplier; |
| 44 | |
| 45 | static const int kOSRCodeSizeAllowancePerTick = |
| 46 | 4 * FullCodeGenerator::kCodeSizeMultiplier; |
| 47 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 48 | // Maximum size in bytes of generated code for a function to be optimized |
| 49 | // the very first time it is seen on the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | static const int kMaxSizeEarlyOpt = |
| 51 | 5 * FullCodeGenerator::kCodeSizeMultiplier; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 52 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 53 | |
| 54 | RuntimeProfiler::RuntimeProfiler(Isolate* isolate) |
| 55 | : isolate_(isolate), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | any_ic_changed_(false) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 59 | static void GetICCounts(JSFunction* function, int* ic_with_type_info_count, |
| 60 | int* ic_generic_count, int* ic_total_count, |
| 61 | int* type_info_percentage, int* generic_percentage) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | *ic_total_count = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | *ic_generic_count = 0; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 64 | *ic_with_type_info_count = 0; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 65 | if (function->code()->kind() == Code::FUNCTION) { |
| 66 | Code* shared_code = function->shared()->code(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 67 | Object* raw_info = shared_code->type_feedback_info(); |
| 68 | if (raw_info->IsTypeFeedbackInfo()) { |
| 69 | TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); |
| 70 | *ic_with_type_info_count = info->ic_with_type_info_count(); |
| 71 | *ic_generic_count = info->ic_generic_count(); |
| 72 | *ic_total_count = info->ic_total_count(); |
| 73 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 74 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 75 | |
| 76 | // Harvest vector-ics as well |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 77 | TypeFeedbackVector* vector = function->feedback_vector(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | int with = 0, gen = 0; |
| 79 | vector->ComputeCounts(&with, &gen); |
| 80 | *ic_with_type_info_count += with; |
| 81 | *ic_generic_count += gen; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 82 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 83 | if (*ic_total_count > 0) { |
| 84 | *type_info_percentage = 100 * *ic_with_type_info_count / *ic_total_count; |
| 85 | *generic_percentage = 100 * *ic_generic_count / *ic_total_count; |
| 86 | } else { |
| 87 | *type_info_percentage = 100; // Compared against lower bound. |
| 88 | *generic_percentage = 0; // Compared against upper bound. |
| 89 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 92 | static void TraceRecompile(JSFunction* function, const char* reason, |
| 93 | const char* type) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 94 | if (FLAG_trace_opt && |
| 95 | function->shared()->PassesFilter(FLAG_hydrogen_filter)) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 96 | PrintF("[marking "); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | function->ShortPrint(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 98 | PrintF(" for %s recompilation, reason: %s", type, reason); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 99 | if (FLAG_type_info_threshold > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | int typeinfo, generic, total, type_percentage, generic_percentage; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 101 | GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
| 102 | &generic_percentage); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 103 | PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, |
| 104 | type_percentage); |
| 105 | PrintF(", generic ICs: %d/%d (%d%%)", generic, total, generic_percentage); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 106 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 107 | PrintF("]\n"); |
| 108 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 109 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 110 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 111 | void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { |
| 112 | TraceRecompile(function, reason, "optimized"); |
| 113 | |
| 114 | // TODO(4280): Fix this to check function is compiled to baseline once we |
| 115 | // have a standard way to check that. For now, if baseline code doesn't have |
| 116 | // a bytecode array. |
| 117 | DCHECK(!function->shared()->HasBytecodeArray()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 118 | function->AttemptConcurrentOptimization(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 121 | void RuntimeProfiler::Baseline(JSFunction* function, const char* reason) { |
| 122 | TraceRecompile(function, reason, "baseline"); |
| 123 | |
| 124 | // TODO(4280): Fix this to check function is compiled for the interpreter |
| 125 | // once we have a standard way to check that. For now function will only |
| 126 | // have a bytecode array if compiled for the interpreter. |
| 127 | DCHECK(function->shared()->HasBytecodeArray()); |
| 128 | function->MarkForBaseline(); |
| 129 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 130 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | void RuntimeProfiler::AttemptOnStackReplacement(JSFunction* function, |
| 132 | int loop_nesting_levels) { |
| 133 | SharedFunctionInfo* shared = function->shared(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 134 | if (!FLAG_use_osr || function->shared()->IsBuiltin()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 138 | // If the code is not optimizable, don't try OSR. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 139 | if (shared->optimization_disabled()) return; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 140 | |
| 141 | // We are not prepared to do OSR for a function that already has an |
| 142 | // allocated arguments object. The optimized code would bypass it for |
| 143 | // arguments accesses, which is unsound. Don't try OSR. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 144 | if (shared->uses_arguments()) return; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 145 | |
| 146 | // We're using on-stack replacement: patch the unoptimized code so that |
| 147 | // any back edge in any unoptimized frame will trigger on-stack |
| 148 | // replacement for that frame. |
| 149 | if (FLAG_trace_osr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | PrintF("[OSR - patching back edges in "); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 151 | function->PrintName(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | PrintF("]\n"); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | for (int i = 0; i < loop_nesting_levels; i++) { |
| 156 | BackEdgeTable::Patch(isolate_, shared->code()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 157 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 160 | void RuntimeProfiler::MaybeOptimizeFullCodegen(JSFunction* function, |
| 161 | int frame_count, |
| 162 | bool frame_optimized) { |
| 163 | SharedFunctionInfo* shared = function->shared(); |
| 164 | Code* shared_code = shared->code(); |
| 165 | if (shared_code->kind() != Code::FUNCTION) return; |
| 166 | if (function->IsInOptimizationQueue()) return; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 167 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 168 | if (FLAG_always_osr) { |
| 169 | AttemptOnStackReplacement(function, Code::kMaxLoopNestingMarker); |
| 170 | // Fall through and do a normal optimized compile as well. |
| 171 | } else if (!frame_optimized && |
| 172 | (function->IsMarkedForOptimization() || |
| 173 | function->IsMarkedForConcurrentOptimization() || |
| 174 | function->IsOptimized())) { |
| 175 | // Attempt OSR if we are still running unoptimized code even though the |
| 176 | // the function has long been marked or even already been optimized. |
| 177 | int ticks = shared_code->profiler_ticks(); |
| 178 | int64_t allowance = |
| 179 | kOSRCodeSizeAllowanceBase + |
| 180 | static_cast<int64_t>(ticks) * kOSRCodeSizeAllowancePerTick; |
| 181 | if (shared_code->CodeSize() > allowance && |
| 182 | ticks < Code::ProfilerTicksField::kMax) { |
| 183 | shared_code->set_profiler_ticks(ticks + 1); |
| 184 | } else { |
| 185 | AttemptOnStackReplacement(function); |
| 186 | } |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | // Only record top-level code on top of the execution stack and |
| 191 | // avoid optimizing excessively large scripts since top-level code |
| 192 | // will be executed only once. |
| 193 | const int kMaxToplevelSourceSize = 10 * 1024; |
| 194 | if (shared->is_toplevel() && |
| 195 | (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) { |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | // Do not record non-optimizable functions. |
| 200 | if (shared->optimization_disabled()) { |
| 201 | if (shared->deopt_count() >= FLAG_max_opt_count) { |
| 202 | // If optimization was disabled due to many deoptimizations, |
| 203 | // then check if the function is hot and try to reenable optimization. |
| 204 | int ticks = shared_code->profiler_ticks(); |
| 205 | if (ticks >= kProfilerTicksBeforeReenablingOptimization) { |
| 206 | shared_code->set_profiler_ticks(0); |
| 207 | shared->TryReenableOptimization(); |
| 208 | } else { |
| 209 | shared_code->set_profiler_ticks(ticks + 1); |
| 210 | } |
| 211 | } |
| 212 | return; |
| 213 | } |
| 214 | if (function->IsOptimized()) return; |
| 215 | |
| 216 | int ticks = shared_code->profiler_ticks(); |
| 217 | |
| 218 | if (ticks >= kProfilerTicksBeforeOptimization) { |
| 219 | int typeinfo, generic, total, type_percentage, generic_percentage; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 220 | GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 221 | &generic_percentage); |
| 222 | if (type_percentage >= FLAG_type_info_threshold && |
| 223 | generic_percentage <= FLAG_generic_ic_threshold) { |
| 224 | // If this particular function hasn't had any ICs patched for enough |
| 225 | // ticks, optimize it now. |
| 226 | Optimize(function, "hot and stable"); |
| 227 | } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { |
| 228 | Optimize(function, "not much type info but very hot"); |
| 229 | } else { |
| 230 | shared_code->set_profiler_ticks(ticks + 1); |
| 231 | if (FLAG_trace_opt_verbose) { |
| 232 | PrintF("[not yet optimizing "); |
| 233 | function->PrintName(); |
| 234 | PrintF(", not enough type info: %d/%d (%d%%)]\n", typeinfo, total, |
| 235 | type_percentage); |
| 236 | } |
| 237 | } |
| 238 | } else if (!any_ic_changed_ && |
| 239 | shared_code->instruction_size() < kMaxSizeEarlyOpt) { |
| 240 | // If no IC was patched since the last tick and this function is very |
| 241 | // small, optimistically optimize it now. |
| 242 | int typeinfo, generic, total, type_percentage, generic_percentage; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 243 | GetICCounts(function, &typeinfo, &generic, &total, &type_percentage, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 244 | &generic_percentage); |
| 245 | if (type_percentage >= FLAG_type_info_threshold && |
| 246 | generic_percentage <= FLAG_generic_ic_threshold) { |
| 247 | Optimize(function, "small function"); |
| 248 | } else { |
| 249 | shared_code->set_profiler_ticks(ticks + 1); |
| 250 | } |
| 251 | } else { |
| 252 | shared_code->set_profiler_ticks(ticks + 1); |
| 253 | } |
| 254 | } |
| 255 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 256 | void RuntimeProfiler::MaybeOptimizeIgnition(JSFunction* function) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 257 | if (function->IsInOptimizationQueue()) return; |
| 258 | |
| 259 | SharedFunctionInfo* shared = function->shared(); |
| 260 | int ticks = shared->profiler_ticks(); |
| 261 | |
| 262 | // TODO(rmcilroy): Also ensure we only OSR top-level code if it is smaller |
| 263 | // than kMaxToplevelSourceSize. |
| 264 | // TODO(rmcilroy): Consider whether we should optimize small functions when |
| 265 | // they are first seen on the stack (e.g., kMaxSizeEarlyOpt). |
| 266 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 267 | if (function->IsMarkedForBaseline() || function->IsMarkedForOptimization() || |
| 268 | function->IsMarkedForConcurrentOptimization() || |
| 269 | function->IsOptimized()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 270 | // TODO(rmcilroy): Support OSR in these cases. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 274 | if (shared->optimization_disabled() && |
| 275 | shared->disable_optimization_reason() == kOptimizationDisabledForTest) { |
| 276 | // Don't baseline functions which have been marked by NeverOptimizeFunction |
| 277 | // in a test. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 281 | if (ticks >= kProfilerTicksBeforeBaseline) { |
| 282 | Baseline(function, "hot enough for baseline"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
| 286 | void RuntimeProfiler::MarkCandidatesForOptimization() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 287 | HandleScope scope(isolate_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 288 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 289 | if (!isolate_->use_crankshaft()) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 290 | |
| 291 | DisallowHeapAllocation no_gc; |
| 292 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 293 | // Run through the JavaScript frames and collect them. If we already |
| 294 | // have a sample of the function, we mark it for optimizations |
| 295 | // (eagerly or lazily). |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 296 | int frame_count = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 297 | int frame_count_limit = FLAG_frame_count; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 298 | for (JavaScriptFrameIterator it(isolate_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 299 | frame_count++ < frame_count_limit && !it.done(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 300 | it.Advance()) { |
| 301 | JavaScriptFrame* frame = it.frame(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | JSFunction* function = frame->function(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 303 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 304 | List<JSFunction*> functions(4); |
| 305 | frame->GetFunctions(&functions); |
| 306 | for (int i = functions.length(); --i >= 0; ) { |
| 307 | SharedFunctionInfo* shared_function_info = functions[i]->shared(); |
| 308 | int ticks = shared_function_info->profiler_ticks(); |
| 309 | if (ticks < Smi::kMaxValue) { |
| 310 | shared_function_info->set_profiler_ticks(ticks + 1); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 314 | if (frame->is_interpreted()) { |
| 315 | DCHECK(!frame->is_optimized()); |
| 316 | MaybeOptimizeIgnition(function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 317 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 318 | MaybeOptimizeFullCodegen(function, frame_count, frame->is_optimized()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 319 | } |
| 320 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | any_ic_changed_ = false; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 325 | } // namespace internal |
| 326 | } // namespace v8 |