Version 3.19.13
Performance and stability improvements on all platforms.
git-svn-id: http://v8.googlecode.com/svn/trunk@15068 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc
index b241f32..94dcce1 100644
--- a/test/cctest/cctest.cc
+++ b/test/cctest/cctest.cc
@@ -98,10 +98,21 @@
v8::Isolate* CcTest::default_isolate_;
+class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+ public:
+ virtual void* Allocate(size_t length) { return malloc(length); }
+ virtual void Free(void* data) { free(data); }
+};
+
+
int main(int argc, char* argv[]) {
v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
v8::internal::FLAG_harmony_array_buffer = true;
v8::internal::FLAG_harmony_typed_arrays = true;
+
+ CcTestArrayBufferAllocator array_buffer_allocator;
+ v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
+
CcTest::set_default_isolate(v8::Isolate::GetCurrent());
CHECK(CcTest::default_isolate() != NULL);
int tests_run = 0;
diff --git a/test/cctest/cctest.status b/test/cctest/cctest.status
index 8ce11eb..59b3dc3 100644
--- a/test/cctest/cctest.status
+++ b/test/cctest/cctest.status
@@ -78,6 +78,9 @@
# BUG(2628): The test sometimes fails on MIPS simulator.
test-cpu-profiler/SampleWhenFrameIsNotSetup: PASS || FAIL
+# BUG(2657): Test sometimes times out on MIPS simulator.
+test-thread-termination/TerminateMultipleV8ThreadsDefaultIsolate: PASS || TIMEOUT
+
##############################################################################
[ $arch == android_arm || $arch == android_ia32 ]
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a69fe90..5d3a79d 100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1037,7 +1037,12 @@
static const double kFastReturnValueDouble = 2.7;
// variable return values
static bool fast_return_value_bool = false;
-static bool fast_return_value_void_is_null = false;
+enum ReturnValueOddball {
+ kNullReturnValue,
+ kUndefinedReturnValue,
+ kEmptyStringReturnValue
+};
+static ReturnValueOddball fast_return_value_void;
static bool fast_return_value_object_is_empty = false;
template<>
@@ -1072,10 +1077,16 @@
void FastReturnValueCallback<void>(
const v8::FunctionCallbackInfo<v8::Value>& info) {
CheckReturnValue(info);
- if (fast_return_value_void_is_null) {
- info.GetReturnValue().SetNull();
- } else {
- info.GetReturnValue().SetUndefined();
+ switch (fast_return_value_void) {
+ case kNullReturnValue:
+ info.GetReturnValue().SetNull();
+ break;
+ case kUndefinedReturnValue:
+ info.GetReturnValue().SetUndefined();
+ break;
+ case kEmptyStringReturnValue:
+ info.GetReturnValue().SetEmptyString();
+ break;
}
}
@@ -1135,13 +1146,25 @@
CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value());
}
// check oddballs
- for (int i = 0; i < 2; i++) {
- fast_return_value_void_is_null = i == 0;
+ ReturnValueOddball oddballs[] = {
+ kNullReturnValue,
+ kUndefinedReturnValue,
+ kEmptyStringReturnValue
+ };
+ for (size_t i = 0; i < ARRAY_SIZE(oddballs); i++) {
+ fast_return_value_void = oddballs[i];
value = TestFastReturnValues<void>();
- if (fast_return_value_void_is_null) {
- CHECK(value->IsNull());
- } else {
- CHECK(value->IsUndefined());
+ switch (fast_return_value_void) {
+ case kNullReturnValue:
+ CHECK(value->IsNull());
+ break;
+ case kUndefinedReturnValue:
+ CHECK(value->IsUndefined());
+ break;
+ case kEmptyStringReturnValue:
+ CHECK(value->IsString());
+ CHECK_EQ(0, v8::String::Cast(*value)->Length());
+ break;
}
}
// check handles
@@ -2547,6 +2570,19 @@
}
+class ScopedArrayBufferContents {
+ public:
+ explicit ScopedArrayBufferContents(
+ const v8::ArrayBuffer::Contents& contents)
+ : contents_(contents) {}
+ ~ScopedArrayBufferContents() { free(contents_.Data()); }
+ void* Data() const { return contents_.Data(); }
+ size_t ByteLength() const { return contents_.ByteLength(); }
+ private:
+ const v8::ArrayBuffer::Contents contents_;
+};
+
+
THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
i::FLAG_harmony_array_buffer = true;
i::FLAG_harmony_typed_arrays = true;
@@ -2560,8 +2596,7 @@
CHECK(!ab->IsExternal());
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
- v8::ArrayBufferContents ab_contents;
- ab->Externalize(&ab_contents);
+ ScopedArrayBufferContents ab_contents(ab->Externalize());
CHECK(ab->IsExternal());
CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
@@ -2603,8 +2638,7 @@
Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result);
CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
CHECK(!ab1->IsExternal());
- v8::ArrayBufferContents ab1_contents;
- ab1->Externalize(&ab1_contents);
+ ScopedArrayBufferContents ab1_contents(ab1->Externalize());
CHECK(ab1->IsExternal());
result = CompileRun("ab1.byteLength");
@@ -2711,8 +2745,7 @@
v8::Handle<v8::Float64Array> f64a =
CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
- v8::ArrayBufferContents contents;
- buffer->Externalize(&contents);
+ ScopedArrayBufferContents contents(buffer->Externalize());
buffer->Neuter();
CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
CheckIsNeutered(u8a);
@@ -2763,8 +2796,7 @@
v8::Handle<v8::Float64Array> f64a(
v8::Float64Array::Cast(*CompileRun("f64a")));
- v8::ArrayBufferContents contents;
- ab->Externalize(&contents);
+ ScopedArrayBufferContents contents(ab->Externalize());
ab->Neuter();
CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
CheckIsNeutered(u8a);
diff --git a/test/cctest/test-compare-nil-ic-stub.cc b/test/cctest/test-compare-nil-ic-stub.cc
index 6177fde..affb8bd 100644
--- a/test/cctest/test-compare-nil-ic-stub.cc
+++ b/test/cctest/test-compare-nil-ic-stub.cc
@@ -46,9 +46,8 @@
TEST(ExternalICStateParsing) {
Types types;
types.Add(CompareNilICStub::UNDEFINED);
- CompareNilICStub stub(kNonStrictEquality, kUndefinedValue, types);
+ CompareNilICStub stub(kUndefinedValue, types);
CompareNilICStub stub2(stub.GetExtraICState());
- CHECK_EQ(stub.GetKind(), stub2.GetKind());
CHECK_EQ(stub.GetNilValue(), stub2.GetNilValue());
CHECK_EQ(stub.GetTypes().ToIntegral(), stub2.GetTypes().ToIntegral());
}
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc
index 188fbd9..a615fe9 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -648,56 +648,57 @@
"}\n";
-class FooAccessorsData {
+class TestApiCallbacks {
public:
- explicit FooAccessorsData(int min_duration_ms)
+ explicit TestApiCallbacks(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_);
+ TestApiCallbacks* data = fromInfo(info);
+ data->Wait();
return v8::Int32::New(2013);
}
static void Setter(v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::AccessorInfo& info) {
- FooAccessorsData* data = fromInfo(info);
- data->setter_duration_ = data->Wait(&data->setter_iterations_);
+ TestApiCallbacks* data = fromInfo(info);
+ data->Wait();
}
- void PrintAccessorTime() {
- i::OS::Print("getter: %f ms (%d); setter: %f ms (%d)\n", getter_duration_,
- getter_iterations_, setter_duration_, setter_iterations_);
+ static void Callback(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ TestApiCallbacks* data = fromInfo(info);
+ data->Wait();
}
+ 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) {
+ static TestApiCallbacks* fromInfo(const v8::AccessorInfo& info) {
void* data = v8::External::Cast(*info.Data())->Value();
- return reinterpret_cast<FooAccessorsData*>(data);
+ return reinterpret_cast<TestApiCallbacks*>(data);
+ }
+
+ static TestApiCallbacks* fromInfo(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ void* data = v8::External::Cast(*info.Data())->Value();
+ return reinterpret_cast<TestApiCallbacks*>(data);
}
int min_duration_ms_;
- double getter_duration_;
- double setter_duration_;
- int getter_iterations_;
- int setter_iterations_;
+ bool is_warming_up_;
};
@@ -705,7 +706,7 @@
// 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());
@@ -714,11 +715,11 @@
v8::Local<v8::ObjectTemplate> instance_template =
func_template->InstanceTemplate();
- FooAccessorsData accessors(100);
+ TestApiCallbacks accessors(100);
v8::Local<v8::External> data = v8::External::New(&accessors);
instance_template->SetAccessor(
- v8::String::New("foo"), &FooAccessorsData::Getter,
- &FooAccessorsData::Setter, data);
+ v8::String::New("foo"), &TestApiCallbacks::Getter,
+ &TestApiCallbacks::Setter, data);
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::New("instance"), instance);
@@ -740,7 +741,6 @@
// 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 +754,7 @@
// 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());
@@ -763,11 +763,11 @@
v8::Local<v8::ObjectTemplate> instance_template =
func_template->InstanceTemplate();
- FooAccessorsData accessors(1);
+ TestApiCallbacks accessors(1);
v8::Local<v8::External> data = v8::External::New(&accessors);
instance_template->SetAccessor(
- v8::String::New("foo"), &FooAccessorsData::Getter,
- &FooAccessorsData::Setter, data);
+ v8::String::New("foo"), &TestApiCallbacks::Getter,
+ &TestApiCallbacks::Setter, data);
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::New("instance"), instance);
@@ -776,6 +776,16 @@
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");
@@ -799,3 +809,111 @@
cpu_profiler->DeleteAllCpuProfiles();
}
+
+
+static const char* native_method_test_source = "function start(count) {\n"
+" for (var i = 0; i < count; i++) {\n"
+" instance.fooMethod();\n"
+" }\n"
+"}\n";
+
+
+TEST(NativeMethodUninitializedIC) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ TestApiCallbacks callbacks(100);
+ v8::Local<v8::External> data = v8::External::New(&callbacks);
+
+ v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
+ func_template->SetClassName(v8::String::New("Test_InstanceCostructor"));
+ v8::Local<v8::ObjectTemplate> proto_template =
+ func_template->PrototypeTemplate();
+ v8::Local<v8::Signature> signature = v8::Signature::New(func_template);
+ proto_template->Set(v8::String::New("fooMethod"), v8::FunctionTemplate::New(
+ &TestApiCallbacks::Callback, data, signature, 0));
+
+ v8::Local<v8::Function> func = func_template->GetFunction();
+ v8::Local<v8::Object> instance = func->NewInstance();
+ env->Global()->Set(v8::String::New("instance"), instance);
+
+ v8::Script::Compile(v8::String::New(native_method_test_source))->Run();
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::New("start")));
+
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
+ v8::Local<v8::String> profile_name = v8::String::New("my_profile");
+
+ cpu_profiler->StartCpuProfiling(profile_name);
+ int32_t repeat_count = 1;
+ v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
+ function->Call(env->Global(), ARRAY_SIZE(args), args);
+ const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
+
+ CHECK_NE(NULL, profile);
+ // Dump collected profile to have a better diagnostic in case of failure.
+ reinterpret_cast<i::CpuProfile*>(
+ const_cast<v8::CpuProfile*>(profile))->Print();
+
+ const v8::CpuProfileNode* root = profile->GetTopDownRoot();
+ const v8::CpuProfileNode* startNode = GetChild(root, "start");
+ GetChild(startNode, "fooMethod");
+
+ cpu_profiler->DeleteAllCpuProfiles();
+}
+
+
+TEST(NativeMethodMonomorphicIC) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ TestApiCallbacks callbacks(1);
+ v8::Local<v8::External> data = v8::External::New(&callbacks);
+
+ v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
+ func_template->SetClassName(v8::String::New("Test_InstanceCostructor"));
+ v8::Local<v8::ObjectTemplate> proto_template =
+ func_template->PrototypeTemplate();
+ v8::Local<v8::Signature> signature = v8::Signature::New(func_template);
+ proto_template->Set(v8::String::New("fooMethod"), v8::FunctionTemplate::New(
+ &TestApiCallbacks::Callback, data, signature, 0));
+
+ v8::Local<v8::Function> func = func_template->GetFunction();
+ v8::Local<v8::Object> instance = func->NewInstance();
+ env->Global()->Set(v8::String::New("instance"), instance);
+
+ v8::Script::Compile(v8::String::New(native_method_test_source))->Run();
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::New("start")));
+ {
+ // Make sure method ICs are in monomorphic state before starting
+ // profiling.
+ callbacks.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);
+ callbacks.set_warming_up(false);
+ }
+
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
+ v8::Local<v8::String> profile_name = v8::String::New("my_profile");
+
+ cpu_profiler->StartCpuProfiling(profile_name);
+ int32_t repeat_count = 100;
+ v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
+ function->Call(env->Global(), ARRAY_SIZE(args), args);
+ const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
+
+ CHECK_NE(NULL, profile);
+ // Dump collected profile to have a better diagnostic in case of failure.
+ reinterpret_cast<i::CpuProfile*>(
+ const_cast<v8::CpuProfile*>(profile))->Print();
+
+ const v8::CpuProfileNode* root = profile->GetTopDownRoot();
+ GetChild(root, "start");
+ // TODO(yurys): in CallIC should be changed to report external callback
+ // invocation.
+ // GetChild(startNode, "fooMethod");
+
+ cpu_profiler->DeleteAllCpuProfiles();
+}