yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "runtime-profiler.h" |
| 31 | |
| 32 | #include "assembler.h" |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "code-stubs.h" |
| 35 | #include "compilation-cache.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "execution.h" |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 37 | #include "full-codegen.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 38 | #include "global-handles.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 39 | #include "isolate-inl.h" |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 40 | #include "mark-compact.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 41 | #include "platform.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 42 | #include "scopeinfo.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 43 | |
| 44 | namespace v8 { |
| 45 | namespace internal { |
| 46 | |
| 47 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 48 | // Number of times a function has to be seen on the stack before it is |
| 49 | // optimized. |
| 50 | static const int kProfilerTicksBeforeOptimization = 2; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 51 | // If the function optimization was disabled due to high deoptimization count, |
| 52 | // but the function is hot and has been seen on the stack this number of times, |
| 53 | // then we try to reenable optimization for this function. |
| 54 | static const int kProfilerTicksBeforeReenablingOptimization = 250; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 55 | // If a function does not have enough type info (according to |
| 56 | // FLAG_type_info_threshold), but has seen a huge number of ticks, |
| 57 | // optimize it as it is. |
| 58 | static const int kTicksWhenNotEnoughTypeInfo = 100; |
| 59 | // We only have one byte to store the number of ticks. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 60 | STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256); |
| 61 | STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 62 | STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 63 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 64 | // Maximum size in bytes of generate code for a function to allow OSR. |
| 65 | static const int kOSRCodeSizeAllowanceBase = |
| 66 | 100 * FullCodeGenerator::kCodeSizeMultiplier; |
| 67 | |
| 68 | static const int kOSRCodeSizeAllowancePerTick = |
| 69 | 3 * FullCodeGenerator::kCodeSizeMultiplier; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 70 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 71 | // Maximum size in bytes of generated code for a function to be optimized |
| 72 | // the very first time it is seen on the stack. |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 73 | static const int kMaxSizeEarlyOpt = |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 74 | 5 * FullCodeGenerator::kCodeSizeMultiplier; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 75 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 76 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 77 | RuntimeProfiler::RuntimeProfiler(Isolate* isolate) |
| 78 | : isolate_(isolate), |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 79 | any_ic_changed_(false) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 83 | static void GetICCounts(Code* shared_code, |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 84 | int* ic_with_type_info_count, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 85 | int* ic_total_count, |
| 86 | int* percentage) { |
| 87 | *ic_total_count = 0; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 88 | *ic_with_type_info_count = 0; |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 89 | Object* raw_info = shared_code->type_feedback_info(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 90 | if (raw_info->IsTypeFeedbackInfo()) { |
| 91 | TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 92 | *ic_with_type_info_count = info->ic_with_type_info_count(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 93 | *ic_total_count = info->ic_total_count(); |
| 94 | } |
| 95 | *percentage = *ic_total_count > 0 |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 96 | ? 100 * *ic_with_type_info_count / *ic_total_count |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 97 | : 100; |
| 98 | } |
| 99 | |
| 100 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 101 | void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 102 | ASSERT(function->IsOptimizable()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 103 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 104 | if (FLAG_trace_opt && function->PassesFilter(FLAG_hydrogen_filter)) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 105 | PrintF("[marking "); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 106 | function->ShortPrint(); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 107 | PrintF(" for recompilation, reason: %s", reason); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 108 | if (FLAG_type_info_threshold > 0) { |
| 109 | int typeinfo, total, percentage; |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 110 | GetICCounts(function->shared()->code(), &typeinfo, &total, &percentage); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 111 | PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, percentage); |
| 112 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 113 | PrintF("]\n"); |
| 114 | } |
| 115 | |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 116 | |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 117 | if (isolate_->concurrent_recompilation_enabled() && |
| 118 | !isolate_->bootstrapper()->IsActive()) { |
| 119 | if (isolate_->concurrent_osr_enabled() && |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 120 | isolate_->optimizing_compiler_thread()->IsQueuedForOSR(function)) { |
| 121 | // Do not attempt regular recompilation if we already queued this for OSR. |
| 122 | // TODO(yangguo): This is necessary so that we don't install optimized |
| 123 | // code on a function that is already optimized, since OSR and regular |
| 124 | // recompilation race. This goes away as soon as OSR becomes one-shot. |
| 125 | return; |
| 126 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 127 | ASSERT(!function->IsInRecompileQueue()); |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 128 | function->MarkForConcurrentRecompilation(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 129 | } else { |
| 130 | // The next call to the function will trigger optimization. |
| 131 | function->MarkForLazyRecompilation(); |
| 132 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 136 | void RuntimeProfiler::AttemptOnStackReplacement(JSFunction* function) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 137 | // See AlwaysFullCompiler (in compiler.cc) comment on why we need |
| 138 | // Debug::has_break_points(). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | if (!FLAG_use_osr || |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 140 | isolate_->DebuggerHasBreakPoints() || |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 141 | function->IsBuiltin()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | return; |
| 143 | } |
| 144 | |
| 145 | SharedFunctionInfo* shared = function->shared(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 146 | // If the code is not optimizable, don't try OSR. |
| 147 | if (!shared->code()->optimizable()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 148 | |
| 149 | // We are not prepared to do OSR for a function that already has an |
| 150 | // allocated arguments object. The optimized code would bypass it for |
| 151 | // arguments accesses, which is unsound. Don't try OSR. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 152 | if (shared->uses_arguments()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 153 | |
| 154 | // We're using on-stack replacement: patch the unoptimized code so that |
| 155 | // any back edge in any unoptimized frame will trigger on-stack |
| 156 | // replacement for that frame. |
| 157 | if (FLAG_trace_osr) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 158 | PrintF("[OSR - patching back edges in "); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 159 | function->PrintName(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 160 | PrintF("]\n"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 161 | } |
| 162 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 163 | BackEdgeTable::Patch(isolate_, shared->code()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 167 | void RuntimeProfiler::OptimizeNow() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 168 | HandleScope scope(isolate_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 169 | |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 170 | if (isolate_->DebuggerHasBreakPoints()) return; |
| 171 | |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 172 | DisallowHeapAllocation no_gc; |
| 173 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 174 | // Run through the JavaScript frames and collect them. If we already |
| 175 | // have a sample of the function, we mark it for optimizations |
| 176 | // (eagerly or lazily). |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 177 | int frame_count = 0; |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 178 | int frame_count_limit = FLAG_frame_count; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 179 | for (JavaScriptFrameIterator it(isolate_); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 180 | frame_count++ < frame_count_limit && !it.done(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 181 | it.Advance()) { |
| 182 | JavaScriptFrame* frame = it.frame(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 183 | JSFunction* function = frame->function(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 184 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 185 | SharedFunctionInfo* shared = function->shared(); |
| 186 | Code* shared_code = shared->code(); |
| 187 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 188 | if (shared_code->kind() != Code::FUNCTION) continue; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 189 | if (function->IsInRecompileQueue()) continue; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 190 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 191 | if (FLAG_always_osr && |
| 192 | shared_code->allow_osr_at_loop_nesting_level() == 0) { |
| 193 | // Testing mode: always try an OSR compile for every function. |
| 194 | for (int i = 0; i < Code::kMaxLoopNestingMarker; i++) { |
| 195 | // TODO(titzer): fix AttemptOnStackReplacement to avoid this dumb loop. |
| 196 | shared_code->set_allow_osr_at_loop_nesting_level(i); |
| 197 | AttemptOnStackReplacement(function); |
| 198 | } |
| 199 | // Fall through and do a normal optimized compile as well. |
| 200 | } else if (!frame->is_optimized() && |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 201 | (function->IsMarkedForLazyRecompilation() || |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 202 | function->IsMarkedForConcurrentRecompilation() || |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 203 | function->IsOptimized())) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 204 | // Attempt OSR if we are still running unoptimized code even though the |
| 205 | // the function has long been marked or even already been optimized. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 206 | int ticks = shared_code->profiler_ticks(); |
| 207 | int allowance = kOSRCodeSizeAllowanceBase + |
| 208 | ticks * kOSRCodeSizeAllowancePerTick; |
| 209 | if (shared_code->CodeSize() > allowance) { |
| 210 | if (ticks < 255) shared_code->set_profiler_ticks(ticks + 1); |
| 211 | } else { |
| 212 | int nesting = shared_code->allow_osr_at_loop_nesting_level(); |
| 213 | if (nesting < Code::kMaxLoopNestingMarker) { |
| 214 | int new_nesting = nesting + 1; |
| 215 | shared_code->set_allow_osr_at_loop_nesting_level(new_nesting); |
| 216 | AttemptOnStackReplacement(function); |
| 217 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 218 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 219 | continue; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 220 | } |
| 221 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 222 | // Only record top-level code on top of the execution stack and |
| 223 | // avoid optimizing excessively large scripts since top-level code |
| 224 | // will be executed only once. |
| 225 | const int kMaxToplevelSourceSize = 10 * 1024; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 226 | if (shared->is_toplevel() && |
| 227 | (frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) { |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 228 | continue; |
| 229 | } |
| 230 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 231 | // Do not record non-optimizable functions. |
| 232 | if (shared->optimization_disabled()) { |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 233 | if (shared->deopt_count() >= FLAG_max_opt_count) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 234 | // If optimization was disabled due to many deoptimizations, |
| 235 | // then check if the function is hot and try to reenable optimization. |
| 236 | int ticks = shared_code->profiler_ticks(); |
| 237 | if (ticks >= kProfilerTicksBeforeReenablingOptimization) { |
| 238 | shared_code->set_profiler_ticks(0); |
| 239 | shared->TryReenableOptimization(); |
| 240 | } else { |
| 241 | shared_code->set_profiler_ticks(ticks + 1); |
| 242 | } |
| 243 | } |
| 244 | continue; |
| 245 | } |
| 246 | if (!function->IsOptimizable()) continue; |
| 247 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 248 | int ticks = shared_code->profiler_ticks(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 249 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 250 | if (ticks >= kProfilerTicksBeforeOptimization) { |
| 251 | int typeinfo, total, percentage; |
| 252 | GetICCounts(shared_code, &typeinfo, &total, &percentage); |
| 253 | if (percentage >= FLAG_type_info_threshold) { |
| 254 | // If this particular function hasn't had any ICs patched for enough |
| 255 | // ticks, optimize it now. |
| 256 | Optimize(function, "hot and stable"); |
| 257 | } else if (ticks >= kTicksWhenNotEnoughTypeInfo) { |
| 258 | Optimize(function, "not much type info but very hot"); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 259 | } else { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 260 | shared_code->set_profiler_ticks(ticks + 1); |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 261 | if (FLAG_trace_opt_verbose) { |
| 262 | PrintF("[not yet optimizing "); |
| 263 | function->PrintName(); |
| 264 | PrintF(", not enough type info: %d/%d (%d%%)]\n", |
| 265 | typeinfo, total, percentage); |
| 266 | } |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 267 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 268 | } else if (!any_ic_changed_ && |
| 269 | shared_code->instruction_size() < kMaxSizeEarlyOpt) { |
| 270 | // If no IC was patched since the last tick and this function is very |
| 271 | // small, optimistically optimize it now. |
| 272 | Optimize(function, "small function"); |
| 273 | } else { |
| 274 | shared_code->set_profiler_ticks(ticks + 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 275 | } |
| 276 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame^] | 277 | any_ic_changed_ = false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 281 | } } // namespace v8::internal |