v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mark-compact-inl.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_MARK_COMPACT_INL_H_
29 #define V8_MARK_COMPACT_INL_H_
30 
31 #include "isolate.h"
32 #include "memory.h"
33 #include "mark-compact.h"
34 
35 
36 namespace v8 {
37 namespace internal {
38 
39 
42  return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr),
43  p->ContainsOnlyData());
44 }
45 
46 
48  sweep_precisely_ = ((flags & Heap::kSweepPreciselyMask) != 0);
49  reduce_memory_footprint_ = ((flags & Heap::kReduceMemoryFootprintMask) != 0);
50  abort_incremental_marking_ =
51  ((flags & Heap::kAbortIncrementalMarkingMask) != 0);
52 }
53 
54 
55 bool MarkCompactCollector::MarkObjectAndPush(HeapObject* obj) {
56  if (MarkObjectWithoutPush(obj)) {
57  marking_deque_.PushBlack(obj);
58  return true;
59  }
60  return false;
61 }
62 
63 
64 void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
65  ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
66  if (!mark_bit.Get()) {
67  mark_bit.Set();
68  MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
69  ProcessNewlyMarkedObject(obj);
70  }
71 }
72 
73 
74 bool MarkCompactCollector::MarkObjectWithoutPush(HeapObject* obj) {
75  MarkBit mark_bit = Marking::MarkBitFrom(obj);
76  if (!mark_bit.Get()) {
77  SetMark(obj, mark_bit);
78  return true;
79  }
80  return false;
81 }
82 
83 
84 void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) {
85  ASSERT(!mark_bit.Get());
86  ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
87  mark_bit.Set();
88  MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
89  if (obj->IsMap()) {
90  heap_->ClearCacheOnMap(Map::cast(obj));
91  }
92 }
93 
94 
96  ASSERT(obj->IsHeapObject());
97  HeapObject* heap_object = HeapObject::cast(obj);
98  return Marking::MarkBitFrom(heap_object).Get();
99 }
100 
101 
102 void MarkCompactCollector::RecordSlot(Object** anchor_slot,
103  Object** slot,
104  Object* object) {
105  Page* object_page = Page::FromAddress(reinterpret_cast<Address>(object));
106  if (object_page->IsEvacuationCandidate() &&
107  !ShouldSkipEvacuationSlotRecording(anchor_slot)) {
108  if (!SlotsBuffer::AddTo(&slots_buffer_allocator_,
109  object_page->slots_buffer_address(),
110  slot,
112  EvictEvacuationCandidate(object_page);
113  }
114  }
115 }
116 
117 
118 } } // namespace v8::internal
119 
120 #endif // V8_MARK_COMPACT_INL_H_
byte * Address
Definition: globals.h:172
static MemoryChunk * FromAddress(Address a)
Definition: spaces.h:304
static HeapObject * cast(Object *obj)
static Map * cast(Object *obj)
Flag flags[]
Definition: flags.cc:1467
#define ASSERT(condition)
Definition: checks.h:270
static void IncrementLiveBytesFromGC(Address address, int by)
Definition: spaces.h:471
static const int kReduceMemoryFootprintMask
Definition: heap.h:1051
static MarkBit MarkBitFrom(Address addr)
static bool IsMarked(Object *obj)
void ClearCacheOnMap(Map *map)
Definition: heap.h:1487
void PushBlack(HeapObject *object)
Definition: mark-compact.h:197
static const int kAbortIncrementalMarkingMask
Definition: heap.h:1052
SlotsBuffer ** slots_buffer_address()
Definition: spaces.h:584
bool IsEvacuationCandidate()
Definition: spaces.h:566
void EvictEvacuationCandidate(Page *page)
Definition: mark-compact.h:533
MarkBit MarkBitFromIndex(uint32_t index, bool data_only=false)
Definition: spaces.h:218
static const int kSweepPreciselyMask
Definition: heap.h:1050
uint32_t AddressToMarkbitIndex(Address addr)
Definition: spaces.h:544
static bool AddTo(SlotsBufferAllocator *allocator, SlotsBuffer **buffer_address, ObjectSlot slot, AdditionMode mode)
Definition: mark-compact.h:349