v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
traced-handles-inl.h
Go to the documentation of this file.
1// Copyright 2023 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_HANDLES_TRACED_HANDLES_INL_H_
6#define V8_HANDLES_TRACED_HANDLES_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
14
15namespace v8::internal {
16
20 auto* node = at(first_free_node_);
21 first_free_node_ = node->next_free();
22 used_++;
23 DCHECK(!node->is_in_use());
24 return node;
25}
26
27std::pair<TracedNodeBlock*, TracedNode*> TracedHandles::AllocateNode() {
30 }
32 auto* node = block->AllocateNode();
33 DCHECK(node->IsMetadataCleared());
34 if (V8_UNLIKELY(block->IsFull())) {
36 }
38 return std::make_pair(block, node);
39}
40
42 TracedNode* node) const {
43 DCHECK(!node->is_in_young_list());
44 return HeapLayout::InYoungGeneration(object);
45}
46
48 // TODO(v8:13475) Consider removing this check when unified-young-gen becomes
49 // default.
50 if (!v8_flags.cppgc_young_generation) return nullptr;
51 auto* cpp_heap = CppHeap::From(isolate->heap()->cpp_heap());
52 if (cpp_heap && cpp_heap->generational_gc_supported()) return cpp_heap;
53 return nullptr;
54}
55
56bool TracedHandles::IsCppGCHostOld(CppHeap& cpp_heap, Address host) const {
57 DCHECK(host);
59 auto* host_ptr = reinterpret_cast<void*>(host);
60 auto* page = cppgc::internal::BasePage::FromInnerAddress(&cpp_heap, host_ptr);
61 // TracedReference may be created on stack, in which case assume it's young
62 // and doesn't need to be remembered, since it'll anyway be scanned.
63 if (!page) return false;
64 return !page->ObjectHeaderFromInnerAddress(host_ptr).IsYoung();
65}
66
68 Tagged<Object> object, TracedNode* node, Address* slot,
69 TracedReferenceStoreMode store_mode) const {
70 DCHECK(!node->has_old_host());
71
72 auto* cpp_heap = GetCppHeapIfUnifiedYoungGC(isolate_);
73 if (!cpp_heap) {
74 return false;
75 }
77 // Don't record initializing stores.
78 return false;
79 }
80 if (is_marking_) {
81 // If marking is in progress, the marking barrier will be issued later.
82 return false;
83 }
84 if (!HeapLayout::InYoungGeneration(object)) {
85 return false;
86 }
87 return IsCppGCHostOld(*cpp_heap, reinterpret_cast<Address>(slot));
88}
89
90// Publishes all internal state to be consumed by other threads.
92 bool needs_young_bit_update,
93 bool needs_black_allocation,
94 bool has_old_host, bool is_droppable_value) {
96
97 flags_ = needs_young_bit_update << IsInYoungList::kShift |
99 is_droppable_value << IsDroppable::kShift | 1 << IsInUse::kShift;
100 if (needs_black_allocation) set_markbit();
101 reinterpret_cast<std::atomic<Address>*>(&object_)->store(
102 object.ptr(), std::memory_order_release);
103 return FullObjectSlot(&object_);
104}
105
107 Address value, Address* slot, TracedReferenceStoreMode store_mode,
108 TracedReferenceHandling reference_handling) {
109 DCHECK_NOT_NULL(slot);
110 Tagged<Object> object(value);
111 auto [block, node] = AllocateNode();
112 const bool needs_young_bit_update = NeedsTrackingInYoungNodes(object, node);
113 const bool has_old_host = NeedsToBeRemembered(object, node, slot, store_mode);
114 const bool needs_black_allocation =
116 const bool is_droppable =
117 reference_handling == TracedReferenceHandling::kDroppable;
118 auto result_slot =
119 node->Publish(object, needs_young_bit_update, needs_black_allocation,
120 has_old_host, is_droppable);
121 // Write barrier and young node tracking may be reordered, so move them below
122 // `Publish()`.
123 if (needs_young_bit_update && !block->InYoungList()) {
125 DCHECK(block->InYoungList());
127 }
128 if (needs_black_allocation) {
130 }
131#ifdef VERIFY_HEAP
132 if (i::v8_flags.verify_heap) {
133 Object::ObjectVerify(*result_slot, isolate_);
134 }
135#endif // VERIFY_HEAP
136 return result_slot;
137}
138
139} // namespace v8::internal
140
141#endif // V8_HANDLES_TRACED_HANDLES_INL_H_
static BasePage * FromInnerAddress(const HeapBase *, void *)
Definition heap-page.cc:40
bool generational_gc_supported() const
Definition heap-base.h:218
static constexpr int kShift
Definition bit-field.h:39
static CppHeap * From(v8::CppHeap *heap)
Definition cpp-heap.h:102
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
V8_INLINE bool NeedsToBeRemembered(Tagged< Object > value, TracedNode *node, Address *slot, TracedReferenceStoreMode store_mode) const
V8_INLINE bool IsCppGCHostOld(CppHeap &cpp_heap, Address host) const
TracedNodeBlock::YoungList young_blocks_
V8_NOINLINE V8_PRESERVE_MOST void RefillUsableNodeBlocks()
TracedNodeBlock::UsableList usable_blocks_
V8_INLINE bool NeedsTrackingInYoungNodes(Tagged< Object > object, TracedNode *node) const
V8_INLINE CppHeap * GetCppHeapIfUnifiedYoungGC(Isolate *isolate) const
V8_INLINE std::pair< TracedNodeBlock *, TracedNode * > AllocateNode()
V8_INLINE FullObjectSlot Create(Address value, Address *slot, TracedReferenceStoreMode store_mode, TracedReferenceHandling reference_handling)
static constexpr TracedNode::IndexType kInvalidFreeListNodeIndex
TracedNode * at(TracedNode::IndexType index)
V8_INLINE TracedNode * AllocateNode()
TracedNode::IndexType first_free_node_
const TracedNode::IndexType capacity_
TracedNode::IndexType used_
V8_INLINE FullObjectSlot Publish(Tagged< Object > object, bool needs_young_bit_update, bool needs_black_allocation, bool has_old_host, bool is_droppable)
static void MarkingFromTracedHandle(Tagged< Object > value)
Node * node
RpoNumber block
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats store(v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) DEFINE_GENERIC_IMPLICATION(trace_gc_object_stats
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define V8_UNLIKELY(condition)
Definition v8config.h:660