Index: src/builtins/builtins.cc |
diff --git a/src/builtins/builtins.cc b/src/builtins/builtins.cc |
index 2188743fc5f5d5e40123d122ed0589bd52fb9f79..77571c40389740dcecd1d4a0e29f837c201670cf 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() {} |
@@ -117,39 +117,47 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
// Create a scope for the handles in the builtins. |
HandleScope scope(isolate); |
- if (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; |
-#define BUILD_TFJ(Name, Argc) \ |
- code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \ |
- kBuiltinFlags, #Name); \ |
- builtins_[index++] = code; |
+ int index = 0; |
+ const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN); |
+ Code* code; |
+ Address entry; |
+ |
+// If setting up a snapshot (or running without a snapshot), the code objects |
+// are created here. Otherwise, we simply leave the code pointer unset as it |
+// will be written later by the deserializer. |
+ |
+#define MAYBE_CODE(call) (create_heap_objects ? (call) : nullptr) |
+#define BUILD_CPP(Name) \ |
+ entry = FUNCTION_ADDR(Builtin_##Name); \ |
+ code = MAYBE_CODE( \ |
+ BuildAdaptor(isolate, entry, BUILTIN_EXIT, kBuiltinFlags, #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, API, entry, code, #Name); |
+#define BUILD_API(Name) \ |
+ entry = FUNCTION_ADDR(Builtin_##Name); \ |
+ code = MAYBE_CODE(BuildAdaptor(isolate, entry, EXIT, kBuiltinFlags, #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, API, entry, code, #Name); |
+#define BUILD_TFJ(Name, Argc) \ |
+ code = MAYBE_CODE(BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, \ |
+ Argc, kBuiltinFlags, #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, TFJ, nullptr, code, #Name); |
#define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ |
{ InterfaceDescriptor##Descriptor descriptor(isolate); } \ |
- code = BuildWithCodeStubAssemblerCS( \ |
+ code = MAYBE_CODE(BuildWithCodeStubAssemblerCS( \ |
isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \ |
- Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
- builtins_[index++] = code; |
-#define BUILD_ASM(Name) \ |
- code = \ |
- BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \ |
- builtins_[index++] = code; |
-#define BUILD_ASH(Name, Kind, Extra) \ |
- code = BuildWithMacroAssembler( \ |
- isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
- builtins_[index++] = code; |
- |
- BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, |
- BUILD_ASH, BUILD_ASM); |
+ Code::ComputeFlags(Code::Kind, Extra), #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, TFS, nullptr, code, #Name); |
+#define BUILD_ASM(Name) \ |
+ code = MAYBE_CODE(BuildWithMacroAssembler(isolate, Generate_##Name, \ |
+ kBuiltinFlags, #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, ASM, nullptr, code, #Name); |
+#define BUILD_ASH(Name, Kind, Extra) \ |
+ code = MAYBE_CODE( \ |
+ BuildWithMacroAssembler(isolate, Generate_##Name, \ |
+ Code::ComputeFlags(Code::Kind, Extra), #Name)); \ |
+ builtins_[index++] = Descriptor(k##Name, ASH, nullptr, code, #Name); |
+ |
+ BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, BUILD_ASH, |
+ BUILD_ASM); |
#undef BUILD_CPP |
#undef BUILD_API |
@@ -157,9 +165,12 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
#undef BUILD_TFS |
#undef BUILD_ASM |
#undef BUILD_ASH |
Jarin
2016/08/18 14:10:43
For consistency, could you say "#undef MAYBE_CODE"
jgruber
2016/08/18 14:41:32
Good catch, thanks. Done.
|
- 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); |
+ |
+ if (create_heap_objects) { |
+ for (int i = 0; i < BUILTIN_COUNT; i++) { |
+ Code::cast(builtins_[i].code)->set_builtin_index(i); |
} |
} |
@@ -170,14 +181,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); |
} |
} |