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);
}
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) {
}
int min_duration_ms_;
- double getter_duration_;
- double setter_duration_;
- int getter_iterations_;
- int setter_iterations_;
+ bool is_warming_up_;
};
// 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());
// 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");
// 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());
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");