• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "include/v8-internal.h"
9 #include "src/base/functional.h"
10 #include "src/base/macros.h"
11 #include "src/handles/handles.h"
12 #include "src/heap/local-heap.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class RootVisitor;
18 
19 class LocalHandles {
20  public:
21   LocalHandles();
22   ~LocalHandles();
23 
24   void Iterate(RootVisitor* visitor);
25 
26 #ifdef DEBUG
27   bool Contains(Address* location);
28 #endif
29 
30  private:
31   HandleScopeData scope_;
32   std::vector<Address*> blocks_;
33 
34   V8_EXPORT_PRIVATE Address* AddBlock();
35   V8_EXPORT_PRIVATE void RemoveUnusedBlocks();
36 
37 #ifdef ENABLE_HANDLE_ZAPPING
38   V8_EXPORT_PRIVATE static void ZapRange(Address* start, Address* end);
39 #endif
40 
41   friend class LocalHandleScope;
42 };
43 
44 class LocalHandleScope {
45  public:
46   explicit inline LocalHandleScope(LocalIsolate* local_isolate);
47   explicit inline LocalHandleScope(LocalHeap* local_heap);
48   inline ~LocalHandleScope();
49 
50   template <typename T>
51   Handle<T> CloseAndEscape(Handle<T> handle_value);
52 
53   V8_INLINE static Address* GetHandle(LocalHeap* local_heap, Address value);
54 
55  private:
56   // Prevent heap allocation or illegal handle scopes.
57   void* operator new(size_t size) = delete;
58   void operator delete(void* size_t) = delete;
59 
60   // Close the handle scope resetting limits to a previous state.
61   static inline void CloseScope(LocalHeap* local_heap, Address* prev_next,
62                                 Address* prev_limit);
63 
64   LocalHeap* local_heap_;
65   Address* prev_limit_;
66   Address* prev_next_;
67 
68   DISALLOW_COPY_AND_ASSIGN(LocalHandleScope);
69 };
70 
71 }  // namespace internal
72 }  // namespace v8
73 
74 #endif  // V8_HANDLES_LOCAL_HANDLES_H_
75