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

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

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months 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.cc » ('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 "vm/freelist.h"
5 #include "platform/assert.h" 6 #include "platform/assert.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), size, 14 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(result), size,
15 VirtualMemory::kReadExecute); 15 VirtualMemory::kReadExecute);
16 ASSERT(status); 16 ASSERT(status);
17 } 17 }
18 return result; 18 return result;
19 } 19 }
20 20
21
22 static void Free(FreeList* free_list, 21 static void Free(FreeList* free_list,
23 uword address, 22 uword address,
24 intptr_t size, 23 intptr_t size,
25 bool is_protected) { 24 bool is_protected) {
26 if (is_protected) { 25 if (is_protected) {
27 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size, 26 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
28 VirtualMemory::kReadWrite); 27 VirtualMemory::kReadWrite);
29 ASSERT(status); 28 ASSERT(status);
30 } 29 }
31 free_list->Free(address, size); 30 free_list->Free(address, size);
32 if (is_protected) { 31 if (is_protected) {
33 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size, 32 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
34 VirtualMemory::kReadExecute); 33 VirtualMemory::kReadExecute);
35 ASSERT(status); 34 ASSERT(status);
36 } 35 }
37 } 36 }
38 37
39
40 static void TestFreeList(VirtualMemory* region, 38 static void TestFreeList(VirtualMemory* region,
41 FreeList* free_list, 39 FreeList* free_list,
42 bool is_protected) { 40 bool is_protected) {
43 const intptr_t kSmallObjectSize = 4 * kWordSize; 41 const intptr_t kSmallObjectSize = 4 * kWordSize;
44 const intptr_t kMediumObjectSize = 16 * kWordSize; 42 const intptr_t kMediumObjectSize = 16 * kWordSize;
45 const intptr_t kLargeObjectSize = 8 * KB; 43 const intptr_t kLargeObjectSize = 8 * KB;
46 uword blob = region->start(); 44 uword blob = region->start();
47 // Enqueue the large blob as one free block. 45 // Enqueue the large blob as one free block.
48 free_list->Free(blob, region->size()); 46 free_list->Free(blob, region->size());
49 47
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); 87 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize);
90 region->Commit(/* is_executable */ false, NULL); 88 region->Commit(/* is_executable */ false, NULL);
91 89
92 TestFreeList(region, free_list, false); 90 TestFreeList(region, free_list, false);
93 91
94 // Delete the memory associated with the test. 92 // Delete the memory associated with the test.
95 delete region; 93 delete region;
96 delete free_list; 94 delete free_list;
97 } 95 }
98 96
99
100 TEST_CASE(FreeListProtected) { 97 TEST_CASE(FreeListProtected) {
101 FreeList* free_list = new FreeList(); 98 FreeList* free_list = new FreeList();
102 const intptr_t kBlobSize = 1 * MB; 99 const intptr_t kBlobSize = 1 * MB;
103 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize); 100 VirtualMemory* region = VirtualMemory::Reserve(kBlobSize);
104 region->Commit(/* is_executable */ false, NULL); 101 region->Commit(/* is_executable */ false, NULL);
105 102
106 TestFreeList(region, free_list, true); 103 TestFreeList(region, free_list, true);
107 104
108 // Delete the memory associated with the test. 105 // Delete the memory associated with the test.
109 delete region; 106 delete region;
110 delete free_list; 107 delete free_list;
111 } 108 }
112 109
113
114 TEST_CASE(FreeListProtectedTinyObjects) { 110 TEST_CASE(FreeListProtectedTinyObjects) {
115 FreeList* free_list = new FreeList(); 111 FreeList* free_list = new FreeList();
116 const intptr_t kBlobSize = 1 * MB; 112 const intptr_t kBlobSize = 1 * MB;
117 const intptr_t kObjectSize = 2 * kWordSize; 113 const intptr_t kObjectSize = 2 * kWordSize;
118 uword* objects = new uword[kBlobSize / kObjectSize]; 114 uword* objects = new uword[kBlobSize / kObjectSize];
119 115
120 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); 116 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize);
121 ASSERT(Utils::IsAligned(blob->start(), 4096)); 117 ASSERT(Utils::IsAligned(blob->start(), 4096));
122 blob->Commit(/* is_executable = */ false, NULL); 118 blob->Commit(/* is_executable = */ false, NULL);
123 blob->Protect(VirtualMemory::kReadWrite); 119 blob->Protect(VirtualMemory::kReadWrite);
(...skipping 17 matching lines...) Expand all
141 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) { 137 for (intptr_t i = 0; i < blob->size() / kObjectSize; i++) {
142 free_list->Free(objects[i], kObjectSize); 138 free_list->Free(objects[i], kObjectSize);
143 } 139 }
144 140
145 // Delete the memory associated with the test. 141 // Delete the memory associated with the test.
146 delete blob; 142 delete blob;
147 delete free_list; 143 delete free_list;
148 delete[] objects; 144 delete[] objects;
149 } 145 }
150 146
151
152 TEST_CASE(FreeListProtectedVariableSizeObjects) { 147 TEST_CASE(FreeListProtectedVariableSizeObjects) {
153 FreeList* free_list = new FreeList(); 148 FreeList* free_list = new FreeList();
154 const intptr_t kBlobSize = 8 * KB; 149 const intptr_t kBlobSize = 8 * KB;
155 const intptr_t kMinSize = 2 * kWordSize; 150 const intptr_t kMinSize = 2 * kWordSize;
156 uword* objects = new uword[kBlobSize / kMinSize]; 151 uword* objects = new uword[kBlobSize / kMinSize];
157 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) { 152 for (intptr_t i = 0; i < kBlobSize / kMinSize; ++i) {
158 objects[i] = static_cast<uword>(NULL); 153 objects[i] = static_cast<uword>(NULL);
159 } 154 }
160 155
161 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize); 156 VirtualMemory* blob = VirtualMemory::Reserve(kBlobSize);
(...skipping 22 matching lines...) Expand all
184 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true); 179 e0 = Allocate(free_list, 3 * KB - 2 * kWordSize, true);
185 ASSERT(e0); 180 ASSERT(e0);
186 181
187 // Delete the memory associated with the test. 182 // Delete the memory associated with the test.
188 delete blob; 183 delete blob;
189 delete free_list; 184 delete free_list;
190 delete[] objects; 185 delete[] objects;
191 } 186 }
192 187
193 } // namespace dart 188 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/freelist.cc ('k') | runtime/vm/gc_marker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698