Commit c06ad086 authored by yangguo's avatar yangguo Committed by Commit bot

[builtins] remove redundant builtins lists.

R=bmeurer@chromium.org
BUG=v8:5197

Review-Url: https://codereview.chromium.org/2155633002
Cr-Commit-Position: refs/heads/master@{#37820}
parent f4234422
......@@ -896,10 +896,8 @@ void ExternalReference::SetUp() {
static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
}
ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
: address_(Redirect(isolate, Builtins::c_function_address(id))) {}
ExternalReference::ExternalReference(Address address, Isolate* isolate)
: address_(Redirect(isolate, address)) {}
ExternalReference::ExternalReference(
ApiFunction* fun,
......
......@@ -859,7 +859,7 @@ class ExternalReference BASE_EMBEDDED {
ExternalReference() : address_(NULL) {}
ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
ExternalReference(Address address, Isolate* isolate);
ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- r0 : number of arguments excluding receiver
......@@ -44,7 +44,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(r0, r1, r3);
__ SmiUntag(r0);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -29,7 +29,7 @@ static void GenerateLoadInternalArrayFunction(MacroAssembler* masm,
__ LoadNativeContextSlot(Context::INTERNAL_ARRAY_FUNCTION_INDEX, result);
}
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- x0 : number of arguments excluding receiver
......@@ -58,7 +58,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(x0, x1, x3);
__ SmiUntag(x0);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
This diff is collapsed.
......@@ -392,17 +392,12 @@ namespace internal {
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \
V, V, V)
#define BUILTIN_LIST_TFS(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, V, \
IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#define BUILTIN_LIST_DBG(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \
IGNORE_BUILTIN, IGNORE_BUILTIN, V)
// Forward declarations.
class CodeStubAssembler;
class BuiltinFunctionTable;
class ObjectVisitor;
class Builtins {
......@@ -421,20 +416,13 @@ class Builtins {
const char* Lookup(byte* pc);
enum Name {
#define DEF_ENUM(name, ...) k##name,
#define DEF_ENUM(Name, ...) k##Name,
BUILTIN_LIST_ALL(DEF_ENUM)
#undef DEF_ENUM
builtin_count
};
enum CFunctionId {
#define DEF_ENUM(name) c_##name,
BUILTIN_LIST_C(DEF_ENUM)
#undef DEF_ENUM
cfunction_count
};
#define DECLARE_BUILTIN_ACCESSOR(name, ...) Handle<Code> name();
#define DECLARE_BUILTIN_ACCESSOR(Name, ...) Handle<Code> Name();
BUILTIN_LIST_ALL(DECLARE_BUILTIN_ACCESSOR)
#undef DECLARE_BUILTIN_ACCESSOR
......@@ -462,13 +450,7 @@ class Builtins {
return reinterpret_cast<Address>(&builtins_[name]);
}
static Address c_function_address(CFunctionId id) { return c_functions_[id]; }
const char* name(int index) {
DCHECK(index >= 0);
DCHECK(index < builtin_count);
return names_[index];
}
const char* name(int index);
bool is_initialized() const { return initialized_; }
......@@ -478,20 +460,12 @@ class Builtins {
enum ExitFrameType { EXIT, BUILTIN_EXIT };
static void Generate_Adaptor(MacroAssembler* masm, Address builtin_address,
ExitFrameType exit_frame_type);
private:
Builtins();
// The external C++ functions called from the code.
static Address const c_functions_[cfunction_count];
// Note: These are always Code objects, but to conform with
// IterateBuiltins() above which assumes Object**'s for the callback
// function f, we use an Object* array here.
Object* builtins_[builtin_count];
const char* names_[builtin_count];
static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
ExitFrameType exit_frame_type);
static void Generate_AllocateInNewSpace(MacroAssembler* masm);
static void Generate_AllocateInOldSpace(MacroAssembler* masm);
static void Generate_ConstructedNonConstructable(MacroAssembler* masm);
......@@ -823,11 +797,12 @@ class Builtins {
static void Generate_AtomicsLoad(CodeStubAssembler* assembler);
static void Generate_AtomicsStore(CodeStubAssembler* assembler);
static void InitBuiltinFunctionTable();
// Note: These are always Code objects, but to conform with
// IterateBuiltins() above which assumes Object**'s for the callback
// function f, we use an Object* array here.
Object* builtins_[builtin_count];
bool initialized_;
friend class BuiltinFunctionTable;
friend class Isolate;
DISALLOW_COPY_AND_ASSIGN(Builtins);
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
......@@ -49,7 +49,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(edx);
__ PushReturnAddressFrom(ecx);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
......@@ -44,8 +44,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(a0, a1, a3);
__ SmiUntag(a0);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()), PROTECT,
exit_frame_type == BUILTIN_EXIT);
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
PROTECT, exit_frame_type == BUILTIN_EXIT);
}
// Load the built-in InternalArray function from the current context.
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
......@@ -44,8 +44,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(a0, a1, a3);
__ SmiUntag(a0);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()), PROTECT,
exit_frame_type == BUILTIN_EXIT);
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
PROTECT, exit_frame_type == BUILTIN_EXIT);
}
// Load the built-in InternalArray function from the current context.
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- r3 : number of arguments excluding receiver
......@@ -44,7 +44,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(r3, r4, r6);
__ SmiUntag(r3);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- r2 : number of arguments excluding receiver
......@@ -44,7 +44,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(r2, r3, r5);
__ SmiUntag(r2);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -14,7 +14,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- rax : number of arguments excluding receiver
......@@ -49,7 +49,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(rdx);
__ PushReturnAddressFrom(kScratchRegister);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -15,7 +15,7 @@ namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address,
ExitFrameType exit_frame_type) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
......@@ -49,7 +49,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
__ Push(edx);
__ PushReturnAddressFrom(ecx);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()),
__ JumpToExternalReference(ExternalReference(address, masm->isolate()),
exit_frame_type == BUILTIN_EXIT);
}
......
......@@ -6,6 +6,7 @@
#include "src/accessors.h"
#include "src/assembler.h"
#include "src/builtins/builtins.h"
#include "src/counters.h"
#include "src/deoptimizer.h"
#include "src/ic/stub-cache.h"
......@@ -13,6 +14,12 @@
namespace v8 {
namespace internal {
// 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
ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) {
ExternalReferenceTable* external_reference_table =
isolate->external_reference_table();
......@@ -24,6 +31,18 @@ ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) {
}
ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
AddReferences(isolate);
AddBuiltins(isolate);
AddRuntimeFunctions(isolate);
AddStatCounters(isolate);
AddIsolateAddresses(isolate);
AddAccessors(isolate);
AddStubCache(isolate);
AddDeoptEntries(isolate);
AddApiReferences(isolate);
}
void ExternalReferenceTable::AddReferences(Isolate* isolate) {
// Miscellaneous
Add(ExternalReference::roots_array_start(isolate).address(),
"Heap::roots_array_start()");
......@@ -234,54 +253,68 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"OffsetsVector::static_offsets_vector");
#endif // V8_INTERPRETED_REGEXP
// The following populates all of the different type of external references
// into the ExternalReferenceTable.
//
// NOTE: This function was originally 100k of code. It has since been
// rewritten to be mostly table driven, as the callback macro style tends to
// very easily cause code bloat. Please be careful in the future when adding
// new references.
// Runtime entries
Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
"HandleScope::DeleteExtensions");
Add(ExternalReference::incremental_marking_record_write_function(isolate)
.address(),
"IncrementalMarking::RecordWrite");
Add(ExternalReference::incremental_marking_record_write_code_entry_function(
isolate)
.address(),
"IncrementalMarking::RecordWriteOfCodeEntryFromCode");
Add(ExternalReference::store_buffer_overflow_function(isolate).address(),
"StoreBuffer::StoreBufferOverflow");
}
struct RefTableEntry {
uint16_t id;
void ExternalReferenceTable::AddBuiltins(Isolate* isolate) {
struct CBuiltinEntry {
Address address;
const char* name;
};
static const RefTableEntry c_builtins[] = {
#define DEF_ENTRY(name) {Builtins::c_##name, "Builtins::" #name},
static const CBuiltinEntry c_builtins[] = {
#define DEF_ENTRY(Name, ...) {FUNCTION_ADDR(&Builtin_##Name), "Builtin_" #Name},
BUILTIN_LIST_C(DEF_ENTRY)
#undef DEF_ENTRY
};
for (unsigned i = 0; i < arraysize(c_builtins); ++i) {
ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id),
isolate);
Add(ref.address(), c_builtins[i].name);
Add(ExternalReference(c_builtins[i].address, isolate).address(),
c_builtins[i].name);
}
static const RefTableEntry builtins[] = {
#define DEF_ENTRY(name, ...) {Builtins::k##name, "Builtins::" #name},
struct BuiltinEntry {
Builtins::Name id;
const char* name;
};
static const BuiltinEntry builtins[] = {
#define DEF_ENTRY(Name, ...) {Builtins::k##Name, "Builtin_" #Name},
BUILTIN_LIST_C(DEF_ENTRY) BUILTIN_LIST_A(DEF_ENTRY)
#undef DEF_ENTRY
};
for (unsigned i = 0; i < arraysize(builtins); ++i) {
ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate);
Add(ref.address(), builtins[i].name);
Add(isolate->builtins()->builtin_address(builtins[i].id), builtins[i].name);
}
}
static const RefTableEntry runtime_functions[] = {
void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate) {
struct RuntimeEntry {
Runtime::FunctionId id;
const char* name;
};
static const RuntimeEntry runtime_functions[] = {
#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) {
ExternalReference ref(
static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate);
ExternalReference ref(runtime_functions[i].id, isolate);
Add(ref.address(), runtime_functions[i].name);
}
}
void ExternalReferenceTable::AddStatCounters(Isolate* isolate) {
// Stat counters
struct StatsRefTableEntry {
StatsCounter* (Counters::*counter)();
......@@ -305,7 +338,9 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
}
Add(address, stats_ref_table[i].name);
}
}
void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate) {
// Top addresses
static const char* address_names[] = {
#define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address",
......@@ -317,7 +352,9 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)),
address_names[i]);
}
}
void ExternalReferenceTable::AddAccessors(Isolate* isolate) {
// Accessors
struct AccessorRefTable {
Address address;
......@@ -346,7 +383,9 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
for (unsigned i = 0; i < arraysize(setters); ++i) {
Add(setters[i].address, setters[i].name);
}
}
void ExternalReferenceTable::AddStubCache(Isolate* isolate) {
StubCache* load_stub_cache = isolate->load_stub_cache();
// Stub cache tables
......@@ -378,21 +417,11 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"Store StubCache::secondary_->value");
Add(store_stub_cache->map_reference(StubCache::kSecondary).address(),
"Store StubCache::secondary_->map");
}
// Runtime entries
Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
"HandleScope::DeleteExtensions");
Add(ExternalReference::incremental_marking_record_write_function(isolate)
.address(),
"IncrementalMarking::RecordWrite");
Add(ExternalReference::incremental_marking_record_write_code_entry_function(
isolate)
.address(),
"IncrementalMarking::RecordWriteOfCodeEntryFromCode");
Add(ExternalReference::store_buffer_overflow_function(isolate).address(),
"StoreBuffer::StoreBufferOverflow");
// Add a small set of deopt entry addresses to encoder without generating the
void ExternalReferenceTable::AddDeoptEntries(Isolate* isolate) {
// Add a small set of deopt entry addresses to encoder without generating
// the
// deopt table code, which isn't possible at deserialization time.
HandleScope scope(isolate);
for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) {
......@@ -401,8 +430,11 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
Deoptimizer::CALCULATE_ENTRY_ADDRESS);
Add(address, "lazy_deopt");
}
}
// Add external references provided by the embedder (a null-terminated array).
void ExternalReferenceTable::AddApiReferences(Isolate* isolate) {
// Add external references provided by the embedder (a null-terminated
// array).
intptr_t* api_external_references = isolate->api_external_references();
if (api_external_references != nullptr) {
while (*api_external_references != 0) {
......
......@@ -40,6 +40,16 @@ class ExternalReferenceTable {
refs_.Add(entry);
}
void AddReferences(Isolate* isolate);
void AddBuiltins(Isolate* isolate);
void AddRuntimeFunctions(Isolate* isolate);
void AddStatCounters(Isolate* isolate);
void AddIsolateAddresses(Isolate* isolate);
void AddAccessors(Isolate* isolate);
void AddStubCache(Isolate* isolate);
void AddDeoptEntries(Isolate* isolate);
void AddApiReferences(Isolate* isolate);
List<ExternalReferenceEntry> refs_;
DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
......
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