blob: f99c09a1e6857a45f0e4a92953cf388032197598 [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_INCREMENTAL_MARKING_INL_H_
29#define V8_INCREMENTAL_MARKING_INL_H_
30
31#include "incremental-marking.h"
32
33namespace v8 {
34namespace internal {
35
36
37bool IncrementalMarking::BaseRecordWrite(HeapObject* obj,
38 Object** slot,
39 Object* value) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000040 MarkBit value_bit = Marking::MarkBitFrom(HeapObject::cast(value));
41 if (Marking::IsWhite(value_bit)) {
42 MarkBit obj_bit = Marking::MarkBitFrom(obj);
43 if (Marking::IsBlack(obj_bit)) {
44 BlackToGreyAndUnshift(obj, obj_bit);
45 RestartIfNotMarking();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000046 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000047
48 // Object is either grey or white. It will be scanned if survives.
49 return false;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000050 }
ulan@chromium.org56c14af2012-09-20 12:51:09 +000051 if (!is_compacting_) return false;
52 MarkBit obj_bit = Marking::MarkBitFrom(obj);
53 return Marking::IsBlack(obj_bit);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000054}
55
56
57void IncrementalMarking::RecordWrite(HeapObject* obj,
58 Object** slot,
59 Object* value) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000060 if (IsMarking() && value->NonFailureIsHeapObject()) {
61 RecordWriteSlow(obj, slot, value);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000062 }
63}
64
65
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000066void IncrementalMarking::RecordWriteOfCodeEntry(JSFunction* host,
67 Object** slot,
68 Code* value) {
69 if (IsMarking()) RecordWriteOfCodeEntrySlow(host, slot, value);
70}
71
72
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000073void IncrementalMarking::RecordWriteIntoCode(HeapObject* obj,
74 RelocInfo* rinfo,
75 Object* value) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000076 if (IsMarking() && value->NonFailureIsHeapObject()) {
77 RecordWriteIntoCodeSlow(obj, rinfo, value);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000078 }
79}
80
81
82void IncrementalMarking::RecordWrites(HeapObject* obj) {
83 if (IsMarking()) {
84 MarkBit obj_bit = Marking::MarkBitFrom(obj);
85 if (Marking::IsBlack(obj_bit)) {
86 BlackToGreyAndUnshift(obj, obj_bit);
87 RestartIfNotMarking();
88 }
89 }
90}
91
92
93void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj,
94 MarkBit mark_bit) {
95 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
96 ASSERT(obj->Size() >= 2*kPointerSize);
97 ASSERT(IsMarking());
98 Marking::BlackToGrey(mark_bit);
99 int obj_size = obj->Size();
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000100 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), -obj_size);
danno@chromium.orgc612e022011-11-10 11:38:15 +0000101 bytes_scanned_ -= obj_size;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000102 int64_t old_bytes_rescanned = bytes_rescanned_;
103 bytes_rescanned_ = old_bytes_rescanned + obj_size;
104 if ((bytes_rescanned_ >> 20) != (old_bytes_rescanned >> 20)) {
jkummerow@chromium.org212d9642012-05-11 15:02:09 +0000105 if (bytes_rescanned_ > 2 * heap_->PromotedSpaceSizeOfObjects()) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000106 // If we have queued twice the heap size for rescanning then we are
107 // going around in circles, scanning the same objects again and again
108 // as the program mutates the heap faster than we can incrementally
109 // trace it. In this case we switch to non-incremental marking in
110 // order to finish off this marking phase.
111 if (FLAG_trace_gc) {
rossberg@chromium.org657d53b2012-07-12 11:06:03 +0000112 PrintPID("Hurrying incremental marking because of lack of progress\n");
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000113 }
114 allocation_marking_factor_ = kMaxAllocationMarkingFactor;
115 }
116 }
117
118 marking_deque_.UnshiftGrey(obj);
119}
120
121
122void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) {
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +0000123 Marking::WhiteToGrey(mark_bit);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000124 marking_deque_.PushGrey(obj);
125}
126
127
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000128} } // namespace v8::internal
129
130#endif // V8_INCREMENTAL_MARKING_INL_H_