Make sure CallIC is in monomorphic state when starting profiling in NativeAccessorNameInProfile2

Changed cctest/test-cpu-profiler/NativeAccessorNameInProfile2 to make a few warm-up cycles before starting profiler so that accessor invocations performed via monomorphic inline caches and slow paths traces do not distort the profile.

Drive-by: removed logging code that was used to diagnose NativeAccessorNameInProfile2 failures on Windows.

BUG=None
R=jkummerow@chromium.org, loislo@chromium.org

Review URL: https://codereview.chromium.org/16758007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15055 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yurys@chromium.org 2013-06-11 08:32:48 +00:00
parent c90e697a30
commit b90bd6987b

View File

@ -652,15 +652,12 @@ class FooAccessorsData {
public:
explicit FooAccessorsData(int min_duration_ms)
: min_duration_ms_(min_duration_ms),
getter_duration_(0),
setter_duration_(0),
getter_iterations_(0),
setter_iterations_(0) {}
is_warming_up_(false) {}
static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name,
const v8::AccessorInfo& info) {
FooAccessorsData* data = fromInfo(info);
data->getter_duration_ = data->Wait(&data->getter_iterations_);
data->Wait();
return v8::Int32::New(2013);
}
@ -668,24 +665,20 @@ class FooAccessorsData {
v8::Local<v8::Value> value,
const v8::AccessorInfo& info) {
FooAccessorsData* data = fromInfo(info);
data->setter_duration_ = data->Wait(&data->setter_iterations_);
data->Wait();
}
void PrintAccessorTime() {
i::OS::Print("getter: %f ms (%d); setter: %f ms (%d)\n", getter_duration_,
getter_iterations_, setter_duration_, setter_iterations_);
}
void set_warming_up(bool value) { is_warming_up_ = value; }
private:
double Wait(int* iterations) {
void Wait() {
if (is_warming_up_) return;
double start = i::OS::TimeCurrentMillis();
double duration = 0;
while (duration < min_duration_ms_) {
i::OS::Sleep(1);
duration = i::OS::TimeCurrentMillis() - start;
++*iterations;
}
return duration;
}
static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) {
@ -694,10 +687,7 @@ class FooAccessorsData {
}
int min_duration_ms_;
double getter_duration_;
double setter_duration_;
int getter_iterations_;
int setter_iterations_;
bool is_warming_up_;
};
@ -705,7 +695,7 @@ class FooAccessorsData {
// This test checks the case when the long-running accessors are called
// only once and the optimizer doesn't have chance to change the invocation
// code.
TEST(NativeAccessorNameInProfile1) {
TEST(NativeAccessorUninitializedIC) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
@ -740,7 +730,6 @@ TEST(NativeAccessorNameInProfile1) {
// Dump collected profile to have a better diagnostic in case of failure.
reinterpret_cast<i::CpuProfile*>(
const_cast<v8::CpuProfile*>(profile))->Print();
accessors.PrintAccessorTime();
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* startNode = GetChild(root, "start");
@ -754,7 +743,7 @@ TEST(NativeAccessorNameInProfile1) {
// Test that native accessors are properly reported in the CPU profile.
// This test makes sure that the accessors are called enough times to become
// hot and to trigger optimizations.
TEST(NativeAccessorNameInProfile2) {
TEST(NativeAccessorMonomorphicIC) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
@ -776,6 +765,16 @@ TEST(NativeAccessorNameInProfile2) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
{
// Make sure accessors ICs are in monomorphic state before starting
// profiling.
accessors.set_warming_up(true);
int32_t warm_up_iterations = 3;
v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) };
function->Call(env->Global(), ARRAY_SIZE(args), args);
accessors.set_warming_up(false);
}
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name = v8::String::New("my_profile");