OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/assembler.h" | 5 #include "vm/assembler.h" |
6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
7 #include "vm/os.h" | 7 #include "vm/os.h" |
8 #include "vm/simulator.h" | 8 #include "vm/simulator.h" |
9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
10 #include "vm/virtual_memory.h" | 10 #include "vm/virtual_memory.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 ASSEMBLER_TEST_EXTERN(StoreIntoObject); | 14 ASSEMBLER_TEST_EXTERN(StoreIntoObject); |
15 | 15 |
16 ASSEMBLER_TEST_RUN(StoreIntoObject, test) { | 16 ASSEMBLER_TEST_RUN(StoreIntoObject, test) { |
17 #if defined(USING_SIMULATOR) | 17 #if defined(USING_SIMULATOR) |
18 #define test_code(ctx, value, growable_array) \ | 18 #define test_code(ctx, value, growable_array, thread) \ |
19 Simulator::Current()->Call( \ | 19 Simulator::Current()->Call( \ |
20 bit_cast<intptr_t, uword>(test->entry()), \ | 20 bit_cast<intptr_t, uword>(test->entry()), \ |
21 reinterpret_cast<intptr_t>(ctx), \ | 21 reinterpret_cast<intptr_t>(ctx), \ |
22 reinterpret_cast<intptr_t>(value), \ | 22 reinterpret_cast<intptr_t>(value), \ |
23 reinterpret_cast<intptr_t>(growable_array), \ | 23 reinterpret_cast<intptr_t>(growable_array), \ |
24 0) | 24 reinterpret_cast<intptr_t>(thread)) |
25 #else | 25 #else |
26 typedef void (*StoreData)(RawContext* ctx, | 26 typedef void (*StoreData)(RawContext* ctx, |
27 RawObject* value, | 27 RawObject* value, |
28 RawObject* growable_array); | 28 RawObject* growable_array, |
| 29 Thread* thread); |
29 StoreData test_code = reinterpret_cast<StoreData>(test->entry()); | 30 StoreData test_code = reinterpret_cast<StoreData>(test->entry()); |
30 #endif | 31 #endif |
31 | 32 |
32 const Array& old_array = Array::Handle(Array::New(3, Heap::kOld)); | 33 const Array& old_array = Array::Handle(Array::New(3, Heap::kOld)); |
33 const Array& new_array = Array::Handle(Array::New(3, Heap::kNew)); | 34 const Array& new_array = Array::Handle(Array::New(3, Heap::kNew)); |
34 const GrowableObjectArray& grow_old_array = GrowableObjectArray::Handle( | 35 const GrowableObjectArray& grow_old_array = GrowableObjectArray::Handle( |
35 GrowableObjectArray::New(old_array, Heap::kOld)); | 36 GrowableObjectArray::New(old_array, Heap::kOld)); |
36 const GrowableObjectArray& grow_new_array = GrowableObjectArray::Handle( | 37 const GrowableObjectArray& grow_new_array = GrowableObjectArray::Handle( |
37 GrowableObjectArray::New(old_array, Heap::kNew)); | 38 GrowableObjectArray::New(old_array, Heap::kNew)); |
38 Smi& smi = Smi::Handle(); | 39 Smi& smi = Smi::Handle(); |
39 const Context& ctx = Context::Handle(Context::New(0)); | 40 const Context& ctx = Context::Handle(Context::New(0)); |
| 41 Thread* thread = Thread::Current(); |
40 | 42 |
41 EXPECT(old_array.raw() == grow_old_array.data()); | 43 EXPECT(old_array.raw() == grow_old_array.data()); |
42 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); | 44 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); |
43 EXPECT(old_array.raw() == grow_new_array.data()); | 45 EXPECT(old_array.raw() == grow_new_array.data()); |
44 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); | 46 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); |
45 | 47 |
46 // Store Smis into the old object. | 48 // Store Smis into the old object. |
47 for (int i = -128; i < 128; i++) { | 49 for (int i = -128; i < 128; i++) { |
48 smi = Smi::New(i); | 50 smi = Smi::New(i); |
49 test_code(ctx.raw(), smi.raw(), grow_old_array.raw()); | 51 test_code(ctx.raw(), smi.raw(), grow_old_array.raw(), thread); |
50 EXPECT(reinterpret_cast<RawArray*>(smi.raw()) == grow_old_array.data()); | 52 EXPECT(reinterpret_cast<RawArray*>(smi.raw()) == grow_old_array.data()); |
51 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); | 53 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); |
52 } | 54 } |
53 | 55 |
54 // Store an old object into the old object. | 56 // Store an old object into the old object. |
55 test_code(ctx.raw(), old_array.raw(), grow_old_array.raw()); | 57 test_code(ctx.raw(), old_array.raw(), grow_old_array.raw(), thread); |
56 EXPECT(old_array.raw() == grow_old_array.data()); | 58 EXPECT(old_array.raw() == grow_old_array.data()); |
57 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); | 59 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); |
58 | 60 |
59 // Store a new object into the old object. | 61 // Store a new object into the old object. |
60 test_code(ctx.raw(), new_array.raw(), grow_old_array.raw()); | 62 test_code(ctx.raw(), new_array.raw(), grow_old_array.raw(), thread); |
61 EXPECT(new_array.raw() == grow_old_array.data()); | 63 EXPECT(new_array.raw() == grow_old_array.data()); |
62 EXPECT(Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); | 64 EXPECT(Isolate::Current()->store_buffer()->Contains(grow_old_array.raw())); |
63 | 65 |
64 // Store a new object into the new object. | 66 // Store a new object into the new object. |
65 test_code(ctx.raw(), new_array.raw(), grow_new_array.raw()); | 67 test_code(ctx.raw(), new_array.raw(), grow_new_array.raw(), thread); |
66 EXPECT(new_array.raw() == grow_new_array.data()); | 68 EXPECT(new_array.raw() == grow_new_array.data()); |
67 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); | 69 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); |
68 | 70 |
69 // Store an old object into the new object. | 71 // Store an old object into the new object. |
70 test_code(ctx.raw(), old_array.raw(), grow_new_array.raw()); | 72 test_code(ctx.raw(), old_array.raw(), grow_new_array.raw(), thread); |
71 EXPECT(old_array.raw() == grow_new_array.data()); | 73 EXPECT(old_array.raw() == grow_new_array.data()); |
72 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); | 74 EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw())); |
73 } | 75 } |
74 | 76 |
75 } // namespace dart | 77 } // namespace dart |
OLD | NEW |