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