2016-03-17 13:14:11 +00:00
|
|
|
// Copyright 2016 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_EXTERNAL_REFERENCE_TABLE_H_
|
|
|
|
#define V8_EXTERNAL_REFERENCE_TABLE_H_
|
|
|
|
|
2017-04-25 03:01:11 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
#include "src/address-map.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class Isolate;
|
|
|
|
|
|
|
|
// ExternalReferenceTable is a helper class that defines the relationship
|
|
|
|
// between external references and their encodings. It is used to build
|
|
|
|
// hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
|
|
|
|
class ExternalReferenceTable {
|
|
|
|
public:
|
|
|
|
static ExternalReferenceTable* instance(Isolate* isolate);
|
2017-04-25 03:01:11 +00:00
|
|
|
~ExternalReferenceTable();
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2016-11-14 07:17:22 +00:00
|
|
|
uint32_t size() const { return static_cast<uint32_t>(refs_.length()); }
|
|
|
|
Address address(uint32_t i) { return refs_[i].address; }
|
|
|
|
const char* name(uint32_t i) { return refs_[i].name; }
|
2017-02-20 12:52:53 +00:00
|
|
|
bool is_api_reference(uint32_t i) { return i >= api_refs_start_; }
|
2017-03-07 16:36:51 +00:00
|
|
|
uint32_t num_api_references() { return size() - api_refs_start_; }
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2016-11-15 08:58:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void increment_count(uint32_t i) { refs_[i].count++; }
|
|
|
|
int count(uint32_t i) { return refs_[i].count; }
|
|
|
|
void ResetCount();
|
|
|
|
void PrintCount();
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2017-04-25 03:01:11 +00:00
|
|
|
static const char* ResolveSymbol(void* address,
|
|
|
|
std::vector<char**>* = nullptr);
|
2016-11-15 08:58:54 +00:00
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
private:
|
|
|
|
struct ExternalReferenceEntry {
|
|
|
|
Address address;
|
|
|
|
const char* name;
|
2016-11-15 08:58:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int count;
|
|
|
|
#endif // DEBUG
|
2016-03-17 13:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit ExternalReferenceTable(Isolate* isolate);
|
|
|
|
|
|
|
|
void Add(Address address, const char* name) {
|
2016-11-15 08:58:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
ExternalReferenceEntry entry = {address, name, 0};
|
|
|
|
#else
|
2016-03-17 13:14:11 +00:00
|
|
|
ExternalReferenceEntry entry = {address, name};
|
2016-11-15 08:58:54 +00:00
|
|
|
#endif // DEBUG
|
2016-03-17 13:14:11 +00:00
|
|
|
refs_.Add(entry);
|
|
|
|
}
|
|
|
|
|
2016-07-18 08:47:04 +00:00
|
|
|
void AddReferences(Isolate* isolate);
|
|
|
|
void AddBuiltins(Isolate* isolate);
|
|
|
|
void AddRuntimeFunctions(Isolate* isolate);
|
|
|
|
void AddIsolateAddresses(Isolate* isolate);
|
|
|
|
void AddAccessors(Isolate* isolate);
|
|
|
|
void AddStubCache(Isolate* isolate);
|
|
|
|
void AddApiReferences(Isolate* isolate);
|
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
List<ExternalReferenceEntry> refs_;
|
2017-04-25 03:01:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
std::vector<char**> symbol_tables_;
|
|
|
|
#endif
|
2017-02-20 12:52:53 +00:00
|
|
|
uint32_t api_refs_start_;
|
2016-03-17 13:14:11 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
#endif // V8_EXTERNAL_REFERENCE_TABLE_H_
|