• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXECUTION_LOCAL_ISOLATE_H_
6 #define V8_EXECUTION_LOCAL_ISOLATE_H_
7 
8 #include "src/base/macros.h"
9 #include "src/execution/thread-id.h"
10 #include "src/handles/handles.h"
11 #include "src/handles/local-handles.h"
12 #include "src/handles/maybe-handles.h"
13 #include "src/heap/local-factory.h"
14 #include "src/heap/local-heap.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 class Isolate;
20 class LocalLogger;
21 
22 // HiddenLocalFactory parallels Isolate's HiddenFactory
23 class V8_EXPORT_PRIVATE HiddenLocalFactory : private LocalFactory {
24  public:
25   // Forward constructors.
26   using LocalFactory::LocalFactory;
27 };
28 
29 // And Isolate-like class that can be passed in to templated methods that need
30 // an isolate syntactically, but are usable off-thread.
31 //
32 // This class holds an LocalFactory, but is otherwise effectively a stub
33 // implementation of an Isolate. In particular, it doesn't allow throwing
34 // exceptions, and hard crashes if you try.
35 class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory {
36  public:
37   using HandleScopeType = LocalHandleScope;
38 
39   explicit LocalIsolate(Isolate* isolate, ThreadKind kind);
40   ~LocalIsolate();
41 
42   // Kinda sketchy.
FromHeap(LocalHeap * heap)43   static LocalIsolate* FromHeap(LocalHeap* heap) {
44     return reinterpret_cast<LocalIsolate*>(reinterpret_cast<Address>(heap) -
45                                            OFFSET_OF(LocalIsolate, heap_));
46   }
47 
heap()48   LocalHeap* heap() { return &heap_; }
49 
50   inline Address isolate_root() const;
51   inline ReadOnlyHeap* read_only_heap() const;
52   inline Object root(RootIndex index) const;
53 
string_table()54   StringTable* string_table() const { return isolate_->string_table(); }
55 
factory()56   v8::internal::LocalFactory* factory() {
57     // Upcast to the privately inherited base-class using c-style casts to avoid
58     // undefined behavior (as static_cast cannot cast across private bases).
59     // NOLINTNEXTLINE (google-readability-casting)
60     return (v8::internal::LocalFactory*)this;  // NOLINT(readability/casting)
61   }
62 
has_pending_exception()63   bool has_pending_exception() const { return false; }
64 
65   template <typename T>
Throw(Handle<Object> exception)66   Handle<T> Throw(Handle<Object> exception) {
67     UNREACHABLE();
68   }
FatalProcessOutOfHeapMemory(const char * location)69   [[noreturn]] void FatalProcessOutOfHeapMemory(const char* location) {
70     UNREACHABLE();
71   }
72 
73   int GetNextScriptId();
74 #if V8_SFI_HAS_UNIQUE_ID
75   int GetNextUniqueSharedFunctionInfoId();
76 #endif  // V8_SFI_HAS_UNIQUE_ID
77 
78   bool is_collecting_type_profile() const;
79 
logger()80   LocalLogger* logger() const { return logger_.get(); }
thread_id()81   ThreadId thread_id() const { return thread_id_; }
stack_limit()82   Address stack_limit() const { return stack_limit_; }
83 
84  private:
85   friend class v8::internal::LocalFactory;
86 
87   LocalHeap heap_;
88 
89   // TODO(leszeks): Extract out the fields of the Isolate we want and store
90   // those instead of the whole thing.
91   Isolate* const isolate_;
92 
93   std::unique_ptr<LocalLogger> logger_;
94   ThreadId const thread_id_;
95   Address const stack_limit_;
96 };
97 
98 }  // namespace internal
99 }  // namespace v8
100 
101 #endif  // V8_EXECUTION_LOCAL_ISOLATE_H_
102