OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "test/cctest/compiler/code-assembler-tester.h" | 10 #include "test/cctest/compiler/code-assembler-tester.h" |
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 // Cheat to enable debug (TODO: do this properly). | 1790 // Cheat to enable debug (TODO: do this properly). |
1791 *debug_is_active = true; | 1791 *debug_is_active = true; |
1792 | 1792 |
1793 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); | 1793 result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); |
1794 CHECK_EQ(isolate->heap()->true_value(), *result); | 1794 CHECK_EQ(isolate->heap()->true_value(), *result); |
1795 | 1795 |
1796 // Reset debug mode. | 1796 // Reset debug mode. |
1797 *debug_is_active = false; | 1797 *debug_is_active = false; |
1798 } | 1798 } |
1799 | 1799 |
| 1800 class AppendJSArrayCodeStubAssembler : public CodeStubAssembler { |
| 1801 public: |
| 1802 AppendJSArrayCodeStubAssembler(compiler::CodeAssemblerState* state, |
| 1803 ElementsKind kind) |
| 1804 : CodeStubAssembler(state), kind_(kind) {} |
| 1805 |
| 1806 void TestAppendJSArrayImpl(Isolate* isolate, CodeAssemblerTester* tester, |
| 1807 Object* o1, Object* o2, Object* o3, Object* o4, |
| 1808 int initial_size, int result_size) { |
| 1809 typedef CodeStubAssembler::Variable Variable; |
| 1810 typedef CodeStubAssembler::Label Label; |
| 1811 Handle<JSArray> array = isolate->factory()->NewJSArray( |
| 1812 kind_, 2, initial_size, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 1813 JSObject::SetElement(isolate, array, 0, |
| 1814 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY) |
| 1815 .Check(); |
| 1816 JSObject::SetElement(isolate, array, 1, |
| 1817 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY) |
| 1818 .Check(); |
| 1819 CodeStubArguments args(this, IntPtrConstant(kNumParams)); |
| 1820 Variable arg_index(this, MachineType::PointerRepresentation()); |
| 1821 Label bailout(this); |
| 1822 arg_index.Bind(IntPtrConstant(0)); |
| 1823 Node* length = BuildAppendJSArray( |
| 1824 kind_, HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), |
| 1825 HeapConstant(array), args, arg_index, &bailout); |
| 1826 Return(length); |
| 1827 |
| 1828 Bind(&bailout); |
| 1829 Return(SmiTag(IntPtrAdd(arg_index.value(), IntPtrConstant(2)))); |
| 1830 |
| 1831 Handle<Code> code = tester->GenerateCode(); |
| 1832 CHECK(!code.is_null()); |
| 1833 |
| 1834 FunctionTester ft(code, kNumParams); |
| 1835 |
| 1836 Handle<Object> result = |
| 1837 ft.Call(Handle<Object>(o1, isolate), Handle<Object>(o2, isolate), |
| 1838 Handle<Object>(o3, isolate), Handle<Object>(o4, isolate)) |
| 1839 .ToHandleChecked(); |
| 1840 |
| 1841 CHECK_EQ(kind_, array->GetElementsKind()); |
| 1842 CHECK_EQ(result_size, Handle<Smi>::cast(result)->value()); |
| 1843 CHECK_EQ(result_size, Smi::cast(array->length())->value()); |
| 1844 Object* obj = *JSObject::GetElement(isolate, array, 2).ToHandleChecked(); |
| 1845 CHECK_EQ(result_size < 3 ? isolate->heap()->undefined_value() : o1, obj); |
| 1846 obj = *JSObject::GetElement(isolate, array, 3).ToHandleChecked(); |
| 1847 CHECK_EQ(result_size < 4 ? isolate->heap()->undefined_value() : o2, obj); |
| 1848 obj = *JSObject::GetElement(isolate, array, 4).ToHandleChecked(); |
| 1849 CHECK_EQ(result_size < 5 ? isolate->heap()->undefined_value() : o3, obj); |
| 1850 obj = *JSObject::GetElement(isolate, array, 5).ToHandleChecked(); |
| 1851 CHECK_EQ(result_size < 6 ? isolate->heap()->undefined_value() : o4, obj); |
| 1852 } |
| 1853 |
| 1854 static void TestAppendJSArray(Isolate* isolate, ElementsKind kind, Object* o1, |
| 1855 Object* o2, Object* o3, Object* o4, |
| 1856 int initial_size, int result_size) { |
| 1857 CodeAssemblerTester data(isolate, kNumParams); |
| 1858 AppendJSArrayCodeStubAssembler m(data.state(), kind); |
| 1859 m.TestAppendJSArrayImpl(isolate, &data, o1, o2, o3, o4, initial_size, |
| 1860 result_size); |
| 1861 } |
| 1862 |
| 1863 private: |
| 1864 static const int kNumParams = 4; |
| 1865 ElementsKind kind_; |
| 1866 }; |
| 1867 |
| 1868 TEST(BuildAppendJSArrayFastElement) { |
| 1869 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1870 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1871 isolate, FAST_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), Smi::FromInt(5), |
| 1872 Smi::FromInt(6), 6, 6); |
| 1873 } |
| 1874 |
| 1875 TEST(BuildAppendJSArrayFastElementGrow) { |
| 1876 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1877 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1878 isolate, FAST_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), Smi::FromInt(5), |
| 1879 Smi::FromInt(6), 2, 6); |
| 1880 } |
| 1881 |
| 1882 TEST(BuildAppendJSArrayFastSmiElement) { |
| 1883 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1884 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1885 isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1886 Smi::FromInt(5), Smi::FromInt(6), 6, 6); |
| 1887 } |
| 1888 |
| 1889 TEST(BuildAppendJSArrayFastSmiElementGrow) { |
| 1890 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1891 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1892 isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1893 Smi::FromInt(5), Smi::FromInt(6), 2, 6); |
| 1894 } |
| 1895 |
| 1896 TEST(BuildAppendJSArrayFastSmiElementObject) { |
| 1897 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1898 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1899 isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1900 isolate->heap()->undefined_value(), Smi::FromInt(6), 6, 4); |
| 1901 } |
| 1902 |
| 1903 TEST(BuildAppendJSArrayFastSmiElementObjectGrow) { |
| 1904 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1905 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1906 isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1907 isolate->heap()->undefined_value(), Smi::FromInt(6), 2, 4); |
| 1908 } |
| 1909 |
| 1910 TEST(BuildAppendJSArrayFastDoubleElements) { |
| 1911 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1912 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1913 isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1914 Smi::FromInt(5), Smi::FromInt(6), 6, 6); |
| 1915 } |
| 1916 |
| 1917 TEST(BuildAppendJSArrayFastDoubleElementsGrow) { |
| 1918 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1919 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1920 isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1921 Smi::FromInt(5), Smi::FromInt(6), 2, 6); |
| 1922 } |
| 1923 |
| 1924 TEST(BuildAppendJSArrayFastDoubleElementsObject) { |
| 1925 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1926 AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
| 1927 isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
| 1928 isolate->heap()->undefined_value(), Smi::FromInt(6), 6, 4); |
| 1929 } |
| 1930 |
1800 } // namespace internal | 1931 } // namespace internal |
1801 } // namespace v8 | 1932 } // namespace v8 |
OLD | NEW |