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

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

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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef PageMemory_h 5 #ifndef PageMemory_h
6 #define PageMemory_h 6 #define PageMemory_h
7 7
8 #include "platform/heap/HeapPage.h" 8 #include "platform/heap/HeapPage.h"
9 #include "platform/wtf/Allocator.h" 9 #include "platform/wtf/Allocator.h"
10 #include "platform/wtf/Assertions.h" 10 #include "platform/wtf/Assertions.h"
11 #include "platform/wtf/Compiler.h" 11 #include "platform/wtf/Compiler.h"
12 #include "platform/wtf/allocator/Partitions.h" 12 #include "platform/wtf/allocator/Partitions.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 class RegionTree; 16 class RegionTree;
17 class RegionTreeNode; 17 class RegionTreeNode;
18 18
19 class MemoryRegion { 19 class MemoryRegion {
20 USING_FAST_MALLOC(MemoryRegion); 20 USING_FAST_MALLOC(MemoryRegion);
21 21
22 public: 22 public:
23 MemoryRegion(Address base, size_t size) : base_(base), size_(size) { 23 MemoryRegion(Address base, size_t size) : base_(base), size_(size) {
24 ASSERT(size > 0); 24 DCHECK_GT(size, 0u);
25 } 25 }
26 26
27 bool Contains(Address addr) const { 27 bool Contains(Address addr) const {
28 return base_ <= addr && addr < (base_ + size_); 28 return base_ <= addr && addr < (base_ + size_);
29 } 29 }
30 30
31 bool Contains(const MemoryRegion& other) const { 31 bool Contains(const MemoryRegion& other) const {
32 return Contains(other.base_) && Contains(other.base_ + other.size_ - 1); 32 return Contains(other.base_) && Contains(other.base_ + other.size_ - 1);
33 } 33 }
34 34
(...skipping 15 matching lines...) Expand all
50 // whole. The PageMemoryRegion allows us to do that by keeping track 50 // whole. The PageMemoryRegion allows us to do that by keeping track
51 // of the number of pages using it in order to be able to release all 51 // of the number of pages using it in order to be able to release all
52 // of the virtual address space when there are no more pages using it. 52 // of the virtual address space when there are no more pages using it.
53 class PageMemoryRegion : public MemoryRegion { 53 class PageMemoryRegion : public MemoryRegion {
54 public: 54 public:
55 ~PageMemoryRegion(); 55 ~PageMemoryRegion();
56 56
57 void PageDeleted(Address); 57 void PageDeleted(Address);
58 58
59 void MarkPageUsed(Address page) { 59 void MarkPageUsed(Address page) {
60 ASSERT(!in_use_[Index(page)]); 60 DCHECK(!in_use_[Index(page)]);
61 in_use_[Index(page)] = true; 61 in_use_[Index(page)] = true;
62 } 62 }
63 63
64 void MarkPageUnused(Address page) { in_use_[Index(page)] = false; } 64 void MarkPageUnused(Address page) { in_use_[Index(page)] = false; }
65 65
66 static PageMemoryRegion* AllocateLargePage(size_t size, 66 static PageMemoryRegion* AllocateLargePage(size_t size,
67 RegionTree* region_tree) { 67 RegionTree* region_tree) {
68 return Allocate(size, 1, region_tree); 68 return Allocate(size, 1, region_tree);
69 } 69 }
70 70
71 static PageMemoryRegion* AllocateNormalPages(RegionTree* region_tree) { 71 static PageMemoryRegion* AllocateNormalPages(RegionTree* region_tree) {
72 return Allocate(kBlinkPageSize * kBlinkPagesPerRegion, kBlinkPagesPerRegion, 72 return Allocate(kBlinkPageSize * kBlinkPagesPerRegion, kBlinkPagesPerRegion,
73 region_tree); 73 region_tree);
74 } 74 }
75 75
76 BasePage* PageFromAddress(Address address) { 76 BasePage* PageFromAddress(Address address) {
77 ASSERT(Contains(address)); 77 DCHECK(Contains(address));
78 if (!in_use_[Index(address)]) 78 if (!in_use_[Index(address)])
79 return nullptr; 79 return nullptr;
80 if (is_large_page_) 80 if (is_large_page_)
81 return PageFromObject(Base()); 81 return PageFromObject(Base());
82 return PageFromObject(address); 82 return PageFromObject(address);
83 } 83 }
84 84
85 private: 85 private:
86 PageMemoryRegion(Address base, size_t, unsigned num_pages, RegionTree*); 86 PageMemoryRegion(Address base, size_t, unsigned num_pages, RegionTree*);
87 87
88 unsigned Index(Address address) const { 88 unsigned Index(Address address) const {
89 ASSERT(Contains(address)); 89 DCHECK(Contains(address));
90 if (is_large_page_) 90 if (is_large_page_)
91 return 0; 91 return 0;
92 size_t offset = BlinkPageAddress(address) - Base(); 92 size_t offset = BlinkPageAddress(address) - Base();
93 ASSERT(offset % kBlinkPageSize == 0); 93 DCHECK_EQ(offset % kBlinkPageSize, 0u);
94 return offset / kBlinkPageSize; 94 return offset / kBlinkPageSize;
95 } 95 }
96 96
97 static PageMemoryRegion* Allocate(size_t, unsigned num_pages, RegionTree*); 97 static PageMemoryRegion* Allocate(size_t, unsigned num_pages, RegionTree*);
98 98
99 const bool is_large_page_; 99 const bool is_large_page_;
100 // A thread owns a page, but not a region. Represent the in-use 100 // A thread owns a page, but not a region. Represent the in-use
101 // bitmap such that thread non-interference comes for free. 101 // bitmap such that thread non-interference comes for free.
102 bool in_use_[kBlinkPagesPerRegion]; 102 bool in_use_[kBlinkPagesPerRegion];
103 int num_pages_; 103 int num_pages_;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 private: 208 private:
209 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable); 209 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable);
210 210
211 PageMemoryRegion* reserved_; 211 PageMemoryRegion* reserved_;
212 MemoryRegion writable_; 212 MemoryRegion writable_;
213 }; 213 };
214 214
215 } // namespace blink 215 } // namespace blink
216 216
217 #endif 217 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698