v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
local-handles-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_HANDLES_LOCAL_HANDLES_INL_H_
6#define V8_HANDLES_LOCAL_HANDLES_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
14
15namespace v8 {
16namespace internal {
17
18// static
20 Address value) {
21 DCHECK(local_heap->IsRunning());
22 if (local_heap->is_main_thread())
23 return LocalHandleScope::GetMainThreadHandle(local_heap, value);
24
25 LocalHandles* handles = local_heap->handles();
26 Address* result = handles->scope_.next;
27 if (result == handles->scope_.limit) {
28 result = handles->AddBlock();
29 }
30 DCHECK_LT(result, handles->scope_.limit);
31 handles->scope_.next++;
32 *result = value;
33 return result;
34}
35
37 : LocalHandleScope(local_isolate->heap()) {}
38
40 DCHECK(local_heap->IsRunning());
41
42 if (local_heap->is_main_thread()) {
43 OpenMainThreadScope(local_heap);
44 } else {
45 LocalHandles* handles = local_heap->handles();
46 local_heap_ = local_heap;
47 prev_next_ = handles->scope_.next;
48 prev_limit_ = handles->scope_.limit;
49 handles->scope_.level++;
50 }
51}
52
55#ifdef V8_ENABLE_CHECKS
56 VerifyMainThreadScope();
57#endif
59 } else {
61 }
62}
63
64template <typename T, template <typename> typename HandleType>
65 requires(std::is_convertible_v<HandleType<T>, DirectHandle<T>>)
66HandleType<T> LocalHandleScope::CloseAndEscape(HandleType<T> handle_value) {
68 Tagged<T> value = *handle_value;
69 // Throw away all handles in the current scope.
70 if (local_heap_->is_main_thread()) {
71#ifdef V8_ENABLE_CHECKS
72 VerifyMainThreadScope();
73#endif
74 current = local_heap_->heap()->isolate()->handle_scope_data();
75 CloseMainThreadScope(local_heap_, prev_next_, prev_limit_);
76 } else {
77 current = &local_heap_->handles()->scope_;
78 CloseScope(local_heap_, prev_next_, prev_limit_);
79 }
80 // Allocate one handle in the parent scope.
81 DCHECK(current->level > current->sealed_level);
82 HandleType<T> result(value, local_heap_);
83 // Reinitialize the current scope (so that it's ready
84 // to be used or closed again).
85 prev_next_ = current->next;
86 prev_limit_ = current->limit;
87 current->level++;
88 return result;
89}
90
91void LocalHandleScope::CloseScope(LocalHeap* local_heap, Address* prev_next,
92 Address* prev_limit) {
93 LocalHandles* handles = local_heap->handles();
94 Address* old_limit = handles->scope_.limit;
95
96 handles->scope_.next = prev_next;
97 handles->scope_.limit = prev_limit;
98 handles->scope_.level--;
99
100 if (old_limit != handles->scope_.limit) {
101 handles->RemoveUnusedBlocks();
102 old_limit = handles->scope_.limit;
103 }
104
105#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
106 LocalHandles::ZapRange(handles->scope_.next, old_limit);
107#endif
108
110 handles->scope_.next,
111 static_cast<size_t>(reinterpret_cast<Address>(old_limit) -
112 reinterpret_cast<Address>(handles->scope_.next)));
113}
114
115} // namespace internal
116} // namespace v8
117
118#endif // V8_HANDLES_LOCAL_HANDLES_INL_H_
V8_EXPORT_PRIVATE void OpenMainThreadScope(LocalHeap *local_heap)
LocalHandleScope(LocalIsolate *local_isolate)
static V8_EXPORT_PRIVATE void CloseMainThreadScope(LocalHeap *local_heap, Address *prev_next, Address *prev_limit)
static V8_EXPORT_PRIVATE Address * GetMainThreadHandle(LocalHeap *local_heap, Address value)
HandleType< T > CloseAndEscape(HandleType< T > handle_value)
static void CloseScope(LocalHeap *local_heap, Address *prev_next, Address *prev_limit)
static V8_INLINE Address * GetHandle(LocalHeap *local_heap, Address value)
LocalHandles * handles()
Definition local-heap.h:70
bool is_main_thread() const
Definition local-heap.h:194
LineAndColumn current
ZoneVector< RpoNumber > & result
#define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size)
Definition msan.h:29
return value
Definition map-inl.h:893
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define V8_INLINE
Definition v8config.h:500