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

Side by Side Diff: src/heap/mark-compact.h

Issue 2139133003: [heap] Untangle Marking and friends from heap dependencies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix comment formatting Created 4 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 | « src/heap/incremental-marking.cc ('k') | src/heap/mark-compact.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 V8_HEAP_MARK_COMPACT_H_ 5 #ifndef V8_HEAP_MARK_COMPACT_H_
6 #define V8_HEAP_MARK_COMPACT_H_ 6 #define V8_HEAP_MARK_COMPACT_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
11 #include "src/heap/marking.h"
11 #include "src/heap/spaces.h" 12 #include "src/heap/spaces.h"
12 #include "src/heap/store-buffer.h" 13 #include "src/heap/store-buffer.h"
13 14
14 namespace v8 { 15 namespace v8 {
15 namespace internal { 16 namespace internal {
16 17
17 // Callback function, returns whether an object is alive. The heap size 18 // Callback function, returns whether an object is alive. The heap size
18 // of the object is returned in size. It optionally updates the offset 19 // of the object is returned in size. It optionally updates the offset
19 // to the first live object in the page (only used for old and map objects). 20 // to the first live object in the page (only used for old and map objects).
20 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); 21 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset);
21 22
22 // Callback function to mark an object in a given heap. 23 // Callback function to mark an object in a given heap.
23 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object); 24 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object);
24 25
25 // Forward declarations. 26 // Forward declarations.
26 class CodeFlusher; 27 class CodeFlusher;
27 class MarkCompactCollector; 28 class MarkCompactCollector;
28 class MarkingVisitor; 29 class MarkingVisitor;
29 class RootMarkingVisitor; 30 class RootMarkingVisitor;
30 31
31 class Marking : public AllStatic { 32 class ObjectMarking : public AllStatic {
32 public: 33 public:
33 INLINE(static MarkBit MarkBitFrom(Address addr)) { 34 INLINE(static MarkBit MarkBitFrom(Address addr)) {
34 MemoryChunk* p = MemoryChunk::FromAddress(addr); 35 MemoryChunk* p = MemoryChunk::FromAddress(addr);
35 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr)); 36 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr));
36 } 37 }
37 38
38 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { 39 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) {
39 return MarkBitFrom(reinterpret_cast<Address>(obj)); 40 return MarkBitFrom(reinterpret_cast<Address>(obj));
40 } 41 }
41 42
42 // Impossible markbits: 01
43 static const char* kImpossibleBitPattern;
44 INLINE(static bool IsImpossible(MarkBit mark_bit)) {
45 return !mark_bit.Get() && mark_bit.Next().Get();
46 }
47
48 // Black markbits: 11
49 static const char* kBlackBitPattern;
50 INLINE(static bool IsBlack(MarkBit mark_bit)) {
51 return mark_bit.Get() && mark_bit.Next().Get();
52 }
53
54 // White markbits: 00 - this is required by the mark bit clearer.
55 static const char* kWhiteBitPattern;
56 INLINE(static bool IsWhite(MarkBit mark_bit)) {
57 DCHECK(!IsImpossible(mark_bit));
58 return !mark_bit.Get();
59 }
60
61 // Grey markbits: 10
62 static const char* kGreyBitPattern;
63 INLINE(static bool IsGrey(MarkBit mark_bit)) {
64 return mark_bit.Get() && !mark_bit.Next().Get();
65 }
66
67 // IsBlackOrGrey assumes that the first bit is set for black or grey
68 // objects.
69 INLINE(static bool IsBlackOrGrey(MarkBit mark_bit)) { return mark_bit.Get(); }
70
71 INLINE(static void MarkBlack(MarkBit mark_bit)) {
72 mark_bit.Set();
73 mark_bit.Next().Set();
74 }
75
76 INLINE(static void MarkWhite(MarkBit mark_bit)) {
77 mark_bit.Clear();
78 mark_bit.Next().Clear();
79 }
80
81 INLINE(static void BlackToWhite(MarkBit markbit)) {
82 DCHECK(IsBlack(markbit));
83 markbit.Clear();
84 markbit.Next().Clear();
85 }
86
87 INLINE(static void GreyToWhite(MarkBit markbit)) {
88 DCHECK(IsGrey(markbit));
89 markbit.Clear();
90 markbit.Next().Clear();
91 }
92
93 INLINE(static void BlackToGrey(MarkBit markbit)) {
94 DCHECK(IsBlack(markbit));
95 markbit.Next().Clear();
96 }
97
98 INLINE(static void WhiteToGrey(MarkBit markbit)) {
99 DCHECK(IsWhite(markbit));
100 markbit.Set();
101 }
102
103 INLINE(static void WhiteToBlack(MarkBit markbit)) {
104 DCHECK(IsWhite(markbit));
105 markbit.Set();
106 markbit.Next().Set();
107 }
108
109 INLINE(static void GreyToBlack(MarkBit markbit)) {
110 DCHECK(IsGrey(markbit));
111 markbit.Next().Set();
112 }
113
114 INLINE(static void BlackToGrey(HeapObject* obj)) {
115 BlackToGrey(MarkBitFrom(obj));
116 }
117
118 INLINE(static void AnyToGrey(MarkBit markbit)) {
119 markbit.Set();
120 markbit.Next().Clear();
121 }
122
123 static void TransferMark(Heap* heap, Address old_start, Address new_start);
124
125 #ifdef DEBUG 43 #ifdef DEBUG
126 enum ObjectColor { 44 static Marking::ObjectColor Color(HeapObject* obj) {
127 BLACK_OBJECT, 45 return Marking::Color(ObjectMarking::MarkBitFrom(obj));
128 WHITE_OBJECT,
129 GREY_OBJECT,
130 IMPOSSIBLE_COLOR
131 };
132
133 static const char* ColorName(ObjectColor color) {
134 switch (color) {
135 case BLACK_OBJECT:
136 return "black";
137 case WHITE_OBJECT:
138 return "white";
139 case GREY_OBJECT:
140 return "grey";
141 case IMPOSSIBLE_COLOR:
142 return "impossible";
143 }
144 return "error";
145 }
146
147 static ObjectColor Color(HeapObject* obj) {
148 return Color(Marking::MarkBitFrom(obj));
149 }
150
151 static ObjectColor Color(MarkBit mark_bit) {
152 if (IsBlack(mark_bit)) return BLACK_OBJECT;
153 if (IsWhite(mark_bit)) return WHITE_OBJECT;
154 if (IsGrey(mark_bit)) return GREY_OBJECT;
155 UNREACHABLE();
156 return IMPOSSIBLE_COLOR;
157 } 46 }
158 #endif 47 #endif
159 48
160 // Returns true if the transferred color is black.
161 INLINE(static bool TransferColor(HeapObject* from, HeapObject* to)) {
162 if (Page::FromAddress(to->address())->IsFlagSet(Page::BLACK_PAGE))
163 return true;
164 MarkBit from_mark_bit = MarkBitFrom(from);
165 MarkBit to_mark_bit = MarkBitFrom(to);
166 DCHECK(Marking::IsWhite(to_mark_bit));
167 if (from_mark_bit.Get()) {
168 to_mark_bit.Set();
169 if (from_mark_bit.Next().Get()) {
170 to_mark_bit.Next().Set();
171 return true;
172 }
173 }
174 return false;
175 }
176
177 private: 49 private:
178 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); 50 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking);
179 }; 51 };
180 52
181 // ---------------------------------------------------------------------------- 53 // ----------------------------------------------------------------------------
182 // Marking deque for tracing live objects. 54 // Marking deque for tracing live objects.
183 class MarkingDeque { 55 class MarkingDeque {
184 public: 56 public:
185 MarkingDeque() 57 MarkingDeque()
186 : array_(NULL), 58 : array_(NULL),
187 top_(0), 59 top_(0),
188 bottom_(0), 60 bottom_(0),
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 private: 758 private:
887 MarkCompactCollector* collector_; 759 MarkCompactCollector* collector_;
888 }; 760 };
889 761
890 762
891 const char* AllocationSpaceName(AllocationSpace space); 763 const char* AllocationSpaceName(AllocationSpace space);
892 } // namespace internal 764 } // namespace internal
893 } // namespace v8 765 } // namespace v8
894 766
895 #endif // V8_HEAP_MARK_COMPACT_H_ 767 #endif // V8_HEAP_MARK_COMPACT_H_
OLDNEW
« no previous file with comments | « src/heap/incremental-marking.cc ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698