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

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

Issue 6713075: Create an abstraction (MarkBit) object to hold the location of the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 27 matching lines...) Expand all
38 // to the first live object in the page (only used for old and map objects). 38 // to the first live object in the page (only used for old and map objects).
39 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); 39 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset);
40 40
41 // Forward declarations. 41 // Forward declarations.
42 class RootMarkingVisitor; 42 class RootMarkingVisitor;
43 class MarkingVisitor; 43 class MarkingVisitor;
44 44
45 45
46 class Marking { 46 class Marking {
47 public: 47 public:
48 INLINE(static bool IsMarked(HeapObject* obj)) { 48 static inline MarkBit MarkBitFrom(HeapObject* obj) {
49 return IsMarked(obj->address()); 49 return MarkBitFrom(reinterpret_cast<Address>(obj));
50 } 50 }
51 51
52 INLINE(static void SetMark(HeapObject* obj)) { 52 static inline MarkBit MarkBitFromNewSpace(HeapObject* obj) {
53 SetMark(obj->address()); 53 ASSERT(Heap::InNewSpace(obj));
54 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(
55 reinterpret_cast<Address>(obj));
56 return new_space_bitmap_->MarkBitFromIndex(index);
54 } 57 }
55 58
56 INLINE(static void ClearMark(HeapObject* obj)) { 59 static inline MarkBit MarkBitFrom(Address addr) {
57 ClearMark(obj->address());
58 }
59
60 INLINE(static bool TestAndMark(Address addr)) {
61 if (Heap::InNewSpace(addr)) { 60 if (Heap::InNewSpace(addr)) {
62 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr); 61 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr);
63 return new_space_bitmap_->TestAndSet(index); 62 return new_space_bitmap_->MarkBitFromIndex(index);
64 } else { 63 } else {
65 Page *p = Page::FromAddress(addr); 64 Page *p = Page::FromAddress(addr);
66 return p->markbits()->TestAndSet(p->AddressToMarkbitIndex(addr)); 65 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr));
67 } 66 }
68 } 67 }
69 68
70 INLINE(static bool IsMarked(Address addr)) { 69 static void ClearRange(Address addr, int size) {
71 if (Heap::InNewSpace(addr)) {
72 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr);
73 return new_space_bitmap_->Get(index);
74 } else {
75 Page *p = Page::FromAddress(addr);
76 return p->markbits()->Get(p->AddressToMarkbitIndex(addr));
77 }
78 }
79
80 INLINE(static void SetMark(Address addr)) {
81 if (Heap::InNewSpace(addr)) {
82 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr);
83 new_space_bitmap_->Set(index);
84 } else {
85 Page *p = Page::FromAddress(addr);
86 p->markbits()->Set(p->FastAddressToMarkbitIndex(addr));
87 }
88 }
89
90 INLINE(static void ClearMark(Address addr)) {
91 if (Heap::InNewSpace(addr)) {
92 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr);
93 new_space_bitmap_->Clear(index);
94 } else {
95 Page *p = Page::FromAddress(addr);
96 p->markbits()->Clear(p->FastAddressToMarkbitIndex(addr));
97 }
98 }
99
100 INLINE(static void ClearRange(Address addr, int size)) {
101 if (Heap::InNewSpace(addr)) { 70 if (Heap::InNewSpace(addr)) {
102 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr); 71 uint32_t index = Heap::new_space()->AddressToMarkbitIndex(addr);
103 new_space_bitmap_->ClearRange(index, size >> kPointerSizeLog2); 72 new_space_bitmap_->ClearRange(index, size >> kPointerSizeLog2);
104 } else { 73 } else {
105 Page *p = Page::FromAddress(addr); 74 Page *p = Page::FromAddress(addr);
106 p->markbits()->ClearRange(p->FastAddressToMarkbitIndex(addr), 75 p->markbits()->ClearRange(p->FastAddressToMarkbitIndex(addr),
107 size >> kPointerSizeLog2); 76 size >> kPointerSizeLog2);
108 } 77 }
109 } 78 }
110 79
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 #endif 214 #endif
246 215
247 // Determine type of object and emit deletion log event. 216 // Determine type of object and emit deletion log event.
248 static void ReportDeleteIfNeeded(HeapObject* obj); 217 static void ReportDeleteIfNeeded(HeapObject* obj);
249 218
250 // Distinguishable invalid map encodings (for single word and multiple words) 219 // Distinguishable invalid map encodings (for single word and multiple words)
251 // that indicate free regions. 220 // that indicate free regions.
252 static const uint32_t kSingleFreeEncoding = 0; 221 static const uint32_t kSingleFreeEncoding = 0;
253 static const uint32_t kMultiFreeEncoding = 1; 222 static const uint32_t kMultiFreeEncoding = 1;
254 223
224 #ifdef DEBUG
225 static bool IsMarked(Object* obj) {
226 ASSERT(obj->IsHeapObject());
227 HeapObject* heap_object = HeapObject::cast(obj);
228 return Marking::MarkBitFrom(heap_object).Get();
229 }
230 #endif
231
255 private: 232 private:
256 #ifdef DEBUG 233 #ifdef DEBUG
257 enum CollectorState { 234 enum CollectorState {
258 IDLE, 235 IDLE,
259 PREPARE_GC, 236 PREPARE_GC,
260 MARK_LIVE_OBJECTS, 237 MARK_LIVE_OBJECTS,
261 SWEEP_SPACES, 238 SWEEP_SPACES,
262 ENCODE_FORWARDING_ADDRESSES, 239 ENCODE_FORWARDING_ADDRESSES,
263 UPDATE_POINTERS, 240 UPDATE_POINTERS,
264 RELOCATE_OBJECTS 241 RELOCATE_OBJECTS
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 friend class SharedFunctionInfoMarkingVisitor; 282 friend class SharedFunctionInfoMarkingVisitor;
306 283
307 static void PrepareForCodeFlushing(); 284 static void PrepareForCodeFlushing();
308 285
309 // Marking operations for objects reachable from roots. 286 // Marking operations for objects reachable from roots.
310 static void MarkLiveObjects(); 287 static void MarkLiveObjects();
311 288
312 static void AfterMarking(); 289 static void AfterMarking();
313 290
314 291
315 INLINE(static void MarkObject(HeapObject* obj)) { 292 INLINE(static void MarkObject(HeapObject* obj, MarkBit mark_bit)) {
316 if (!Marking::TestAndMark(obj->address())) { 293 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
294 if (!mark_bit.Get()) {
295 mark_bit.Set();
317 tracer_->increment_marked_count(); 296 tracer_->increment_marked_count();
318 #ifdef DEBUG 297 #ifdef DEBUG
319 UpdateLiveObjectCount(obj); 298 UpdateLiveObjectCount(obj);
320 #endif 299 #endif
321 ProcessNewlyMarkedObject(obj); 300 ProcessNewlyMarkedObject(obj);
322 } 301 }
323 } 302 }
324 303
325 INLINE(static void SetMark(HeapObject* obj)) { 304 INLINE(static void SetMark(HeapObject* obj, MarkBit mark_bit)) {
326 Marking::SetMark(obj); 305 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
306 mark_bit.Set();
327 tracer_->increment_marked_count(); 307 tracer_->increment_marked_count();
328 #ifdef DEBUG 308 #ifdef DEBUG
329 UpdateLiveObjectCount(obj); 309 UpdateLiveObjectCount(obj);
330 #endif 310 #endif
331 } 311 }
332 312
333 static void ProcessNewlyMarkedObject(HeapObject* obj); 313 static void ProcessNewlyMarkedObject(HeapObject* obj);
334 314
335 // Creates back pointers for all map transitions, stores them in 315 // Creates back pointers for all map transitions, stores them in
336 // the prototype field. The original prototype pointers are restored 316 // the prototype field. The original prototype pointers are restored
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 437
458 friend class UnmarkObjectVisitor; 438 friend class UnmarkObjectVisitor;
459 static void UnmarkObject(HeapObject* obj); 439 static void UnmarkObject(HeapObject* obj);
460 #endif 440 #endif
461 }; 441 };
462 442
463 443
464 } } // namespace v8::internal 444 } } // namespace v8::internal
465 445
466 #endif // V8_MARK_COMPACT_H_ 446 #endif // V8_MARK_COMPACT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698