v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
local-handles.h
Go to the documentation of this file.
1// Copyright 2011 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_H_
6#define V8_HANDLES_LOCAL_HANDLES_H_
7
9#include "src/base/hashing.h"
10#include "src/base/macros.h"
11#include "src/handles/handles.h"
12#include "src/heap/local-heap.h"
13
14namespace v8 {
15namespace internal {
16
17class RootVisitor;
18
20 public:
23
24 void Iterate(RootVisitor* visitor);
25
26#ifdef DEBUG
27 bool Contains(Address* location);
28#endif
29
30 private:
32 std::vector<Address*> blocks_;
33
36
37#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
38 V8_EXPORT_PRIVATE static void ZapRange(Address* start, Address* end);
39#endif
40
41 friend class LocalHandleScope;
42};
43
45 public:
46 explicit inline LocalHandleScope(LocalIsolate* local_isolate);
47 explicit inline LocalHandleScope(LocalHeap* local_heap);
48 inline ~LocalHandleScope();
51
52 // TODO(42203211): When direct handles are enabled, the version with
53 // HandleType = DirectHandle does not need to be called, as it simply
54 // closes the scope (which is done by the scope's destructor anyway)
55 // and returns its parameter. This will be cleaned up after direct
56 // handles ship.
57 template <typename T, template <typename> typename HandleType>
58 requires(std::is_convertible_v<HandleType<T>, DirectHandle<T>>)
59 HandleType<T> CloseAndEscape(HandleType<T> handle_value);
60
61 V8_INLINE static Address* GetHandle(LocalHeap* local_heap, Address value);
62
63 private:
64 // Prevent heap allocation or illegal handle scopes.
65 void* operator new(size_t size) = delete;
66 void operator delete(void* size_t) = delete;
67
68 // Close the handle scope resetting limits to a previous state.
69 static inline void CloseScope(LocalHeap* local_heap, Address* prev_next,
70 Address* prev_limit);
71 V8_EXPORT_PRIVATE static void CloseMainThreadScope(LocalHeap* local_heap,
72 Address* prev_next,
73 Address* prev_limit);
74
75 V8_EXPORT_PRIVATE void OpenMainThreadScope(LocalHeap* local_heap);
76
77 V8_EXPORT_PRIVATE static Address* GetMainThreadHandle(LocalHeap* local_heap,
78 Address value);
79
81 Address* prev_limit_;
82 Address* prev_next_;
83
84#ifdef V8_ENABLE_CHECKS
85 int scope_level_ = 0;
86
87 V8_EXPORT_PRIVATE void VerifyMainThreadScope() const;
88#endif
89};
90
91} // namespace internal
92} // namespace v8
93
94#endif // V8_HANDLES_LOCAL_HANDLES_H_
LocalHandleScope(const LocalHandleScope &)=delete
LocalHandleScope & operator=(const LocalHandleScope &)=delete
std::vector< Address * > blocks_
V8_EXPORT_PRIVATE Address * AddBlock()
V8_EXPORT_PRIVATE void RemoveUnusedBlocks()
void Iterate(RootVisitor *visitor)
int start
int end
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_INLINE
Definition v8config.h:500
#define V8_NODISCARD
Definition v8config.h:693