Chromium Code Reviews| Index: src/builtins/builtins.cc |
| diff --git a/src/builtins/builtins.cc b/src/builtins/builtins.cc |
| index 2188743fc5f5d5e40123d122ed0589bd52fb9f79..c5018d469e2f5dae7bb4a436b71890ddf3cae785 100644 |
| --- a/src/builtins/builtins.cc |
| +++ b/src/builtins/builtins.cc |
| @@ -20,7 +20,7 @@ namespace internal { |
| BUILTIN_LIST_C(FORWARD_DECLARE) |
| Builtins::Builtins() : initialized_(false) { |
| - memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); |
| + memset(builtins_, 0, sizeof(builtins_[0]) * BUILTIN_COUNT); |
| } |
| Builtins::~Builtins() {} |
| @@ -121,32 +121,33 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
| int index = 0; |
| const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN); |
| Code* code; |
| -#define BUILD_CPP(Name) \ |
| - code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), BUILTIN_EXIT, \ |
| - kBuiltinFlags, #Name); \ |
| - builtins_[index++] = code; |
| -#define BUILD_API(Name) \ |
| - code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), EXIT, \ |
| - kBuiltinFlags, #Name); \ |
| - builtins_[index++] = code; |
| + Address entry; |
| +#define BUILD_CPP(Name) \ |
| + entry = FUNCTION_ADDR(Builtin_##Name); \ |
| + code = BuildAdaptor(isolate, entry, BUILTIN_EXIT, kBuiltinFlags, #Name); \ |
| + builtins_[index++].code = code; |
|
Jarin
2016/08/18 12:11:18
Instead of just setting the code, should not we co
jgruber
2016/08/18 12:51:34
Done.
|
| +#define BUILD_API(Name) \ |
| + entry = FUNCTION_ADDR(Builtin_##Name); \ |
| + code = BuildAdaptor(isolate, entry, EXIT, kBuiltinFlags, #Name); \ |
| + builtins_[index++].code = code; |
| #define BUILD_TFJ(Name, Argc) \ |
| code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \ |
| kBuiltinFlags, #Name); \ |
| - builtins_[index++] = code; |
| + builtins_[index++].code = code; |
| #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ |
| { InterfaceDescriptor##Descriptor descriptor(isolate); } \ |
| code = BuildWithCodeStubAssemblerCS( \ |
| isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \ |
| Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
| - builtins_[index++] = code; |
| + builtins_[index++].code = code; |
| #define BUILD_ASM(Name) \ |
| code = \ |
| BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \ |
| - builtins_[index++] = code; |
| + builtins_[index++].code = code; |
| #define BUILD_ASH(Name, Kind, Extra) \ |
| code = BuildWithMacroAssembler( \ |
| isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
| - builtins_[index++] = code; |
| + builtins_[index++].code = code; |
| BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, |
| BUILD_ASH, BUILD_ASM); |
| @@ -157,10 +158,46 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
| #undef BUILD_TFS |
| #undef BUILD_ASM |
| #undef BUILD_ASH |
| - CHECK_EQ(builtin_count, index); |
| - for (int i = 0; i < builtin_count; i++) { |
| - Code::cast(builtins_[i])->set_builtin_index(i); |
| + CHECK_EQ(BUILTIN_COUNT, index); |
| + for (int i = 0; i < BUILTIN_COUNT; i++) { |
| + Code::cast(builtins_[i].code)->set_builtin_index(i); |
| } |
| + } else { |
| + DCHECK(!create_heap_objects); |
| + int index = 0; |
| + Address entry; |
| +#define BUILD_CPP(Name) \ |
| + entry = FUNCTION_ADDR(Builtin_##Name); \ |
| + builtins_[index] = {k##Name, API, entry, builtins_[index].code, #Name}; \ |
|
Jarin
2016/08/18 12:11:18
Please define a constructor on the Descriptor clas
jgruber
2016/08/18 12:51:34
Done, and refactored this for more code reuse
|
| + index++; |
| +#define BUILD_API(Name) \ |
| + entry = FUNCTION_ADDR(Builtin_##Name); \ |
| + builtins_[index] = {k##Name, API, entry, builtins_[index].code, #Name}; \ |
| + index++; |
| +#define BUILD_TFJ(Name, Argc) \ |
| + builtins_[index] = {k##Name, TFJ, nullptr, builtins_[index].code, #Name}; \ |
| + index++; |
| +#define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ |
| + builtins_[index] = {k##Name, TFS, nullptr, builtins_[index].code, #Name}; \ |
| + index++; |
| +#define BUILD_ASM(Name) \ |
| + builtins_[index] = {k##Name, ASM, nullptr, builtins_[index].code, #Name}; \ |
| + index++; |
| +#define BUILD_ASH(Name, Kind, Extra) \ |
| + builtins_[index] = {k##Name, ASH, nullptr, builtins_[index].code, #Name}; \ |
| + index++; |
| + |
| + BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, |
| + BUILD_ASH, BUILD_ASM); |
| + |
| +#undef BUILD_CPP |
| +#undef BUILD_API |
| +#undef BUILD_TFJ |
| +#undef BUILD_TFS |
| +#undef BUILD_ASM |
| +#undef BUILD_ASH |
| + |
| + CHECK_EQ(BUILTIN_COUNT, index); |
| } |
| // Mark as initialized. |
| @@ -170,14 +207,16 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
| void Builtins::TearDown() { initialized_ = false; } |
| void Builtins::IterateBuiltins(ObjectVisitor* v) { |
| - v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); |
| + for (int i = 0; i < BUILTIN_COUNT; i++) { |
| + v->VisitPointer(&builtins_[i].code); |
| + } |
| } |
| const char* Builtins::Lookup(byte* pc) { |
| // may be called during initialization (disassembler!) |
| if (initialized_) { |
| - for (int i = 0; i < builtin_count; i++) { |
| - Code* entry = Code::cast(builtins_[i]); |
| + for (int i = 0; i < BUILTIN_COUNT; i++) { |
| + Code* entry = Code::cast(builtins_[i].code); |
| if (entry->contains(pc)) return name(i); |
| } |
| } |