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 |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "vm/compiler/assembler/assembler.h" |
6 | #include "vm/globals.h" |
7 | #include "vm/os.h" |
8 | #include "vm/simulator.h" |
9 | #include "vm/unit_test.h" |
10 | #include "vm/virtual_memory.h" |
11 | |
12 | namespace dart { |
13 | |
14 | namespace compiler { |
15 | ASSEMBLER_TEST_EXTERN(StoreIntoObject); |
16 | } // namespace compiler |
17 | |
18 | ASSEMBLER_TEST_RUN(StoreIntoObject, test) { |
19 | #define TEST_CODE(value, growable_array, thread) \ |
20 | test->Invoke<void, ObjectPtr, ObjectPtr, Thread*>(value, growable_array, \ |
21 | thread) |
22 | |
23 | const Array& old_array = Array::Handle(Array::New(3, Heap::kOld)); |
24 | const Array& new_array = Array::Handle(Array::New(3, Heap::kNew)); |
25 | const GrowableObjectArray& grow_old_array = GrowableObjectArray::Handle( |
26 | GrowableObjectArray::New(old_array, Heap::kOld)); |
27 | const GrowableObjectArray& grow_new_array = GrowableObjectArray::Handle( |
28 | GrowableObjectArray::New(old_array, Heap::kNew)); |
29 | Smi& smi = Smi::Handle(); |
30 | Thread* thread = Thread::Current(); |
31 | |
32 | EXPECT(old_array.raw() == grow_old_array.data()); |
33 | EXPECT(!thread->StoreBufferContains(grow_old_array.raw())); |
34 | EXPECT(old_array.raw() == grow_new_array.data()); |
35 | EXPECT(!thread->StoreBufferContains(grow_new_array.raw())); |
36 | |
37 | // Store Smis into the old object. |
38 | for (int i = -128; i < 128; i++) { |
39 | smi = Smi::New(i); |
40 | TEST_CODE(smi.raw(), grow_old_array.raw(), thread); |
41 | EXPECT(static_cast<ArrayPtr>(smi.raw()) == grow_old_array.data()); |
42 | EXPECT(!thread->StoreBufferContains(grow_old_array.raw())); |
43 | } |
44 | |
45 | // Store an old object into the old object. |
46 | TEST_CODE(old_array.raw(), grow_old_array.raw(), thread); |
47 | EXPECT(old_array.raw() == grow_old_array.data()); |
48 | EXPECT(!thread->StoreBufferContains(grow_old_array.raw())); |
49 | |
50 | // Store a new object into the old object. |
51 | TEST_CODE(new_array.raw(), grow_old_array.raw(), thread); |
52 | EXPECT(new_array.raw() == grow_old_array.data()); |
53 | EXPECT(thread->StoreBufferContains(grow_old_array.raw())); |
54 | |
55 | // Store a new object into the new object. |
56 | TEST_CODE(new_array.raw(), grow_new_array.raw(), thread); |
57 | EXPECT(new_array.raw() == grow_new_array.data()); |
58 | EXPECT(!thread->StoreBufferContains(grow_new_array.raw())); |
59 | |
60 | // Store an old object into the new object. |
61 | TEST_CODE(old_array.raw(), grow_new_array.raw(), thread); |
62 | EXPECT(old_array.raw() == grow_new_array.data()); |
63 | EXPECT(!thread->StoreBufferContains(grow_new_array.raw())); |
64 | } |
65 | |
66 | } // namespace dart |
67 | |