11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_HEAP_MARKING_BARRIER_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_HEAP_MARKING_BARRIER_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/heap/incremental-marking-inl.h" 91cb0ef41Sopenharmony_ci#include "src/heap/incremental-marking.h" 101cb0ef41Sopenharmony_ci#include "src/heap/marking-barrier.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinamespace v8 { 131cb0ef41Sopenharmony_cinamespace internal { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cibool MarkingBarrier::MarkValue(HeapObject host, HeapObject value) { 161cb0ef41Sopenharmony_ci DCHECK(IsCurrentMarkingBarrier()); 171cb0ef41Sopenharmony_ci DCHECK(is_activated_); 181cb0ef41Sopenharmony_ci DCHECK(!marking_state_.IsImpossible(value)); 191cb0ef41Sopenharmony_ci // Host may have an impossible markbit pattern if manual allocation folding 201cb0ef41Sopenharmony_ci // is performed and host happens to be the last word of an allocated region. 211cb0ef41Sopenharmony_ci // In that case host has only one markbit and the second markbit belongs to 221cb0ef41Sopenharmony_ci // another object. We can detect that case by checking if value is a one word 231cb0ef41Sopenharmony_ci // filler map. 241cb0ef41Sopenharmony_ci DCHECK(!marking_state_.IsImpossible(host) || 251cb0ef41Sopenharmony_ci value == ReadOnlyRoots(heap_->isolate()).one_pointer_filler_map()); 261cb0ef41Sopenharmony_ci if (!V8_CONCURRENT_MARKING_BOOL && !marking_state_.IsBlack(host)) { 271cb0ef41Sopenharmony_ci // The value will be marked and the slot will be recorded when the marker 281cb0ef41Sopenharmony_ci // visits the host object. 291cb0ef41Sopenharmony_ci return false; 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci BasicMemoryChunk* target_page = BasicMemoryChunk::FromHeapObject(value); 321cb0ef41Sopenharmony_ci if (is_shared_heap_ != target_page->InSharedHeap()) return false; 331cb0ef41Sopenharmony_ci if (WhiteToGreyAndPush(value)) { 341cb0ef41Sopenharmony_ci if (is_main_thread_barrier_) { 351cb0ef41Sopenharmony_ci incremental_marking_->RestartIfNotMarking(); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci if (V8_UNLIKELY(FLAG_track_retaining_path)) { 391cb0ef41Sopenharmony_ci heap_->AddRetainingRoot(Root::kWriteBarrier, value); 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci return true; 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_citemplate <typename TSlot> 461cb0ef41Sopenharmony_ciinline void MarkingBarrier::MarkRange(HeapObject host, TSlot start, TSlot end) { 471cb0ef41Sopenharmony_ci auto* isolate = heap_->isolate(); 481cb0ef41Sopenharmony_ci for (TSlot slot = start; slot < end; ++slot) { 491cb0ef41Sopenharmony_ci typename TSlot::TObject object = slot.Relaxed_Load(); 501cb0ef41Sopenharmony_ci HeapObject heap_object; 511cb0ef41Sopenharmony_ci // Mark both, weak and strong edges. 521cb0ef41Sopenharmony_ci if (object.GetHeapObject(isolate, &heap_object)) { 531cb0ef41Sopenharmony_ci if (MarkValue(host, heap_object) && is_compacting_) { 541cb0ef41Sopenharmony_ci collector_->RecordSlot(host, HeapObjectSlot(slot), heap_object); 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci} 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_cibool MarkingBarrier::WhiteToGreyAndPush(HeapObject obj) { 611cb0ef41Sopenharmony_ci if (marking_state_.WhiteToGrey(obj)) { 621cb0ef41Sopenharmony_ci worklist_.Push(obj); 631cb0ef41Sopenharmony_ci return true; 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci return false; 661cb0ef41Sopenharmony_ci} 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci} // namespace internal 691cb0ef41Sopenharmony_ci} // namespace v8 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci#endif // V8_HEAP_MARKING_BARRIER_INL_H_ 72