| 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/ic/stub-cache.h" | 6 #include "src/ic/stub-cache.h" |
| 7 #include "src/interface-descriptors.h" | |
| 8 #include "src/isolate.h" | 7 #include "src/isolate.h" |
| 8 #include "test/cctest/compiler/code-assembler-tester.h" |
| 9 #include "test/cctest/compiler/function-tester.h" | 9 #include "test/cctest/compiler/function-tester.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 using compiler::FunctionTester; | 14 using compiler::FunctionTester; |
| 15 using compiler::Node; | 15 using compiler::Node; |
| 16 | 16 |
| 17 class ZoneHolder { | 17 typedef compiler::CodeAssemblerTesterImpl<CodeStubAssembler> |
| 18 public: | 18 CodeStubAssemblerTester; |
| 19 explicit ZoneHolder(Isolate* isolate) : zone_(isolate->allocator()) {} | |
| 20 Zone* zone() { return &zone_; } | |
| 21 | |
| 22 private: | |
| 23 Zone zone_; | |
| 24 }; | |
| 25 | |
| 26 // Inherit from ZoneHolder in order to create a zone that can be passed to | |
| 27 // CodeStubAssembler base class constructor. | |
| 28 class CodeStubAssemblerTester : private ZoneHolder, public CodeStubAssembler { | |
| 29 public: | |
| 30 // Test generating code for a stub. | |
| 31 CodeStubAssemblerTester(Isolate* isolate, | |
| 32 const CallInterfaceDescriptor& descriptor) | |
| 33 : ZoneHolder(isolate), | |
| 34 CodeStubAssembler(isolate, ZoneHolder::zone(), descriptor, | |
| 35 Code::ComputeFlags(Code::STUB), "test"), | |
| 36 scope_(isolate) {} | |
| 37 | |
| 38 // Test generating code for a JS function (e.g. builtins). | |
| 39 CodeStubAssemblerTester(Isolate* isolate, int parameter_count) | |
| 40 : ZoneHolder(isolate), | |
| 41 CodeStubAssembler(isolate, ZoneHolder::zone(), parameter_count, | |
| 42 Code::ComputeFlags(Code::FUNCTION), "test"), | |
| 43 scope_(isolate) {} | |
| 44 | |
| 45 // This constructor is intended to be used for creating code objects with | |
| 46 // specific flags. | |
| 47 CodeStubAssemblerTester(Isolate* isolate, Code::Flags flags) | |
| 48 : ZoneHolder(isolate), | |
| 49 CodeStubAssembler(isolate, ZoneHolder::zone(), 0, flags, "test"), | |
| 50 scope_(isolate) {} | |
| 51 | |
| 52 Handle<Code> GenerateCodeCloseAndEscape() { | |
| 53 return scope_.CloseAndEscape(GenerateCode()); | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 HandleScope scope_; | |
| 58 LocalContext context_; | |
| 59 }; | |
| 60 | |
| 61 TEST(SimpleSmiReturn) { | |
| 62 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 63 VoidDescriptor descriptor(isolate); | |
| 64 CodeStubAssemblerTester m(isolate, descriptor); | |
| 65 m.Return(m.SmiTag(m.Int32Constant(37))); | |
| 66 Handle<Code> code = m.GenerateCode(); | |
| 67 FunctionTester ft(descriptor, code); | |
| 68 MaybeHandle<Object> result = ft.Call(); | |
| 69 CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
| 70 } | |
| 71 | |
| 72 TEST(SimpleIntPtrReturn) { | |
| 73 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 74 VoidDescriptor descriptor(isolate); | |
| 75 CodeStubAssemblerTester m(isolate, descriptor); | |
| 76 int test; | |
| 77 m.Return(m.IntPtrConstant(reinterpret_cast<intptr_t>(&test))); | |
| 78 Handle<Code> code = m.GenerateCode(); | |
| 79 FunctionTester ft(descriptor, code); | |
| 80 MaybeHandle<Object> result = ft.Call(); | |
| 81 CHECK_EQ(reinterpret_cast<intptr_t>(&test), | |
| 82 reinterpret_cast<intptr_t>(*result.ToHandleChecked())); | |
| 83 } | |
| 84 | |
| 85 TEST(SimpleDoubleReturn) { | |
| 86 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 87 VoidDescriptor descriptor(isolate); | |
| 88 CodeStubAssemblerTester m(isolate, descriptor); | |
| 89 m.Return(m.NumberConstant(0.5)); | |
| 90 Handle<Code> code = m.GenerateCode(); | |
| 91 FunctionTester ft(descriptor, code); | |
| 92 MaybeHandle<Object> result = ft.Call(); | |
| 93 CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value()); | |
| 94 } | |
| 95 | |
| 96 TEST(SimpleCallRuntime1Arg) { | |
| 97 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 98 VoidDescriptor descriptor(isolate); | |
| 99 CodeStubAssemblerTester m(isolate, descriptor); | |
| 100 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 101 Node* b = m.SmiTag(m.Int32Constant(0)); | |
| 102 m.Return(m.CallRuntime(Runtime::kNumberToSmi, context, b)); | |
| 103 Handle<Code> code = m.GenerateCode(); | |
| 104 FunctionTester ft(descriptor, code); | |
| 105 MaybeHandle<Object> result = ft.Call(); | |
| 106 CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
| 107 } | |
| 108 | |
| 109 TEST(SimpleTailCallRuntime1Arg) { | |
| 110 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 111 VoidDescriptor descriptor(isolate); | |
| 112 CodeStubAssemblerTester m(isolate, descriptor); | |
| 113 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 114 Node* b = m.SmiTag(m.Int32Constant(0)); | |
| 115 m.TailCallRuntime(Runtime::kNumberToSmi, context, b); | |
| 116 Handle<Code> code = m.GenerateCode(); | |
| 117 FunctionTester ft(descriptor, code); | |
| 118 MaybeHandle<Object> result = ft.Call(); | |
| 119 CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
| 120 } | |
| 121 | |
| 122 TEST(SimpleCallRuntime2Arg) { | |
| 123 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 124 VoidDescriptor descriptor(isolate); | |
| 125 CodeStubAssemblerTester m(isolate, descriptor); | |
| 126 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 127 Node* a = m.SmiTag(m.Int32Constant(2)); | |
| 128 Node* b = m.SmiTag(m.Int32Constant(4)); | |
| 129 m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b)); | |
| 130 Handle<Code> code = m.GenerateCode(); | |
| 131 FunctionTester ft(descriptor, code); | |
| 132 MaybeHandle<Object> result = ft.Call(); | |
| 133 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
| 134 } | |
| 135 | |
| 136 TEST(SimpleTailCallRuntime2Arg) { | |
| 137 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 138 VoidDescriptor descriptor(isolate); | |
| 139 CodeStubAssemblerTester m(isolate, descriptor); | |
| 140 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 141 Node* a = m.SmiTag(m.Int32Constant(2)); | |
| 142 Node* b = m.SmiTag(m.Int32Constant(4)); | |
| 143 m.TailCallRuntime(Runtime::kMathPow, context, a, b); | |
| 144 Handle<Code> code = m.GenerateCode(); | |
| 145 FunctionTester ft(descriptor, code); | |
| 146 MaybeHandle<Object> result = ft.Call(); | |
| 147 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
| 148 } | |
| 149 | |
| 150 TEST(VariableMerge1) { | |
| 151 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 152 VoidDescriptor descriptor(isolate); | |
| 153 CodeStubAssemblerTester m(isolate, descriptor); | |
| 154 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); | |
| 155 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); | |
| 156 Node* temp = m.Int32Constant(0); | |
| 157 var1.Bind(temp); | |
| 158 m.Branch(m.Int32Constant(1), &l1, &l2); | |
| 159 m.Bind(&l1); | |
| 160 CHECK_EQ(var1.value(), temp); | |
| 161 m.Goto(&merge); | |
| 162 m.Bind(&l2); | |
| 163 CHECK_EQ(var1.value(), temp); | |
| 164 m.Goto(&merge); | |
| 165 m.Bind(&merge); | |
| 166 CHECK_EQ(var1.value(), temp); | |
| 167 } | |
| 168 | |
| 169 TEST(VariableMerge2) { | |
| 170 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 171 VoidDescriptor descriptor(isolate); | |
| 172 CodeStubAssemblerTester m(isolate, descriptor); | |
| 173 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); | |
| 174 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); | |
| 175 Node* temp = m.Int32Constant(0); | |
| 176 var1.Bind(temp); | |
| 177 m.Branch(m.Int32Constant(1), &l1, &l2); | |
| 178 m.Bind(&l1); | |
| 179 CHECK_EQ(var1.value(), temp); | |
| 180 m.Goto(&merge); | |
| 181 m.Bind(&l2); | |
| 182 Node* temp2 = m.Int32Constant(2); | |
| 183 var1.Bind(temp2); | |
| 184 CHECK_EQ(var1.value(), temp2); | |
| 185 m.Goto(&merge); | |
| 186 m.Bind(&merge); | |
| 187 CHECK_NE(var1.value(), temp); | |
| 188 } | |
| 189 | |
| 190 TEST(VariableMerge3) { | |
| 191 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 192 VoidDescriptor descriptor(isolate); | |
| 193 CodeStubAssemblerTester m(isolate, descriptor); | |
| 194 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); | |
| 195 CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged); | |
| 196 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); | |
| 197 Node* temp = m.Int32Constant(0); | |
| 198 var1.Bind(temp); | |
| 199 var2.Bind(temp); | |
| 200 m.Branch(m.Int32Constant(1), &l1, &l2); | |
| 201 m.Bind(&l1); | |
| 202 CHECK_EQ(var1.value(), temp); | |
| 203 m.Goto(&merge); | |
| 204 m.Bind(&l2); | |
| 205 Node* temp2 = m.Int32Constant(2); | |
| 206 var1.Bind(temp2); | |
| 207 CHECK_EQ(var1.value(), temp2); | |
| 208 m.Goto(&merge); | |
| 209 m.Bind(&merge); | |
| 210 CHECK_NE(var1.value(), temp); | |
| 211 CHECK_NE(var1.value(), temp2); | |
| 212 CHECK_EQ(var2.value(), temp); | |
| 213 } | |
| 214 | |
| 215 TEST(VariableMergeBindFirst) { | |
| 216 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 217 VoidDescriptor descriptor(isolate); | |
| 218 CodeStubAssemblerTester m(isolate, descriptor); | |
| 219 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); | |
| 220 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m); | |
| 221 Node* temp = m.Int32Constant(0); | |
| 222 var1.Bind(temp); | |
| 223 m.Branch(m.Int32Constant(1), &l1, &l2); | |
| 224 m.Bind(&l1); | |
| 225 CHECK_EQ(var1.value(), temp); | |
| 226 m.Goto(&merge); | |
| 227 m.Bind(&merge); | |
| 228 CHECK(var1.value() != temp); | |
| 229 CHECK(var1.value() != nullptr); | |
| 230 m.Goto(&end); | |
| 231 m.Bind(&l2); | |
| 232 Node* temp2 = m.Int32Constant(2); | |
| 233 var1.Bind(temp2); | |
| 234 CHECK_EQ(var1.value(), temp2); | |
| 235 m.Goto(&merge); | |
| 236 m.Bind(&end); | |
| 237 CHECK(var1.value() != temp); | |
| 238 CHECK(var1.value() != nullptr); | |
| 239 } | |
| 240 | |
| 241 TEST(VariableMergeSwitch) { | |
| 242 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 243 VoidDescriptor descriptor(isolate); | |
| 244 CodeStubAssemblerTester m(isolate, descriptor); | |
| 245 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); | |
| 246 CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m); | |
| 247 CodeStubAssembler::Label* labels[] = {&l1, &l2}; | |
| 248 int32_t values[] = {1, 2}; | |
| 249 Node* temp = m.Int32Constant(0); | |
| 250 var1.Bind(temp); | |
| 251 m.Switch(m.Int32Constant(2), &default_label, values, labels, 2); | |
| 252 m.Bind(&l1); | |
| 253 DCHECK_EQ(temp, var1.value()); | |
| 254 m.Return(temp); | |
| 255 m.Bind(&l2); | |
| 256 DCHECK_EQ(temp, var1.value()); | |
| 257 m.Return(temp); | |
| 258 m.Bind(&default_label); | |
| 259 DCHECK_EQ(temp, var1.value()); | |
| 260 m.Return(temp); | |
| 261 } | |
| 262 | 19 |
| 263 TEST(FixedArrayAccessSmiIndex) { | 20 TEST(FixedArrayAccessSmiIndex) { |
| 264 Isolate* isolate(CcTest::InitIsolateOnce()); | 21 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 265 VoidDescriptor descriptor(isolate); | 22 VoidDescriptor descriptor(isolate); |
| 266 CodeStubAssemblerTester m(isolate, descriptor); | 23 CodeStubAssemblerTester m(isolate, descriptor); |
| 267 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); | 24 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); |
| 268 array->set(4, Smi::FromInt(733)); | 25 array->set(4, Smi::FromInt(733)); |
| 269 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array), | 26 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array), |
| 270 m.SmiTag(m.Int32Constant(4)), 0, | 27 m.SmiTag(m.Int32Constant(4)), 0, |
| 271 CodeStubAssembler::SMI_PARAMETERS)); | 28 CodeStubAssembler::SMI_PARAMETERS)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 294 CodeStubAssemblerTester m(isolate, descriptor); | 51 CodeStubAssemblerTester m(isolate, descriptor); |
| 295 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); | 52 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); |
| 296 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined)))); | 53 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined)))); |
| 297 Handle<Code> code = m.GenerateCode(); | 54 Handle<Code> code = m.GenerateCode(); |
| 298 FunctionTester ft(descriptor, code); | 55 FunctionTester ft(descriptor, code); |
| 299 MaybeHandle<Object> result = ft.Call(); | 56 MaybeHandle<Object> result = ft.Call(); |
| 300 CHECK_EQ(InstanceType::ODDBALL_TYPE, | 57 CHECK_EQ(InstanceType::ODDBALL_TYPE, |
| 301 Handle<Smi>::cast(result.ToHandleChecked())->value()); | 58 Handle<Smi>::cast(result.ToHandleChecked())->value()); |
| 302 } | 59 } |
| 303 | 60 |
| 304 namespace { | |
| 305 | |
| 306 class TestBitField : public BitField<unsigned, 3, 3> {}; | |
| 307 | |
| 308 } // namespace | |
| 309 | |
| 310 TEST(BitFieldDecode) { | 61 TEST(BitFieldDecode) { |
| 311 Isolate* isolate(CcTest::InitIsolateOnce()); | 62 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 312 VoidDescriptor descriptor(isolate); | 63 VoidDescriptor descriptor(isolate); |
| 313 CodeStubAssemblerTester m(isolate, descriptor); | 64 CodeStubAssemblerTester m(isolate, descriptor); |
| 65 |
| 66 class TestBitField : public BitField<unsigned, 3, 3> {}; |
| 314 m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f)))); | 67 m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f)))); |
| 315 Handle<Code> code = m.GenerateCode(); | 68 Handle<Code> code = m.GenerateCode(); |
| 316 FunctionTester ft(descriptor, code); | 69 FunctionTester ft(descriptor, code); |
| 317 MaybeHandle<Object> result = ft.Call(); | 70 MaybeHandle<Object> result = ft.Call(); |
| 318 // value = 00101111 | 71 // value = 00101111 |
| 319 // mask = 00111000 | 72 // mask = 00111000 |
| 320 // result = 101 | 73 // result = 101 |
| 321 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 74 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
| 322 } | 75 } |
| 323 | 76 |
| 324 namespace { | |
| 325 | |
| 326 Handle<JSFunction> CreateFunctionFromCode(int parameter_count_with_receiver, | |
| 327 Handle<Code> code) { | |
| 328 Isolate* isolate = code->GetIsolate(); | |
| 329 Handle<String> name = isolate->factory()->InternalizeUtf8String("test"); | |
| 330 Handle<JSFunction> function = | |
| 331 isolate->factory()->NewFunctionWithoutPrototype(name, code); | |
| 332 function->shared()->set_internal_formal_parameter_count( | |
| 333 parameter_count_with_receiver - 1); // Implicit undefined receiver. | |
| 334 return function; | |
| 335 } | |
| 336 | |
| 337 } // namespace | |
| 338 | |
| 339 TEST(JSFunction) { | 77 TEST(JSFunction) { |
| 340 const int kNumParams = 3; // Receiver, left, right. | 78 const int kNumParams = 3; // Receiver, left, right. |
| 341 Isolate* isolate(CcTest::InitIsolateOnce()); | 79 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 342 CodeStubAssemblerTester m(isolate, kNumParams); | 80 CodeStubAssemblerTester m(isolate, kNumParams); |
| 343 m.Return(m.SmiTag(m.Int32Add(m.SmiToWord32(m.Parameter(1)), | 81 m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)), |
| 344 m.SmiToWord32(m.Parameter(2))))); | 82 m.SmiToWord32(m.Parameter(2))))); |
| 83 |
| 345 Handle<Code> code = m.GenerateCode(); | 84 Handle<Code> code = m.GenerateCode(); |
| 346 Handle<JSFunction> function = CreateFunctionFromCode(kNumParams, code); | 85 FunctionTester ft(code, kNumParams); |
| 347 Handle<Object> args[] = {Handle<Smi>(Smi::FromInt(23), isolate), | 86 |
| 348 Handle<Smi>(Smi::FromInt(34), isolate)}; | 87 MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(), |
| 349 MaybeHandle<Object> result = | 88 handle(Smi::FromInt(23), isolate), |
| 350 Execution::Call(isolate, function, isolate->factory()->undefined_value(), | 89 handle(Smi::FromInt(34), isolate)); |
| 351 arraysize(args), args); | |
| 352 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 90 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
| 353 } | 91 } |
| 354 | 92 |
| 355 TEST(SplitEdgeBranchMerge) { | |
| 356 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 357 VoidDescriptor descriptor(isolate); | |
| 358 CodeStubAssemblerTester m(isolate, descriptor); | |
| 359 CodeStubAssembler::Label l1(&m), merge(&m); | |
| 360 m.Branch(m.Int32Constant(1), &l1, &merge); | |
| 361 m.Bind(&l1); | |
| 362 m.Goto(&merge); | |
| 363 m.Bind(&merge); | |
| 364 USE(m.GenerateCode()); | |
| 365 } | |
| 366 | |
| 367 TEST(SplitEdgeSwitchMerge) { | |
| 368 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 369 VoidDescriptor descriptor(isolate); | |
| 370 CodeStubAssemblerTester m(isolate, descriptor); | |
| 371 CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m); | |
| 372 CodeStubAssembler::Label* labels[] = {&l1, &l2}; | |
| 373 int32_t values[] = {1, 2}; | |
| 374 m.Branch(m.Int32Constant(1), &l3, &l1); | |
| 375 m.Bind(&l3); | |
| 376 m.Switch(m.Int32Constant(2), &default_label, values, labels, 2); | |
| 377 m.Bind(&l1); | |
| 378 m.Goto(&l2); | |
| 379 m.Bind(&l2); | |
| 380 m.Goto(&default_label); | |
| 381 m.Bind(&default_label); | |
| 382 USE(m.GenerateCode()); | |
| 383 } | |
| 384 | |
| 385 TEST(TestToConstant) { | |
| 386 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 387 VoidDescriptor descriptor(isolate); | |
| 388 CodeStubAssemblerTester m(isolate, descriptor); | |
| 389 int32_t value32; | |
| 390 int64_t value64; | |
| 391 Node* a = m.Int32Constant(5); | |
| 392 CHECK(m.ToInt32Constant(a, value32)); | |
| 393 CHECK(m.ToInt64Constant(a, value64)); | |
| 394 | |
| 395 a = m.Int64Constant(static_cast<int64_t>(1) << 32); | |
| 396 CHECK(!m.ToInt32Constant(a, value32)); | |
| 397 CHECK(m.ToInt64Constant(a, value64)); | |
| 398 | |
| 399 a = m.Int64Constant(13); | |
| 400 CHECK(m.ToInt32Constant(a, value32)); | |
| 401 CHECK(m.ToInt64Constant(a, value64)); | |
| 402 | |
| 403 a = m.UndefinedConstant(); | |
| 404 CHECK(!m.ToInt32Constant(a, value32)); | |
| 405 CHECK(!m.ToInt64Constant(a, value64)); | |
| 406 | |
| 407 a = m.UndefinedConstant(); | |
| 408 CHECK(!m.ToInt32Constant(a, value32)); | |
| 409 CHECK(!m.ToInt64Constant(a, value64)); | |
| 410 } | |
| 411 | |
| 412 TEST(ComputeIntegerHash) { | 93 TEST(ComputeIntegerHash) { |
| 413 Isolate* isolate(CcTest::InitIsolateOnce()); | 94 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 414 const int param_count = 2; | 95 const int kNumParams = 2; |
| 415 CodeStubAssemblerTester m(isolate, param_count); | 96 CodeStubAssemblerTester m(isolate, kNumParams); |
| 416 m.Return(m.SmiFromWord32(m.ComputeIntegerHash( | 97 m.Return(m.SmiFromWord32(m.ComputeIntegerHash( |
| 417 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); | 98 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); |
| 418 | 99 |
| 419 Handle<Code> code = m.GenerateCode(); | 100 Handle<Code> code = m.GenerateCode(); |
| 420 FunctionTester ft(code, param_count); | 101 FunctionTester ft(code, kNumParams); |
| 421 | 102 |
| 422 Handle<Smi> hash_seed = isolate->factory()->hash_seed(); | 103 Handle<Smi> hash_seed = isolate->factory()->hash_seed(); |
| 423 | 104 |
| 424 base::RandomNumberGenerator rand_gen(FLAG_random_seed); | 105 base::RandomNumberGenerator rand_gen(FLAG_random_seed); |
| 425 | 106 |
| 426 for (int i = 0; i < 1024; i++) { | 107 for (int i = 0; i < 1024; i++) { |
| 427 int k = rand_gen.NextInt(Smi::kMaxValue); | 108 int k = rand_gen.NextInt(Smi::kMaxValue); |
| 428 | 109 |
| 429 Handle<Smi> key(Smi::FromInt(k), isolate); | 110 Handle<Smi> key(Smi::FromInt(k), isolate); |
| 430 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked(); | 111 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked(); |
| 431 | 112 |
| 432 uint32_t hash = ComputeIntegerHash(k, hash_seed->value()); | 113 uint32_t hash = ComputeIntegerHash(k, hash_seed->value()); |
| 433 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue); | 114 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue); |
| 434 CHECK_EQ(expected, Smi::cast(*result)); | 115 CHECK_EQ(expected, Smi::cast(*result)); |
| 435 } | 116 } |
| 436 } | 117 } |
| 437 | 118 |
| 438 TEST(TryToName) { | 119 TEST(TryToName) { |
| 439 typedef CodeStubAssembler::Label Label; | 120 typedef CodeStubAssembler::Label Label; |
| 440 typedef CodeStubAssembler::Variable Variable; | 121 typedef CodeStubAssembler::Variable Variable; |
| 441 Isolate* isolate(CcTest::InitIsolateOnce()); | 122 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 442 | 123 |
| 443 const int param_count = 3; | 124 const int kNumParams = 3; |
| 444 CodeStubAssemblerTester m(isolate, param_count); | 125 CodeStubAssemblerTester m(isolate, kNumParams); |
| 445 | 126 |
| 446 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; | 127 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; |
| 447 { | 128 { |
| 448 Node* key = m.Parameter(0); | 129 Node* key = m.Parameter(0); |
| 449 Node* expected_result = m.Parameter(1); | 130 Node* expected_result = m.Parameter(1); |
| 450 Node* expected_arg = m.Parameter(2); | 131 Node* expected_arg = m.Parameter(2); |
| 451 | 132 |
| 452 Label passed(&m), failed(&m); | 133 Label passed(&m), failed(&m); |
| 453 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); | 134 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); |
| 454 Variable var_index(&m, MachineRepresentation::kWord32); | 135 Variable var_index(&m, MachineRepresentation::kWord32); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 474 &passed, &failed); | 155 &passed, &failed); |
| 475 | 156 |
| 476 m.Bind(&passed); | 157 m.Bind(&passed); |
| 477 m.Return(m.BooleanConstant(true)); | 158 m.Return(m.BooleanConstant(true)); |
| 478 | 159 |
| 479 m.Bind(&failed); | 160 m.Bind(&failed); |
| 480 m.Return(m.BooleanConstant(false)); | 161 m.Return(m.BooleanConstant(false)); |
| 481 } | 162 } |
| 482 | 163 |
| 483 Handle<Code> code = m.GenerateCode(); | 164 Handle<Code> code = m.GenerateCode(); |
| 484 FunctionTester ft(code, param_count); | 165 FunctionTester ft(code, kNumParams); |
| 485 | 166 |
| 486 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate); | 167 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate); |
| 487 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate); | 168 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate); |
| 488 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); | 169 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); |
| 489 | 170 |
| 490 { | 171 { |
| 491 // TryToName(<zero smi>) => if_keyisindex: smi value. | 172 // TryToName(<zero smi>) => if_keyisindex: smi value. |
| 492 Handle<Object> key(Smi::FromInt(0), isolate); | 173 Handle<Object> key(Smi::FromInt(0), isolate); |
| 493 ft.CheckTrue(key, expect_index, key); | 174 ft.CheckTrue(key, expect_index, key); |
| 494 } | 175 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 } | 213 } |
| 533 | 214 |
| 534 namespace { | 215 namespace { |
| 535 | 216 |
| 536 template <typename Dictionary> | 217 template <typename Dictionary> |
| 537 void TestNameDictionaryLookup() { | 218 void TestNameDictionaryLookup() { |
| 538 typedef CodeStubAssembler::Label Label; | 219 typedef CodeStubAssembler::Label Label; |
| 539 typedef CodeStubAssembler::Variable Variable; | 220 typedef CodeStubAssembler::Variable Variable; |
| 540 Isolate* isolate(CcTest::InitIsolateOnce()); | 221 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 541 | 222 |
| 542 const int param_count = 4; | 223 const int kNumParams = 4; |
| 543 CodeStubAssemblerTester m(isolate, param_count); | 224 CodeStubAssemblerTester m(isolate, kNumParams); |
| 544 | 225 |
| 545 enum Result { kFound, kNotFound }; | 226 enum Result { kFound, kNotFound }; |
| 546 { | 227 { |
| 547 Node* dictionary = m.Parameter(0); | 228 Node* dictionary = m.Parameter(0); |
| 548 Node* unique_name = m.Parameter(1); | 229 Node* unique_name = m.Parameter(1); |
| 549 Node* expected_result = m.Parameter(2); | 230 Node* expected_result = m.Parameter(2); |
| 550 Node* expected_arg = m.Parameter(3); | 231 Node* expected_arg = m.Parameter(3); |
| 551 | 232 |
| 552 Label passed(&m), failed(&m); | 233 Label passed(&m), failed(&m); |
| 553 Label if_found(&m), if_not_found(&m); | 234 Label if_found(&m), if_not_found(&m); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 568 &passed, &failed); | 249 &passed, &failed); |
| 569 | 250 |
| 570 m.Bind(&passed); | 251 m.Bind(&passed); |
| 571 m.Return(m.BooleanConstant(true)); | 252 m.Return(m.BooleanConstant(true)); |
| 572 | 253 |
| 573 m.Bind(&failed); | 254 m.Bind(&failed); |
| 574 m.Return(m.BooleanConstant(false)); | 255 m.Return(m.BooleanConstant(false)); |
| 575 } | 256 } |
| 576 | 257 |
| 577 Handle<Code> code = m.GenerateCode(); | 258 Handle<Code> code = m.GenerateCode(); |
| 578 FunctionTester ft(code, param_count); | 259 FunctionTester ft(code, kNumParams); |
| 579 | 260 |
| 580 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); | 261 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); |
| 581 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); | 262 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); |
| 582 | 263 |
| 583 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40); | 264 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40); |
| 584 PropertyDetails fake_details = PropertyDetails::Empty(); | 265 PropertyDetails fake_details = PropertyDetails::Empty(); |
| 585 | 266 |
| 586 Factory* factory = isolate->factory(); | 267 Factory* factory = isolate->factory(); |
| 587 Handle<Name> keys[] = { | 268 Handle<Name> keys[] = { |
| 588 factory->InternalizeUtf8String("0"), | 269 factory->InternalizeUtf8String("0"), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 TEST(GlobalDictionaryLookup) { TestNameDictionaryLookup<GlobalDictionary>(); } | 317 TEST(GlobalDictionaryLookup) { TestNameDictionaryLookup<GlobalDictionary>(); } |
| 637 | 318 |
| 638 namespace { | 319 namespace { |
| 639 | 320 |
| 640 template <typename Dictionary> | 321 template <typename Dictionary> |
| 641 void TestNumberDictionaryLookup() { | 322 void TestNumberDictionaryLookup() { |
| 642 typedef CodeStubAssembler::Label Label; | 323 typedef CodeStubAssembler::Label Label; |
| 643 typedef CodeStubAssembler::Variable Variable; | 324 typedef CodeStubAssembler::Variable Variable; |
| 644 Isolate* isolate(CcTest::InitIsolateOnce()); | 325 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 645 | 326 |
| 646 const int param_count = 4; | 327 const int kNumParams = 4; |
| 647 CodeStubAssemblerTester m(isolate, param_count); | 328 CodeStubAssemblerTester m(isolate, kNumParams); |
| 648 | 329 |
| 649 enum Result { kFound, kNotFound }; | 330 enum Result { kFound, kNotFound }; |
| 650 { | 331 { |
| 651 Node* dictionary = m.Parameter(0); | 332 Node* dictionary = m.Parameter(0); |
| 652 Node* key = m.SmiToWord32(m.Parameter(1)); | 333 Node* key = m.SmiToWord32(m.Parameter(1)); |
| 653 Node* expected_result = m.Parameter(2); | 334 Node* expected_result = m.Parameter(2); |
| 654 Node* expected_arg = m.Parameter(3); | 335 Node* expected_arg = m.Parameter(3); |
| 655 | 336 |
| 656 Label passed(&m), failed(&m); | 337 Label passed(&m), failed(&m); |
| 657 Label if_found(&m), if_not_found(&m); | 338 Label if_found(&m), if_not_found(&m); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 672 &passed, &failed); | 353 &passed, &failed); |
| 673 | 354 |
| 674 m.Bind(&passed); | 355 m.Bind(&passed); |
| 675 m.Return(m.BooleanConstant(true)); | 356 m.Return(m.BooleanConstant(true)); |
| 676 | 357 |
| 677 m.Bind(&failed); | 358 m.Bind(&failed); |
| 678 m.Return(m.BooleanConstant(false)); | 359 m.Return(m.BooleanConstant(false)); |
| 679 } | 360 } |
| 680 | 361 |
| 681 Handle<Code> code = m.GenerateCode(); | 362 Handle<Code> code = m.GenerateCode(); |
| 682 FunctionTester ft(code, param_count); | 363 FunctionTester ft(code, kNumParams); |
| 683 | 364 |
| 684 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); | 365 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); |
| 685 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); | 366 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); |
| 686 | 367 |
| 687 const int kKeysCount = 1000; | 368 const int kKeysCount = 1000; |
| 688 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount); | 369 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount); |
| 689 uint32_t keys[kKeysCount]; | 370 uint32_t keys[kKeysCount]; |
| 690 | 371 |
| 691 Handle<Object> fake_value(Smi::FromInt(42), isolate); | 372 Handle<Object> fake_value(Smi::FromInt(42), isolate); |
| 692 PropertyDetails fake_details = PropertyDetails::Empty(); | 373 PropertyDetails fake_details = PropertyDetails::Empty(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 JSObject::AddProperty(object, names[i], value, NONE); | 423 JSObject::AddProperty(object, names[i], value, NONE); |
| 743 } | 424 } |
| 744 } | 425 } |
| 745 | 426 |
| 746 } // namespace | 427 } // namespace |
| 747 | 428 |
| 748 TEST(TryLookupProperty) { | 429 TEST(TryLookupProperty) { |
| 749 typedef CodeStubAssembler::Label Label; | 430 typedef CodeStubAssembler::Label Label; |
| 750 Isolate* isolate(CcTest::InitIsolateOnce()); | 431 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 751 | 432 |
| 752 const int param_count = 4; | 433 const int kNumParams = 4; |
| 753 CodeStubAssemblerTester m(isolate, param_count); | 434 CodeStubAssemblerTester m(isolate, kNumParams); |
| 754 | 435 |
| 755 enum Result { kFound, kNotFound, kBailout }; | 436 enum Result { kFound, kNotFound, kBailout }; |
| 756 { | 437 { |
| 757 Node* object = m.Parameter(0); | 438 Node* object = m.Parameter(0); |
| 758 Node* unique_name = m.Parameter(1); | 439 Node* unique_name = m.Parameter(1); |
| 759 Node* expected_result = m.Parameter(2); | 440 Node* expected_result = m.Parameter(2); |
| 760 | 441 |
| 761 Label passed(&m), failed(&m); | 442 Label passed(&m), failed(&m); |
| 762 Label if_found(&m), if_not_found(&m), if_bailout(&m); | 443 Label if_found(&m), if_not_found(&m), if_bailout(&m); |
| 763 | 444 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 782 &passed, &failed); | 463 &passed, &failed); |
| 783 | 464 |
| 784 m.Bind(&passed); | 465 m.Bind(&passed); |
| 785 m.Return(m.BooleanConstant(true)); | 466 m.Return(m.BooleanConstant(true)); |
| 786 | 467 |
| 787 m.Bind(&failed); | 468 m.Bind(&failed); |
| 788 m.Return(m.BooleanConstant(false)); | 469 m.Return(m.BooleanConstant(false)); |
| 789 } | 470 } |
| 790 | 471 |
| 791 Handle<Code> code = m.GenerateCode(); | 472 Handle<Code> code = m.GenerateCode(); |
| 792 FunctionTester ft(code, param_count); | 473 FunctionTester ft(code, kNumParams); |
| 793 | 474 |
| 794 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); | 475 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); |
| 795 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); | 476 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); |
| 796 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); | 477 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); |
| 797 | 478 |
| 798 Factory* factory = isolate->factory(); | 479 Factory* factory = isolate->factory(); |
| 799 Handle<Name> names[] = { | 480 Handle<Name> names[] = { |
| 800 factory->InternalizeUtf8String("a"), | 481 factory->InternalizeUtf8String("a"), |
| 801 factory->InternalizeUtf8String("bb"), | 482 factory->InternalizeUtf8String("bb"), |
| 802 factory->InternalizeUtf8String("ccc"), | 483 factory->InternalizeUtf8String("ccc"), |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 PropertyAttributes attributes = NONE) { | 570 PropertyAttributes attributes = NONE) { |
| 890 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked(); | 571 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked(); |
| 891 } | 572 } |
| 892 | 573 |
| 893 } // namespace | 574 } // namespace |
| 894 | 575 |
| 895 TEST(TryLookupElement) { | 576 TEST(TryLookupElement) { |
| 896 typedef CodeStubAssembler::Label Label; | 577 typedef CodeStubAssembler::Label Label; |
| 897 Isolate* isolate(CcTest::InitIsolateOnce()); | 578 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 898 | 579 |
| 899 const int param_count = 4; | 580 const int kNumParams = 4; |
| 900 CodeStubAssemblerTester m(isolate, param_count); | 581 CodeStubAssemblerTester m(isolate, kNumParams); |
| 901 | 582 |
| 902 enum Result { kFound, kNotFound, kBailout }; | 583 enum Result { kFound, kNotFound, kBailout }; |
| 903 { | 584 { |
| 904 Node* object = m.Parameter(0); | 585 Node* object = m.Parameter(0); |
| 905 Node* index = m.SmiToWord32(m.Parameter(1)); | 586 Node* index = m.SmiToWord32(m.Parameter(1)); |
| 906 Node* expected_result = m.Parameter(2); | 587 Node* expected_result = m.Parameter(2); |
| 907 | 588 |
| 908 Label passed(&m), failed(&m); | 589 Label passed(&m), failed(&m); |
| 909 Label if_found(&m), if_not_found(&m), if_bailout(&m); | 590 Label if_found(&m), if_not_found(&m), if_bailout(&m); |
| 910 | 591 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 929 &passed, &failed); | 610 &passed, &failed); |
| 930 | 611 |
| 931 m.Bind(&passed); | 612 m.Bind(&passed); |
| 932 m.Return(m.BooleanConstant(true)); | 613 m.Return(m.BooleanConstant(true)); |
| 933 | 614 |
| 934 m.Bind(&failed); | 615 m.Bind(&failed); |
| 935 m.Return(m.BooleanConstant(false)); | 616 m.Return(m.BooleanConstant(false)); |
| 936 } | 617 } |
| 937 | 618 |
| 938 Handle<Code> code = m.GenerateCode(); | 619 Handle<Code> code = m.GenerateCode(); |
| 939 FunctionTester ft(code, param_count); | 620 FunctionTester ft(code, kNumParams); |
| 940 | 621 |
| 941 Factory* factory = isolate->factory(); | 622 Factory* factory = isolate->factory(); |
| 942 Handle<Object> smi0(Smi::FromInt(0), isolate); | 623 Handle<Object> smi0(Smi::FromInt(0), isolate); |
| 943 Handle<Object> smi1(Smi::FromInt(1), isolate); | 624 Handle<Object> smi1(Smi::FromInt(1), isolate); |
| 944 Handle<Object> smi7(Smi::FromInt(7), isolate); | 625 Handle<Object> smi7(Smi::FromInt(7), isolate); |
| 945 Handle<Object> smi13(Smi::FromInt(13), isolate); | 626 Handle<Object> smi13(Smi::FromInt(13), isolate); |
| 946 Handle<Object> smi42(Smi::FromInt(42), isolate); | 627 Handle<Object> smi42(Smi::FromInt(42), isolate); |
| 947 | 628 |
| 948 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); | 629 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); |
| 949 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); | 630 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 } | 811 } |
| 1131 m.Bind(&block1); | 812 m.Bind(&block1); |
| 1132 CHECK(!m.GenerateCode().is_null()); | 813 CHECK(!m.GenerateCode().is_null()); |
| 1133 } | 814 } |
| 1134 | 815 |
| 1135 namespace { | 816 namespace { |
| 1136 | 817 |
| 1137 void TestStubCacheOffsetCalculation(StubCache::Table table, | 818 void TestStubCacheOffsetCalculation(StubCache::Table table, |
| 1138 Code::Kind handler_kind) { | 819 Code::Kind handler_kind) { |
| 1139 Isolate* isolate(CcTest::InitIsolateOnce()); | 820 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1140 const int param_count = 2; | 821 const int kNumParams = 2; |
| 1141 CodeStubAssemblerTester m(isolate, param_count); | 822 CodeStubAssemblerTester m(isolate, kNumParams); |
| 1142 | 823 |
| 1143 Code::Flags code_flags = | 824 Code::Flags code_flags = |
| 1144 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind)); | 825 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind)); |
| 1145 { | 826 { |
| 1146 Node* name = m.Parameter(0); | 827 Node* name = m.Parameter(0); |
| 1147 Node* map = m.Parameter(1); | 828 Node* map = m.Parameter(1); |
| 1148 Node* primary_offset = m.StubCachePrimaryOffset(name, code_flags, map); | 829 Node* primary_offset = m.StubCachePrimaryOffset(name, code_flags, map); |
| 1149 Node* result; | 830 Node* result; |
| 1150 if (table == StubCache::kPrimary) { | 831 if (table == StubCache::kPrimary) { |
| 1151 result = primary_offset; | 832 result = primary_offset; |
| 1152 } else { | 833 } else { |
| 1153 CHECK_EQ(StubCache::kSecondary, table); | 834 CHECK_EQ(StubCache::kSecondary, table); |
| 1154 result = m.StubCacheSecondaryOffset(name, code_flags, primary_offset); | 835 result = m.StubCacheSecondaryOffset(name, code_flags, primary_offset); |
| 1155 } | 836 } |
| 1156 m.Return(m.SmiFromWord32(result)); | 837 m.Return(m.SmiFromWord32(result)); |
| 1157 } | 838 } |
| 1158 | 839 |
| 1159 Handle<Code> code = m.GenerateCode(); | 840 Handle<Code> code = m.GenerateCode(); |
| 1160 FunctionTester ft(code, param_count); | 841 FunctionTester ft(code, kNumParams); |
| 1161 | 842 |
| 1162 Factory* factory = isolate->factory(); | 843 Factory* factory = isolate->factory(); |
| 1163 Handle<Name> names[] = { | 844 Handle<Name> names[] = { |
| 1164 factory->NewSymbol(), | 845 factory->NewSymbol(), |
| 1165 factory->InternalizeUtf8String("a"), | 846 factory->InternalizeUtf8String("a"), |
| 1166 factory->InternalizeUtf8String("bb"), | 847 factory->InternalizeUtf8String("bb"), |
| 1167 factory->InternalizeUtf8String("ccc"), | 848 factory->InternalizeUtf8String("ccc"), |
| 1168 factory->NewPrivateSymbol(), | 849 factory->NewPrivateSymbol(), |
| 1169 factory->InternalizeUtf8String("dddd"), | 850 factory->InternalizeUtf8String("dddd"), |
| 1170 factory->InternalizeUtf8String("eeeee"), | 851 factory->InternalizeUtf8String("eeeee"), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 m.Return(m.UndefinedConstant()); | 918 m.Return(m.UndefinedConstant()); |
| 1238 return m.GenerateCodeCloseAndEscape(); | 919 return m.GenerateCodeCloseAndEscape(); |
| 1239 } | 920 } |
| 1240 | 921 |
| 1241 } // namespace | 922 } // namespace |
| 1242 | 923 |
| 1243 TEST(TryProbeStubCache) { | 924 TEST(TryProbeStubCache) { |
| 1244 typedef CodeStubAssembler::Label Label; | 925 typedef CodeStubAssembler::Label Label; |
| 1245 typedef CodeStubAssembler::Variable Variable; | 926 typedef CodeStubAssembler::Variable Variable; |
| 1246 Isolate* isolate(CcTest::InitIsolateOnce()); | 927 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 1247 const int param_count = 3; | 928 const int kNumParams = 3; |
| 1248 CodeStubAssemblerTester m(isolate, param_count); | 929 CodeStubAssemblerTester m(isolate, kNumParams); |
| 1249 | 930 |
| 1250 Code::Flags flags_to_query = | 931 Code::Flags flags_to_query = |
| 1251 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC)); | 932 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 1252 | 933 |
| 1253 StubCache stub_cache(isolate); | 934 StubCache stub_cache(isolate); |
| 1254 stub_cache.Clear(); | 935 stub_cache.Clear(); |
| 1255 | 936 |
| 1256 { | 937 { |
| 1257 Node* receiver = m.Parameter(0); | 938 Node* receiver = m.Parameter(0); |
| 1258 Node* name = m.Parameter(1); | 939 Node* name = m.Parameter(1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1274 &failed); | 955 &failed); |
| 1275 | 956 |
| 1276 m.Bind(&passed); | 957 m.Bind(&passed); |
| 1277 m.Return(m.BooleanConstant(true)); | 958 m.Return(m.BooleanConstant(true)); |
| 1278 | 959 |
| 1279 m.Bind(&failed); | 960 m.Bind(&failed); |
| 1280 m.Return(m.BooleanConstant(false)); | 961 m.Return(m.BooleanConstant(false)); |
| 1281 } | 962 } |
| 1282 | 963 |
| 1283 Handle<Code> code = m.GenerateCode(); | 964 Handle<Code> code = m.GenerateCode(); |
| 1284 FunctionTester ft(code, param_count); | 965 FunctionTester ft(code, kNumParams); |
| 1285 | 966 |
| 1286 std::vector<Handle<Name>> names; | 967 std::vector<Handle<Name>> names; |
| 1287 std::vector<Handle<JSObject>> receivers; | 968 std::vector<Handle<JSObject>> receivers; |
| 1288 std::vector<Handle<Code>> handlers; | 969 std::vector<Handle<Code>> handlers; |
| 1289 | 970 |
| 1290 base::RandomNumberGenerator rand_gen(FLAG_random_seed); | 971 base::RandomNumberGenerator rand_gen(FLAG_random_seed); |
| 1291 | 972 |
| 1292 Factory* factory = isolate->factory(); | 973 Factory* factory = isolate->factory(); |
| 1293 | 974 |
| 1294 // Generate some number of names. | 975 // Generate some number of names. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 | 1078 |
| 1398 Handle<Code> expected_handler(handler, isolate); | 1079 Handle<Code> expected_handler(handler, isolate); |
| 1399 ft.CheckTrue(receiver, name, expected_handler); | 1080 ft.CheckTrue(receiver, name, expected_handler); |
| 1400 } | 1081 } |
| 1401 // Ensure we performed both kind of queries. | 1082 // Ensure we performed both kind of queries. |
| 1402 CHECK(queried_existing && queried_non_existing); | 1083 CHECK(queried_existing && queried_non_existing); |
| 1403 } | 1084 } |
| 1404 | 1085 |
| 1405 } // namespace internal | 1086 } // namespace internal |
| 1406 } // namespace v8 | 1087 } // namespace v8 |
| OLD | NEW |