Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1407)

Unified Diff: test/cctest/test-code-stub-assembler.cc

Issue 2497243002: [stubs] Port builtin for Array.push fast-case from Crankshaft to TF (Closed)
Patch Set: Cleanup Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-code-stub-assembler.cc
diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc
index 28cdc55318a61b6c359933841fcc149a43bbb125..f112ccebe08c60bef28e56cb411d2b42bcc19334 100644
--- a/test/cctest/test-code-stub-assembler.cc
+++ b/test/cctest/test-code-stub-assembler.cc
@@ -2003,5 +2003,272 @@ TEST(ArgumentsForEach) {
CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
}
+TEST(BuildAppendJSArrayFastElement) {
Jakob Kummerow 2016/11/23 17:17:06 High-level comment: We certainly shouldn't over-en
danno 2016/11/29 14:40:00 Done.
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ typedef CodeStubAssembler::Variable Variable;
+ typedef CodeStubAssembler::Label Label;
+
+ const int kNumParams = 4;
+ CodeAssemblerTester data(isolate, kNumParams);
+ CodeStubAssembler m(data.state());
+
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+ (void)JSObject::SetElement(isolate, array, 0,
Jakob Kummerow 2016/11/23 17:17:06 Instead of "(void)JSObject::SetElement(...)", do "
danno 2016/11/29 14:40:00 Done.
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY);
+ (void)JSObject::SetElement(isolate, array, 1,
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY);
+ CodeStubArguments args(&m, m.IntPtrConstant(4));
+ Variable arg_index(&m, MachineType::PointerRepresentation());
+ Label bailout(&m);
+ arg_index.Bind(m.IntPtrConstant(0));
+ Node* length = m.BuildAppendJSArray(
+ FAST_ELEMENTS,
+ m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
+ m.HeapConstant(array), args, arg_index, &bailout);
+
+ m.PopAndReturn(m.IntPtrConstant(4), length);
+
+ Handle<Code> code = data.GenerateCode();
+ CHECK(!code.is_null());
+
+ FunctionTester ft(code, kNumParams);
+ Handle<Object> result;
+ result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate),
+ Handle<Smi>(Smi::FromInt(4), isolate),
+ Handle<Smi>(Smi::FromInt(5), isolate),
+ Handle<Smi>(Smi::FromInt(6), isolate))
+ .ToHandleChecked();
+
+ CHECK_EQ(6, Handle<Smi>::cast(result)->value());
+ CHECK_EQ(3, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 2).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 3).ToHandleChecked())
+ ->value());
+ CHECK_EQ(5, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 4).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 5).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Smi::cast(array->length())->value());
+}
+
+TEST(BuildAppendJSArrayFastElementGrow) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ typedef CodeStubAssembler::Variable Variable;
+ typedef CodeStubAssembler::Label Label;
+
+ const int kNumParams = 4;
+ CodeAssemblerTester data(isolate, 0);
Jakob Kummerow 2016/11/23 17:17:06 don't you mean s/0/kNumParams/? How does this even
danno 2016/11/29 14:39:59 Done.
+ CodeStubAssembler m(data.state());
+
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_ELEMENTS, 2, 3, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+ (void)JSObject::SetElement(isolate, array, 0,
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY);
+ (void)JSObject::SetElement(isolate, array, 1,
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY);
+ CodeStubArguments args(&m, m.IntPtrConstant(4));
+ Variable arg_index(&m, MachineType::PointerRepresentation());
+ Label bailout(&m);
+ arg_index.Bind(m.IntPtrConstant(0));
+ Node* length = m.BuildAppendJSArray(
+ FAST_ELEMENTS,
+ m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
+ m.HeapConstant(array), args, arg_index, &bailout);
+
+ m.PopAndReturn(m.IntPtrConstant(4), length);
+
+ Handle<Code> code = data.GenerateCode();
+ CHECK(!code.is_null());
+
+ FunctionTester ft(code, kNumParams);
+ Handle<Object> result;
+ result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate),
+ Handle<Smi>(Smi::FromInt(4), isolate),
+ Handle<Smi>(Smi::FromInt(5), isolate),
+ Handle<Smi>(Smi::FromInt(6), isolate))
+ .ToHandleChecked();
+
+ CHECK_EQ(6, Handle<Smi>::cast(result)->value());
+ CHECK_EQ(3, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 2).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 3).ToHandleChecked())
+ ->value());
+ CHECK_EQ(5, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 4).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 5).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Smi::cast(array->length())->value());
+}
+
+TEST(BuildAppendJSArrayFastSmiElement) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ typedef CodeStubAssembler::Variable Variable;
+ typedef CodeStubAssembler::Label Label;
+
+ const int kNumParams = 4;
+ CodeAssemblerTester data(isolate, 0);
Jakob Kummerow 2016/11/23 17:17:06 same here
danno 2016/11/29 14:39:59 Done.
+ CodeStubAssembler m(data.state());
+
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+ (void)JSObject::SetElement(isolate, array, 0,
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY);
+ (void)JSObject::SetElement(isolate, array, 1,
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY);
+ CodeStubArguments args(&m, m.IntPtrConstant(4));
+ Variable arg_index(&m, MachineType::PointerRepresentation());
+ Label bailout(&m);
+ arg_index.Bind(m.IntPtrConstant(0));
+ Node* length = m.BuildAppendJSArray(
+ FAST_SMI_ELEMENTS,
+ m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
+ m.HeapConstant(array), args, arg_index, &bailout);
+
+ m.PopAndReturn(m.IntPtrConstant(4), length);
+
+ Handle<Code> code = data.GenerateCode();
+ CHECK(!code.is_null());
+
+ FunctionTester ft(code, kNumParams);
+ Handle<Object> result;
+ result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate),
+ Handle<Smi>(Smi::FromInt(4), isolate),
+ Handle<Smi>(Smi::FromInt(5), isolate),
+ Handle<Smi>(Smi::FromInt(6), isolate))
+ .ToHandleChecked();
+
+ CHECK_EQ(6, Handle<Smi>::cast(result)->value());
+ CHECK_EQ(3, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 2).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 3).ToHandleChecked())
+ ->value());
+ CHECK_EQ(5, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 4).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 5).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Smi::cast(array->length())->value());
+ CHECK_EQ(FAST_SMI_ELEMENTS, array->GetElementsKind());
+}
+
+TEST(BuildAppendJSArrayFastSmiElementObject) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ typedef CodeStubAssembler::Variable Variable;
+ typedef CodeStubAssembler::Label Label;
+
+ const int kNumParams = 4;
+ CodeAssemblerTester data(isolate, 0);
Jakob Kummerow 2016/11/23 17:17:06 same here
danno 2016/11/29 14:40:00 Done.
+ CodeStubAssembler m(data.state());
+
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+ (void)JSObject::SetElement(isolate, array, 0,
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY);
+ (void)JSObject::SetElement(isolate, array, 1,
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY);
+ CodeStubArguments args(&m, m.IntPtrConstant(4));
+ Variable arg_index(&m, MachineType::PointerRepresentation());
+ Label bailout(&m);
+ arg_index.Bind(m.IntPtrConstant(0));
+ Node* length = m.BuildAppendJSArray(
+ FAST_SMI_ELEMENTS,
+ m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
+ m.HeapConstant(array), args, arg_index, &bailout);
+
+ m.PopAndReturn(m.IntPtrConstant(4), length);
+
+ m.Bind(&bailout);
+ m.PopAndReturn(m.IntPtrConstant(4), m.SmiTag(arg_index.value()));
+
+ Handle<Code> code = data.GenerateCode();
+ CHECK(!code.is_null());
+
+ FunctionTester ft(code, kNumParams);
+ Handle<Object> result;
+ Handle<HeapObject> undefined = isolate->factory()->undefined_value();
+ result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate),
+ Handle<Smi>(Smi::FromInt(4), isolate), undefined,
+ Handle<Smi>(Smi::FromInt(6), isolate))
+ .ToHandleChecked();
+
+ CHECK_EQ(2, Smi::cast(*result)->value());
+ CHECK_EQ(3, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 2).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 3).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Smi::cast(array->length())->value());
+}
+
+TEST(BuildAppendJSArrayFastDoubleElements) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ typedef CodeStubAssembler::Variable Variable;
+ typedef CodeStubAssembler::Label Label;
+
+ const int kNumParams = 4;
+ CodeAssemblerTester data(isolate, 0);
Jakob Kummerow 2016/11/23 17:17:06 same here
danno 2016/11/29 14:40:00 Done.
+ CodeStubAssembler m(data.state());
+
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+ (void)JSObject::SetElement(isolate, array, 0,
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY);
+ (void)JSObject::SetElement(isolate, array, 1,
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY);
+ JSObject::TransitionElementsKind(array, FAST_DOUBLE_ELEMENTS);
+ CodeStubArguments args(&m, m.IntPtrConstant(4));
+ Variable arg_index(&m, MachineType::PointerRepresentation());
+ Label bailout(&m);
+ arg_index.Bind(m.IntPtrConstant(0));
+ Node* length = m.BuildAppendJSArray(
+ FAST_DOUBLE_ELEMENTS,
+ m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
+ m.HeapConstant(array), args, arg_index, &bailout);
+ m.PopAndReturn(m.IntPtrConstant(4), length);
+
+ m.Bind(&bailout);
+ m.PopAndReturn(m.IntPtrConstant(4), m.SmiTag(arg_index.value()));
+
+ Handle<Code> code = data.GenerateCode();
+ CHECK(!code.is_null());
+
+ FunctionTester ft(code, kNumParams);
+ Handle<Object> result;
+ result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate),
+ Handle<Smi>(Smi::FromInt(4), isolate),
+ Handle<Smi>(Smi::FromInt(5), isolate),
+ Handle<Smi>(Smi::FromInt(6), isolate))
+ .ToHandleChecked();
+
+ CHECK_EQ(6, Handle<Smi>::cast(result)->value());
+ CHECK_EQ(3, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 2).ToHandleChecked())
+ ->value());
+ CHECK_EQ(4, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 3).ToHandleChecked())
+ ->value());
+ CHECK_EQ(5, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 4).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Handle<Smi>::cast(
+ JSObject::GetElement(isolate, array, 5).ToHandleChecked())
+ ->value());
+ CHECK_EQ(6, Smi::cast(array->length())->value());
+ CHECK_EQ(FAST_DOUBLE_ELEMENTS, array->GetElementsKind());
+}
+
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698