2012-02-09 10:19:46 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-12-07 11:31:57 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "runtime-profiler.h"
|
|
|
|
|
|
|
|
#include "assembler.h"
|
2013-04-18 14:34:34 +00:00
|
|
|
#include "bootstrapper.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "code-stubs.h"
|
|
|
|
#include "compilation-cache.h"
|
|
|
|
#include "deoptimizer.h"
|
|
|
|
#include "execution.h"
|
2012-07-25 13:51:29 +00:00
|
|
|
#include "full-codegen.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "global-handles.h"
|
2011-10-03 11:13:20 +00:00
|
|
|
#include "isolate-inl.h"
|
2011-03-02 10:16:47 +00:00
|
|
|
#include "mark-compact.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
#include "platform.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "scopeinfo.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
// Optimization sampler constants.
|
|
|
|
static const int kSamplerFrameCount = 2;
|
2012-02-09 10:19:46 +00:00
|
|
|
|
|
|
|
// Constants for statistical profiler.
|
2010-12-07 11:31:57 +00:00
|
|
|
static const int kSamplerFrameWeight[kSamplerFrameCount] = { 2, 1 };
|
|
|
|
|
2010-12-09 13:12:23 +00:00
|
|
|
static const int kSamplerTicksBetweenThresholdAdjustment = 32;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
static const int kSamplerThresholdInit = 3;
|
|
|
|
static const int kSamplerThresholdMin = 1;
|
|
|
|
static const int kSamplerThresholdDelta = 1;
|
|
|
|
|
|
|
|
static const int kSamplerThresholdSizeFactorInit = 3;
|
|
|
|
|
|
|
|
static const int kSizeLimit = 1500;
|
|
|
|
|
2012-02-09 10:19:46 +00:00
|
|
|
// Constants for counter based profiler.
|
|
|
|
|
|
|
|
// Number of times a function has to be seen on the stack before it is
|
|
|
|
// optimized.
|
|
|
|
static const int kProfilerTicksBeforeOptimization = 2;
|
2012-06-11 16:57:27 +00:00
|
|
|
// If the function optimization was disabled due to high deoptimization count,
|
|
|
|
// but the function is hot and has been seen on the stack this number of times,
|
|
|
|
// then we try to reenable optimization for this function.
|
|
|
|
static const int kProfilerTicksBeforeReenablingOptimization = 250;
|
2012-03-27 12:19:50 +00:00
|
|
|
// If a function does not have enough type info (according to
|
|
|
|
// FLAG_type_info_threshold), but has seen a huge number of ticks,
|
|
|
|
// optimize it as it is.
|
|
|
|
static const int kTicksWhenNotEnoughTypeInfo = 100;
|
|
|
|
// We only have one byte to store the number of ticks.
|
2012-06-11 16:57:27 +00:00
|
|
|
STATIC_ASSERT(kProfilerTicksBeforeOptimization < 256);
|
|
|
|
STATIC_ASSERT(kProfilerTicksBeforeReenablingOptimization < 256);
|
2012-03-27 12:19:50 +00:00
|
|
|
STATIC_ASSERT(kTicksWhenNotEnoughTypeInfo < 256);
|
2012-02-09 10:19:46 +00:00
|
|
|
|
2013-06-14 11:35:00 +00:00
|
|
|
// Maximum size in bytes of generate code for a function to allow OSR.
|
|
|
|
static const int kOSRCodeSizeAllowanceBase =
|
|
|
|
100 * FullCodeGenerator::kCodeSizeMultiplier;
|
|
|
|
|
|
|
|
static const int kOSRCodeSizeAllowancePerTick =
|
|
|
|
3 * FullCodeGenerator::kCodeSizeMultiplier;
|
2012-06-11 16:57:27 +00:00
|
|
|
|
2012-02-09 10:19:46 +00:00
|
|
|
// Maximum size in bytes of generated code for a function to be optimized
|
|
|
|
// the very first time it is seen on the stack.
|
2012-07-25 13:51:29 +00:00
|
|
|
static const int kMaxSizeEarlyOpt =
|
2013-06-14 11:35:00 +00:00
|
|
|
5 * FullCodeGenerator::kCodeSizeMultiplier;
|
2012-02-09 10:19:46 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
|
|
|
|
: isolate_(isolate),
|
|
|
|
sampler_threshold_(kSamplerThresholdInit),
|
|
|
|
sampler_threshold_size_factor_(kSamplerThresholdSizeFactorInit),
|
|
|
|
sampler_ticks_until_threshold_adjustment_(
|
2011-06-29 14:56:08 +00:00
|
|
|
kSamplerTicksBetweenThresholdAdjustment),
|
2012-03-23 15:26:04 +00:00
|
|
|
sampler_window_position_(0),
|
|
|
|
any_ic_changed_(false),
|
|
|
|
code_generated_(false) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ClearSampleBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 11:35:00 +00:00
|
|
|
static void GetICCounts(Code* shared_code,
|
2012-03-27 12:19:50 +00:00
|
|
|
int* ic_with_type_info_count,
|
2012-02-20 12:57:23 +00:00
|
|
|
int* ic_total_count,
|
|
|
|
int* percentage) {
|
|
|
|
*ic_total_count = 0;
|
2012-03-27 12:19:50 +00:00
|
|
|
*ic_with_type_info_count = 0;
|
2013-06-14 11:35:00 +00:00
|
|
|
Object* raw_info = shared_code->type_feedback_info();
|
2012-02-20 12:57:23 +00:00
|
|
|
if (raw_info->IsTypeFeedbackInfo()) {
|
|
|
|
TypeFeedbackInfo* info = TypeFeedbackInfo::cast(raw_info);
|
2012-03-27 12:19:50 +00:00
|
|
|
*ic_with_type_info_count = info->ic_with_type_info_count();
|
2012-02-20 12:57:23 +00:00
|
|
|
*ic_total_count = info->ic_total_count();
|
|
|
|
}
|
|
|
|
*percentage = *ic_total_count > 0
|
2012-03-27 12:19:50 +00:00
|
|
|
? 100 * *ic_with_type_info_count / *ic_total_count
|
2012-02-20 12:57:23 +00:00
|
|
|
: 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-09 10:19:46 +00:00
|
|
|
void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
|
2011-04-11 13:24:50 +00:00
|
|
|
ASSERT(function->IsOptimizable());
|
2012-11-16 10:57:50 +00:00
|
|
|
|
2013-05-13 11:10:31 +00:00
|
|
|
if (FLAG_trace_opt && function->PassesHydrogenFilter()) {
|
2011-06-29 14:56:08 +00:00
|
|
|
PrintF("[marking ");
|
2013-05-13 11:10:31 +00:00
|
|
|
function->ShortPrint();
|
2012-02-09 10:19:46 +00:00
|
|
|
PrintF(" for recompilation, reason: %s", reason);
|
2012-02-20 12:57:23 +00:00
|
|
|
if (FLAG_type_info_threshold > 0) {
|
|
|
|
int typeinfo, total, percentage;
|
2013-06-14 11:35:00 +00:00
|
|
|
GetICCounts(function->shared()->code(), &typeinfo, &total, &percentage);
|
2012-02-20 12:57:23 +00:00
|
|
|
PrintF(", ICs with typeinfo: %d/%d (%d%%)", typeinfo, total, percentage);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
|
2013-08-22 16:14:37 +00:00
|
|
|
if (FLAG_concurrent_recompilation && !isolate_->bootstrapper()->IsActive()) {
|
2013-03-12 18:03:18 +00:00
|
|
|
ASSERT(!function->IsMarkedForInstallingRecompiledCode());
|
|
|
|
ASSERT(!function->IsInRecompileQueue());
|
2013-08-22 16:14:37 +00:00
|
|
|
function->MarkForConcurrentRecompilation();
|
2012-07-19 18:58:23 +00:00
|
|
|
} else {
|
|
|
|
// The next call to the function will trigger optimization.
|
|
|
|
function->MarkForLazyRecompilation();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void RuntimeProfiler::AttemptOnStackReplacement(JSFunction* function) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// See AlwaysFullCompiler (in compiler.cc) comment on why we need
|
|
|
|
// Debug::has_break_points().
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!FLAG_use_osr ||
|
2011-04-26 13:53:19 +00:00
|
|
|
isolate_->DebuggerHasBreakPoints() ||
|
2011-03-18 20:35:07 +00:00
|
|
|
function->IsBuiltin()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedFunctionInfo* shared = function->shared();
|
2011-09-02 09:29:21 +00:00
|
|
|
// If the code is not optimizable, don't try OSR.
|
|
|
|
if (!shared->code()->optimizable()) return;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// We are not prepared to do OSR for a function that already has an
|
|
|
|
// allocated arguments object. The optimized code would bypass it for
|
|
|
|
// arguments accesses, which is unsound. Don't try OSR.
|
2011-06-16 14:12:58 +00:00
|
|
|
if (shared->uses_arguments()) return;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// We're using on-stack replacement: patch the unoptimized code so that
|
|
|
|
// any back edge in any unoptimized frame will trigger on-stack
|
|
|
|
// replacement for that frame.
|
|
|
|
if (FLAG_trace_osr) {
|
2013-04-10 09:24:31 +00:00
|
|
|
PrintF("[patching back edges in ");
|
2010-12-07 11:31:57 +00:00
|
|
|
function->PrintName();
|
|
|
|
PrintF(" for on-stack replacement]\n");
|
|
|
|
}
|
|
|
|
|
2013-04-10 09:24:31 +00:00
|
|
|
// Get the interrupt stub code object to match against. We aren't
|
2010-12-07 11:31:57 +00:00
|
|
|
// prepared to generate it, but we don't expect to have to.
|
2013-04-10 09:24:31 +00:00
|
|
|
Code* interrupt_code = NULL;
|
2012-12-07 08:55:06 +00:00
|
|
|
InterruptStub interrupt_stub;
|
2013-04-10 09:24:31 +00:00
|
|
|
bool found_code = interrupt_stub.FindCodeInCache(&interrupt_code, isolate_);
|
2012-02-14 14:00:31 +00:00
|
|
|
if (found_code) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Code* replacement_code =
|
2011-03-23 13:40:07 +00:00
|
|
|
isolate_->builtins()->builtin(Builtins::kOnStackReplacement);
|
2010-12-07 11:31:57 +00:00
|
|
|
Code* unoptimized_code = shared->code();
|
2013-04-10 09:24:31 +00:00
|
|
|
Deoptimizer::PatchInterruptCode(
|
|
|
|
unoptimized_code, interrupt_code, replacement_code);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void RuntimeProfiler::ClearSampleBuffer() {
|
|
|
|
memset(sampler_window_, 0, sizeof(sampler_window_));
|
|
|
|
memset(sampler_window_weight_, 0, sizeof(sampler_window_weight_));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
int RuntimeProfiler::LookupSample(JSFunction* function) {
|
2010-12-07 11:31:57 +00:00
|
|
|
int weight = 0;
|
|
|
|
for (int i = 0; i < kSamplerWindowSize; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Object* sample = sampler_window_[i];
|
2010-12-07 11:31:57 +00:00
|
|
|
if (sample != NULL) {
|
2012-06-14 14:06:22 +00:00
|
|
|
bool fits = FLAG_lookup_sample_by_shared
|
|
|
|
? (function->shared() == JSFunction::cast(sample)->shared())
|
|
|
|
: (function == JSFunction::cast(sample));
|
|
|
|
if (fits) {
|
2011-03-18 20:35:07 +00:00
|
|
|
weight += sampler_window_weight_[i];
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void RuntimeProfiler::AddSample(JSFunction* function, int weight) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(IsPowerOf2(kSamplerWindowSize));
|
2011-03-18 20:35:07 +00:00
|
|
|
sampler_window_[sampler_window_position_] = function;
|
|
|
|
sampler_window_weight_[sampler_window_position_] = weight;
|
|
|
|
sampler_window_position_ = (sampler_window_position_ + 1) &
|
2010-12-07 11:31:57 +00:00
|
|
|
(kSamplerWindowSize - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RuntimeProfiler::OptimizeNow() {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate_);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-07-02 15:30:33 +00:00
|
|
|
if (isolate_->DebuggerHasBreakPoints()) return;
|
|
|
|
|
2013-08-22 16:14:37 +00:00
|
|
|
if (FLAG_concurrent_recompilation) {
|
2013-03-12 18:03:18 +00:00
|
|
|
// Take this as opportunity to process the optimizing compiler thread's
|
|
|
|
// output queue so that it does not unnecessarily keep objects alive.
|
|
|
|
isolate_->optimizing_compiler_thread()->InstallOptimizedFunctions();
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Run through the JavaScript frames and collect them. If we already
|
|
|
|
// have a sample of the function, we mark it for optimizations
|
|
|
|
// (eagerly or lazily).
|
|
|
|
JSFunction* samples[kSamplerFrameCount];
|
2010-12-10 12:00:26 +00:00
|
|
|
int sample_count = 0;
|
|
|
|
int frame_count = 0;
|
2012-02-14 14:28:37 +00:00
|
|
|
int frame_count_limit = FLAG_watch_ic_patching ? FLAG_frame_count
|
|
|
|
: kSamplerFrameCount;
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
for (JavaScriptFrameIterator it(isolate_);
|
2012-02-14 14:28:37 +00:00
|
|
|
frame_count++ < frame_count_limit && !it.done();
|
2010-12-07 11:31:57 +00:00
|
|
|
it.Advance()) {
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
2013-07-11 16:45:58 +00:00
|
|
|
JSFunction* function = frame->function();
|
2010-12-09 13:12:23 +00:00
|
|
|
|
2012-02-09 13:30:01 +00:00
|
|
|
if (!FLAG_watch_ic_patching) {
|
2012-02-09 10:19:46 +00:00
|
|
|
// Adjust threshold each time we have processed
|
|
|
|
// a certain number of ticks.
|
|
|
|
if (sampler_ticks_until_threshold_adjustment_ > 0) {
|
|
|
|
sampler_ticks_until_threshold_adjustment_--;
|
|
|
|
if (sampler_ticks_until_threshold_adjustment_ <= 0) {
|
|
|
|
// If the threshold is not already at the minimum
|
|
|
|
// modify and reset the ticks until next adjustment.
|
|
|
|
if (sampler_threshold_ > kSamplerThresholdMin) {
|
|
|
|
sampler_threshold_ -= kSamplerThresholdDelta;
|
|
|
|
sampler_ticks_until_threshold_adjustment_ =
|
|
|
|
kSamplerTicksBetweenThresholdAdjustment;
|
|
|
|
}
|
2010-12-09 13:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 16:57:27 +00:00
|
|
|
SharedFunctionInfo* shared = function->shared();
|
|
|
|
Code* shared_code = shared->code();
|
|
|
|
|
2012-03-27 12:19:50 +00:00
|
|
|
if (shared_code->kind() != Code::FUNCTION) continue;
|
2013-03-12 18:03:18 +00:00
|
|
|
if (function->IsInRecompileQueue()) continue;
|
|
|
|
|
2013-06-26 08:43:27 +00:00
|
|
|
if (FLAG_always_osr &&
|
|
|
|
shared_code->allow_osr_at_loop_nesting_level() == 0) {
|
|
|
|
// Testing mode: always try an OSR compile for every function.
|
|
|
|
for (int i = 0; i < Code::kMaxLoopNestingMarker; i++) {
|
|
|
|
// TODO(titzer): fix AttemptOnStackReplacement to avoid this dumb loop.
|
|
|
|
shared_code->set_allow_osr_at_loop_nesting_level(i);
|
|
|
|
AttemptOnStackReplacement(function);
|
|
|
|
}
|
|
|
|
// Fall through and do a normal optimized compile as well.
|
|
|
|
} else if (!frame->is_optimized() &&
|
2013-03-12 18:03:18 +00:00
|
|
|
(function->IsMarkedForLazyRecompilation() ||
|
2013-08-22 16:14:37 +00:00
|
|
|
function->IsMarkedForConcurrentRecompilation() ||
|
2013-03-12 18:03:18 +00:00
|
|
|
function->IsOptimized())) {
|
2013-06-26 08:43:27 +00:00
|
|
|
// Attempt OSR if we are still running unoptimized code even though the
|
|
|
|
// the function has long been marked or even already been optimized.
|
2013-06-14 11:35:00 +00:00
|
|
|
int ticks = shared_code->profiler_ticks();
|
|
|
|
int allowance = kOSRCodeSizeAllowanceBase +
|
|
|
|
ticks * kOSRCodeSizeAllowancePerTick;
|
|
|
|
if (shared_code->CodeSize() > allowance) {
|
|
|
|
if (ticks < 255) shared_code->set_profiler_ticks(ticks + 1);
|
|
|
|
} else {
|
|
|
|
int nesting = shared_code->allow_osr_at_loop_nesting_level();
|
|
|
|
if (nesting < Code::kMaxLoopNestingMarker) {
|
|
|
|
int new_nesting = nesting + 1;
|
|
|
|
shared_code->set_allow_osr_at_loop_nesting_level(new_nesting);
|
|
|
|
AttemptOnStackReplacement(function);
|
|
|
|
}
|
2013-04-10 09:24:31 +00:00
|
|
|
}
|
2013-06-14 11:35:00 +00:00
|
|
|
continue;
|
2010-12-09 13:12:23 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 14:14:51 +00:00
|
|
|
// Only record top-level code on top of the execution stack and
|
|
|
|
// avoid optimizing excessively large scripts since top-level code
|
|
|
|
// will be executed only once.
|
|
|
|
const int kMaxToplevelSourceSize = 10 * 1024;
|
2012-06-11 16:57:27 +00:00
|
|
|
if (shared->is_toplevel() &&
|
|
|
|
(frame_count > 1 || shared->SourceSize() > kMaxToplevelSourceSize)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not record non-optimizable functions.
|
|
|
|
if (shared->optimization_disabled()) {
|
2012-08-16 11:40:03 +00:00
|
|
|
if (shared->deopt_count() >= FLAG_max_opt_count) {
|
2012-06-11 16:57:27 +00:00
|
|
|
// If optimization was disabled due to many deoptimizations,
|
|
|
|
// then check if the function is hot and try to reenable optimization.
|
|
|
|
int ticks = shared_code->profiler_ticks();
|
|
|
|
if (ticks >= kProfilerTicksBeforeReenablingOptimization) {
|
|
|
|
shared_code->set_profiler_ticks(0);
|
|
|
|
shared->TryReenableOptimization();
|
|
|
|
} else {
|
|
|
|
shared_code->set_profiler_ticks(ticks + 1);
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 14:14:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-06-11 16:57:27 +00:00
|
|
|
if (!function->IsOptimizable()) continue;
|
|
|
|
|
2012-02-09 13:30:01 +00:00
|
|
|
if (FLAG_watch_ic_patching) {
|
2012-03-27 12:19:50 +00:00
|
|
|
int ticks = shared_code->profiler_ticks();
|
2012-02-09 10:19:46 +00:00
|
|
|
|
|
|
|
if (ticks >= kProfilerTicksBeforeOptimization) {
|
2012-02-20 12:57:23 +00:00
|
|
|
int typeinfo, total, percentage;
|
2013-06-14 11:35:00 +00:00
|
|
|
GetICCounts(shared_code, &typeinfo, &total, &percentage);
|
2012-02-20 12:57:23 +00:00
|
|
|
if (percentage >= FLAG_type_info_threshold) {
|
|
|
|
// If this particular function hasn't had any ICs patched for enough
|
|
|
|
// ticks, optimize it now.
|
|
|
|
Optimize(function, "hot and stable");
|
2012-03-27 12:19:50 +00:00
|
|
|
} else if (ticks >= kTicksWhenNotEnoughTypeInfo) {
|
2012-03-22 11:05:33 +00:00
|
|
|
Optimize(function, "not much type info but very hot");
|
2012-02-20 12:57:23 +00:00
|
|
|
} else {
|
2012-03-27 12:19:50 +00:00
|
|
|
shared_code->set_profiler_ticks(ticks + 1);
|
2012-02-20 12:57:23 +00:00
|
|
|
if (FLAG_trace_opt_verbose) {
|
|
|
|
PrintF("[not yet optimizing ");
|
|
|
|
function->PrintName();
|
|
|
|
PrintF(", not enough type info: %d/%d (%d%%)]\n",
|
|
|
|
typeinfo, total, percentage);
|
|
|
|
}
|
|
|
|
}
|
2012-02-09 10:19:46 +00:00
|
|
|
} else if (!any_ic_changed_ &&
|
2012-07-25 13:51:29 +00:00
|
|
|
shared_code->instruction_size() < kMaxSizeEarlyOpt) {
|
2012-02-09 10:19:46 +00:00
|
|
|
// If no IC was patched since the last tick and this function is very
|
|
|
|
// small, optimistically optimize it now.
|
|
|
|
Optimize(function, "small function");
|
|
|
|
} else {
|
2012-03-27 12:19:50 +00:00
|
|
|
shared_code->set_profiler_ticks(ticks + 1);
|
2012-02-09 10:19:46 +00:00
|
|
|
}
|
2012-02-14 14:00:31 +00:00
|
|
|
} else { // !FLAG_watch_ic_patching
|
2012-02-09 10:19:46 +00:00
|
|
|
samples[sample_count++] = function;
|
|
|
|
|
2012-04-30 11:54:34 +00:00
|
|
|
int function_size = function->shared()->SourceSize();
|
2012-02-09 10:19:46 +00:00
|
|
|
int threshold_size_factor = (function_size > kSizeLimit)
|
|
|
|
? sampler_threshold_size_factor_
|
|
|
|
: 1;
|
2010-12-09 13:12:23 +00:00
|
|
|
|
2012-02-09 10:19:46 +00:00
|
|
|
int threshold = sampler_threshold_ * threshold_size_factor;
|
2010-12-09 13:12:23 +00:00
|
|
|
|
2012-02-09 10:19:46 +00:00
|
|
|
if (LookupSample(function) >= threshold) {
|
|
|
|
Optimize(function, "sampler window lookup");
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-09 13:30:01 +00:00
|
|
|
if (FLAG_watch_ic_patching) {
|
2012-02-09 10:19:46 +00:00
|
|
|
any_ic_changed_ = false;
|
2012-02-14 14:00:31 +00:00
|
|
|
} else { // !FLAG_watch_ic_patching
|
2012-02-09 10:19:46 +00:00
|
|
|
// Add the collected functions as samples. It's important not to do
|
|
|
|
// this as part of collecting them because this will interfere with
|
|
|
|
// the sample lookup in case of recursive functions.
|
|
|
|
for (int i = 0; i < sample_count; i++) {
|
|
|
|
AddSample(samples[i], kSamplerFrameWeight[i]);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
void RuntimeProfiler::SetUp() {
|
2012-02-09 13:30:01 +00:00
|
|
|
if (!FLAG_watch_ic_patching) {
|
2012-02-09 10:19:46 +00:00
|
|
|
ClearSampleBuffer();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RuntimeProfiler::Reset() {
|
2012-03-27 12:26:58 +00:00
|
|
|
if (!FLAG_watch_ic_patching) {
|
2012-02-09 10:19:46 +00:00
|
|
|
sampler_threshold_ = kSamplerThresholdInit;
|
|
|
|
sampler_threshold_size_factor_ = kSamplerThresholdSizeFactorInit;
|
|
|
|
sampler_ticks_until_threshold_adjustment_ =
|
|
|
|
kSamplerTicksBetweenThresholdAdjustment;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RuntimeProfiler::TearDown() {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 10:16:47 +00:00
|
|
|
// Update the pointers in the sampler window after a GC.
|
|
|
|
void RuntimeProfiler::UpdateSamplesAfterScavenge() {
|
|
|
|
for (int i = 0; i < kSamplerWindowSize; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Object* function = sampler_window_[i];
|
|
|
|
if (function != NULL && isolate_->heap()->InNewSpace(function)) {
|
2011-03-02 10:16:47 +00:00
|
|
|
MapWord map_word = HeapObject::cast(function)->map_word();
|
|
|
|
if (map_word.IsForwardingAddress()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
sampler_window_[i] = map_word.ToForwardingAddress();
|
2011-03-02 10:16:47 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
sampler_window_[i] = NULL;
|
2011-03-02 10:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RuntimeProfiler::RemoveDeadSamples() {
|
|
|
|
for (int i = 0; i < kSamplerWindowSize; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Object* function = sampler_window_[i];
|
2011-09-19 18:36:47 +00:00
|
|
|
if (function != NULL &&
|
|
|
|
!Marking::MarkBitFrom(HeapObject::cast(function)).Get()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
sampler_window_[i] = NULL;
|
2011-03-02 10:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) {
|
|
|
|
for (int i = 0; i < kSamplerWindowSize; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
visitor->VisitPointer(&sampler_window_[i]);
|
2011-03-02 10:16:47 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|