v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
local-heap-inl.h
Go to the documentation of this file.
1// Copyright 2020 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_HEAP_LOCAL_HEAP_INL_H_
6#define V8_HEAP_LOCAL_HEAP_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include <atomic>
12
15#include "src/heap/heap.h"
19#include "src/heap/zapping.h"
20
21namespace v8 {
22namespace internal {
23
24#define ROOT_ACCESSOR(type, name, CamelName) \
25 inline Tagged<type> LocalHeap::name() { return heap()->name(); }
27#undef ROOT_ACCESSOR
28
30 AllocationOrigin origin,
31 AllocationAlignment alignment) {
32 return heap_allocator_.AllocateRaw(size_in_bytes, type, origin, alignment);
33}
34
35template <typename HeapAllocator::AllocationRetryMode mode>
37 AllocationType type,
38 AllocationOrigin origin,
39 AllocationAlignment alignment) {
40 object_size = ALIGN_TO_ALLOCATION_ALIGNMENT(object_size);
41 return heap_allocator_.AllocateRawWith<mode>(object_size, type, origin,
42 alignment);
43}
44
46 AllocationOrigin origin,
47 AllocationAlignment alignment) {
48 return AllocateRawWith<HeapAllocator::kRetryOrFail>(object_size, type, origin,
49 alignment)
50 .address();
51}
52
53template <typename Callback>
55 // This method is given as a callback to the stack trampoline, when the stack
56 // marker has just been set.
57#if defined(V8_ENABLE_DIRECT_HANDLE) && defined(ENABLE_SLOW_DCHECKS)
58 // Reset the number of direct handles that are below the stack marker.
59 // It will be restored before the method returns.
60 DirectHandleBase::ResetNumberOfHandlesScope scope;
61#endif // V8_ENABLE_DIRECT_HANDLE && ENABLE_SLOW_DCHECKS
62 ParkedScope parked(this);
63 // Provide the parked scope as a witness, if the callback expects it.
64 if constexpr (std::is_invocable_v<Callback, const ParkedScope&>) {
65 callback(parked);
66 } else {
67 callback();
68 }
69}
70
71template <typename Callback>
73 if (is_main_thread()) {
74 heap()->stack().SetMarkerAndCallback(callback);
75 } else {
76 heap()->stack().SetMarkerForBackgroundThreadAndCallback(
77 ThreadId::Current().ToInteger(), callback);
78 }
79}
80
81template <typename Callback>
86
87template <typename Callback>
90 heap()->stack().SetMarkerAndCallback(
92}
93
94template <typename Callback>
96 Callback callback) {
98 heap()->stack().SetMarkerForBackgroundThreadAndCallback(
99 ThreadId::Current().ToInteger(),
101}
102
104 if (is_main_thread()) {
105 return heap_->stack().IsMarkerSet();
106 } else {
107 return heap_->stack().IsMarkerSetForBackgroundThread(
108 ThreadId::Current().ToInteger());
109 }
110}
111
112} // namespace internal
113} // namespace v8
114
115#endif // V8_HEAP_LOCAL_HEAP_INL_H_
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult AllocateRaw(int size_in_bytes, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
V8_WARN_UNUSED_RESULT V8_INLINE Tagged< HeapObject > AllocateRawWith(int size, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
V8_EXPORT_PRIVATE::heap::base::Stack & stack()
Definition heap.cc:6057
V8_WARN_UNUSED_RESULT AllocationResult AllocateRaw(int size_in_bytes, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
bool is_main_thread() const
Definition local-heap.h:194
V8_INLINE void ExecuteBackgroundThreadWhileParked(Callback callback)
Tagged< HeapObject > AllocateRawWith(int size_in_bytes, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
V8_INLINE bool is_in_trampoline() const
Heap * heap() const
Definition local-heap.h:122
V8_INLINE void ParkAndExecuteCallback(Callback callback)
V8_INLINE void ExecuteWhileParked(Callback callback)
HeapAllocator heap_allocator_
Definition local-heap.h:400
V8_INLINE void ExecuteMainThreadWhileParked(Callback callback)
V8_WARN_UNUSED_RESULT Address AllocateRawOrFail(int size_in_bytes, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
V8_INLINE void ExecuteWithStackMarker(Callback callback)
static ThreadId Current()
Definition thread-id.h:32
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
#define ROOT_ACCESSOR(Type, name, CamelName)
TNode< Object > callback
#define MUTABLE_ROOT_LIST(V)
Definition roots.h:483
#define DCHECK(condition)
Definition logging.h:482
#define V8_INLINE
Definition v8config.h:500
wasm::ValueType type