OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/freelist.h" | 6 #include "vm/freelist.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 EXPECT_EQ(small_object4 + kSmallObjectSize, large_object); | 80 EXPECT_EQ(small_object4 + kSmallObjectSize, large_object); |
81 // Get another large object from the large unallocated remainder. | 81 // Get another large object from the large unallocated remainder. |
82 uword large_object2 = Allocate(free_list, kLargeObjectSize, is_protected); | 82 uword large_object2 = Allocate(free_list, kLargeObjectSize, is_protected); |
83 EXPECT_EQ(small_object3 + kSmallObjectSize, large_object2); | 83 EXPECT_EQ(small_object3 + kSmallObjectSize, large_object2); |
84 } | 84 } |
85 | 85 |
86 TEST_CASE(FreeList) { | 86 TEST_CASE(FreeList) { |
87 FreeList* free_list = new FreeList(); | 87 FreeList* free_list = new FreeList(); |
88 const intptr_t kBlobSize = 1 * MB; | 88 const intptr_t kBlobSize = 1 * MB; |
89 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); | 89 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); |
90 region->Commit(/* is_executable */ false); | 90 region->Commit(/* is_executable */ false, NULL); |
91 | 91 |
92 TestFreeList(region, free_list, false); | 92 TestFreeList(region, free_list, false); |
93 | 93 |
94 // Delete the memory associated with the test. | 94 // Delete the memory associated with the test. |
95 delete region; | 95 delete region; |
96 delete free_list; | 96 delete free_list; |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 TEST_CASE(FreeListProtected) { | 100 TEST_CASE(FreeListProtected) { |
101 FreeList* free_list = new FreeList(); | 101 FreeList* free_list = new FreeList(); |
102 const intptr_t kBlobSize = 1 * MB; | 102 const intptr_t kBlobSize = 1 * MB; |
103 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); | 103 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); |
104 region->Commit(/* is_executable */ false); | 104 region->Commit(/* is_executable */ false, NULL); |
105 | 105 |
106 TestFreeList(region, free_list, true); | 106 TestFreeList(region, free_list, true); |
107 | 107 |
108 // Delete the memory associated with the test. | 108 // Delete the memory associated with the test. |
109 delete region; | 109 delete region; |
110 delete free_list; | 110 delete free_list; |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 TEST_CASE(FreeListProtectedTinyObjects) { | 114 TEST_CASE(FreeListProtectedTinyObjects) { |
115 FreeList* free_list = new FreeList(); | 115 FreeList* free_list = new FreeList(); |
116 const intptr_t kBlobSize = 1 * MB; | 116 const intptr_t kBlobSize = 1 * MB; |
117 const intptr_t kObjectSize = 2 * kWordSize; | 117 const intptr_t kObjectSize = 2 * kWordSize; |
118 uword* objects = new uword[kBlobSize / kObjectSize]; | 118 uword* objects = new uword[kBlobSize / kObjectSize]; |
119 | 119 |
120 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); | 120 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); |
121 ASSERT(Utils::IsAligned(blob->start(), 4096)); | 121 ASSERT(Utils::IsAligned(blob->start(), 4096)); |
122 blob->Commit(/* is_executable = */ false); | 122 blob->Commit(/* is_executable = */ false, NULL); |
123 blob->Protect(VirtualMemory::kReadWrite); | 123 blob->Protect(VirtualMemory::kReadWrite); |
124 | 124 |
125 // Enqueue the large blob as one free block. | 125 // Enqueue the large blob as one free block. |
126 free_list->Free(blob->start(), blob->size()); | 126 free_list->Free(blob->start(), blob->size()); |
127 | 127 |
128 // Write protect the whole region. | 128 // Write protect the whole region. |
129 blob->Protect(VirtualMemory::kReadExecute); | 129 blob->Protect(VirtualMemory::kReadExecute); |
130 | 130 |
131 // Allocate small objects. | 131 // Allocate small objects. |
132 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) { | 132 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) { |
(...skipping 20 matching lines...) Expand all Loading... |
153 FreeList* free_list = new FreeList(); | 153 FreeList* free_list = new FreeList(); |
154 const intptr_t kBlobSize = 8 * KB; | 154 const intptr_t kBlobSize = 8 * KB; |
155 const intptr_t kMinSize = 2 * kWordSize; | 155 const intptr_t kMinSize = 2 * kWordSize; |
156 uword* objects = new uword[kBlobSize / kMinSize]; | 156 uword* objects = new uword[kBlobSize / kMinSize]; |
157 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) { | 157 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) { |
158 objects[i] = static_cast<uword>(NULL); | 158 objects[i] = static_cast<uword>(NULL); |
159 } | 159 } |
160 | 160 |
161 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); | 161 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); |
162 ASSERT(Utils::IsAligned(blob->start(), 4096)); | 162 ASSERT(Utils::IsAligned(blob->start(), 4096)); |
163 blob->Commit(/* is_executable = */ false); | 163 blob->Commit(/* is_executable = */ false, NULL); |
164 blob->Protect(VirtualMemory::kReadWrite); | 164 blob->Protect(VirtualMemory::kReadWrite); |
165 | 165 |
166 // Enqueue the large blob as one free block. | 166 // Enqueue the large blob as one free block. |
167 free_list->Free(blob->start(), blob->size()); | 167 free_list->Free(blob->start(), blob->size()); |
168 | 168 |
169 // Write protect the whole region. | 169 // Write protect the whole region. |
170 blob->Protect(VirtualMemory::kReadExecute); | 170 blob->Protect(VirtualMemory::kReadExecute); |
171 | 171 |
172 // Allocate and free objects so that free list has > 1 elements. | 172 // Allocate and free objects so that free list has > 1 elements. |
173 uword e0 = Allocate(free_list, 1 * KB, true); | 173 uword e0 = Allocate(free_list, 1 * KB, true); |
(...skipping 10 matching lines...) Expand all Loading... |
184 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); | 184 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); |
185 ASSERT(e0); | 185 ASSERT(e0); |
186 | 186 |
187 // Delete the memory associated with the test. | 187 // Delete the memory associated with the test. |
188 delete blob; | 188 delete blob; |
189 delete free_list; | 189 delete free_list; |
190 delete[] objects; | 190 delete[] objects; |
191 } | 191 } |
192 | 192 |
193 } // namespace dart | 193 } // namespace dart |
OLD | NEW |