Welcome to mirror list, hosted at ThFree Co, Russian Federation.

off-thread-isolate.h « execution « src « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a75c3285916a5bbc22302220438f03d06becf78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_EXECUTION_OFF_THREAD_ISOLATE_H_
#define V8_EXECUTION_OFF_THREAD_ISOLATE_H_

#include "src/base/logging.h"
#include "src/execution/thread-id.h"
#include "src/handles/handles.h"
#include "src/heap/off-thread-factory.h"

namespace v8 {
namespace internal {

class Isolate;
class OffThreadLogger;

// HiddenOffThreadFactory parallels Isolate's HiddenFactory
class V8_EXPORT_PRIVATE HiddenOffThreadFactory : private OffThreadFactory {
 public:
  // Forward constructors.
  using OffThreadFactory::OffThreadFactory;
};

// And Isolate-like class that can be passed in to templated methods that need
// an isolate syntactically, but are usable off-thread.
//
// This class holds an OffThreadFactory, but is otherwise effectively a stub
// implementation of an Isolate. In particular, it doesn't allow throwing
// exceptions, and hard crashes if you try.
class V8_EXPORT_PRIVATE OffThreadIsolate final
    : private HiddenOffThreadFactory {
 public:
  using HandleScopeType = OffThreadHandleScope;

  explicit OffThreadIsolate(Isolate* isolate, Zone* zone);
  ~OffThreadIsolate();

  v8::internal::OffThreadFactory* factory() {
    // Upcast to the privately inherited base-class using c-style casts to avoid
    // undefined behavior (as static_cast cannot cast across private bases).
    // NOLINTNEXTLINE (google-readability-casting)
    return (
        v8::internal::OffThreadFactory*)this;  // NOLINT(readability/casting)
  }

  // This method finishes the use of the off-thread Isolate, and can be safely
  // called off-thread.
  void FinishOffThread() {
    factory()->FinishOffThread();
    handle_zone_ = nullptr;
  }

  template <typename T>
  Handle<T> Throw(Handle<Object> exception) {
    UNREACHABLE();
  }
  [[noreturn]] void FatalProcessOutOfHeapMemory(const char* location) {
    UNREACHABLE();
  }

  Address* NewHandle(Address object) {
    DCHECK_NOT_NULL(handle_zone_);
    Address* location =
        static_cast<Address*>(handle_zone_->New(sizeof(Address)));
    *location = object;
    return location;
  }

  int GetNextScriptId();
#if V8_SFI_HAS_UNIQUE_ID
  int GetNextUniqueSharedFunctionInfoId();
#endif  // V8_SFI_HAS_UNIQUE_ID

  bool NeedsSourcePositionsForProfiling();
  bool is_collecting_type_profile();

  OffThreadLogger* logger() { return logger_; }

  void PinToCurrentThread();
  ThreadId thread_id() { return thread_id_; }

 private:
  friend class v8::internal::OffThreadFactory;

  // TODO(leszeks): Extract out the fields of the Isolate we want and store
  // those instead of the whole thing.
  Isolate* isolate_;

  OffThreadLogger* logger_;
  ThreadId thread_id_;
  Zone* handle_zone_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_EXECUTION_OFF_THREAD_ISOLATE_H_