marking-barrier-inl.h 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_MARKING_BARRIER_INL_H_
#define V8_HEAP_MARKING_BARRIER_INL_H_

#include "src/heap/incremental-marking-inl.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/marking-barrier.h"

namespace v8 {
namespace internal {

bool MarkingBarrier::MarkValue(HeapObject host, HeapObject value) {
16
  DCHECK(IsCurrentMarkingBarrier());
17 18
  DCHECK(is_activated_);
  DCHECK(!marking_state_.IsImpossible(value));
19 20 21 22 23 24 25
  // Host may have an impossible markbit pattern if manual allocation folding
  // is performed and host happens to be the last word of an allocated region.
  // In that case host has only one markbit and the second markbit belongs to
  // another object. We can detect that case by checking if value is a one word
  // filler map.
  DCHECK(!marking_state_.IsImpossible(host) ||
         value == ReadOnlyRoots(heap_->isolate()).one_pointer_filler_map());
26
  if (!V8_CONCURRENT_MARKING_BOOL && !marking_state_.IsBlack(host)) {
27 28 29 30
    // The value will be marked and the slot will be recorded when the marker
    // visits the host object.
    return false;
  }
31 32
  BasicMemoryChunk* target_page = BasicMemoryChunk::FromHeapObject(value);
  if (is_shared_heap_ != target_page->InSharedHeap()) return false;
33 34 35 36 37 38 39 40
  if (WhiteToGreyAndPush(value)) {
    if (is_main_thread_barrier_) {
      incremental_marking_->RestartIfNotMarking();
    }

    if (V8_UNLIKELY(FLAG_track_retaining_path)) {
      heap_->AddRetainingRoot(Root::kWriteBarrier, value);
    }
41 42 43 44
  }
  return true;
}

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
template <typename TSlot>
inline void MarkingBarrier::MarkRange(HeapObject host, TSlot start, TSlot end) {
  auto* isolate = heap_->isolate();
  for (TSlot slot = start; slot < end; ++slot) {
    typename TSlot::TObject object = slot.Relaxed_Load();
    HeapObject heap_object;
    // Mark both, weak and strong edges.
    if (object.GetHeapObject(isolate, &heap_object)) {
      if (MarkValue(host, heap_object) && is_compacting_) {
        collector_->RecordSlot(host, HeapObjectSlot(slot), heap_object);
      }
    }
  }
}

60 61
bool MarkingBarrier::WhiteToGreyAndPush(HeapObject obj) {
  if (marking_state_.WhiteToGrey(obj)) {
62
    worklist_.Push(obj);
63 64 65 66 67 68 69 70 71
    return true;
  }
  return false;
}

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_MARKING_BARRIER_INL_H_