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

Side by Side Diff: runtime/vm/freelist_test.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge 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
« no previous file with comments | « runtime/vm/freelist.cc ('k') | runtime/vm/gc_marker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 static uword Allocate(FreeList* free_list, intptr_t size, bool is_protected) { 11 static uword Allocate(FreeList* free_list, intptr_t size, bool is_protected) {
12 uword result = free_list->TryAllocate(size, is_protected); 12 uword result = free_list->TryAllocate(size, is_protected);
13 if (result && is_protected) { 13 if (result && is_protected) {
14 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(result), 14 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(result), size,
15 size,
16 VirtualMemory::kReadExecute); 15 VirtualMemory::kReadExecute);
17 ASSERT(status); 16 ASSERT(status);
18 } 17 }
19 return result; 18 return result;
20 } 19 }
21 20
22 21
23 static void Free(FreeList* free_list, 22 static void Free(FreeList* free_list,
24 uword address, 23 uword address,
25 intptr_t size, 24 intptr_t size,
26 bool is_protected) { 25 bool is_protected) {
27 if (is_protected) { 26 if (is_protected) {
28 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), 27 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
29 size,
30 VirtualMemory::kReadWrite); 28 VirtualMemory::kReadWrite);
31 ASSERT(status); 29 ASSERT(status);
32 } 30 }
33 free_list->Free(address, size); 31 free_list->Free(address, size);
34 if (is_protected) { 32 if (is_protected) {
35 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), 33 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
36 size,
37 VirtualMemory::kReadExecute); 34 VirtualMemory::kReadExecute);
38 ASSERT(status); 35 ASSERT(status);
39 } 36 }
40 } 37 }
41 38
42 39
43 static void TestFreeList(VirtualMemory* region, 40 static void TestFreeList(VirtualMemory* region,
44 FreeList* free_list, 41 FreeList* free_list,
45 bool is_protected) { 42 bool is_protected) {
46 const intptr_t kSmallObjectSize = 4 * kWordSize; 43 const intptr_t kSmallObjectSize = 4 * kWordSize;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 blob->Protect(VirtualMemory::kReadWrite); 123 blob->Protect(VirtualMemory::kReadWrite);
127 124
128 // Enqueue the large blob as one free block. 125 // Enqueue the large blob as one free block.
129 free_list->Free(blob->start(), blob->size()); 126 free_list->Free(blob->start(), blob->size());
130 127
131 // Write protect the whole region. 128 // Write protect the whole region.
132 blob->Protect(VirtualMemory::kReadExecute); 129 blob->Protect(VirtualMemory::kReadExecute);
133 130
134 // Allocate small objects. 131 // Allocate small objects.
135 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) { 132 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) {
136 objects[i] = Allocate(free_list, 133 objects[i] = Allocate(free_list, kObjectSize, true); // is_protected
137 kObjectSize,
138 true); // is_protected
139 } 134 }
140 135
141 // All space is occupied. Expect failed allocation. 136 // All space is occupied. Expect failed allocation.
142 ASSERT(Allocate(free_list, kObjectSize, true) == 0); 137 ASSERT(Allocate(free_list, kObjectSize, true) == 0);
143 138
144 // Free all objects again. Make the whole region writable for this. 139 // Free all objects again. Make the whole region writable for this.
145 blob->Protect(VirtualMemory::kReadWrite); 140 blob->Protect(VirtualMemory::kReadWrite);
146 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) { 141 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) {
147 free_list->Free(objects[i], kObjectSize); 142 free_list->Free(objects[i], kObjectSize);
148 } 143 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); 184 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true);
190 ASSERT(e0); 185 ASSERT(e0);
191 186
192 // Delete the memory associated with the test. 187 // Delete the memory associated with the test.
193 delete blob; 188 delete blob;
194 delete free_list; 189 delete free_list;
195 delete[] objects; 190 delete[] objects;
196 } 191 }
197 192
198 } // namespace dart 193 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/freelist.cc ('k') | runtime/vm/gc_marker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698