Commit 94833cbf authored by jgruber's avatar jgruber Committed by Commit Bot

Introduce a static layout for external reference table

This is another step towards efficient external reference access from
off-heap builtins.

Bug: v8:6666
Change-Id: I6f128a8a64724acaa092f28b1fceae01e3c05487
Reviewed-on: https://chromium-review.googlesource.com/968481Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52039}
parent 0fa0b28a
......@@ -82,6 +82,16 @@ class Accessors : public AllStatic {
ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
#undef ACCESSOR_SETTER_DECLARATION
static constexpr int kAccessorInfoCount =
#define COUNT_ACCESSOR(...) +1
ACCESSOR_INFO_LIST(COUNT_ACCESSOR);
#undef COUNT_ACCESSOR
static constexpr int kAccessorSetterCount =
#define COUNT_ACCESSOR(...) +1
ACCESSOR_SETTER_LIST(COUNT_ACCESSOR);
#undef COUNT_ACCESSOR
static void ModuleNamespaceEntryGetter(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);
......
......@@ -35,14 +35,18 @@ ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) {
}
ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
int index = 0;
// nullptr is preserved through serialization/deserialization.
Add(nullptr, "nullptr");
AddReferences(isolate);
AddBuiltins(isolate);
AddRuntimeFunctions(isolate);
AddIsolateAddresses(isolate);
AddAccessors(isolate);
AddStubCache(isolate);
Add(nullptr, "nullptr", &index);
AddReferences(isolate, &index);
AddBuiltins(isolate, &index);
AddRuntimeFunctions(isolate, &index);
AddIsolateAddresses(isolate, &index);
AddAccessors(isolate, &index);
AddStubCache(isolate, &index);
CHECK_EQ(kSize, index);
}
const char* ExternalReferenceTable::ResolveSymbol(void* address) {
......@@ -58,18 +62,25 @@ const char* ExternalReferenceTable::ResolveSymbol(void* address) {
#endif // SYMBOLIZE_FUNCTION
}
void ExternalReferenceTable::Add(Address address, const char* name) {
refs_.emplace_back(address, name);
void ExternalReferenceTable::Add(Address address, const char* name,
int* index) {
refs_[(*index)++] = {address, name};
}
void ExternalReferenceTable::AddReferences(Isolate* isolate) {
void ExternalReferenceTable::AddReferences(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount, *index);
#define ADD_EXTERNAL_REFERENCE(name, desc) \
Add(ExternalReference::name(isolate).address(), desc);
Add(ExternalReference::name(isolate).address(), desc, index);
EXTERNAL_REFERENCE_LIST(ADD_EXTERNAL_REFERENCE)
#undef ADD_EXTERNAL_REFERENCE
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount, *index);
}
void ExternalReferenceTable::AddBuiltins(Isolate* isolate) {
void ExternalReferenceTable::AddBuiltins(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount, *index);
struct CBuiltinEntry {
Address address;
const char* name;
......@@ -81,11 +92,19 @@ void ExternalReferenceTable::AddBuiltins(Isolate* isolate) {
};
for (unsigned i = 0; i < arraysize(c_builtins); ++i) {
Add(ExternalReference(c_builtins[i].address, isolate).address(),
c_builtins[i].name);
c_builtins[i].name, index);
}
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount,
*index);
}
void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate) {
void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount,
*index);
struct RuntimeEntry {
Runtime::FunctionId id;
const char* name;
......@@ -99,11 +118,19 @@ void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate) {
for (unsigned i = 0; i < arraysize(runtime_functions); ++i) {
ExternalReference ref(runtime_functions[i].id, isolate);
Add(ref.address(), runtime_functions[i].name);
Add(ref.address(), runtime_functions[i].name, index);
}
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount,
*index);
}
void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate) {
void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount,
*index);
// Top addresses
static const char* address_names[] = {
#define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address",
......@@ -113,11 +140,21 @@ void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate) {
for (int i = 0; i < IsolateAddressId::kIsolateAddressCount; ++i) {
Add(isolate->get_address_from_id(static_cast<IsolateAddressId>(i)),
address_names[i]);
address_names[i], index);
}
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount,
*index);
}
void ExternalReferenceTable::AddAccessors(Isolate* isolate) {
void ExternalReferenceTable::AddAccessors(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount,
*index);
// Accessors
struct AccessorRefTable {
Address address;
......@@ -139,46 +176,63 @@ void ExternalReferenceTable::AddAccessors(Isolate* isolate) {
};
for (unsigned i = 0; i < arraysize(getters); ++i) {
Add(getters[i].address, getters[i].name);
Add(getters[i].address, getters[i].name, index);
}
for (unsigned i = 0; i < arraysize(setters); ++i) {
Add(setters[i].address, setters[i].name);
Add(setters[i].address, setters[i].name, index);
}
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount + kAccessorReferenceCount,
*index);
}
void ExternalReferenceTable::AddStubCache(Isolate* isolate) {
void ExternalReferenceTable::AddStubCache(Isolate* isolate, int* index) {
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount + kAccessorReferenceCount,
*index);
StubCache* load_stub_cache = isolate->load_stub_cache();
// Stub cache tables
Add(load_stub_cache->key_reference(StubCache::kPrimary).address(),
"Load StubCache::primary_->key");
"Load StubCache::primary_->key", index);
Add(load_stub_cache->value_reference(StubCache::kPrimary).address(),
"Load StubCache::primary_->value");
"Load StubCache::primary_->value", index);
Add(load_stub_cache->map_reference(StubCache::kPrimary).address(),
"Load StubCache::primary_->map");
"Load StubCache::primary_->map", index);
Add(load_stub_cache->key_reference(StubCache::kSecondary).address(),
"Load StubCache::secondary_->key");
"Load StubCache::secondary_->key", index);
Add(load_stub_cache->value_reference(StubCache::kSecondary).address(),
"Load StubCache::secondary_->value");
"Load StubCache::secondary_->value", index);
Add(load_stub_cache->map_reference(StubCache::kSecondary).address(),
"Load StubCache::secondary_->map");
"Load StubCache::secondary_->map", index);
StubCache* store_stub_cache = isolate->store_stub_cache();
// Stub cache tables
Add(store_stub_cache->key_reference(StubCache::kPrimary).address(),
"Store StubCache::primary_->key");
"Store StubCache::primary_->key", index);
Add(store_stub_cache->value_reference(StubCache::kPrimary).address(),
"Store StubCache::primary_->value");
"Store StubCache::primary_->value", index);
Add(store_stub_cache->map_reference(StubCache::kPrimary).address(),
"Store StubCache::primary_->map");
"Store StubCache::primary_->map", index);
Add(store_stub_cache->key_reference(StubCache::kSecondary).address(),
"Store StubCache::secondary_->key");
"Store StubCache::secondary_->key", index);
Add(store_stub_cache->value_reference(StubCache::kSecondary).address(),
"Store StubCache::secondary_->value");
"Store StubCache::secondary_->value", index);
Add(store_stub_cache->map_reference(StubCache::kSecondary).address(),
"Store StubCache::secondary_->map");
"Store StubCache::secondary_->map", index);
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount + kAccessorReferenceCount +
kStubCacheReferenceCount,
*index);
CHECK_EQ(kSize, *index);
}
} // namespace internal
......
......@@ -9,6 +9,7 @@
#include "src/address-map.h"
#include "src/builtins/builtins.h"
#include "src/external-reference.h"
namespace v8 {
namespace internal {
......@@ -22,7 +23,28 @@ class ExternalReferenceTable {
public:
static ExternalReferenceTable* instance(Isolate* isolate);
uint32_t size() const { return static_cast<uint32_t>(refs_.size()); }
// For the nullptr ref, see the constructor.
static constexpr int kSpecialReferenceCount = 1;
static constexpr int kExternalReferenceCount =
ExternalReference::kExternalReferenceCount;
static constexpr int kBuiltinsReferenceCount =
#define COUNT_C_BUILTIN(...) +1
BUILTIN_LIST_C(COUNT_C_BUILTIN);
#undef COUNT_C_BUILTIN
static constexpr int kRuntimeReferenceCount =
Runtime::kNumFunctions / 2; // Don't count dupe kInline... functions.
static constexpr int kIsolateAddressReferenceCount = kIsolateAddressCount;
static constexpr int kAccessorReferenceCount =
Accessors::kAccessorInfoCount + Accessors::kAccessorSetterCount;
// The number of stub cache external references, see AddStubCache.
static constexpr int kStubCacheReferenceCount = 12;
static constexpr int kSize =
kSpecialReferenceCount + kExternalReferenceCount +
kBuiltinsReferenceCount + kRuntimeReferenceCount +
kIsolateAddressReferenceCount + kAccessorReferenceCount +
kStubCacheReferenceCount;
uint32_t size() const { return static_cast<uint32_t>(kSize); }
Address address(uint32_t i) { return refs_[i].address; }
const char* name(uint32_t i) { return refs_[i].name; }
......@@ -33,22 +55,23 @@ class ExternalReferenceTable {
Address address;
const char* name;
ExternalReferenceEntry() : address(nullptr), name(nullptr) {}
ExternalReferenceEntry(Address address, const char* name)
: address(address), name(name) {}
};
explicit ExternalReferenceTable(Isolate* isolate);
void Add(Address address, const char* name);
void Add(Address address, const char* name, int* index);
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 AddReferences(Isolate* isolate, int* index);
void AddBuiltins(Isolate* isolate, int* index);
void AddRuntimeFunctions(Isolate* isolate, int* index);
void AddIsolateAddresses(Isolate* isolate, int* index);
void AddAccessors(Isolate* isolate, int* index);
void AddStubCache(Isolate* isolate, int* index);
std::vector<ExternalReferenceEntry> refs_;
ExternalReferenceEntry refs_[kSize];
DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
};
......
......@@ -242,6 +242,11 @@ class ExternalReference BASE_EMBEDDED {
PROFILING_GETTER_CALL
};
static constexpr int kExternalReferenceCount =
#define COUNT_EXTERNAL_REFERENCE(name, desc) +1
EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE);
#undef COUNT_EXTERNAL_REFERENCE
static void SetUp();
typedef void* ExternalReferenceRedirector(void* original, Type type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment