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.
|
|
|
|
|
|
|
|
#include "src/external-reference-table.h"
|
|
|
|
|
|
|
|
#include "src/accessors.h"
|
|
|
|
#include "src/counters.h"
|
2018-03-09 15:59:20 +00:00
|
|
|
#include "src/external-reference.h"
|
2016-03-17 13:14:11 +00:00
|
|
|
#include "src/ic/stub-cache.h"
|
|
|
|
|
2016-11-15 08:58:54 +00:00
|
|
|
#if defined(DEBUG) && defined(V8_OS_LINUX) && !defined(V8_OS_ANDROID)
|
|
|
|
#define SYMBOLIZE_FUNCTION
|
|
|
|
#include <execinfo.h>
|
2017-04-25 03:01:11 +00:00
|
|
|
#include <vector>
|
2016-11-15 08:58:54 +00:00
|
|
|
#endif // DEBUG && V8_OS_LINUX && !V8_OS_ANDROID
|
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2016-07-18 08:47:04 +00:00
|
|
|
// Forward declarations for C++ builtins.
|
|
|
|
#define FORWARD_DECLARE(Name) \
|
|
|
|
Object* Builtin_##Name(int argc, Object** args, Isolate* isolate);
|
|
|
|
BUILTIN_LIST_C(FORWARD_DECLARE)
|
|
|
|
#undef FORWARD_DECLARE
|
|
|
|
|
2018-03-26 09:24:15 +00:00
|
|
|
void ExternalReferenceTable::Init(Isolate* isolate) {
|
2018-03-19 14:36:52 +00:00
|
|
|
int index = 0;
|
|
|
|
|
2016-11-14 07:17:22 +00:00
|
|
|
// nullptr is preserved through serialization/deserialization.
|
2018-03-19 14:36:52 +00:00
|
|
|
Add(nullptr, "nullptr", &index);
|
|
|
|
AddReferences(isolate, &index);
|
|
|
|
AddBuiltins(isolate, &index);
|
|
|
|
AddRuntimeFunctions(isolate, &index);
|
|
|
|
AddIsolateAddresses(isolate, &index);
|
|
|
|
AddAccessors(isolate, &index);
|
|
|
|
AddStubCache(isolate, &index);
|
2018-03-26 09:24:15 +00:00
|
|
|
is_initialized_ = true;
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSize, index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 10:26:42 +00:00
|
|
|
const char* ExternalReferenceTable::ResolveSymbol(void* address) {
|
2016-11-15 08:58:54 +00:00
|
|
|
#ifdef SYMBOLIZE_FUNCTION
|
2017-08-11 10:26:42 +00:00
|
|
|
char** names = backtrace_symbols(&address, 1);
|
|
|
|
const char* name = names[0];
|
|
|
|
// The array of names is malloc'ed. However, each name string is static
|
|
|
|
// and do not need to be freed.
|
|
|
|
free(names);
|
|
|
|
return name;
|
2016-11-15 08:58:54 +00:00
|
|
|
#else
|
|
|
|
return "<unresolved>";
|
|
|
|
#endif // SYMBOLIZE_FUNCTION
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::Add(Address address, const char* name,
|
|
|
|
int* index) {
|
|
|
|
refs_[(*index)++] = {address, name};
|
2017-09-11 13:02:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddReferences(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount, *index);
|
|
|
|
|
2018-03-09 15:59:20 +00:00
|
|
|
#define ADD_EXTERNAL_REFERENCE(name, desc) \
|
2018-03-19 14:36:52 +00:00
|
|
|
Add(ExternalReference::name(isolate).address(), desc, index);
|
2018-03-09 15:59:20 +00:00
|
|
|
EXTERNAL_REFERENCE_LIST(ADD_EXTERNAL_REFERENCE)
|
|
|
|
#undef ADD_EXTERNAL_REFERENCE
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount, *index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddBuiltins(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount, *index);
|
|
|
|
|
2016-07-18 08:47:04 +00:00
|
|
|
struct CBuiltinEntry {
|
|
|
|
Address address;
|
2016-03-17 13:14:11 +00:00
|
|
|
const char* name;
|
|
|
|
};
|
2016-07-18 08:47:04 +00:00
|
|
|
static const CBuiltinEntry c_builtins[] = {
|
|
|
|
#define DEF_ENTRY(Name, ...) {FUNCTION_ADDR(&Builtin_##Name), "Builtin_" #Name},
|
2016-07-14 12:45:56 +00:00
|
|
|
BUILTIN_LIST_C(DEF_ENTRY)
|
|
|
|
#undef DEF_ENTRY
|
2016-03-17 13:14:11 +00:00
|
|
|
};
|
|
|
|
for (unsigned i = 0; i < arraysize(c_builtins); ++i) {
|
2016-07-18 08:47:04 +00:00
|
|
|
Add(ExternalReference(c_builtins[i].address, isolate).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
c_builtins[i].name, index);
|
2016-03-17 13:14:11 +00:00
|
|
|
}
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount,
|
|
|
|
*index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount,
|
|
|
|
*index);
|
|
|
|
|
2016-07-18 08:47:04 +00:00
|
|
|
struct RuntimeEntry {
|
|
|
|
Runtime::FunctionId id;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const RuntimeEntry runtime_functions[] = {
|
2016-03-17 13:14:11 +00:00
|
|
|
#define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name},
|
|
|
|
FOR_EACH_INTRINSIC(RUNTIME_ENTRY)
|
|
|
|
#undef RUNTIME_ENTRY
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < arraysize(runtime_functions); ++i) {
|
2016-07-18 08:47:04 +00:00
|
|
|
ExternalReference ref(runtime_functions[i].id, isolate);
|
2018-03-19 14:36:52 +00:00
|
|
|
Add(ref.address(), runtime_functions[i].name, index);
|
2016-03-17 13:14:11 +00:00
|
|
|
}
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount,
|
|
|
|
*index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount,
|
|
|
|
*index);
|
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
// Top addresses
|
|
|
|
static const char* address_names[] = {
|
|
|
|
#define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address",
|
2017-10-13 16:33:03 +00:00
|
|
|
FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) nullptr
|
2016-03-17 13:14:11 +00:00
|
|
|
#undef BUILD_NAME_LITERAL
|
|
|
|
};
|
|
|
|
|
2017-06-23 12:21:39 +00:00
|
|
|
for (int i = 0; i < IsolateAddressId::kIsolateAddressCount; ++i) {
|
|
|
|
Add(isolate->get_address_from_id(static_cast<IsolateAddressId>(i)),
|
2018-03-19 14:36:52 +00:00
|
|
|
address_names[i], index);
|
2016-03-17 13:14:11 +00:00
|
|
|
}
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount +
|
|
|
|
kIsolateAddressReferenceCount,
|
|
|
|
*index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddAccessors(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount +
|
|
|
|
kIsolateAddressReferenceCount,
|
|
|
|
*index);
|
|
|
|
|
2016-03-17 13:14:11 +00:00
|
|
|
// Accessors
|
|
|
|
struct AccessorRefTable {
|
|
|
|
Address address;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
2016-04-20 08:01:08 +00:00
|
|
|
static const AccessorRefTable getters[] = {
|
2017-10-27 09:06:44 +00:00
|
|
|
#define ACCESSOR_INFO_DECLARATION(accessor_name, AccessorName) \
|
|
|
|
{FUNCTION_ADDR(&Accessors::AccessorName##Getter), \
|
|
|
|
"Accessors::" #AccessorName "Getter"}, /* NOLINT(whitespace/indent) */
|
2016-11-15 07:42:55 +00:00
|
|
|
ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
|
2016-03-17 13:14:11 +00:00
|
|
|
#undef ACCESSOR_INFO_DECLARATION
|
2016-04-20 08:01:08 +00:00
|
|
|
};
|
|
|
|
static const AccessorRefTable setters[] = {
|
2016-03-17 13:14:11 +00:00
|
|
|
#define ACCESSOR_SETTER_DECLARATION(name) \
|
2016-11-15 08:58:54 +00:00
|
|
|
{ FUNCTION_ADDR(&Accessors::name), "Accessors::" #name},
|
2016-11-15 07:42:55 +00:00
|
|
|
ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
|
2017-10-27 09:06:44 +00:00
|
|
|
#undef ACCESSOR_SETTER_DECLARATION
|
2016-03-17 13:14:11 +00:00
|
|
|
};
|
|
|
|
|
2016-04-20 08:01:08 +00:00
|
|
|
for (unsigned i = 0; i < arraysize(getters); ++i) {
|
2018-03-19 14:36:52 +00:00
|
|
|
Add(getters[i].address, getters[i].name, index);
|
2016-04-20 08:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < arraysize(setters); ++i) {
|
2018-03-19 14:36:52 +00:00
|
|
|
Add(setters[i].address, setters[i].name, index);
|
2016-03-17 13:14:11 +00:00
|
|
|
}
|
2018-03-19 14:36:52 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount +
|
|
|
|
kIsolateAddressReferenceCount + kAccessorReferenceCount,
|
|
|
|
*index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
void ExternalReferenceTable::AddStubCache(Isolate* isolate, int* index) {
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount +
|
|
|
|
kIsolateAddressReferenceCount + kAccessorReferenceCount,
|
|
|
|
*index);
|
|
|
|
|
2016-07-13 10:24:55 +00:00
|
|
|
StubCache* load_stub_cache = isolate->load_stub_cache();
|
2016-03-17 13:14:11 +00:00
|
|
|
|
|
|
|
// Stub cache tables
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->key_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::primary_->key", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->value_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::primary_->value", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->map_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::primary_->map", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->key_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::secondary_->key", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->value_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::secondary_->value", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(load_stub_cache->map_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Load StubCache::secondary_->map", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
|
|
|
|
StubCache* store_stub_cache = isolate->store_stub_cache();
|
|
|
|
|
|
|
|
// Stub cache tables
|
|
|
|
Add(store_stub_cache->key_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::primary_->key", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(store_stub_cache->value_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::primary_->value", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(store_stub_cache->map_reference(StubCache::kPrimary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::primary_->map", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(store_stub_cache->key_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::secondary_->key", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(store_stub_cache->value_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::secondary_->value", index);
|
2016-07-13 10:24:55 +00:00
|
|
|
Add(store_stub_cache->map_reference(StubCache::kSecondary).address(),
|
2018-03-19 14:36:52 +00:00
|
|
|
"Store StubCache::secondary_->map", index);
|
|
|
|
|
|
|
|
CHECK_EQ(kSpecialReferenceCount + kExternalReferenceCount +
|
|
|
|
kBuiltinsReferenceCount + kRuntimeReferenceCount +
|
|
|
|
kIsolateAddressReferenceCount + kAccessorReferenceCount +
|
|
|
|
kStubCacheReferenceCount,
|
|
|
|
*index);
|
|
|
|
CHECK_EQ(kSize, *index);
|
2016-07-18 08:47:04 +00:00
|
|
|
}
|
2016-03-17 13:14:11 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2017-10-27 09:06:44 +00:00
|
|
|
|
|
|
|
#undef SYMBOLIZE_FUNCTION
|