Line data Source code
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/address-map.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : class Isolate;
16 :
17 : // ExternalReferenceTable is a helper class that defines the relationship
18 : // between external references and their encodings. It is used to build
19 : // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
20 : class ExternalReferenceTable {
21 : public:
22 : static ExternalReferenceTable* instance(Isolate* isolate);
23 : ~ExternalReferenceTable();
24 :
25 1028817 : uint32_t size() const { return static_cast<uint32_t>(refs_.length()); }
26 791479470 : Address address(uint32_t i) { return refs_[i].address; }
27 0 : const char* name(uint32_t i) { return refs_[i].name; }
28 : bool is_api_reference(uint32_t i) { return i >= api_refs_start_; }
29 338534 : uint32_t num_api_references() { return size() - api_refs_start_; }
30 :
31 : #ifdef DEBUG
32 : void increment_count(uint32_t i) { refs_[i].count++; }
33 : int count(uint32_t i) { return refs_[i].count; }
34 : void ResetCount();
35 : void PrintCount();
36 : #endif // DEBUG
37 :
38 : static const char* ResolveSymbol(void* address,
39 : std::vector<char**>* = nullptr);
40 :
41 : private:
42 : struct ExternalReferenceEntry {
43 : Address address;
44 : const char* name;
45 : #ifdef DEBUG
46 : int count;
47 : #endif // DEBUG
48 : };
49 :
50 : explicit ExternalReferenceTable(Isolate* isolate);
51 :
52 : void Add(Address address, const char* name) {
53 : #ifdef DEBUG
54 : ExternalReferenceEntry entry = {address, name, 0};
55 : #else
56 78929949 : ExternalReferenceEntry entry = {address, name};
57 : #endif // DEBUG
58 78929949 : refs_.Add(entry);
59 : }
60 :
61 : void AddReferences(Isolate* isolate);
62 : void AddBuiltins(Isolate* isolate);
63 : void AddRuntimeFunctions(Isolate* isolate);
64 : void AddIsolateAddresses(Isolate* isolate);
65 : void AddAccessors(Isolate* isolate);
66 : void AddStubCache(Isolate* isolate);
67 : void AddApiReferences(Isolate* isolate);
68 :
69 : List<ExternalReferenceEntry> refs_;
70 : #ifdef DEBUG
71 : std::vector<char**> symbol_tables_;
72 : #endif
73 : uint32_t api_refs_start_;
74 :
75 : DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
76 : };
77 :
78 : } // namespace internal
79 : } // namespace v8
80 : #endif // V8_EXTERNAL_REFERENCE_TABLE_H_
|