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
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.
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.
28
#ifndef V8_INCREMENTAL_MARKING_INL_H_
29
#define V8_INCREMENTAL_MARKING_INL_H_
31
#include "incremental-marking.h"
37
bool IncrementalMarking::BaseRecordWrite(HeapObject* obj,
40
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();
48
// Object is either grey or white. It will be scanned if survives.
51
if (!is_compacting_) return false;
52
MarkBit obj_bit = Marking::MarkBitFrom(obj);
53
return Marking::IsBlack(obj_bit);
57
void IncrementalMarking::RecordWrite(HeapObject* obj,
60
if (IsMarking() && value->NonFailureIsHeapObject()) {
61
RecordWriteSlow(obj, slot, value);
66
void IncrementalMarking::RecordWriteOfCodeEntry(JSFunction* host,
69
if (IsMarking()) RecordWriteOfCodeEntrySlow(host, slot, value);
73
void IncrementalMarking::RecordWriteIntoCode(HeapObject* obj,
76
if (IsMarking() && value->NonFailureIsHeapObject()) {
77
RecordWriteIntoCodeSlow(obj, rinfo, value);
82
void IncrementalMarking::RecordWrites(HeapObject* obj) {
84
MarkBit obj_bit = Marking::MarkBitFrom(obj);
85
if (Marking::IsBlack(obj_bit)) {
86
BlackToGreyAndUnshift(obj, obj_bit);
87
RestartIfNotMarking();
93
void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj,
95
ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
96
ASSERT(obj->Size() >= 2*kPointerSize);
98
Marking::BlackToGrey(mark_bit);
99
int obj_size = obj->Size();
100
MemoryChunk::IncrementLiveBytesFromGC(obj->address(), -obj_size);
101
bytes_scanned_ -= obj_size;
102
int64_t old_bytes_rescanned = bytes_rescanned_;
103
bytes_rescanned_ = old_bytes_rescanned + obj_size;
104
if ((bytes_rescanned_ >> 20) != (old_bytes_rescanned >> 20)) {
105
if (bytes_rescanned_ > 2 * heap_->PromotedSpaceSizeOfObjects()) {
106
// 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.
112
PrintPID("Hurrying incremental marking because of lack of progress\n");
114
marking_speed_ = kMaxMarkingSpeed;
118
marking_deque_.UnshiftGrey(obj);
122
void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) {
123
Marking::WhiteToGrey(mark_bit);
124
marking_deque_.PushGrey(obj);
128
} } // namespace v8::internal
130
#endif // V8_INCREMENTAL_MARKING_INL_H_