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

Side by Side Diff: third_party/WebKit/Source/platform/heap/PageMemory.cpp

Issue 2816033003: Replace ASSERT with DHCECK_op in platform/heap (Closed)
Patch Set: Replace ASSERT with CHECK_op in platform/heap Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/heap/PageMemory.h" 5 #include "platform/heap/PageMemory.h"
6 6
7 #include "platform/heap/Heap.h" 7 #include "platform/heap/Heap.h"
8 #include "platform/wtf/AddressSanitizer.h" 8 #include "platform/wtf/AddressSanitizer.h"
9 #include "platform/wtf/Assertions.h" 9 #include "platform/wtf/Assertions.h"
10 #include "platform/wtf/Atomics.h" 10 #include "platform/wtf/Atomics.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 while (current) { 76 while (current) {
77 Address base = current->region_->Base(); 77 Address base = current->region_->Base();
78 if (address < base) { 78 if (address < base) {
79 current = current->left_; 79 current = current->left_;
80 continue; 80 continue;
81 } 81 }
82 if (address >= base + current->region_->size()) { 82 if (address >= base + current->region_->size()) {
83 current = current->right_; 83 current = current->right_;
84 continue; 84 continue;
85 } 85 }
86 ASSERT(current->region_->Contains(address)); 86 DCHECK(current->region_->Contains(address));
87 return current->region_; 87 return current->region_;
88 } 88 }
89 return nullptr; 89 return nullptr;
90 } 90 }
91 91
92 void RegionTree::Add(PageMemoryRegion* region) { 92 void RegionTree::Add(PageMemoryRegion* region) {
93 ASSERT(region); 93 DCHECK(region);
94 RegionTreeNode* new_tree = new RegionTreeNode(region); 94 RegionTreeNode* new_tree = new RegionTreeNode(region);
95 new_tree->AddTo(&root_); 95 new_tree->AddTo(&root_);
96 } 96 }
97 97
98 void RegionTreeNode::AddTo(RegionTreeNode** context) { 98 void RegionTreeNode::AddTo(RegionTreeNode** context) {
99 Address base = region_->Base(); 99 Address base = region_->Base();
100 for (RegionTreeNode* current = *context; current; current = *context) { 100 for (RegionTreeNode* current = *context; current; current = *context) {
101 ASSERT(!current->region_->Contains(base)); 101 DCHECK(!current->region_->Contains(base));
102 context = 102 context =
103 (base < current->region_->Base()) ? &current->left_ : &current->right_; 103 (base < current->region_->Base()) ? &current->left_ : &current->right_;
104 } 104 }
105 *context = this; 105 *context = this;
106 } 106 }
107 107
108 void RegionTree::Remove(PageMemoryRegion* region) { 108 void RegionTree::Remove(PageMemoryRegion* region) {
109 ASSERT(region); 109 DCHECK(region);
110 ASSERT(root_); 110 DCHECK(root_);
111 Address base = region->Base(); 111 Address base = region->Base();
112 RegionTreeNode** context = &root_; 112 RegionTreeNode** context = &root_;
113 RegionTreeNode* current = root_; 113 RegionTreeNode* current = root_;
114 for (; current; current = *context) { 114 for (; current; current = *context) {
115 if (region == current->region_) 115 if (region == current->region_)
116 break; 116 break;
117 context = 117 context =
118 (base < current->region_->Base()) ? &current->left_ : &current->right_; 118 (base < current->region_->Base()) ? &current->left_ : &current->right_;
119 } 119 }
120 120
121 // Shutdown via detachMainThread might not have populated the region tree. 121 // Shutdown via detachMainThread might not have populated the region tree.
122 if (!current) 122 if (!current)
123 return; 123 return;
124 124
125 *context = nullptr; 125 *context = nullptr;
126 if (current->left_) { 126 if (current->left_) {
127 current->left_->AddTo(context); 127 current->left_->AddTo(context);
128 current->left_ = nullptr; 128 current->left_ = nullptr;
129 } 129 }
130 if (current->right_) { 130 if (current->right_) {
131 current->right_->AddTo(context); 131 current->right_->AddTo(context);
132 current->right_ = nullptr; 132 current->right_ = nullptr;
133 } 133 }
134 delete current; 134 delete current;
135 } 135 }
136 136
137 PageMemory::PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable) 137 PageMemory::PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable)
138 : reserved_(reserved), writable_(writable) { 138 : reserved_(reserved), writable_(writable) {
139 ASSERT(reserved->Contains(writable)); 139 DCHECK(reserved->Contains(writable));
140 140
141 // Register the writable area of the memory as part of the LSan root set. 141 // Register the writable area of the memory as part of the LSan root set.
142 // Only the writable area is mapped and can contain C++ objects. Those 142 // Only the writable area is mapped and can contain C++ objects. Those
143 // C++ objects can contain pointers to objects outside of the heap and 143 // C++ objects can contain pointers to objects outside of the heap and
144 // should therefore be part of the LSan root set. 144 // should therefore be part of the LSan root set.
145 __lsan_register_root_region(writable_.Base(), writable_.size()); 145 __lsan_register_root_region(writable_.Base(), writable_.size());
146 } 146 }
147 147
148 PageMemory* PageMemory::SetupPageMemoryInRegion(PageMemoryRegion* region, 148 PageMemory* PageMemory::SetupPageMemoryInRegion(PageMemoryRegion* region,
149 size_t page_offset, 149 size_t page_offset,
150 size_t payload_size) { 150 size_t payload_size) {
151 // Setup the payload one guard page into the page memory. 151 // Setup the payload one guard page into the page memory.
152 Address payload_address = region->Base() + page_offset + kBlinkGuardPageSize; 152 Address payload_address = region->Base() + page_offset + kBlinkGuardPageSize;
153 return new PageMemory(region, MemoryRegion(payload_address, payload_size)); 153 return new PageMemory(region, MemoryRegion(payload_address, payload_size));
154 } 154 }
155 155
156 static size_t RoundToOsPageSize(size_t size) { 156 static size_t RoundToOsPageSize(size_t size) {
157 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1); 157 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1);
158 } 158 }
159 159
160 PageMemory* PageMemory::Allocate(size_t payload_size, RegionTree* region_tree) { 160 PageMemory* PageMemory::Allocate(size_t payload_size, RegionTree* region_tree) {
161 ASSERT(payload_size > 0); 161 DCHECK_GT(payload_size, 0u);
162 162
163 // Virtual memory allocation routines operate in OS page sizes. 163 // Virtual memory allocation routines operate in OS page sizes.
164 // Round up the requested size to nearest os page size. 164 // Round up the requested size to nearest os page size.
165 payload_size = RoundToOsPageSize(payload_size); 165 payload_size = RoundToOsPageSize(payload_size);
166 166
167 // Overallocate by 2 times OS page size to have space for a 167 // Overallocate by 2 times OS page size to have space for a
168 // guard page at the beginning and end of blink heap page. 168 // guard page at the beginning and end of blink heap page.
169 size_t allocation_size = payload_size + 2 * kBlinkGuardPageSize; 169 size_t allocation_size = payload_size + 2 * kBlinkGuardPageSize;
170 PageMemoryRegion* page_memory_region = 170 PageMemoryRegion* page_memory_region =
171 PageMemoryRegion::AllocateLargePage(allocation_size, region_tree); 171 PageMemoryRegion::AllocateLargePage(allocation_size, region_tree);
172 PageMemory* storage = 172 PageMemory* storage =
173 SetupPageMemoryInRegion(page_memory_region, 0, payload_size); 173 SetupPageMemoryInRegion(page_memory_region, 0, payload_size);
174 CHECK(storage->Commit()); 174 CHECK(storage->Commit());
175 return storage; 175 return storage;
176 } 176 }
177 177
178 } // namespace blink 178 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698