1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_HEAP_INCREMENTAL_MARKING_INL_H_
6 #define V8_HEAP_INCREMENTAL_MARKING_INL_H_
7
8 #include "src/heap/incremental-marking.h"
9 #include "src/isolate.h"
10 #include "src/objects-inl.h"
11 #include "src/objects/maybe-object.h"
12
13 namespace v8 {
14 namespace internal {
15
16
RecordWrite(HeapObject * obj,Object ** slot,Object * value)17 void IncrementalMarking::RecordWrite(HeapObject* obj, Object** slot,
18 Object* value) {
19 DCHECK_IMPLIES(slot != nullptr, !HasWeakHeapObjectTag(*slot));
20 DCHECK(!HasWeakHeapObjectTag(value));
21 if (IsMarking() && value->IsHeapObject()) {
22 RecordWriteSlow(obj, reinterpret_cast<HeapObjectReference**>(slot),
23 HeapObject::cast(value));
24 }
25 }
26
RecordMaybeWeakWrite(HeapObject * obj,MaybeObject ** slot,MaybeObject * value)27 void IncrementalMarking::RecordMaybeWeakWrite(HeapObject* obj,
28 MaybeObject** slot,
29 MaybeObject* value) {
30 // When writing a weak reference, treat it as strong for the purposes of the
31 // marking barrier.
32 HeapObject* heap_object;
33 if (IsMarking() && value->ToStrongOrWeakHeapObject(&heap_object)) {
34 RecordWriteSlow(obj, reinterpret_cast<HeapObjectReference**>(slot),
35 heap_object);
36 }
37 }
38
RestartIfNotMarking()39 void IncrementalMarking::RestartIfNotMarking() {
40 if (state_ == COMPLETE) {
41 state_ = MARKING;
42 if (FLAG_trace_incremental_marking) {
43 heap()->isolate()->PrintWithTimestamp(
44 "[IncrementalMarking] Restarting (new grey objects)\n");
45 }
46 }
47 }
48
49 } // namespace internal
50 } // namespace v8
51
52 #endif // V8_HEAP_INCREMENTAL_MARKING_INL_H_
53