blob: 10773e7202a3ee124cdd8d290411509dd32c7778 [file] [log] [blame]
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +00001// Copyright 2012 the V8 project authors. All rights reserved.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002// 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
36namespace v8 {
37namespace internal {
38
39
40MarkBit Marking::MarkBitFrom(Address addr) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000041 MemoryChunk* p = MemoryChunk::FromAddress(addr);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000042 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr),
43 p->ContainsOnlyData());
44}
45
46
47void MarkCompactCollector::SetFlags(int flags) {
erik.corry@gmail.combbceb572012-03-09 10:52:05 +000048 sweep_precisely_ = ((flags & Heap::kSweepPreciselyMask) != 0);
rossberg@chromium.org994edf62012-02-06 10:12:55 +000049 reduce_memory_footprint_ = ((flags & Heap::kReduceMemoryFootprintMask) != 0);
erik.corry@gmail.combbceb572012-03-09 10:52:05 +000050 abort_incremental_marking_ =
51 ((flags & Heap::kAbortIncrementalMarkingMask) != 0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000052}
53
54
55void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
56 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
57 if (!mark_bit.Get()) {
58 mark_bit.Set();
ulan@chromium.org2efb9002012-01-19 15:36:35 +000059 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000060 ASSERT(IsMarked(obj));
61 ASSERT(HEAP->Contains(obj));
62 marking_deque_.PushBlack(obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000063 }
64}
65
66
67void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) {
68 ASSERT(!mark_bit.Get());
69 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
70 mark_bit.Set();
ulan@chromium.org2efb9002012-01-19 15:36:35 +000071 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000072}
73
74
75bool MarkCompactCollector::IsMarked(Object* obj) {
76 ASSERT(obj->IsHeapObject());
77 HeapObject* heap_object = HeapObject::cast(obj);
78 return Marking::MarkBitFrom(heap_object).Get();
79}
80
81
82void MarkCompactCollector::RecordSlot(Object** anchor_slot,
83 Object** slot,
84 Object* object) {
85 Page* object_page = Page::FromAddress(reinterpret_cast<Address>(object));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000086 if (object_page->IsEvacuationCandidate() &&
87 !ShouldSkipEvacuationSlotRecording(anchor_slot)) {
88 if (!SlotsBuffer::AddTo(&slots_buffer_allocator_,
89 object_page->slots_buffer_address(),
90 slot,
91 SlotsBuffer::FAIL_ON_OVERFLOW)) {
92 EvictEvacuationCandidate(object_page);
93 }
94 }
95}
96
97
98} } // namespace v8::internal
99
100#endif // V8_MARK_COMPACT_INL_H_