v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
casting-inl.h
Go to the documentation of this file.
1// Copyright 2024 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_OBJECTS_CASTING_INL_H_
6#define V8_OBJECTS_CASTING_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/common/globals.h"
14#include "src/heap/heap.h"
16
17namespace v8::internal {
18
19#ifdef DEBUG
20template <typename T>
21bool GCAwareObjectTypeCheck(Tagged<Object> object, const Heap* heap) {
23 // `heap_object` must be of type `T`. One of 4 cases can apply:
24 // 1) A scavenger is ongoing and `object` is a promoted large object.
25 if ((heap->gc_state() == Heap::SCAVENGE) &&
27 return true;
28 }
29 // 2) A conservative scavenge is ongoing and `object` was pinned by
30 // conservative stack scanning.
31 MapWord map_word = heap_object->map_word(
32 PtrComprCageBase(heap->isolate()->cage_base()), kRelaxedLoad);
33 if ((heap->gc_state() == Heap::SCAVENGE) &&
34 HeapLayout::InYoungGeneration(heap_object) &&
35 (v8_flags.scavenger_conservative_object_pinning ||
36 v8_flags.scavenger_precise_object_pinning) &&
37 map_word.IsForwardingAddress() &&
38 HeapLayout::IsSelfForwarded(heap_object)) {
39 return true;
40 }
41 // 3) A GC is ongoing, `object` was evacuated, and the new instance is a
42 // `T`.
43 if (heap->IsInGC() && map_word.IsForwardingAddress() &&
44 Is<T>(map_word.ToForwardingAddress(heap_object))) {
45 return true;
46 }
47 // 4) If none of the above special cases apply, `heap_object` must be a `T`.
48 return Is<T>(object);
49}
50#endif // DEBUG
51
52} // namespace v8::internal
53
54#endif // V8_OBJECTS_CASTING_INL_H_
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
static bool IsSelfForwarded(Tagged< HeapObject > object)
static V8_INLINE MemoryChunk * FromHeapObject(Tagged< HeapObject > object)
bool Is(IndirectHandle< U > value)
Definition handles-inl.h:51
kInterpreterTrampolineOffset Tagged< HeapObject >
Handle< To > UncheckedCast(Handle< From > value)
Definition handles-inl.h:55
V8_EXPORT_PRIVATE FlagValues v8_flags
static constexpr RelaxedLoadTag kRelaxedLoad
Definition globals.h:2909