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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2504913002: Revert of [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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"
11 #include "test/cctest/compiler/code-assembler-tester.h" 11 #include "test/cctest/compiler/code-assembler-tester.h"
12 #include "test/cctest/compiler/function-tester.h" 12 #include "test/cctest/compiler/function-tester.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 using compiler::CodeAssemblerTester;
18 using compiler::FunctionTester; 17 using compiler::FunctionTester;
19 using compiler::Node; 18 using compiler::Node;
20 19
20 typedef compiler::CodeAssemblerTesterImpl<CodeStubAssembler>
21 CodeStubAssemblerTester;
22
21 TEST(FixedArrayAccessSmiIndex) { 23 TEST(FixedArrayAccessSmiIndex) {
22 Isolate* isolate(CcTest::InitIsolateOnce()); 24 Isolate* isolate(CcTest::InitIsolateOnce());
23 CodeAssemblerTester data(isolate); 25 VoidDescriptor descriptor(isolate);
24 CodeStubAssembler m(data.state()); 26 CodeStubAssemblerTester m(isolate, descriptor);
25 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); 27 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5);
26 array->set(4, Smi::FromInt(733)); 28 array->set(4, Smi::FromInt(733));
27 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array), 29 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array),
28 m.SmiTag(m.Int32Constant(4)), 0, 30 m.SmiTag(m.Int32Constant(4)), 0,
29 CodeStubAssembler::SMI_PARAMETERS)); 31 CodeStubAssembler::SMI_PARAMETERS));
30 Handle<Code> code = data.GenerateCode(); 32 Handle<Code> code = m.GenerateCode();
31 FunctionTester ft(code); 33 FunctionTester ft(descriptor, code);
32 MaybeHandle<Object> result = ft.Call(); 34 MaybeHandle<Object> result = ft.Call();
33 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); 35 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value());
34 } 36 }
35 37
36 TEST(LoadHeapNumberValue) { 38 TEST(LoadHeapNumberValue) {
37 Isolate* isolate(CcTest::InitIsolateOnce()); 39 Isolate* isolate(CcTest::InitIsolateOnce());
38 CodeAssemblerTester data(isolate); 40 VoidDescriptor descriptor(isolate);
39 CodeStubAssembler m(data.state()); 41 CodeStubAssemblerTester m(isolate, descriptor);
40 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234); 42 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234);
41 m.Return(m.SmiTag( 43 m.Return(m.SmiTag(
42 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number))))); 44 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number)))));
43 Handle<Code> code = data.GenerateCode(); 45 Handle<Code> code = m.GenerateCode();
44 FunctionTester ft(code); 46 FunctionTester ft(descriptor, code);
45 MaybeHandle<Object> result = ft.Call(); 47 MaybeHandle<Object> result = ft.Call();
46 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value()); 48 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value());
47 } 49 }
48 50
49 TEST(LoadInstanceType) { 51 TEST(LoadInstanceType) {
50 Isolate* isolate(CcTest::InitIsolateOnce()); 52 Isolate* isolate(CcTest::InitIsolateOnce());
51 CodeAssemblerTester data(isolate); 53 VoidDescriptor descriptor(isolate);
52 CodeStubAssembler m(data.state()); 54 CodeStubAssemblerTester m(isolate, descriptor);
53 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); 55 Handle<HeapObject> undefined = isolate->factory()->undefined_value();
54 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined)))); 56 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined))));
55 Handle<Code> code = data.GenerateCode(); 57 Handle<Code> code = m.GenerateCode();
56 FunctionTester ft(code); 58 FunctionTester ft(descriptor, code);
57 MaybeHandle<Object> result = ft.Call(); 59 MaybeHandle<Object> result = ft.Call();
58 CHECK_EQ(InstanceType::ODDBALL_TYPE, 60 CHECK_EQ(InstanceType::ODDBALL_TYPE,
59 Handle<Smi>::cast(result.ToHandleChecked())->value()); 61 Handle<Smi>::cast(result.ToHandleChecked())->value());
60 } 62 }
61 63
62 TEST(DecodeWordFromWord32) { 64 TEST(DecodeWordFromWord32) {
63 Isolate* isolate(CcTest::InitIsolateOnce()); 65 Isolate* isolate(CcTest::InitIsolateOnce());
64 CodeAssemblerTester data(isolate); 66 VoidDescriptor descriptor(isolate);
65 CodeStubAssembler m(data.state()); 67 CodeStubAssemblerTester m(isolate, descriptor);
66 68
67 class TestBitField : public BitField<unsigned, 3, 3> {}; 69 class TestBitField : public BitField<unsigned, 3, 3> {};
68 m.Return( 70 m.Return(
69 m.SmiTag(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2f)))); 71 m.SmiTag(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2f))));
70 Handle<Code> code = data.GenerateCode(); 72 Handle<Code> code = m.GenerateCode();
71 FunctionTester ft(code); 73 FunctionTester ft(descriptor, code);
72 MaybeHandle<Object> result = ft.Call(); 74 MaybeHandle<Object> result = ft.Call();
73 // value = 00101111 75 // value = 00101111
74 // mask = 00111000 76 // mask = 00111000
75 // result = 101 77 // result = 101
76 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value()); 78 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
77 } 79 }
78 80
79 TEST(JSFunction) { 81 TEST(JSFunction) {
80 const int kNumParams = 3; // Receiver, left, right. 82 const int kNumParams = 3; // Receiver, left, right.
81 Isolate* isolate(CcTest::InitIsolateOnce()); 83 Isolate* isolate(CcTest::InitIsolateOnce());
82 CodeAssemblerTester data(isolate, kNumParams); 84 CodeStubAssemblerTester m(isolate, kNumParams);
83 CodeStubAssembler m(data.state());
84 m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)), 85 m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
85 m.SmiToWord32(m.Parameter(2))))); 86 m.SmiToWord32(m.Parameter(2)))));
86 87
87 Handle<Code> code = data.GenerateCode(); 88 Handle<Code> code = m.GenerateCode();
88 FunctionTester ft(code, kNumParams); 89 FunctionTester ft(code, kNumParams);
89 90
90 MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(), 91 MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(),
91 handle(Smi::FromInt(23), isolate), 92 handle(Smi::FromInt(23), isolate),
92 handle(Smi::FromInt(34), isolate)); 93 handle(Smi::FromInt(34), isolate));
93 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); 94 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
94 } 95 }
95 96
96 TEST(ComputeIntegerHash) { 97 TEST(ComputeIntegerHash) {
97 Isolate* isolate(CcTest::InitIsolateOnce()); 98 Isolate* isolate(CcTest::InitIsolateOnce());
98 const int kNumParams = 2; 99 const int kNumParams = 2;
99 CodeAssemblerTester data(isolate, kNumParams); 100 CodeStubAssemblerTester m(isolate, kNumParams);
100 CodeStubAssembler m(data.state());
101 m.Return(m.SmiFromWord32(m.ComputeIntegerHash( 101 m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
102 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); 102 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
103 103
104 Handle<Code> code = data.GenerateCode(); 104 Handle<Code> code = m.GenerateCode();
105 FunctionTester ft(code, kNumParams); 105 FunctionTester ft(code, kNumParams);
106 106
107 Handle<Smi> hash_seed = isolate->factory()->hash_seed(); 107 Handle<Smi> hash_seed = isolate->factory()->hash_seed();
108 108
109 base::RandomNumberGenerator rand_gen(FLAG_random_seed); 109 base::RandomNumberGenerator rand_gen(FLAG_random_seed);
110 110
111 for (int i = 0; i < 1024; i++) { 111 for (int i = 0; i < 1024; i++) {
112 int k = rand_gen.NextInt(Smi::kMaxValue); 112 int k = rand_gen.NextInt(Smi::kMaxValue);
113 113
114 Handle<Smi> key(Smi::FromInt(k), isolate); 114 Handle<Smi> key(Smi::FromInt(k), isolate);
115 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked(); 115 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked();
116 116
117 uint32_t hash = ComputeIntegerHash(k, hash_seed->value()); 117 uint32_t hash = ComputeIntegerHash(k, hash_seed->value());
118 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue); 118 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue);
119 CHECK_EQ(expected, Smi::cast(*result)); 119 CHECK_EQ(expected, Smi::cast(*result));
120 } 120 }
121 } 121 }
122 122
123 TEST(ToString) { 123 TEST(ToString) {
124 Isolate* isolate(CcTest::InitIsolateOnce()); 124 Isolate* isolate(CcTest::InitIsolateOnce());
125 const int kNumParams = 1; 125 const int kNumParams = 1;
126 CodeAssemblerTester data(isolate, kNumParams); 126 CodeStubAssemblerTester m(isolate, kNumParams);
127 CodeStubAssembler m(data.state());
128 m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0))); 127 m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0)));
129 128
130 Handle<Code> code = data.GenerateCode(); 129 Handle<Code> code = m.GenerateCode();
131 FunctionTester ft(code, kNumParams); 130 FunctionTester ft(code, kNumParams);
132 131
133 Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5); 132 Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5);
134 Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2); 133 Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2);
135 smi_test->set(0, Smi::FromInt(42)); 134 smi_test->set(0, Smi::FromInt(42));
136 Handle<String> str(isolate->factory()->InternalizeUtf8String("42")); 135 Handle<String> str(isolate->factory()->InternalizeUtf8String("42"));
137 smi_test->set(1, *str); 136 smi_test->set(1, *str);
138 test_cases->set(0, *smi_test); 137 test_cases->set(0, *smi_test);
139 138
140 Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2); 139 Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Handle<String> expected = handle(String::cast(test->get(1))); 172 Handle<String> expected = handle(String::cast(test->get(1)));
174 Handle<Object> result = ft.Call(obj).ToHandleChecked(); 173 Handle<Object> result = ft.Call(obj).ToHandleChecked();
175 CHECK(result->IsString()); 174 CHECK(result->IsString());
176 CHECK(String::Equals(Handle<String>::cast(result), expected)); 175 CHECK(String::Equals(Handle<String>::cast(result), expected));
177 } 176 }
178 } 177 }
179 178
180 TEST(FlattenString) { 179 TEST(FlattenString) {
181 Isolate* isolate(CcTest::InitIsolateOnce()); 180 Isolate* isolate(CcTest::InitIsolateOnce());
182 const int kNumParams = 1; 181 const int kNumParams = 1;
183 CodeAssemblerTester data(isolate, kNumParams); 182 CodeStubAssemblerTester m(isolate, kNumParams);
184 CodeStubAssembler m(data.state());
185 m.Return(m.FlattenString(m.Parameter(0))); 183 m.Return(m.FlattenString(m.Parameter(0)));
186 184
187 Handle<Code> code = data.GenerateCode(); 185 Handle<Code> code = m.GenerateCode();
188 FunctionTester ft(code, kNumParams); 186 FunctionTester ft(code, kNumParams);
189 187
190 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4)); 188 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4));
191 Handle<String> expected( 189 Handle<String> expected(
192 isolate->factory()->InternalizeUtf8String("hello, world!")); 190 isolate->factory()->InternalizeUtf8String("hello, world!"));
193 test_cases->set(0, *expected); 191 test_cases->set(0, *expected);
194 192
195 Handle<String> string( 193 Handle<String> string(
196 isolate->factory()->InternalizeUtf8String("filler hello, world! filler")); 194 isolate->factory()->InternalizeUtf8String("filler hello, world! filler"));
197 Handle<String> sub_string( 195 Handle<String> sub_string(
(...skipping 19 matching lines...) Expand all
217 CHECK(String::Equals(Handle<String>::cast(result), expected)); 215 CHECK(String::Equals(Handle<String>::cast(result), expected));
218 } 216 }
219 } 217 }
220 218
221 TEST(TryToName) { 219 TEST(TryToName) {
222 typedef CodeStubAssembler::Label Label; 220 typedef CodeStubAssembler::Label Label;
223 typedef CodeStubAssembler::Variable Variable; 221 typedef CodeStubAssembler::Variable Variable;
224 Isolate* isolate(CcTest::InitIsolateOnce()); 222 Isolate* isolate(CcTest::InitIsolateOnce());
225 223
226 const int kNumParams = 3; 224 const int kNumParams = 3;
227 CodeAssemblerTester data(isolate, kNumParams); 225 CodeStubAssemblerTester m(isolate, kNumParams);
228 CodeStubAssembler m(data.state());
229 226
230 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 227 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
231 { 228 {
232 Node* key = m.Parameter(0); 229 Node* key = m.Parameter(0);
233 Node* expected_result = m.Parameter(1); 230 Node* expected_result = m.Parameter(1);
234 Node* expected_arg = m.Parameter(2); 231 Node* expected_arg = m.Parameter(2);
235 232
236 Label passed(&m), failed(&m); 233 Label passed(&m), failed(&m);
237 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); 234 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m);
238 Variable var_index(&m, MachineType::PointerRepresentation()); 235 Variable var_index(&m, MachineType::PointerRepresentation());
(...skipping 18 matching lines...) Expand all
257 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 254 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
258 &passed, &failed); 255 &passed, &failed);
259 256
260 m.Bind(&passed); 257 m.Bind(&passed);
261 m.Return(m.BooleanConstant(true)); 258 m.Return(m.BooleanConstant(true));
262 259
263 m.Bind(&failed); 260 m.Bind(&failed);
264 m.Return(m.BooleanConstant(false)); 261 m.Return(m.BooleanConstant(false));
265 } 262 }
266 263
267 Handle<Code> code = data.GenerateCode(); 264 Handle<Code> code = m.GenerateCode();
268 FunctionTester ft(code, kNumParams); 265 FunctionTester ft(code, kNumParams);
269 266
270 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate); 267 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate);
271 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate); 268 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate);
272 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); 269 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
273 270
274 { 271 {
275 // TryToName(<zero smi>) => if_keyisindex: smi value. 272 // TryToName(<zero smi>) => if_keyisindex: smi value.
276 Handle<Object> key(Smi::kZero, isolate); 273 Handle<Object> key(Smi::kZero, isolate);
277 ft.CheckTrue(key, expect_index, key); 274 ft.CheckTrue(key, expect_index, key);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 345 }
349 } 346 }
350 347
351 namespace { 348 namespace {
352 349
353 template <typename Dictionary> 350 template <typename Dictionary>
354 void TestEntryToIndex() { 351 void TestEntryToIndex() {
355 Isolate* isolate(CcTest::InitIsolateOnce()); 352 Isolate* isolate(CcTest::InitIsolateOnce());
356 353
357 const int kNumParams = 1; 354 const int kNumParams = 1;
358 CodeAssemblerTester data(isolate, kNumParams); 355 CodeStubAssemblerTester m(isolate, kNumParams);
359 CodeStubAssembler m(data.state());
360 { 356 {
361 Node* entry = m.SmiUntag(m.Parameter(0)); 357 Node* entry = m.SmiUntag(m.Parameter(0));
362 Node* result = m.EntryToIndex<Dictionary>(entry); 358 Node* result = m.EntryToIndex<Dictionary>(entry);
363 m.Return(m.SmiTag(result)); 359 m.Return(m.SmiTag(result));
364 } 360 }
365 361
366 Handle<Code> code = data.GenerateCode(); 362 Handle<Code> code = m.GenerateCode();
367 FunctionTester ft(code, kNumParams); 363 FunctionTester ft(code, kNumParams);
368 364
369 // Test a wide range of entries but staying linear in the first 100 entries. 365 // Test a wide range of entries but staying linear in the first 100 entries.
370 for (int entry = 0; entry < Dictionary::kMaxCapacity; 366 for (int entry = 0; entry < Dictionary::kMaxCapacity;
371 entry = entry * 1.01 + 1) { 367 entry = entry * 1.01 + 1) {
372 Handle<Object> result = 368 Handle<Object> result =
373 ft.Call(handle(Smi::FromInt(entry), isolate)).ToHandleChecked(); 369 ft.Call(handle(Smi::FromInt(entry), isolate)).ToHandleChecked();
374 CHECK_EQ(Dictionary::EntryToIndex(entry), Smi::cast(*result)->value()); 370 CHECK_EQ(Dictionary::EntryToIndex(entry), Smi::cast(*result)->value());
375 } 371 }
376 } 372 }
377 373
378 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); } 374 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); }
379 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); } 375 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); }
380 376
381 } // namespace 377 } // namespace
382 378
383 namespace { 379 namespace {
384 380
385 template <typename Dictionary> 381 template <typename Dictionary>
386 void TestNameDictionaryLookup() { 382 void TestNameDictionaryLookup() {
387 typedef CodeStubAssembler::Label Label; 383 typedef CodeStubAssembler::Label Label;
388 typedef CodeStubAssembler::Variable Variable; 384 typedef CodeStubAssembler::Variable Variable;
389 Isolate* isolate(CcTest::InitIsolateOnce()); 385 Isolate* isolate(CcTest::InitIsolateOnce());
390 386
391 const int kNumParams = 4; 387 const int kNumParams = 4;
392 CodeAssemblerTester data(isolate, kNumParams); 388 CodeStubAssemblerTester m(isolate, kNumParams);
393 CodeStubAssembler m(data.state());
394 389
395 enum Result { kFound, kNotFound }; 390 enum Result { kFound, kNotFound };
396 { 391 {
397 Node* dictionary = m.Parameter(0); 392 Node* dictionary = m.Parameter(0);
398 Node* unique_name = m.Parameter(1); 393 Node* unique_name = m.Parameter(1);
399 Node* expected_result = m.Parameter(2); 394 Node* expected_result = m.Parameter(2);
400 Node* expected_arg = m.Parameter(3); 395 Node* expected_arg = m.Parameter(3);
401 396
402 Label passed(&m), failed(&m); 397 Label passed(&m), failed(&m);
403 Label if_found(&m), if_not_found(&m); 398 Label if_found(&m), if_not_found(&m);
(...skipping 13 matching lines...) Expand all
417 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 412 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
418 &passed, &failed); 413 &passed, &failed);
419 414
420 m.Bind(&passed); 415 m.Bind(&passed);
421 m.Return(m.BooleanConstant(true)); 416 m.Return(m.BooleanConstant(true));
422 417
423 m.Bind(&failed); 418 m.Bind(&failed);
424 m.Return(m.BooleanConstant(false)); 419 m.Return(m.BooleanConstant(false));
425 } 420 }
426 421
427 Handle<Code> code = data.GenerateCode(); 422 Handle<Code> code = m.GenerateCode();
428 FunctionTester ft(code, kNumParams); 423 FunctionTester ft(code, kNumParams);
429 424
430 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 425 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
431 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 426 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
432 427
433 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40); 428 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40);
434 PropertyDetails fake_details = PropertyDetails::Empty(); 429 PropertyDetails fake_details = PropertyDetails::Empty();
435 430
436 Factory* factory = isolate->factory(); 431 Factory* factory = isolate->factory();
437 Handle<Name> keys[] = { 432 Handle<Name> keys[] = {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 484
490 namespace { 485 namespace {
491 486
492 template <typename Dictionary> 487 template <typename Dictionary>
493 void TestNumberDictionaryLookup() { 488 void TestNumberDictionaryLookup() {
494 typedef CodeStubAssembler::Label Label; 489 typedef CodeStubAssembler::Label Label;
495 typedef CodeStubAssembler::Variable Variable; 490 typedef CodeStubAssembler::Variable Variable;
496 Isolate* isolate(CcTest::InitIsolateOnce()); 491 Isolate* isolate(CcTest::InitIsolateOnce());
497 492
498 const int kNumParams = 4; 493 const int kNumParams = 4;
499 CodeAssemblerTester data(isolate, kNumParams); 494 CodeStubAssemblerTester m(isolate, kNumParams);
500 CodeStubAssembler m(data.state());
501 495
502 enum Result { kFound, kNotFound }; 496 enum Result { kFound, kNotFound };
503 { 497 {
504 Node* dictionary = m.Parameter(0); 498 Node* dictionary = m.Parameter(0);
505 Node* key = m.SmiToWord32(m.Parameter(1)); 499 Node* key = m.SmiToWord32(m.Parameter(1));
506 Node* expected_result = m.Parameter(2); 500 Node* expected_result = m.Parameter(2);
507 Node* expected_arg = m.Parameter(3); 501 Node* expected_arg = m.Parameter(3);
508 502
509 Label passed(&m), failed(&m); 503 Label passed(&m), failed(&m);
510 Label if_found(&m), if_not_found(&m); 504 Label if_found(&m), if_not_found(&m);
(...skipping 13 matching lines...) Expand all
524 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 518 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
525 &passed, &failed); 519 &passed, &failed);
526 520
527 m.Bind(&passed); 521 m.Bind(&passed);
528 m.Return(m.BooleanConstant(true)); 522 m.Return(m.BooleanConstant(true));
529 523
530 m.Bind(&failed); 524 m.Bind(&failed);
531 m.Return(m.BooleanConstant(false)); 525 m.Return(m.BooleanConstant(false));
532 } 526 }
533 527
534 Handle<Code> code = data.GenerateCode(); 528 Handle<Code> code = m.GenerateCode();
535 FunctionTester ft(code, kNumParams); 529 FunctionTester ft(code, kNumParams);
536 530
537 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 531 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
538 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 532 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
539 533
540 const int kKeysCount = 1000; 534 const int kKeysCount = 1000;
541 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount); 535 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount);
542 uint32_t keys[kKeysCount]; 536 uint32_t keys[kKeysCount];
543 537
544 Handle<Object> fake_value(Smi::FromInt(42), isolate); 538 Handle<Object> fake_value(Smi::FromInt(42), isolate);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 621 }
628 } 622 }
629 623
630 } // namespace 624 } // namespace
631 625
632 TEST(TryHasOwnProperty) { 626 TEST(TryHasOwnProperty) {
633 typedef CodeStubAssembler::Label Label; 627 typedef CodeStubAssembler::Label Label;
634 Isolate* isolate(CcTest::InitIsolateOnce()); 628 Isolate* isolate(CcTest::InitIsolateOnce());
635 629
636 const int kNumParams = 4; 630 const int kNumParams = 4;
637 CodeAssemblerTester data(isolate, kNumParams); 631 CodeStubAssemblerTester m(isolate, kNumParams);
638 CodeStubAssembler m(data.state());
639 632
640 enum Result { kFound, kNotFound, kBailout }; 633 enum Result { kFound, kNotFound, kBailout };
641 { 634 {
642 Node* object = m.Parameter(0); 635 Node* object = m.Parameter(0);
643 Node* unique_name = m.Parameter(1); 636 Node* unique_name = m.Parameter(1);
644 Node* expected_result = m.Parameter(2); 637 Node* expected_result = m.Parameter(2);
645 638
646 Label passed(&m), failed(&m); 639 Label passed(&m), failed(&m);
647 Label if_found(&m), if_not_found(&m), if_bailout(&m); 640 Label if_found(&m), if_not_found(&m), if_bailout(&m);
648 641
(...skipping 17 matching lines...) Expand all
666 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 659 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
667 &passed, &failed); 660 &passed, &failed);
668 661
669 m.Bind(&passed); 662 m.Bind(&passed);
670 m.Return(m.BooleanConstant(true)); 663 m.Return(m.BooleanConstant(true));
671 664
672 m.Bind(&failed); 665 m.Bind(&failed);
673 m.Return(m.BooleanConstant(false)); 666 m.Return(m.BooleanConstant(false));
674 } 667 }
675 668
676 Handle<Code> code = data.GenerateCode(); 669 Handle<Code> code = m.GenerateCode();
677 FunctionTester ft(code, kNumParams); 670 FunctionTester ft(code, kNumParams);
678 671
679 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 672 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
680 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 673 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
681 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); 674 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
682 675
683 Factory* factory = isolate->factory(); 676 Factory* factory = isolate->factory();
684 677
685 Handle<Name> deleted_property_name = 678 Handle<Name> deleted_property_name =
686 factory->InternalizeUtf8String("deleted"); 679 factory->InternalizeUtf8String("deleted");
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } 807 }
815 } 808 }
816 809
817 TEST(TryGetOwnProperty) { 810 TEST(TryGetOwnProperty) {
818 typedef CodeStubAssembler::Label Label; 811 typedef CodeStubAssembler::Label Label;
819 typedef CodeStubAssembler::Variable Variable; 812 typedef CodeStubAssembler::Variable Variable;
820 Isolate* isolate(CcTest::InitIsolateOnce()); 813 Isolate* isolate(CcTest::InitIsolateOnce());
821 Factory* factory = isolate->factory(); 814 Factory* factory = isolate->factory();
822 815
823 const int kNumParams = 2; 816 const int kNumParams = 2;
824 CodeAssemblerTester data(isolate, kNumParams); 817 CodeStubAssemblerTester m(isolate, kNumParams);
825 CodeStubAssembler m(data.state());
826 818
827 Handle<Symbol> not_found_symbol = factory->NewSymbol(); 819 Handle<Symbol> not_found_symbol = factory->NewSymbol();
828 Handle<Symbol> bailout_symbol = factory->NewSymbol(); 820 Handle<Symbol> bailout_symbol = factory->NewSymbol();
829 { 821 {
830 Node* object = m.Parameter(0); 822 Node* object = m.Parameter(0);
831 Node* unique_name = m.Parameter(1); 823 Node* unique_name = m.Parameter(1);
832 Node* context = m.Parameter(kNumParams + 2); 824 Node* context = m.Parameter(kNumParams + 2);
833 825
834 Variable var_value(&m, MachineRepresentation::kTagged); 826 Variable var_value(&m, MachineRepresentation::kTagged);
835 Label if_found(&m), if_not_found(&m), if_bailout(&m); 827 Label if_found(&m), if_not_found(&m), if_bailout(&m);
836 828
837 Node* map = m.LoadMap(object); 829 Node* map = m.LoadMap(object);
838 Node* instance_type = m.LoadMapInstanceType(map); 830 Node* instance_type = m.LoadMapInstanceType(map);
839 831
840 m.TryGetOwnProperty(context, object, object, map, instance_type, 832 m.TryGetOwnProperty(context, object, object, map, instance_type,
841 unique_name, &if_found, &var_value, &if_not_found, 833 unique_name, &if_found, &var_value, &if_not_found,
842 &if_bailout); 834 &if_bailout);
843 835
844 m.Bind(&if_found); 836 m.Bind(&if_found);
845 m.Return(var_value.value()); 837 m.Return(var_value.value());
846 838
847 m.Bind(&if_not_found); 839 m.Bind(&if_not_found);
848 m.Return(m.HeapConstant(not_found_symbol)); 840 m.Return(m.HeapConstant(not_found_symbol));
849 841
850 m.Bind(&if_bailout); 842 m.Bind(&if_bailout);
851 m.Return(m.HeapConstant(bailout_symbol)); 843 m.Return(m.HeapConstant(bailout_symbol));
852 } 844 }
853 845
854 Handle<Code> code = data.GenerateCode(); 846 Handle<Code> code = m.GenerateCode();
855 FunctionTester ft(code, kNumParams); 847 FunctionTester ft(code, kNumParams);
856 848
857 Handle<Name> deleted_property_name = 849 Handle<Name> deleted_property_name =
858 factory->InternalizeUtf8String("deleted"); 850 factory->InternalizeUtf8String("deleted");
859 851
860 Handle<Name> names[] = { 852 Handle<Name> names[] = {
861 factory->InternalizeUtf8String("bb"), 853 factory->InternalizeUtf8String("bb"),
862 factory->NewSymbol(), 854 factory->NewSymbol(),
863 factory->InternalizeUtf8String("a"), 855 factory->InternalizeUtf8String("a"),
864 factory->InternalizeUtf8String("ccc"), 856 factory->InternalizeUtf8String("ccc"),
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked(); 1023 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked();
1032 } 1024 }
1033 1025
1034 } // namespace 1026 } // namespace
1035 1027
1036 TEST(TryLookupElement) { 1028 TEST(TryLookupElement) {
1037 typedef CodeStubAssembler::Label Label; 1029 typedef CodeStubAssembler::Label Label;
1038 Isolate* isolate(CcTest::InitIsolateOnce()); 1030 Isolate* isolate(CcTest::InitIsolateOnce());
1039 1031
1040 const int kNumParams = 3; 1032 const int kNumParams = 3;
1041 CodeAssemblerTester data(isolate, kNumParams); 1033 CodeStubAssemblerTester m(isolate, kNumParams);
1042 CodeStubAssembler m(data.state());
1043 1034
1044 enum Result { kFound, kNotFound, kBailout }; 1035 enum Result { kFound, kNotFound, kBailout };
1045 { 1036 {
1046 Node* object = m.Parameter(0); 1037 Node* object = m.Parameter(0);
1047 Node* index = m.SmiToWord32(m.Parameter(1)); 1038 Node* index = m.SmiToWord32(m.Parameter(1));
1048 Node* expected_result = m.Parameter(2); 1039 Node* expected_result = m.Parameter(2);
1049 1040
1050 Label passed(&m), failed(&m); 1041 Label passed(&m), failed(&m);
1051 Label if_found(&m), if_not_found(&m), if_bailout(&m); 1042 Label if_found(&m), if_not_found(&m), if_bailout(&m);
1052 1043
(...skipping 17 matching lines...) Expand all
1070 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 1061 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
1071 &passed, &failed); 1062 &passed, &failed);
1072 1063
1073 m.Bind(&passed); 1064 m.Bind(&passed);
1074 m.Return(m.BooleanConstant(true)); 1065 m.Return(m.BooleanConstant(true));
1075 1066
1076 m.Bind(&failed); 1067 m.Bind(&failed);
1077 m.Return(m.BooleanConstant(false)); 1068 m.Return(m.BooleanConstant(false));
1078 } 1069 }
1079 1070
1080 Handle<Code> code = data.GenerateCode(); 1071 Handle<Code> code = m.GenerateCode();
1081 FunctionTester ft(code, kNumParams); 1072 FunctionTester ft(code, kNumParams);
1082 1073
1083 Factory* factory = isolate->factory(); 1074 Factory* factory = isolate->factory();
1084 Handle<Object> smi0(Smi::kZero, isolate); 1075 Handle<Object> smi0(Smi::kZero, isolate);
1085 Handle<Object> smi1(Smi::FromInt(1), isolate); 1076 Handle<Object> smi1(Smi::FromInt(1), isolate);
1086 Handle<Object> smi7(Smi::FromInt(7), isolate); 1077 Handle<Object> smi7(Smi::FromInt(7), isolate);
1087 Handle<Object> smi13(Smi::FromInt(13), isolate); 1078 Handle<Object> smi13(Smi::FromInt(13), isolate);
1088 Handle<Object> smi42(Smi::FromInt(42), isolate); 1079 Handle<Object> smi42(Smi::FromInt(42), isolate);
1089 1080
1090 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 1081 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type()); 1209 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
1219 ft.CheckTrue(object, smi0, expect_bailout); 1210 ft.CheckTrue(object, smi0, expect_bailout);
1220 } 1211 }
1221 } 1212 }
1222 1213
1223 TEST(DeferredCodePhiHints) { 1214 TEST(DeferredCodePhiHints) {
1224 typedef compiler::Node Node; 1215 typedef compiler::Node Node;
1225 typedef CodeStubAssembler::Label Label; 1216 typedef CodeStubAssembler::Label Label;
1226 typedef CodeStubAssembler::Variable Variable; 1217 typedef CodeStubAssembler::Variable Variable;
1227 Isolate* isolate(CcTest::InitIsolateOnce()); 1218 Isolate* isolate(CcTest::InitIsolateOnce());
1228 CodeAssemblerTester data(isolate); 1219 VoidDescriptor descriptor(isolate);
1229 CodeStubAssembler m(data.state()); 1220 CodeStubAssemblerTester m(isolate, descriptor);
1230 Label block1(&m, Label::kDeferred); 1221 Label block1(&m, Label::kDeferred);
1231 m.Goto(&block1); 1222 m.Goto(&block1);
1232 m.Bind(&block1); 1223 m.Bind(&block1);
1233 { 1224 {
1234 Variable var_object(&m, MachineRepresentation::kTagged); 1225 Variable var_object(&m, MachineRepresentation::kTagged);
1235 Label loop(&m, &var_object); 1226 Label loop(&m, &var_object);
1236 var_object.Bind(m.IntPtrConstant(0)); 1227 var_object.Bind(m.IntPtrConstant(0));
1237 m.Goto(&loop); 1228 m.Goto(&loop);
1238 m.Bind(&loop); 1229 m.Bind(&loop);
1239 { 1230 {
1240 Node* map = m.LoadMap(var_object.value()); 1231 Node* map = m.LoadMap(var_object.value());
1241 var_object.Bind(map); 1232 var_object.Bind(map);
1242 m.Goto(&loop); 1233 m.Goto(&loop);
1243 } 1234 }
1244 } 1235 }
1245 CHECK(!data.GenerateCode().is_null()); 1236 CHECK(!m.GenerateCode().is_null());
1246 } 1237 }
1247 1238
1248 TEST(TestOutOfScopeVariable) { 1239 TEST(TestOutOfScopeVariable) {
1249 typedef CodeStubAssembler::Label Label; 1240 typedef CodeStubAssembler::Label Label;
1250 typedef CodeStubAssembler::Variable Variable; 1241 typedef CodeStubAssembler::Variable Variable;
1251 Isolate* isolate(CcTest::InitIsolateOnce()); 1242 Isolate* isolate(CcTest::InitIsolateOnce());
1252 CodeAssemblerTester data(isolate); 1243 VoidDescriptor descriptor(isolate);
1253 CodeStubAssembler m(data.state()); 1244 CodeStubAssemblerTester m(isolate, descriptor);
1254 Label block1(&m); 1245 Label block1(&m);
1255 Label block2(&m); 1246 Label block2(&m);
1256 Label block3(&m); 1247 Label block3(&m);
1257 Label block4(&m); 1248 Label block4(&m);
1258 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4); 1249 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4);
1259 m.Bind(&block4); 1250 m.Bind(&block4);
1260 { 1251 {
1261 Variable var_object(&m, MachineRepresentation::kTagged); 1252 Variable var_object(&m, MachineRepresentation::kTagged);
1262 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2, 1253 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2,
1263 &block3); 1254 &block3);
1264 1255
1265 m.Bind(&block2); 1256 m.Bind(&block2);
1266 var_object.Bind(m.IntPtrConstant(55)); 1257 var_object.Bind(m.IntPtrConstant(55));
1267 m.Goto(&block1); 1258 m.Goto(&block1);
1268 1259
1269 m.Bind(&block3); 1260 m.Bind(&block3);
1270 var_object.Bind(m.IntPtrConstant(66)); 1261 var_object.Bind(m.IntPtrConstant(66));
1271 m.Goto(&block1); 1262 m.Goto(&block1);
1272 } 1263 }
1273 m.Bind(&block1); 1264 m.Bind(&block1);
1274 CHECK(!data.GenerateCode().is_null()); 1265 CHECK(!m.GenerateCode().is_null());
1275 } 1266 }
1276 1267
1277 namespace { 1268 namespace {
1278 1269
1279 void TestStubCacheOffsetCalculation(StubCache::Table table) { 1270 void TestStubCacheOffsetCalculation(StubCache::Table table) {
1280 Isolate* isolate(CcTest::InitIsolateOnce()); 1271 Isolate* isolate(CcTest::InitIsolateOnce());
1281 const int kNumParams = 2; 1272 const int kNumParams = 2;
1282 CodeAssemblerTester data(isolate, kNumParams); 1273 CodeStubAssemblerTester m(isolate, kNumParams);
1283 CodeStubAssembler m(data.state());
1284 1274
1285 { 1275 {
1286 Node* name = m.Parameter(0); 1276 Node* name = m.Parameter(0);
1287 Node* map = m.Parameter(1); 1277 Node* map = m.Parameter(1);
1288 Node* primary_offset = m.StubCachePrimaryOffset(name, map); 1278 Node* primary_offset = m.StubCachePrimaryOffset(name, map);
1289 Node* result; 1279 Node* result;
1290 if (table == StubCache::kPrimary) { 1280 if (table == StubCache::kPrimary) {
1291 result = primary_offset; 1281 result = primary_offset;
1292 } else { 1282 } else {
1293 CHECK_EQ(StubCache::kSecondary, table); 1283 CHECK_EQ(StubCache::kSecondary, table);
1294 result = m.StubCacheSecondaryOffset(name, primary_offset); 1284 result = m.StubCacheSecondaryOffset(name, primary_offset);
1295 } 1285 }
1296 m.Return(m.SmiFromWord32(result)); 1286 m.Return(m.SmiFromWord32(result));
1297 } 1287 }
1298 1288
1299 Handle<Code> code = data.GenerateCode(); 1289 Handle<Code> code = m.GenerateCode();
1300 FunctionTester ft(code, kNumParams); 1290 FunctionTester ft(code, kNumParams);
1301 1291
1302 Factory* factory = isolate->factory(); 1292 Factory* factory = isolate->factory();
1303 Handle<Name> names[] = { 1293 Handle<Name> names[] = {
1304 factory->NewSymbol(), 1294 factory->NewSymbol(),
1305 factory->InternalizeUtf8String("a"), 1295 factory->InternalizeUtf8String("a"),
1306 factory->InternalizeUtf8String("bb"), 1296 factory->InternalizeUtf8String("bb"),
1307 factory->InternalizeUtf8String("ccc"), 1297 factory->InternalizeUtf8String("ccc"),
1308 factory->NewPrivateSymbol(), 1298 factory->NewPrivateSymbol(),
1309 factory->InternalizeUtf8String("dddd"), 1299 factory->InternalizeUtf8String("dddd"),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 } 1347 }
1358 1348
1359 TEST(StubCacheSecondaryOffset) { 1349 TEST(StubCacheSecondaryOffset) {
1360 TestStubCacheOffsetCalculation(StubCache::kSecondary); 1350 TestStubCacheOffsetCalculation(StubCache::kSecondary);
1361 } 1351 }
1362 1352
1363 namespace { 1353 namespace {
1364 1354
1365 Handle<Code> CreateCodeWithFlags(Code::Flags flags) { 1355 Handle<Code> CreateCodeWithFlags(Code::Flags flags) {
1366 Isolate* isolate(CcTest::InitIsolateOnce()); 1356 Isolate* isolate(CcTest::InitIsolateOnce());
1367 CodeAssemblerTester data(isolate, flags); 1357 CodeStubAssemblerTester m(isolate, flags);
1368 CodeStubAssembler m(data.state());
1369 m.Return(m.UndefinedConstant()); 1358 m.Return(m.UndefinedConstant());
1370 return data.GenerateCodeCloseAndEscape(); 1359 return m.GenerateCodeCloseAndEscape();
1371 } 1360 }
1372 1361
1373 } // namespace 1362 } // namespace
1374 1363
1375 TEST(TryProbeStubCache) { 1364 TEST(TryProbeStubCache) {
1376 typedef CodeStubAssembler::Label Label; 1365 typedef CodeStubAssembler::Label Label;
1377 typedef CodeStubAssembler::Variable Variable; 1366 typedef CodeStubAssembler::Variable Variable;
1378 Isolate* isolate(CcTest::InitIsolateOnce()); 1367 Isolate* isolate(CcTest::InitIsolateOnce());
1379 const int kNumParams = 3; 1368 const int kNumParams = 3;
1380 CodeAssemblerTester data(isolate, kNumParams); 1369 CodeStubAssemblerTester m(isolate, kNumParams);
1381 CodeStubAssembler m(data.state());
1382 1370
1383 Code::Kind ic_kind = Code::LOAD_IC; 1371 Code::Kind ic_kind = Code::LOAD_IC;
1384 StubCache stub_cache(isolate, ic_kind); 1372 StubCache stub_cache(isolate, ic_kind);
1385 stub_cache.Clear(); 1373 stub_cache.Clear();
1386 1374
1387 { 1375 {
1388 Node* receiver = m.Parameter(0); 1376 Node* receiver = m.Parameter(0);
1389 Node* name = m.Parameter(1); 1377 Node* name = m.Parameter(1);
1390 Node* expected_handler = m.Parameter(2); 1378 Node* expected_handler = m.Parameter(2);
1391 1379
(...skipping 12 matching lines...) Expand all
1404 m.Branch(m.WordEqual(expected_handler, m.IntPtrConstant(0)), &passed, 1392 m.Branch(m.WordEqual(expected_handler, m.IntPtrConstant(0)), &passed,
1405 &failed); 1393 &failed);
1406 1394
1407 m.Bind(&passed); 1395 m.Bind(&passed);
1408 m.Return(m.BooleanConstant(true)); 1396 m.Return(m.BooleanConstant(true));
1409 1397
1410 m.Bind(&failed); 1398 m.Bind(&failed);
1411 m.Return(m.BooleanConstant(false)); 1399 m.Return(m.BooleanConstant(false));
1412 } 1400 }
1413 1401
1414 Handle<Code> code = data.GenerateCode(); 1402 Handle<Code> code = m.GenerateCode();
1415 FunctionTester ft(code, kNumParams); 1403 FunctionTester ft(code, kNumParams);
1416 1404
1417 std::vector<Handle<Name>> names; 1405 std::vector<Handle<Name>> names;
1418 std::vector<Handle<JSObject>> receivers; 1406 std::vector<Handle<JSObject>> receivers;
1419 std::vector<Handle<Code>> handlers; 1407 std::vector<Handle<Code>> handlers;
1420 1408
1421 base::RandomNumberGenerator rand_gen(FLAG_random_seed); 1409 base::RandomNumberGenerator rand_gen(FLAG_random_seed);
1422 1410
1423 Factory* factory = isolate->factory(); 1411 Factory* factory = isolate->factory();
1424 1412
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 // Ensure we performed both kind of queries. 1503 // Ensure we performed both kind of queries.
1516 CHECK(queried_existing && queried_non_existing); 1504 CHECK(queried_existing && queried_non_existing);
1517 } 1505 }
1518 1506
1519 TEST(GotoIfException) { 1507 TEST(GotoIfException) {
1520 typedef CodeStubAssembler::Label Label; 1508 typedef CodeStubAssembler::Label Label;
1521 typedef CodeStubAssembler::Variable Variable; 1509 typedef CodeStubAssembler::Variable Variable;
1522 Isolate* isolate(CcTest::InitIsolateOnce()); 1510 Isolate* isolate(CcTest::InitIsolateOnce());
1523 1511
1524 const int kNumParams = 1; 1512 const int kNumParams = 1;
1525 CodeAssemblerTester data(isolate, kNumParams); 1513 // Emulate TFJ builtin
1526 CodeStubAssembler m(data.state()); 1514 CodeStubAssemblerTester m(isolate, kNumParams, Code::BUILTIN);
1527 1515
1528 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); 1516 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1529 Node* to_string_tag = 1517 Node* to_string_tag =
1530 m.HeapConstant(isolate->factory()->to_string_tag_symbol()); 1518 m.HeapConstant(isolate->factory()->to_string_tag_symbol());
1531 Variable exception(&m, MachineRepresentation::kTagged); 1519 Variable exception(&m, MachineRepresentation::kTagged);
1532 1520
1533 Label exception_handler(&m); 1521 Label exception_handler(&m);
1534 Callable to_string = CodeFactory::ToString(isolate); 1522 Callable to_string = CodeFactory::ToString(isolate);
1535 Node* string = m.CallStub(to_string, context, to_string_tag); 1523 Node* string = m.CallStub(to_string, context, to_string_tag);
1536 m.GotoIfException(string, &exception_handler, &exception); 1524 m.GotoIfException(string, &exception_handler, &exception);
1537 m.Return(string); 1525 m.Return(string);
1538 1526
1539 m.Bind(&exception_handler); 1527 m.Bind(&exception_handler);
1540 m.Return(exception.value()); 1528 m.Return(exception.value());
1541 1529
1542 Handle<Code> code = data.GenerateCode(); 1530 Handle<Code> code = m.GenerateCode();
1543 CHECK(!code.is_null()); 1531 CHECK(!code.is_null());
1544 1532
1545 FunctionTester ft(code, kNumParams); 1533 FunctionTester ft(code, kNumParams);
1546 Handle<Object> result = ft.Call().ToHandleChecked(); 1534 Handle<Object> result = ft.Call().ToHandleChecked();
1547 1535
1548 // Should be a TypeError. 1536 // Should be a TypeError
1549 CHECK(result->IsJSObject()); 1537 CHECK(result->IsJSObject());
1550 1538
1551 Handle<Object> constructor = 1539 Handle<Object> constructor =
1552 Object::GetPropertyOrElement(result, 1540 Object::GetPropertyOrElement(result,
1553 isolate->factory()->constructor_string()) 1541 isolate->factory()->constructor_string())
1554 .ToHandleChecked(); 1542 .ToHandleChecked();
1555 CHECK(constructor->SameValue(*isolate->type_error_function())); 1543 CHECK(constructor->SameValue(*isolate->type_error_function()));
1556 } 1544 }
1557 1545
1558 TEST(GotoIfExceptionMultiple) { 1546 TEST(GotoIfExceptionMultiple) {
1559 typedef CodeStubAssembler::Label Label; 1547 typedef CodeStubAssembler::Label Label;
1560 typedef CodeStubAssembler::Variable Variable; 1548 typedef CodeStubAssembler::Variable Variable;
1561 Isolate* isolate(CcTest::InitIsolateOnce()); 1549 Isolate* isolate(CcTest::InitIsolateOnce());
1562 1550
1563 const int kNumParams = 4; // receiver, first, second, third 1551 const int kNumParams = 4; // receiver, first, second, third
1564 CodeAssemblerTester data(isolate, kNumParams); 1552 // Emulate TFJ builtin
1565 CodeStubAssembler m(data.state()); 1553 CodeStubAssemblerTester m(isolate, kNumParams, Code::BUILTIN);
1566 1554
1567 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); 1555 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1568 Node* first_value = m.Parameter(0); 1556 Node* first_value = m.Parameter(0);
1569 Node* second_value = m.Parameter(1); 1557 Node* second_value = m.Parameter(1);
1570 Node* third_value = m.Parameter(2); 1558 Node* third_value = m.Parameter(2);
1571 1559
1572 Label exception_handler1(&m); 1560 Label exception_handler1(&m);
1573 Label exception_handler2(&m); 1561 Label exception_handler2(&m);
1574 Label exception_handler3(&m); 1562 Label exception_handler3(&m);
1575 Variable return_value(&m, MachineRepresentation::kWord32); 1563 Variable return_value(&m, MachineRepresentation::kWord32);
(...skipping 21 matching lines...) Expand all
1597 error.Bind(m.UndefinedConstant()); 1585 error.Bind(m.UndefinedConstant());
1598 string = m.CallStub(to_string, context, third_value); 1586 string = m.CallStub(to_string, context, third_value);
1599 m.GotoIfException(string, &exception_handler3, &error); 1587 m.GotoIfException(string, &exception_handler3, &error);
1600 m.Return(m.SmiFromWord32( 1588 m.Return(m.SmiFromWord32(
1601 m.Word32And(return_value.value(), 1589 m.Word32And(return_value.value(),
1602 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1))))); 1590 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1)))));
1603 1591
1604 m.Bind(&exception_handler3); 1592 m.Bind(&exception_handler3);
1605 m.Return(error.value()); 1593 m.Return(error.value());
1606 1594
1607 Handle<Code> code = data.GenerateCode(); 1595 Handle<Code> code = m.GenerateCode();
1608 CHECK(!code.is_null()); 1596 CHECK(!code.is_null());
1609 1597
1610 FunctionTester ft(code, kNumParams); 1598 FunctionTester ft(code, kNumParams);
1611 1599
1612 Handle<Object> result; 1600 Handle<Object> result;
1613 // First handler does not throw, returns result of first value. 1601 // First handler does not throw, returns result of first value
1614 result = ft.Call(isolate->factory()->undefined_value(), 1602 result = ft.Call(isolate->factory()->undefined_value(),
1615 isolate->factory()->to_string_tag_symbol()) 1603 isolate->factory()->to_string_tag_symbol())
1616 .ToHandleChecked(); 1604 .ToHandleChecked();
1617 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined"))); 1605 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined")));
1618 1606
1619 // First handler returns a number. 1607 // First handler returns a number
1620 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1608 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1621 isolate->factory()->undefined_value()) 1609 isolate->factory()->undefined_value())
1622 .ToHandleChecked(); 1610 .ToHandleChecked();
1623 CHECK_EQ(7, Smi::cast(*result)->value()); 1611 CHECK_EQ(7, Smi::cast(*result)->value());
1624 1612
1625 // First handler throws, second handler returns a number. 1613 // First handler throws, second handler returns a number
1626 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1614 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1627 isolate->factory()->to_primitive_symbol()) 1615 isolate->factory()->to_primitive_symbol())
1628 .ToHandleChecked(); 1616 .ToHandleChecked();
1629 CHECK_EQ(7 & ~2, Smi::cast(*result)->value()); 1617 CHECK_EQ(7 & ~2, Smi::cast(*result)->value());
1630 1618
1631 // First handler throws, second handler throws, third handler returns thrown 1619 // First handler throws, second handler throws, third handler returns thrown
1632 // value. 1620 // value.
1633 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1621 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1634 isolate->factory()->to_primitive_symbol(), 1622 isolate->factory()->to_primitive_symbol(),
1635 isolate->factory()->unscopables_symbol()) 1623 isolate->factory()->unscopables_symbol())
1636 .ToHandleChecked(); 1624 .ToHandleChecked();
1637 1625
1638 // Should be a TypeError. 1626 // Should be a TypeError
1639 CHECK(result->IsJSObject()); 1627 CHECK(result->IsJSObject());
1640 1628
1641 Handle<Object> constructor = 1629 Handle<Object> constructor =
1642 Object::GetPropertyOrElement(result, 1630 Object::GetPropertyOrElement(result,
1643 isolate->factory()->constructor_string()) 1631 isolate->factory()->constructor_string())
1644 .ToHandleChecked(); 1632 .ToHandleChecked();
1645 CHECK(constructor->SameValue(*isolate->type_error_function())); 1633 CHECK(constructor->SameValue(*isolate->type_error_function()));
1646 } 1634 }
1647 1635
1648 TEST(AllocateJSObjectFromMap) { 1636 TEST(AllocateJSObjectFromMap) {
1649 Isolate* isolate(CcTest::InitIsolateOnce()); 1637 Isolate* isolate(CcTest::InitIsolateOnce());
1650 Factory* factory = isolate->factory(); 1638 Factory* factory = isolate->factory();
1651 1639
1652 const int kNumParams = 3; 1640 const int kNumParams = 3;
1653 CodeAssemblerTester data(isolate, kNumParams); 1641 CodeStubAssemblerTester m(isolate, kNumParams);
1654 CodeStubAssembler m(data.state());
1655 1642
1656 { 1643 {
1657 Node* map = m.Parameter(0); 1644 Node* map = m.Parameter(0);
1658 Node* properties = m.Parameter(1); 1645 Node* properties = m.Parameter(1);
1659 Node* elements = m.Parameter(2); 1646 Node* elements = m.Parameter(2);
1660 1647
1661 Node* result = m.AllocateJSObjectFromMap(map, properties, elements); 1648 Node* result = m.AllocateJSObjectFromMap(map, properties, elements);
1662 1649
1663 m.Return(result); 1650 m.Return(result);
1664 } 1651 }
1665 1652
1666 Handle<Code> code = data.GenerateCode(); 1653 Handle<Code> code = m.GenerateCode();
1667 FunctionTester ft(code, kNumParams); 1654 FunctionTester ft(code, kNumParams);
1668 1655
1669 Handle<Map> maps[] = { 1656 Handle<Map> maps[] = {
1670 handle(isolate->object_function()->initial_map(), isolate), 1657 handle(isolate->object_function()->initial_map(), isolate),
1671 handle(isolate->array_function()->initial_map(), isolate), 1658 handle(isolate->array_function()->initial_map(), isolate),
1672 }; 1659 };
1673 1660
1674 #define VERIFY(result, map_value, properties_value, elements_value) \ 1661 #define VERIFY(result, map_value, properties_value, elements_value) \
1675 CHECK_EQ(result->map(), map_value); \ 1662 CHECK_EQ(result->map(), map_value); \
1676 CHECK_EQ(result->properties(), properties_value); \ 1663 CHECK_EQ(result->properties(), properties_value); \
(...skipping 30 matching lines...) Expand all
1707 isolate->heap()->Verify(); 1694 isolate->heap()->Verify();
1708 #endif 1695 #endif
1709 } 1696 }
1710 #undef VERIFY 1697 #undef VERIFY
1711 } 1698 }
1712 1699
1713 TEST(AllocateNameDictionary) { 1700 TEST(AllocateNameDictionary) {
1714 Isolate* isolate(CcTest::InitIsolateOnce()); 1701 Isolate* isolate(CcTest::InitIsolateOnce());
1715 1702
1716 const int kNumParams = 1; 1703 const int kNumParams = 1;
1717 CodeAssemblerTester data(isolate, kNumParams); 1704 CodeStubAssemblerTester m(isolate, kNumParams);
1718 CodeStubAssembler m(data.state());
1719 1705
1720 { 1706 {
1721 Node* capacity = m.Parameter(0); 1707 Node* capacity = m.Parameter(0);
1722 Node* result = m.AllocateNameDictionary(m.SmiUntag(capacity)); 1708 Node* result = m.AllocateNameDictionary(m.SmiUntag(capacity));
1723 m.Return(result); 1709 m.Return(result);
1724 } 1710 }
1725 1711
1726 Handle<Code> code = data.GenerateCode(); 1712 Handle<Code> code = m.GenerateCode();
1727 FunctionTester ft(code, kNumParams); 1713 FunctionTester ft(code, kNumParams);
1728 1714
1729 { 1715 {
1730 for (int i = 0; i < 256; i = i * 1.1 + 1) { 1716 for (int i = 0; i < 256; i = i * 1.1 + 1) {
1731 Handle<Object> result = 1717 Handle<Object> result =
1732 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked(); 1718 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked();
1733 Handle<NameDictionary> dict = NameDictionary::New(isolate, i); 1719 Handle<NameDictionary> dict = NameDictionary::New(isolate, i);
1734 // Both dictionaries should be memory equal. 1720 // Both dictionaries should be memory equal.
1735 int size = 1721 int size =
1736 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize; 1722 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize;
1737 CHECK_EQ(0, memcmp(*dict, *result, size)); 1723 CHECK_EQ(0, memcmp(*dict, *result, size));
1738 } 1724 }
1739 } 1725 }
1740 } 1726 }
1741 1727
1742 TEST(PopAndReturnConstant) { 1728 TEST(PopAndReturnConstant) {
1743 Isolate* isolate(CcTest::InitIsolateOnce()); 1729 Isolate* isolate(CcTest::InitIsolateOnce());
1744 1730
1745 const int kNumParams = 4; 1731 const int kNumParams = 4;
1746 const int kNumProgrammaticParams = 2; 1732 const int kNumProgramaticParams = 2;
1747 CodeAssemblerTester data(isolate, kNumParams - kNumProgrammaticParams); 1733 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams);
1748 CodeStubAssembler m(data.state());
1749 1734
1750 // Call a function that return |kNumProgramaticParams| parameters in addition 1735 // Call a function that return |kNumProgramaticParams| parameters in addition
1751 // to those specified by the static descriptor. |kNumProgramaticParams| is 1736 // to those specified by the static descriptor. |kNumProgramaticParams| is
1752 // specified as a constant. 1737 // specified as a constant.
1753 m.PopAndReturn(m.Int32Constant(kNumProgrammaticParams), 1738 m.PopAndReturn(m.Int32Constant(kNumProgramaticParams),
1754 m.SmiConstant(Smi::FromInt(1234))); 1739 m.SmiConstant(Smi::FromInt(1234)));
1755 1740
1756 Handle<Code> code = data.GenerateCode(); 1741 Handle<Code> code = m.GenerateCode();
1757 CHECK(!code.is_null()); 1742 CHECK(!code.is_null());
1758 1743
1759 FunctionTester ft(code, kNumParams); 1744 FunctionTester ft(code, kNumParams);
1760 Handle<Object> result; 1745 Handle<Object> result;
1761 for (int test_count = 0; test_count < 100; ++test_count) { 1746 for (int test_count = 0; test_count < 100; ++test_count) {
1762 result = ft.Call(isolate->factory()->undefined_value(), 1747 result = ft.Call(isolate->factory()->undefined_value(),
1763 Handle<Smi>(Smi::FromInt(1234), isolate), 1748 Handle<Smi>(Smi::FromInt(1234), isolate),
1764 isolate->factory()->undefined_value(), 1749 isolate->factory()->undefined_value(),
1765 isolate->factory()->undefined_value()) 1750 isolate->factory()->undefined_value())
1766 .ToHandleChecked(); 1751 .ToHandleChecked();
1767 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); 1752 CHECK_EQ(1234, Handle<Smi>::cast(result)->value());
1768 } 1753 }
1769 } 1754 }
1770 1755
1771 TEST(PopAndReturnVariable) { 1756 TEST(PopAndReturnVariable) {
1772 Isolate* isolate(CcTest::InitIsolateOnce()); 1757 Isolate* isolate(CcTest::InitIsolateOnce());
1773 1758
1774 const int kNumParams = 4; 1759 const int kNumParams = 4;
1775 const int kNumProgrammaticParams = 2; 1760 const int kNumProgramaticParams = 2;
1776 CodeAssemblerTester data(isolate, kNumParams - kNumProgrammaticParams); 1761 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams);
1777 CodeStubAssembler m(data.state());
1778 1762
1779 // Call a function that return |kNumProgramaticParams| parameters in addition 1763 // Call a function that return |kNumProgramaticParams| parameters in addition
1780 // to those specified by the static descriptor. |kNumProgramaticParams| is 1764 // to those specified by the static descriptor. |kNumProgramaticParams| is
1781 // passed in as a parameter to the function so that it can't be recongized as 1765 // passed in as a parameter to the function so that it can't be recongized as
1782 // a constant. 1766 // a constant.
1783 m.PopAndReturn(m.SmiUntag(m.Parameter(1)), m.SmiConstant(Smi::FromInt(1234))); 1767 m.PopAndReturn(m.SmiUntag(m.Parameter(1)), m.SmiConstant(Smi::FromInt(1234)));
1784 1768
1785 Handle<Code> code = data.GenerateCode(); 1769 Handle<Code> code = m.GenerateCode();
1786 CHECK(!code.is_null()); 1770 CHECK(!code.is_null());
1787 1771
1788 FunctionTester ft(code, kNumParams); 1772 FunctionTester ft(code, kNumParams);
1789 Handle<Object> result; 1773 Handle<Object> result;
1790 for (int test_count = 0; test_count < 100; ++test_count) { 1774 for (int test_count = 0; test_count < 100; ++test_count) {
1791 result = ft.Call(isolate->factory()->undefined_value(), 1775 result = ft.Call(isolate->factory()->undefined_value(),
1792 Handle<Smi>(Smi::FromInt(1234), isolate), 1776 Handle<Smi>(Smi::FromInt(1234), isolate),
1793 isolate->factory()->undefined_value(), 1777 isolate->factory()->undefined_value(),
1794 Handle<Smi>(Smi::FromInt(kNumProgrammaticParams), isolate)) 1778 Handle<Smi>(Smi::FromInt(kNumProgramaticParams), isolate))
1795 .ToHandleChecked(); 1779 .ToHandleChecked();
1796 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); 1780 CHECK_EQ(1234, Handle<Smi>::cast(result)->value());
1797 } 1781 }
1798 } 1782 }
1799 1783
1800 TEST(OneToTwoByteStringCopy) { 1784 TEST(OneToTwoByteStringCopy) {
1801 Isolate* isolate(CcTest::InitIsolateOnce()); 1785 Isolate* isolate(CcTest::InitIsolateOnce());
1802 1786
1803 const int kNumParams = 2; 1787 CodeStubAssemblerTester m(isolate, 2);
1804 CodeAssemblerTester data(isolate, kNumParams);
1805 CodeStubAssembler m(data.state());
1806 1788
1807 m.CopyStringCharacters( 1789 m.CopyStringCharacters(
1808 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1790 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1809 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1791 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1810 String::ONE_BYTE_ENCODING, String::TWO_BYTE_ENCODING, 1792 String::ONE_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
1811 CodeStubAssembler::SMI_PARAMETERS); 1793 CodeStubAssembler::SMI_PARAMETERS);
1812 m.Return(m.SmiConstant(Smi::FromInt(0))); 1794 m.Return(m.SmiConstant(Smi::FromInt(0)));
1813 1795
1814 Handle<Code> code = data.GenerateCode(); 1796 Handle<Code> code = m.GenerateCode();
1815 CHECK(!code.is_null()); 1797 CHECK(!code.is_null());
1816 1798
1817 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1799 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1818 uc16 array[] = {1000, 1001, 1002, 1003, 1004}; 1800 uc16 array[] = {1000, 1001, 1002, 1003, 1004};
1819 Vector<const uc16> str(array); 1801 Vector<const uc16> str(array);
1820 Handle<String> string2 = 1802 Handle<String> string2 =
1821 isolate->factory()->NewStringFromTwoByte(str).ToHandleChecked(); 1803 isolate->factory()->NewStringFromTwoByte(str).ToHandleChecked();
1822 FunctionTester ft(code, 2); 1804 FunctionTester ft(code, 2);
1823 ft.Call(string1, string2); 1805 ft.Call(string1, string2);
1824 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1806 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1825 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]); 1807 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
1826 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1808 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1827 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1809 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1828 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2], 1810 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
1829 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1811 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1830 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3], 1812 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
1831 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1813 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1832 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4], 1814 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
1833 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1815 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1834 } 1816 }
1835 1817
1836 TEST(OneToOneByteStringCopy) { 1818 TEST(OneToOneByteStringCopy) {
1837 Isolate* isolate(CcTest::InitIsolateOnce()); 1819 Isolate* isolate(CcTest::InitIsolateOnce());
1838 1820
1839 const int kNumParams = 2; 1821 CodeStubAssemblerTester m(isolate, 2);
1840 CodeAssemblerTester data(isolate, kNumParams);
1841 CodeStubAssembler m(data.state());
1842 1822
1843 m.CopyStringCharacters( 1823 m.CopyStringCharacters(
1844 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1824 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1845 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1825 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1846 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING, 1826 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
1847 CodeStubAssembler::SMI_PARAMETERS); 1827 CodeStubAssembler::SMI_PARAMETERS);
1848 m.Return(m.SmiConstant(Smi::FromInt(0))); 1828 m.Return(m.SmiConstant(Smi::FromInt(0)));
1849 1829
1850 Handle<Code> code = data.GenerateCode(); 1830 Handle<Code> code = m.GenerateCode();
1851 CHECK(!code.is_null()); 1831 CHECK(!code.is_null());
1852 1832
1853 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1833 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1854 uint8_t array[] = {100, 101, 102, 103, 104}; 1834 uint8_t array[] = {100, 101, 102, 103, 104};
1855 Vector<const uint8_t> str(array); 1835 Vector<const uint8_t> str(array);
1856 Handle<String> string2 = 1836 Handle<String> string2 =
1857 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked(); 1837 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
1858 FunctionTester ft(code, 2); 1838 FunctionTester ft(code, 2);
1859 ft.Call(string1, string2); 1839 ft.Call(string1, string2);
1860 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1840 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1861 Handle<SeqOneByteString>::cast(string2)->GetChars()[0]); 1841 Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
1862 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1842 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1863 Handle<SeqOneByteString>::cast(string2)->GetChars()[1]); 1843 Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
1864 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2], 1844 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
1865 Handle<SeqOneByteString>::cast(string2)->GetChars()[2]); 1845 Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
1866 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3], 1846 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
1867 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]); 1847 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
1868 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4], 1848 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
1869 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]); 1849 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
1870 } 1850 }
1871 1851
1872 TEST(OneToOneByteStringCopyNonZeroStart) { 1852 TEST(OneToOneByteStringCopyNonZeroStart) {
1873 Isolate* isolate(CcTest::InitIsolateOnce()); 1853 Isolate* isolate(CcTest::InitIsolateOnce());
1874 1854
1875 const int kNumParams = 2; 1855 CodeStubAssemblerTester m(isolate, 2);
1876 CodeAssemblerTester data(isolate, kNumParams);
1877 CodeStubAssembler m(data.state());
1878 1856
1879 m.CopyStringCharacters( 1857 m.CopyStringCharacters(
1880 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1858 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1881 m.SmiConstant(Smi::FromInt(3)), m.SmiConstant(Smi::FromInt(2)), 1859 m.SmiConstant(Smi::FromInt(3)), m.SmiConstant(Smi::FromInt(2)),
1882 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING, 1860 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
1883 CodeStubAssembler::SMI_PARAMETERS); 1861 CodeStubAssembler::SMI_PARAMETERS);
1884 m.Return(m.SmiConstant(Smi::FromInt(0))); 1862 m.Return(m.SmiConstant(Smi::FromInt(0)));
1885 1863
1886 Handle<Code> code = data.GenerateCode(); 1864 Handle<Code> code = m.GenerateCode();
1887 CHECK(!code.is_null()); 1865 CHECK(!code.is_null());
1888 1866
1889 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1867 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1890 uint8_t array[] = {100, 101, 102, 103, 104}; 1868 uint8_t array[] = {100, 101, 102, 103, 104};
1891 Vector<const uint8_t> str(array); 1869 Vector<const uint8_t> str(array);
1892 Handle<String> string2 = 1870 Handle<String> string2 =
1893 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked(); 1871 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
1894 FunctionTester ft(code, 2); 1872 FunctionTester ft(code, 2);
1895 ft.Call(string1, string2); 1873 ft.Call(string1, string2);
1896 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1874 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1897 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]); 1875 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
1898 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1876 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1899 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]); 1877 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
1900 CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]); 1878 CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
1901 CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]); 1879 CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
1902 CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]); 1880 CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
1903 } 1881 }
1904 1882
1905 TEST(TwoToTwoByteStringCopy) { 1883 TEST(TwoToTwoByteStringCopy) {
1906 Isolate* isolate(CcTest::InitIsolateOnce()); 1884 Isolate* isolate(CcTest::InitIsolateOnce());
1907 1885
1908 const int kNumParams = 2; 1886 CodeStubAssemblerTester m(isolate, 2);
1909 CodeAssemblerTester data(isolate, kNumParams);
1910 CodeStubAssembler m(data.state());
1911 1887
1912 m.CopyStringCharacters( 1888 m.CopyStringCharacters(
1913 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1889 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1914 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1890 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1915 String::TWO_BYTE_ENCODING, String::TWO_BYTE_ENCODING, 1891 String::TWO_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
1916 CodeStubAssembler::SMI_PARAMETERS); 1892 CodeStubAssembler::SMI_PARAMETERS);
1917 m.Return(m.SmiConstant(Smi::FromInt(0))); 1893 m.Return(m.SmiConstant(Smi::FromInt(0)));
1918 1894
1919 Handle<Code> code = data.GenerateCode(); 1895 Handle<Code> code = m.GenerateCode();
1920 CHECK(!code.is_null()); 1896 CHECK(!code.is_null());
1921 1897
1922 uc16 array1[] = {2000, 2001, 2002, 2003, 2004}; 1898 uc16 array1[] = {2000, 2001, 2002, 2003, 2004};
1923 Vector<const uc16> str1(array1); 1899 Vector<const uc16> str1(array1);
1924 Handle<String> string1 = 1900 Handle<String> string1 =
1925 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked(); 1901 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked();
1926 uc16 array2[] = {1000, 1001, 1002, 1003, 1004}; 1902 uc16 array2[] = {1000, 1001, 1002, 1003, 1004};
1927 Vector<const uc16> str2(array2); 1903 Vector<const uc16> str2(array2);
1928 Handle<String> string2 = 1904 Handle<String> string2 =
1929 isolate->factory()->NewStringFromTwoByte(str2).ToHandleChecked(); 1905 isolate->factory()->NewStringFromTwoByte(str2).ToHandleChecked();
1930 FunctionTester ft(code, 2); 1906 FunctionTester ft(code, 2);
1931 ft.Call(string1, string2); 1907 ft.Call(string1, string2);
1932 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0], 1908 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0],
1933 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]); 1909 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
1934 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1], 1910 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
1935 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1911 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1936 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2], 1912 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
1937 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1913 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1938 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3], 1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
1939 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1940 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4], 1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
1941 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1942 } 1918 }
1943 1919
1944 TEST(Arguments) { 1920 TEST(Arguments) {
1945 Isolate* isolate(CcTest::InitIsolateOnce()); 1921 Isolate* isolate(CcTest::InitIsolateOnce());
1946 1922
1947 const int kNumParams = 4; 1923 const int kNumParams = 4;
1948 CodeAssemblerTester data(isolate, kNumParams); 1924 CodeStubAssemblerTester m(isolate, kNumParams);
1949 CodeStubAssembler m(data.state());
1950 1925
1951 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1926 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1952 1927
1953 CSA_ASSERT( 1928 CSA_ASSERT(
1954 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12)))); 1929 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12))));
1955 CSA_ASSERT( 1930 CSA_ASSERT(
1956 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13)))); 1931 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13))));
1957 CSA_ASSERT( 1932 CSA_ASSERT(
1958 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14)))); 1933 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14))));
1959 1934
1960 m.Return(arguments.GetReceiver()); 1935 m.Return(arguments.GetReceiver());
1961 1936
1962 Handle<Code> code = data.GenerateCode(); 1937 Handle<Code> code = m.GenerateCode();
1963 CHECK(!code.is_null()); 1938 CHECK(!code.is_null());
1964 1939
1965 FunctionTester ft(code, kNumParams); 1940 FunctionTester ft(code, kNumParams);
1966 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1941 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1967 Handle<Smi>(Smi::FromInt(12), isolate), 1942 Handle<Smi>(Smi::FromInt(12), isolate),
1968 Handle<Smi>(Smi::FromInt(13), isolate), 1943 Handle<Smi>(Smi::FromInt(13), isolate),
1969 Handle<Smi>(Smi::FromInt(14), isolate)) 1944 Handle<Smi>(Smi::FromInt(14), isolate))
1970 .ToHandleChecked(); 1945 .ToHandleChecked();
1971 CHECK_EQ(*isolate->factory()->undefined_value(), *result); 1946 CHECK_EQ(*isolate->factory()->undefined_value(), *result);
1972 } 1947 }
1973 1948
1974 TEST(ArgumentsForEach) { 1949 TEST(ArgumentsForEach) {
1975 Isolate* isolate(CcTest::InitIsolateOnce()); 1950 Isolate* isolate(CcTest::InitIsolateOnce());
1976 1951
1977 const int kNumParams = 4; 1952 const int kNumParams = 4;
1978 CodeAssemblerTester data(isolate, kNumParams); 1953 CodeStubAssemblerTester m(isolate, kNumParams);
1979 CodeStubAssembler m(data.state());
1980 1954
1981 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1955 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1982 1956
1983 CodeStubAssembler::Variable sum(&m, MachineType::PointerRepresentation()); 1957 CodeStubAssemblerTester::Variable sum(&m,
1984 CodeStubAssembler::VariableList list({&sum}, m.zone()); 1958 MachineType::PointerRepresentation());
1959 CodeStubAssemblerTester::VariableList list({&sum}, m.zone());
1985 1960
1986 sum.Bind(m.IntPtrConstant(0)); 1961 sum.Bind(m.IntPtrConstant(0));
1987 1962
1988 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) { 1963 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) {
1989 sum.Bind(assembler->IntPtrAdd(sum.value(), arg)); 1964 sum.Bind(assembler->IntPtrAdd(sum.value(), arg));
1990 }); 1965 });
1991 1966
1992 m.Return(sum.value()); 1967 m.Return(sum.value());
1993 1968
1994 Handle<Code> code = data.GenerateCode(); 1969 Handle<Code> code = m.GenerateCode();
1995 CHECK(!code.is_null()); 1970 CHECK(!code.is_null());
1996 1971
1997 FunctionTester ft(code, kNumParams); 1972 FunctionTester ft(code, kNumParams);
1998 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1973 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1999 Handle<Smi>(Smi::FromInt(12), isolate), 1974 Handle<Smi>(Smi::FromInt(12), isolate),
2000 Handle<Smi>(Smi::FromInt(13), isolate), 1975 Handle<Smi>(Smi::FromInt(13), isolate),
2001 Handle<Smi>(Smi::FromInt(14), isolate)) 1976 Handle<Smi>(Smi::FromInt(14), isolate))
2002 .ToHandleChecked(); 1977 .ToHandleChecked();
2003 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result); 1978 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
2004 } 1979 }
2005 1980
2006 } // namespace internal 1981 } // namespace internal
2007 } // namespace v8 1982 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-code-assembler.cc ('k') | test/unittests/interpreter/interpreter-assembler-unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698