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/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1996 | 1996 |
1997 FunctionTester ft(code, kNumParams); | 1997 FunctionTester ft(code, kNumParams); |
1998 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), | 1998 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), |
1999 Handle<Smi>(Smi::FromInt(12), isolate), | 1999 Handle<Smi>(Smi::FromInt(12), isolate), |
2000 Handle<Smi>(Smi::FromInt(13), isolate), | 2000 Handle<Smi>(Smi::FromInt(13), isolate), |
2001 Handle<Smi>(Smi::FromInt(14), isolate)) | 2001 Handle<Smi>(Smi::FromInt(14), isolate)) |
2002 .ToHandleChecked(); | 2002 .ToHandleChecked(); |
2003 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result); | 2003 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result); |
2004 } | 2004 } |
2005 | 2005 |
2006 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.
| |
2007 Isolate* isolate(CcTest::InitIsolateOnce()); | |
2008 typedef CodeStubAssembler::Variable Variable; | |
2009 typedef CodeStubAssembler::Label Label; | |
2010 | |
2011 const int kNumParams = 4; | |
2012 CodeAssemblerTester data(isolate, kNumParams); | |
2013 CodeStubAssembler m(data.state()); | |
2014 | |
2015 Handle<JSArray> array = isolate->factory()->NewJSArray( | |
2016 FAST_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
2017 (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.
| |
2018 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY); | |
2019 (void)JSObject::SetElement(isolate, array, 1, | |
2020 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY); | |
2021 CodeStubArguments args(&m, m.IntPtrConstant(4)); | |
2022 Variable arg_index(&m, MachineType::PointerRepresentation()); | |
2023 Label bailout(&m); | |
2024 arg_index.Bind(m.IntPtrConstant(0)); | |
2025 Node* length = m.BuildAppendJSArray( | |
2026 FAST_ELEMENTS, | |
2027 m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), | |
2028 m.HeapConstant(array), args, arg_index, &bailout); | |
2029 | |
2030 m.PopAndReturn(m.IntPtrConstant(4), length); | |
2031 | |
2032 Handle<Code> code = data.GenerateCode(); | |
2033 CHECK(!code.is_null()); | |
2034 | |
2035 FunctionTester ft(code, kNumParams); | |
2036 Handle<Object> result; | |
2037 result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate), | |
2038 Handle<Smi>(Smi::FromInt(4), isolate), | |
2039 Handle<Smi>(Smi::FromInt(5), isolate), | |
2040 Handle<Smi>(Smi::FromInt(6), isolate)) | |
2041 .ToHandleChecked(); | |
2042 | |
2043 CHECK_EQ(6, Handle<Smi>::cast(result)->value()); | |
2044 CHECK_EQ(3, Handle<Smi>::cast( | |
2045 JSObject::GetElement(isolate, array, 2).ToHandleChecked()) | |
2046 ->value()); | |
2047 CHECK_EQ(4, Handle<Smi>::cast( | |
2048 JSObject::GetElement(isolate, array, 3).ToHandleChecked()) | |
2049 ->value()); | |
2050 CHECK_EQ(5, Handle<Smi>::cast( | |
2051 JSObject::GetElement(isolate, array, 4).ToHandleChecked()) | |
2052 ->value()); | |
2053 CHECK_EQ(6, Handle<Smi>::cast( | |
2054 JSObject::GetElement(isolate, array, 5).ToHandleChecked()) | |
2055 ->value()); | |
2056 CHECK_EQ(6, Smi::cast(array->length())->value()); | |
2057 } | |
2058 | |
2059 TEST(BuildAppendJSArrayFastElementGrow) { | |
2060 Isolate* isolate(CcTest::InitIsolateOnce()); | |
2061 typedef CodeStubAssembler::Variable Variable; | |
2062 typedef CodeStubAssembler::Label Label; | |
2063 | |
2064 const int kNumParams = 4; | |
2065 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.
| |
2066 CodeStubAssembler m(data.state()); | |
2067 | |
2068 Handle<JSArray> array = isolate->factory()->NewJSArray( | |
2069 FAST_ELEMENTS, 2, 3, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
2070 (void)JSObject::SetElement(isolate, array, 0, | |
2071 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY); | |
2072 (void)JSObject::SetElement(isolate, array, 1, | |
2073 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY); | |
2074 CodeStubArguments args(&m, m.IntPtrConstant(4)); | |
2075 Variable arg_index(&m, MachineType::PointerRepresentation()); | |
2076 Label bailout(&m); | |
2077 arg_index.Bind(m.IntPtrConstant(0)); | |
2078 Node* length = m.BuildAppendJSArray( | |
2079 FAST_ELEMENTS, | |
2080 m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), | |
2081 m.HeapConstant(array), args, arg_index, &bailout); | |
2082 | |
2083 m.PopAndReturn(m.IntPtrConstant(4), length); | |
2084 | |
2085 Handle<Code> code = data.GenerateCode(); | |
2086 CHECK(!code.is_null()); | |
2087 | |
2088 FunctionTester ft(code, kNumParams); | |
2089 Handle<Object> result; | |
2090 result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate), | |
2091 Handle<Smi>(Smi::FromInt(4), isolate), | |
2092 Handle<Smi>(Smi::FromInt(5), isolate), | |
2093 Handle<Smi>(Smi::FromInt(6), isolate)) | |
2094 .ToHandleChecked(); | |
2095 | |
2096 CHECK_EQ(6, Handle<Smi>::cast(result)->value()); | |
2097 CHECK_EQ(3, Handle<Smi>::cast( | |
2098 JSObject::GetElement(isolate, array, 2).ToHandleChecked()) | |
2099 ->value()); | |
2100 CHECK_EQ(4, Handle<Smi>::cast( | |
2101 JSObject::GetElement(isolate, array, 3).ToHandleChecked()) | |
2102 ->value()); | |
2103 CHECK_EQ(5, Handle<Smi>::cast( | |
2104 JSObject::GetElement(isolate, array, 4).ToHandleChecked()) | |
2105 ->value()); | |
2106 CHECK_EQ(6, Handle<Smi>::cast( | |
2107 JSObject::GetElement(isolate, array, 5).ToHandleChecked()) | |
2108 ->value()); | |
2109 CHECK_EQ(6, Smi::cast(array->length())->value()); | |
2110 } | |
2111 | |
2112 TEST(BuildAppendJSArrayFastSmiElement) { | |
2113 Isolate* isolate(CcTest::InitIsolateOnce()); | |
2114 typedef CodeStubAssembler::Variable Variable; | |
2115 typedef CodeStubAssembler::Label Label; | |
2116 | |
2117 const int kNumParams = 4; | |
2118 CodeAssemblerTester data(isolate, 0); | |
Jakob Kummerow
2016/11/23 17:17:06
same here
danno
2016/11/29 14:39:59
Done.
| |
2119 CodeStubAssembler m(data.state()); | |
2120 | |
2121 Handle<JSArray> array = isolate->factory()->NewJSArray( | |
2122 FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
2123 (void)JSObject::SetElement(isolate, array, 0, | |
2124 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY); | |
2125 (void)JSObject::SetElement(isolate, array, 1, | |
2126 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY); | |
2127 CodeStubArguments args(&m, m.IntPtrConstant(4)); | |
2128 Variable arg_index(&m, MachineType::PointerRepresentation()); | |
2129 Label bailout(&m); | |
2130 arg_index.Bind(m.IntPtrConstant(0)); | |
2131 Node* length = m.BuildAppendJSArray( | |
2132 FAST_SMI_ELEMENTS, | |
2133 m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), | |
2134 m.HeapConstant(array), args, arg_index, &bailout); | |
2135 | |
2136 m.PopAndReturn(m.IntPtrConstant(4), length); | |
2137 | |
2138 Handle<Code> code = data.GenerateCode(); | |
2139 CHECK(!code.is_null()); | |
2140 | |
2141 FunctionTester ft(code, kNumParams); | |
2142 Handle<Object> result; | |
2143 result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate), | |
2144 Handle<Smi>(Smi::FromInt(4), isolate), | |
2145 Handle<Smi>(Smi::FromInt(5), isolate), | |
2146 Handle<Smi>(Smi::FromInt(6), isolate)) | |
2147 .ToHandleChecked(); | |
2148 | |
2149 CHECK_EQ(6, Handle<Smi>::cast(result)->value()); | |
2150 CHECK_EQ(3, Handle<Smi>::cast( | |
2151 JSObject::GetElement(isolate, array, 2).ToHandleChecked()) | |
2152 ->value()); | |
2153 CHECK_EQ(4, Handle<Smi>::cast( | |
2154 JSObject::GetElement(isolate, array, 3).ToHandleChecked()) | |
2155 ->value()); | |
2156 CHECK_EQ(5, Handle<Smi>::cast( | |
2157 JSObject::GetElement(isolate, array, 4).ToHandleChecked()) | |
2158 ->value()); | |
2159 CHECK_EQ(6, Handle<Smi>::cast( | |
2160 JSObject::GetElement(isolate, array, 5).ToHandleChecked()) | |
2161 ->value()); | |
2162 CHECK_EQ(6, Smi::cast(array->length())->value()); | |
2163 CHECK_EQ(FAST_SMI_ELEMENTS, array->GetElementsKind()); | |
2164 } | |
2165 | |
2166 TEST(BuildAppendJSArrayFastSmiElementObject) { | |
2167 Isolate* isolate(CcTest::InitIsolateOnce()); | |
2168 typedef CodeStubAssembler::Variable Variable; | |
2169 typedef CodeStubAssembler::Label Label; | |
2170 | |
2171 const int kNumParams = 4; | |
2172 CodeAssemblerTester data(isolate, 0); | |
Jakob Kummerow
2016/11/23 17:17:06
same here
danno
2016/11/29 14:40:00
Done.
| |
2173 CodeStubAssembler m(data.state()); | |
2174 | |
2175 Handle<JSArray> array = isolate->factory()->NewJSArray( | |
2176 FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
2177 (void)JSObject::SetElement(isolate, array, 0, | |
2178 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY); | |
2179 (void)JSObject::SetElement(isolate, array, 1, | |
2180 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY); | |
2181 CodeStubArguments args(&m, m.IntPtrConstant(4)); | |
2182 Variable arg_index(&m, MachineType::PointerRepresentation()); | |
2183 Label bailout(&m); | |
2184 arg_index.Bind(m.IntPtrConstant(0)); | |
2185 Node* length = m.BuildAppendJSArray( | |
2186 FAST_SMI_ELEMENTS, | |
2187 m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), | |
2188 m.HeapConstant(array), args, arg_index, &bailout); | |
2189 | |
2190 m.PopAndReturn(m.IntPtrConstant(4), length); | |
2191 | |
2192 m.Bind(&bailout); | |
2193 m.PopAndReturn(m.IntPtrConstant(4), m.SmiTag(arg_index.value())); | |
2194 | |
2195 Handle<Code> code = data.GenerateCode(); | |
2196 CHECK(!code.is_null()); | |
2197 | |
2198 FunctionTester ft(code, kNumParams); | |
2199 Handle<Object> result; | |
2200 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); | |
2201 result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate), | |
2202 Handle<Smi>(Smi::FromInt(4), isolate), undefined, | |
2203 Handle<Smi>(Smi::FromInt(6), isolate)) | |
2204 .ToHandleChecked(); | |
2205 | |
2206 CHECK_EQ(2, Smi::cast(*result)->value()); | |
2207 CHECK_EQ(3, Handle<Smi>::cast( | |
2208 JSObject::GetElement(isolate, array, 2).ToHandleChecked()) | |
2209 ->value()); | |
2210 CHECK_EQ(4, Handle<Smi>::cast( | |
2211 JSObject::GetElement(isolate, array, 3).ToHandleChecked()) | |
2212 ->value()); | |
2213 CHECK_EQ(4, Smi::cast(array->length())->value()); | |
2214 } | |
2215 | |
2216 TEST(BuildAppendJSArrayFastDoubleElements) { | |
2217 Isolate* isolate(CcTest::InitIsolateOnce()); | |
2218 typedef CodeStubAssembler::Variable Variable; | |
2219 typedef CodeStubAssembler::Label Label; | |
2220 | |
2221 const int kNumParams = 4; | |
2222 CodeAssemblerTester data(isolate, 0); | |
Jakob Kummerow
2016/11/23 17:17:06
same here
danno
2016/11/29 14:40:00
Done.
| |
2223 CodeStubAssembler m(data.state()); | |
2224 | |
2225 Handle<JSArray> array = isolate->factory()->NewJSArray( | |
2226 FAST_SMI_ELEMENTS, 2, 6, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
2227 (void)JSObject::SetElement(isolate, array, 0, | |
2228 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY); | |
2229 (void)JSObject::SetElement(isolate, array, 1, | |
2230 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY); | |
2231 JSObject::TransitionElementsKind(array, FAST_DOUBLE_ELEMENTS); | |
2232 CodeStubArguments args(&m, m.IntPtrConstant(4)); | |
2233 Variable arg_index(&m, MachineType::PointerRepresentation()); | |
2234 Label bailout(&m); | |
2235 arg_index.Bind(m.IntPtrConstant(0)); | |
2236 Node* length = m.BuildAppendJSArray( | |
2237 FAST_DOUBLE_ELEMENTS, | |
2238 m.HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), | |
2239 m.HeapConstant(array), args, arg_index, &bailout); | |
2240 m.PopAndReturn(m.IntPtrConstant(4), length); | |
2241 | |
2242 m.Bind(&bailout); | |
2243 m.PopAndReturn(m.IntPtrConstant(4), m.SmiTag(arg_index.value())); | |
2244 | |
2245 Handle<Code> code = data.GenerateCode(); | |
2246 CHECK(!code.is_null()); | |
2247 | |
2248 FunctionTester ft(code, kNumParams); | |
2249 Handle<Object> result; | |
2250 result = ft.Call(Handle<Smi>(Smi::FromInt(3), isolate), | |
2251 Handle<Smi>(Smi::FromInt(4), isolate), | |
2252 Handle<Smi>(Smi::FromInt(5), isolate), | |
2253 Handle<Smi>(Smi::FromInt(6), isolate)) | |
2254 .ToHandleChecked(); | |
2255 | |
2256 CHECK_EQ(6, Handle<Smi>::cast(result)->value()); | |
2257 CHECK_EQ(3, Handle<Smi>::cast( | |
2258 JSObject::GetElement(isolate, array, 2).ToHandleChecked()) | |
2259 ->value()); | |
2260 CHECK_EQ(4, Handle<Smi>::cast( | |
2261 JSObject::GetElement(isolate, array, 3).ToHandleChecked()) | |
2262 ->value()); | |
2263 CHECK_EQ(5, Handle<Smi>::cast( | |
2264 JSObject::GetElement(isolate, array, 4).ToHandleChecked()) | |
2265 ->value()); | |
2266 CHECK_EQ(6, Handle<Smi>::cast( | |
2267 JSObject::GetElement(isolate, array, 5).ToHandleChecked()) | |
2268 ->value()); | |
2269 CHECK_EQ(6, Smi::cast(array->length())->value()); | |
2270 CHECK_EQ(FAST_DOUBLE_ELEMENTS, array->GetElementsKind()); | |
2271 } | |
2272 | |
2006 } // namespace internal | 2273 } // namespace internal |
2007 } // namespace v8 | 2274 } // namespace v8 |
OLD | NEW |