incremental-marking-inl.h 2.11 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_HEAP_INCREMENTAL_MARKING_INL_H_
#define V8_HEAP_INCREMENTAL_MARKING_INL_H_
7

8
#include "src/heap/incremental-marking.h"
9 10

#include "src/heap/mark-compact-inl.h"
11
#include "src/isolate.h"
12
#include "src/objects-inl.h"
13
#include "src/objects/maybe-object.h"
14 15 16 17

namespace v8 {
namespace internal {

18
void IncrementalMarking::TransferColor(HeapObject from, HeapObject to) {
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  if (atomic_marking_state()->IsBlack(to)) {
    DCHECK(black_allocation());
    return;
  }

  DCHECK(atomic_marking_state()->IsWhite(to));
  if (atomic_marking_state()->IsGrey(from)) {
    bool success = atomic_marking_state()->WhiteToGrey(to);
    DCHECK(success);
    USE(success);
  } else if (atomic_marking_state()->IsBlack(from)) {
    bool success = atomic_marking_state()->WhiteToBlack(to);
    DCHECK(success);
    USE(success);
  }
}
35

36
void IncrementalMarking::RecordWrite(HeapObject obj, ObjectSlot slot,
37
                                     Object value) {
38
  DCHECK_IMPLIES(slot.address() != kNullAddress, !HasWeakHeapObjectTag(*slot));
39
  DCHECK(!HasWeakHeapObjectTag(value));
40
  if (IsMarking() && value->IsHeapObject()) {
41
    RecordWriteSlow(obj, HeapObjectSlot(slot), HeapObject::cast(value));
42
  }
43 44
}

45
void IncrementalMarking::RecordMaybeWeakWrite(HeapObject obj,
46
                                              MaybeObjectSlot slot,
47
                                              MaybeObject value) {
48 49
  // When writing a weak reference, treat it as strong for the purposes of the
  // marking barrier.
50
  HeapObject heap_object;
51
  if (IsMarking() && value->GetHeapObject(&heap_object)) {
52
    RecordWriteSlow(obj, HeapObjectSlot(slot), heap_object);
53 54 55
  }
}

56 57 58 59 60 61 62 63 64
void IncrementalMarking::RestartIfNotMarking() {
  if (state_ == COMPLETE) {
    state_ = MARKING;
    if (FLAG_trace_incremental_marking) {
      heap()->isolate()->PrintWithTimestamp(
          "[IncrementalMarking] Restarting (new grey objects)\n");
    }
  }
}
65

66 67
}  // namespace internal
}  // namespace v8
68

69
#endif  // V8_HEAP_INCREMENTAL_MARKING_INL_H_