| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 delete free_list; | 113 delete free_list; |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 TEST_CASE(FreeListProtectedTinyObjects) { | 117 TEST_CASE(FreeListProtectedTinyObjects) { |
| 118 FreeList* free_list = new FreeList(); | 118 FreeList* free_list = new FreeList(); |
| 119 const intptr_t kBlobSize = 1 * MB; | 119 const intptr_t kBlobSize = 1 * MB; |
| 120 const intptr_t kObjectSize = 2 * kWordSize; | 120 const intptr_t kObjectSize = 2 * kWordSize; |
| 121 uword* objects = new uword[kBlobSize / kObjectSize]; | 121 uword* objects = new uword[kBlobSize / kObjectSize]; |
| 122 | 122 |
| 123 VirtualMemory* blob = VirtualMemory::ReserveAligned(kBlobSize, 4096); | 123 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); |
| 124 ASSERT(Utils::IsAligned(blob->start(), 4096)); |
| 124 blob->Commit(/* is_executable = */ false); | 125 blob->Commit(/* is_executable = */ false); |
| 125 blob->Protect(VirtualMemory::kReadWrite); | 126 blob->Protect(VirtualMemory::kReadWrite); |
| 126 | 127 |
| 127 // Enqueue the large blob as one free block. | 128 // Enqueue the large blob as one free block. |
| 128 free_list->Free(blob->start(), blob->size()); | 129 free_list->Free(blob->start(), blob->size()); |
| 129 | 130 |
| 130 // Write protect the whole region. | 131 // Write protect the whole region. |
| 131 blob->Protect(VirtualMemory::kReadExecute); | 132 blob->Protect(VirtualMemory::kReadExecute); |
| 132 | 133 |
| 133 // Allocate small objects. | 134 // Allocate small objects. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 155 | 156 |
| 156 TEST_CASE(FreeListProtectedVariableSizeObjects) { | 157 TEST_CASE(FreeListProtectedVariableSizeObjects) { |
| 157 FreeList* free_list = new FreeList(); | 158 FreeList* free_list = new FreeList(); |
| 158 const intptr_t kBlobSize = 8 * KB; | 159 const intptr_t kBlobSize = 8 * KB; |
| 159 const intptr_t kMinSize = 2 * kWordSize; | 160 const intptr_t kMinSize = 2 * kWordSize; |
| 160 uword* objects = new uword[kBlobSize / kMinSize]; | 161 uword* objects = new uword[kBlobSize / kMinSize]; |
| 161 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) { | 162 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) { |
| 162 objects[i] = static_cast<uword>(NULL); | 163 objects[i] = static_cast<uword>(NULL); |
| 163 } | 164 } |
| 164 | 165 |
| 165 VirtualMemory* blob = VirtualMemory::ReserveAligned(kBlobSize, 4096); | 166 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); |
| 167 ASSERT(Utils::IsAligned(blob->start(), 4096)); |
| 166 blob->Commit(/* is_executable = */ false); | 168 blob->Commit(/* is_executable = */ false); |
| 167 blob->Protect(VirtualMemory::kReadWrite); | 169 blob->Protect(VirtualMemory::kReadWrite); |
| 168 | 170 |
| 169 // Enqueue the large blob as one free block. | 171 // Enqueue the large blob as one free block. |
| 170 free_list->Free(blob->start(), blob->size()); | 172 free_list->Free(blob->start(), blob->size()); |
| 171 | 173 |
| 172 // Write protect the whole region. | 174 // Write protect the whole region. |
| 173 blob->Protect(VirtualMemory::kReadExecute); | 175 blob->Protect(VirtualMemory::kReadExecute); |
| 174 | 176 |
| 175 // Allocate and free objects so that free list has > 1 elements. | 177 // Allocate and free objects so that free list has > 1 elements. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); | 189 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); |
| 188 ASSERT(e0); | 190 ASSERT(e0); |
| 189 | 191 |
| 190 // Delete the memory associated with the test. | 192 // Delete the memory associated with the test. |
| 191 delete blob; | 193 delete blob; |
| 192 delete free_list; | 194 delete free_list; |
| 193 delete[] objects; | 195 delete[] objects; |
| 194 } | 196 } |
| 195 | 197 |
| 196 } // namespace dart | 198 } // namespace dart |
| OLD | NEW |