TEST(OptimizedPretenuringAllocationFolding) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
- i::FLAG_allocation_site_pretenuring = false;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "function DataObject() {"
- " this.a = 1.1;"
- " this.b = [{}];"
- " this.c = 1.2;"
- " this.d = [{}];"
- " this.e = 1.3;"
- " this.f = [{}];"
- "}"
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array();"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
- " elements[i] = new DataObject();"
+ " elements[i] = [[{}], [1.1]];"
" }"
" return elements[number_elements-1]"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
-
- Handle<JSObject> o =
- v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(0)));
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1)));
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2)));
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(3)));
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(4)));
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(5)));
-}
-
-
-TEST(OptimizedPretenuringAllocationFoldingBlocks) {
- i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
- i::FLAG_allocation_site_pretenuring = false;
- CcTest::InitializeVM();
- if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
- if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
- v8::HandleScope scope(CcTest::isolate());
+ v8::Local<v8::Value> res = CompileRun(source.start());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 30000;"
- "var elements = new Array(number_elements);"
- "function DataObject() {"
- " this.a = [{}];"
- " this.b = [{}];"
- " this.c = 1.1;"
- " this.d = 1.2;"
- " this.e = [{}];"
- " this.f = 1.3;"
- "}"
- "function f() {"
- " for (var i = 0; i < number_elements; i++) {"
- " elements[i] = new DataObject();"
- " }"
- " return elements[number_elements - 1];"
- "};"
- "f(); f(); f();"
- "%OptimizeFunctionOnNextCall(f);"
- "f();");
+ v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0"));
+ Handle<JSObject> int_array_handle =
+ v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array));
+ v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1"));
+ Handle<JSObject> double_array_handle =
+ v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array));
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
-
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0)));
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1)));
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2)));
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(3)));
- CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(4)));
- CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(5)));
+ CHECK(CcTest::heap()->InOldPointerSpace(*o));
+ CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle));
+ CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle->elements()));
+ CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle));
+ CHECK(CcTest::heap()->InOldDataSpace(double_array_handle->elements()));
}
TEST(OptimizedPretenuringObjectArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
TEST(OptimizedPretenuringMixedInObjectProperties) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
TEST(OptimizedPretenuringDoubleArrayProperties) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 30000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[i - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
TEST(OptimizedPretenuringdoubleArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 30000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
TEST(OptimizedPretenuringNestedMixedArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = 100;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0"));
Handle<JSObject> int_array_handle =
TEST(OptimizedPretenuringNestedObjectLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0"));
Handle<JSObject> int_array_handle_1 =
TEST(OptimizedPretenuringNestedDoubleLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function f() {"
" for (var i = 0; i < number_elements; i++) {"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
v8::Local<v8::Value> double_array_1 =
v8::Object::Cast(*res)->Get(v8_str("0"));
// Make sure pretenuring feedback is gathered for constructed objects as well
// as for literals.
TEST(OptimizedPretenuringConstructorCalls) {
- if (!FLAG_allocation_site_pretenuring || !i::FLAG_pretenuring_call_new) {
+ if (!i::FLAG_pretenuring_call_new) {
// FLAG_pretenuring_call_new needs to be synced with the snapshot.
return;
}
i::FLAG_allow_natives_syntax = true;
- i::FLAG_max_semi_space_size = 1;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
- "var number_elements = 20000;"
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = %d;"
"var elements = new Array(number_elements);"
"function foo() {"
" this.a = 3;"
" }"
" return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
}
-// Test regular array literals allocation.
-TEST(OptimizedAllocationArrayLiterals) {
+TEST(OptimizedPretenuringCallNew) {
+ if (!i::FLAG_pretenuring_call_new) {
+ // FLAG_pretenuring_call_new needs to be synced with the snapshot.
+ return;
+ }
i::FLAG_allow_natives_syntax = true;
+ i::FLAG_expose_gc = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- v8::Local<v8::Value> res = CompileRun(
+ i::ScopedVector<char> source(1024);
+ i::OS::SNPrintF(
+ source,
+ "var number_elements = 100;"
+ "var elements = new Array(number_elements);"
+ "function g() { this.a = 0; }"
"function f() {"
- " var numbers = new Array(1, 2, 3);"
- " numbers[0] = 3.14;"
- " return numbers;"
+ " for (var i = 0; i < number_elements; i++) {"
+ " elements[i] = new g();"
+ " }"
+ " return elements[number_elements - 1];"
"};"
- "f(); f(); f();"
+ "f(); gc();"
+ "f(); f();"
"%OptimizeFunctionOnNextCall(f);"
- "f();");
- CHECK_EQ(static_cast<int>(3.14),
- v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value());
+ "f();",
+ AllocationSite::kPretenureMinimumCreated);
+
+ v8::Local<v8::Value> res = CompileRun(source.start());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
-
- CHECK(CcTest::heap()->InNewSpace(o->elements()));
+ CHECK(CcTest::heap()->InOldPointerSpace(*o));
}
-// Test global pretenuring call new.
-TEST(OptimizedPretenuringCallNew) {
+// Test regular array literals allocation.
+TEST(OptimizedAllocationArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_allocation_site_pretenuring = false;
- i::FLAG_pretenuring_call_new = true;
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope(CcTest::isolate());
- AlwaysAllocateScope always_allocate(CcTest::i_isolate());
v8::Local<v8::Value> res = CompileRun(
- "function g() { this.a = 0; }"
"function f() {"
- " return new g();"
+ " var numbers = new Array(1, 2, 3);"
+ " numbers[0] = 3.14;"
+ " return numbers;"
"};"
"f(); f(); f();"
"%OptimizeFunctionOnNextCall(f);"
"f();");
+ CHECK_EQ(static_cast<int>(3.14),
+ v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
- CHECK(CcTest::heap()->InOldPointerSpace(*o));
+
+ CHECK(CcTest::heap()->InNewSpace(o->elements()));
}