V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
external-reference-table.h
1 // Copyright 2016 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_EXTERNAL_REFERENCE_TABLE_H_
6 #define V8_EXTERNAL_REFERENCE_TABLE_H_
7 
8 #include <vector>
9 
10 #include "src/accessors.h"
11 #include "src/builtins/builtins.h"
12 #include "src/external-reference.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class Isolate;
18 
19 // ExternalReferenceTable is a helper class that defines the relationship
20 // between external references and their encodings. It is used to build
21 // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
23  public:
24  // For the nullptr ref, see the constructor.
25  static constexpr int kSpecialReferenceCount = 1;
26  static constexpr int kExternalReferenceCount =
27  ExternalReference::kExternalReferenceCount;
28  static constexpr int kBuiltinsReferenceCount =
29 #define COUNT_C_BUILTIN(...) +1
30  BUILTIN_LIST_C(COUNT_C_BUILTIN);
31 #undef COUNT_C_BUILTIN
32  static constexpr int kRuntimeReferenceCount =
33  Runtime::kNumFunctions -
34  Runtime::kNumInlineFunctions; // Don't count dupe kInline... functions.
35  static constexpr int kIsolateAddressReferenceCount = kIsolateAddressCount;
36  static constexpr int kAccessorReferenceCount =
37  Accessors::kAccessorInfoCount + Accessors::kAccessorSetterCount;
38  // The number of stub cache external references, see AddStubCache.
39  static constexpr int kStubCacheReferenceCount = 12;
40  static constexpr int kSize =
41  kSpecialReferenceCount + kExternalReferenceCount +
42  kBuiltinsReferenceCount + kRuntimeReferenceCount +
43  kIsolateAddressReferenceCount + kAccessorReferenceCount +
44  kStubCacheReferenceCount;
45 
46  static constexpr uint32_t size() { return static_cast<uint32_t>(kSize); }
47  Address address(uint32_t i) { return refs_[i].address; }
48  const char* name(uint32_t i) { return refs_[i].name; }
49 
50  bool is_initialized() const { return is_initialized_ != 0; }
51 
52  static const char* ResolveSymbol(void* address);
53 
54  static constexpr uint32_t EntrySize() {
55  return sizeof(ExternalReferenceEntry);
56  }
57 
58  static constexpr uint32_t OffsetOfEntry(uint32_t i) {
59  // Used in CodeAssembler::LookupExternalReference.
60  STATIC_ASSERT(offsetof(ExternalReferenceEntry, address) == 0);
61  return i * EntrySize();
62  }
63 
64  const char* NameFromOffset(uint32_t offset) {
65  DCHECK_EQ(offset % EntrySize(), 0);
66  DCHECK_LT(offset, SizeInBytes());
67  int index = offset / EntrySize();
68  return name(index);
69  }
70 
71  static constexpr uint32_t SizeInBytes() {
72  STATIC_ASSERT(OffsetOfEntry(size()) + 2 * kUInt32Size ==
73  sizeof(ExternalReferenceTable));
74  return OffsetOfEntry(size()) + 2 * kUInt32Size;
75  }
76 
77  ExternalReferenceTable() = default;
78  void Init(Isolate* isolate);
79 
80  private:
81  struct ExternalReferenceEntry {
82  Address address;
83  const char* name;
84 
85  ExternalReferenceEntry() : address(kNullAddress), name(nullptr) {}
86  ExternalReferenceEntry(Address address, const char* name)
87  : address(address), name(name) {}
88  };
89 
90  void Add(Address address, const char* name, int* index);
91 
92  void AddReferences(Isolate* isolate, int* index);
93  void AddBuiltins(int* index);
94  void AddRuntimeFunctions(int* index);
95  void AddIsolateAddresses(Isolate* isolate, int* index);
96  void AddAccessors(int* index);
97  void AddStubCache(Isolate* isolate, int* index);
98 
99  ExternalReferenceEntry refs_[kSize];
100  uint32_t is_initialized_ = 0; // Not bool to guarantee deterministic size.
101  uint32_t unused_padding_ = 0; // For alignment.
102 
103  DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
104 };
105 
106 } // namespace internal
107 } // namespace v8
108 #endif // V8_EXTERNAL_REFERENCE_TABLE_H_
Definition: libplatform.h:13