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

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

Issue 2531973002: Simple BlinkGC heap compaction. (Closed)
Patch Set: add pointer alignment handling to SparseHeapBitmap Created 4 years 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
(Empty)
1 // Copyright 2016 Opera Software AS. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/heap/SparseHeapBitmap.h"
6
7 #include "wtf/PtrUtil.h"
8
9 namespace blink {
10
11 // Return the subtree/bitmap that covers the
12 // [address, address + size) range. Null if there is none.
13 SparseHeapBitmap* SparseHeapBitmap::hasRange(Address address, size_t size) {
14 DCHECK(!(reinterpret_cast<uintptr_t>(address) & s_pointerAlignmentMask));
15 SparseHeapBitmap* bitmap = this;
16 while (bitmap) {
17 // Interval starts after, |m_right| handles.
18 if (address > bitmap->end()) {
19 bitmap = bitmap->m_right.get();
20 continue;
21 }
22 // Interval starts within, |bitmap| is included in the resulting range.
23 if (address >= bitmap->base())
24 break;
25
26 Address right = address + size - 1;
27 // Interval starts before, but intersects with |bitmap|'s range.
28 if (right >= bitmap->base())
29 break;
30
31 // Interval is before entirely, for |m_left| to handle.
32 bitmap = bitmap->m_left.get();
33 }
34 return bitmap;
35 }
36
37 bool SparseHeapBitmap::isSet(Address address) {
38 DCHECK(!(reinterpret_cast<uintptr_t>(address) & s_pointerAlignmentMask));
39 SparseHeapBitmap* bitmap = this;
40 while (bitmap) {
41 if (address > bitmap->end()) {
42 bitmap = bitmap->m_right.get();
43 continue;
44 }
45 if (address >= bitmap->base()) {
46 if (bitmap->m_bitmap) {
47 return bitmap->m_bitmap->test((address - bitmap->base()) >>
48 s_pointerAlignmentInBits);
49 }
50 return bitmap->size() == 1;
haraken 2016/12/09 07:25:56 Would you help me understand when this can happen?
sof 2016/12/09 21:44:04 This case will happen if |this| represents a singl
51 }
52 bitmap = bitmap->m_left.get();
53 }
54 return false;
55 }
56
57 void SparseHeapBitmap::add(Address address) {
58 DCHECK(!(reinterpret_cast<uintptr_t>(address) & s_pointerAlignmentMask));
59 // |address| is beyond the maximum that this SparseHeapBitmap node can
60 // encompass.
61 if (address >= maxEnd()) {
62 if (!m_right) {
63 m_right = SparseHeapBitmap::create(address);
64 return;
65 }
66 m_right->add(address);
67 return;
68 }
69 // Same on the other side.
70 if (address < minStart()) {
71 if (!m_left) {
72 m_left = SparseHeapBitmap::create(address);
73 return;
74 }
75 m_left->add(address);
76 return;
77 }
78 if (address == base())
79 return;
80 // |address| can be encompassed by |this| by expanding its size.
81 if (address > base()) {
82 if (!m_bitmap)
83 createBitmap();
84 m_bitmap->set((address - base()) >> s_pointerAlignmentInBits);
85 return;
86 }
87 // Use |address| as the new base for this interval.
88 Address oldBase = swapBase(address);
haraken 2016/12/09 07:25:56 Why is this left expansion safe? What happens if t
sof 2016/12/09 21:44:04 It is safe because |this| is a single address bitm
89 createBitmap();
90 m_bitmap->set((oldBase - address) >> s_pointerAlignmentInBits);
91 }
92
93 void SparseHeapBitmap::createBitmap() {
94 DCHECK(!m_bitmap && size() == 1);
95 m_bitmap = makeUnique<std::bitset<s_bitmapChunkSize>>();
96 m_size = s_bitmapChunkRange;
97 m_bitmap->set(0);
98 }
99
100 size_t SparseHeapBitmap::intervalCount() const {
101 size_t count = 1;
102 if (m_left)
103 count += m_left->intervalCount();
104 if (m_right)
105 count += m_right->intervalCount();
106 return count;
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698