Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
| 6 #include "src/code-events.h" | 6 #include "src/code-events.h" |
| 7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
| 8 #include "src/ic/ic-state.h" | 8 #include "src/ic/ic-state.h" |
| 9 #include "src/interface-descriptors.h" | 9 #include "src/interface-descriptors.h" |
| 10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| 11 #include "src/macro-assembler.h" | 11 #include "src/macro-assembler.h" |
| 12 #include "src/objects.h" | 12 #include "src/objects.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 // Forward declarations for C++ builtins. | 17 // Forward declarations for C++ builtins. |
| 18 #define FORWARD_DECLARE(Name) \ | 18 #define FORWARD_DECLARE(Name) \ |
| 19 Object* Builtin_##Name(int argc, Object** args, Isolate* isolate); | 19 Object* Builtin_##Name(int argc, Object** args, Isolate* isolate); |
| 20 BUILTIN_LIST_C(FORWARD_DECLARE) | 20 BUILTIN_LIST_C(FORWARD_DECLARE) |
| 21 | 21 |
| 22 Builtins::Builtins() : initialized_(false) { | 22 Builtins::Builtins() : initialized_(false) { |
| 23 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); | 23 memset(builtins_, 0, sizeof(builtins_[0]) * BUILTIN_COUNT); |
| 24 } | 24 } |
| 25 | 25 |
| 26 Builtins::~Builtins() {} | 26 Builtins::~Builtins() {} |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 void PostBuildProfileAndTracing(Isolate* isolate, Code* code, | 29 void PostBuildProfileAndTracing(Isolate* isolate, Code* code, |
| 30 const char* name) { | 30 const char* name) { |
| 31 PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG, | 31 PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG, |
| 32 AbstractCode::cast(code), name)); | 32 AbstractCode::cast(code), name)); |
| 33 #ifdef ENABLE_DISASSEMBLER | 33 #ifdef ENABLE_DISASSEMBLER |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { | 114 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
| 115 DCHECK(!initialized_); | 115 DCHECK(!initialized_); |
| 116 | 116 |
| 117 // Create a scope for the handles in the builtins. | 117 // Create a scope for the handles in the builtins. |
| 118 HandleScope scope(isolate); | 118 HandleScope scope(isolate); |
| 119 | 119 |
| 120 if (create_heap_objects) { | 120 if (create_heap_objects) { |
| 121 int index = 0; | 121 int index = 0; |
| 122 const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN); | 122 const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN); |
| 123 Code* code; | 123 Code* code; |
| 124 #define BUILD_CPP(Name) \ | 124 Address entry; |
| 125 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), BUILTIN_EXIT, \ | 125 #define BUILD_CPP(Name) \ |
| 126 kBuiltinFlags, #Name); \ | 126 entry = FUNCTION_ADDR(Builtin_##Name); \ |
| 127 builtins_[index++] = code; | 127 code = BuildAdaptor(isolate, entry, BUILTIN_EXIT, kBuiltinFlags, #Name); \ |
| 128 #define BUILD_API(Name) \ | 128 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.
| |
| 129 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), EXIT, \ | 129 #define BUILD_API(Name) \ |
| 130 kBuiltinFlags, #Name); \ | 130 entry = FUNCTION_ADDR(Builtin_##Name); \ |
| 131 builtins_[index++] = code; | 131 code = BuildAdaptor(isolate, entry, EXIT, kBuiltinFlags, #Name); \ |
| 132 builtins_[index++].code = code; | |
| 132 #define BUILD_TFJ(Name, Argc) \ | 133 #define BUILD_TFJ(Name, Argc) \ |
| 133 code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \ | 134 code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \ |
| 134 kBuiltinFlags, #Name); \ | 135 kBuiltinFlags, #Name); \ |
| 135 builtins_[index++] = code; | 136 builtins_[index++].code = code; |
| 136 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ | 137 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ |
| 137 { InterfaceDescriptor##Descriptor descriptor(isolate); } \ | 138 { InterfaceDescriptor##Descriptor descriptor(isolate); } \ |
| 138 code = BuildWithCodeStubAssemblerCS( \ | 139 code = BuildWithCodeStubAssemblerCS( \ |
| 139 isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \ | 140 isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \ |
| 140 Code::ComputeFlags(Code::Kind, Extra), #Name); \ | 141 Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
| 141 builtins_[index++] = code; | 142 builtins_[index++].code = code; |
| 142 #define BUILD_ASM(Name) \ | 143 #define BUILD_ASM(Name) \ |
| 143 code = \ | 144 code = \ |
| 144 BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \ | 145 BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \ |
| 145 builtins_[index++] = code; | 146 builtins_[index++].code = code; |
| 146 #define BUILD_ASH(Name, Kind, Extra) \ | 147 #define BUILD_ASH(Name, Kind, Extra) \ |
| 147 code = BuildWithMacroAssembler( \ | 148 code = BuildWithMacroAssembler( \ |
| 148 isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \ | 149 isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \ |
| 149 builtins_[index++] = code; | 150 builtins_[index++].code = code; |
| 150 | 151 |
| 151 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, | 152 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, |
| 152 BUILD_ASH, BUILD_ASM); | 153 BUILD_ASH, BUILD_ASM); |
| 153 | 154 |
| 154 #undef BUILD_CPP | 155 #undef BUILD_CPP |
| 155 #undef BUILD_API | 156 #undef BUILD_API |
| 156 #undef BUILD_TFJ | 157 #undef BUILD_TFJ |
| 157 #undef BUILD_TFS | 158 #undef BUILD_TFS |
| 158 #undef BUILD_ASM | 159 #undef BUILD_ASM |
| 159 #undef BUILD_ASH | 160 #undef BUILD_ASH |
| 160 CHECK_EQ(builtin_count, index); | 161 CHECK_EQ(BUILTIN_COUNT, index); |
| 161 for (int i = 0; i < builtin_count; i++) { | 162 for (int i = 0; i < BUILTIN_COUNT; i++) { |
| 162 Code::cast(builtins_[i])->set_builtin_index(i); | 163 Code::cast(builtins_[i].code)->set_builtin_index(i); |
| 163 } | 164 } |
| 165 } else { | |
| 166 DCHECK(!create_heap_objects); | |
| 167 int index = 0; | |
| 168 Address entry; | |
| 169 #define BUILD_CPP(Name) \ | |
| 170 entry = FUNCTION_ADDR(Builtin_##Name); \ | |
| 171 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
| |
| 172 index++; | |
| 173 #define BUILD_API(Name) \ | |
| 174 entry = FUNCTION_ADDR(Builtin_##Name); \ | |
| 175 builtins_[index] = {k##Name, API, entry, builtins_[index].code, #Name}; \ | |
| 176 index++; | |
| 177 #define BUILD_TFJ(Name, Argc) \ | |
| 178 builtins_[index] = {k##Name, TFJ, nullptr, builtins_[index].code, #Name}; \ | |
| 179 index++; | |
| 180 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ | |
| 181 builtins_[index] = {k##Name, TFS, nullptr, builtins_[index].code, #Name}; \ | |
| 182 index++; | |
| 183 #define BUILD_ASM(Name) \ | |
| 184 builtins_[index] = {k##Name, ASM, nullptr, builtins_[index].code, #Name}; \ | |
| 185 index++; | |
| 186 #define BUILD_ASH(Name, Kind, Extra) \ | |
| 187 builtins_[index] = {k##Name, ASH, nullptr, builtins_[index].code, #Name}; \ | |
| 188 index++; | |
| 189 | |
| 190 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, | |
| 191 BUILD_ASH, BUILD_ASM); | |
| 192 | |
| 193 #undef BUILD_CPP | |
| 194 #undef BUILD_API | |
| 195 #undef BUILD_TFJ | |
| 196 #undef BUILD_TFS | |
| 197 #undef BUILD_ASM | |
| 198 #undef BUILD_ASH | |
| 199 | |
| 200 CHECK_EQ(BUILTIN_COUNT, index); | |
| 164 } | 201 } |
| 165 | 202 |
| 166 // Mark as initialized. | 203 // Mark as initialized. |
| 167 initialized_ = true; | 204 initialized_ = true; |
| 168 } | 205 } |
| 169 | 206 |
| 170 void Builtins::TearDown() { initialized_ = false; } | 207 void Builtins::TearDown() { initialized_ = false; } |
| 171 | 208 |
| 172 void Builtins::IterateBuiltins(ObjectVisitor* v) { | 209 void Builtins::IterateBuiltins(ObjectVisitor* v) { |
| 173 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); | 210 for (int i = 0; i < BUILTIN_COUNT; i++) { |
| 211 v->VisitPointer(&builtins_[i].code); | |
| 212 } | |
| 174 } | 213 } |
| 175 | 214 |
| 176 const char* Builtins::Lookup(byte* pc) { | 215 const char* Builtins::Lookup(byte* pc) { |
| 177 // may be called during initialization (disassembler!) | 216 // may be called during initialization (disassembler!) |
| 178 if (initialized_) { | 217 if (initialized_) { |
| 179 for (int i = 0; i < builtin_count; i++) { | 218 for (int i = 0; i < BUILTIN_COUNT; i++) { |
| 180 Code* entry = Code::cast(builtins_[i]); | 219 Code* entry = Code::cast(builtins_[i].code); |
| 181 if (entry->contains(pc)) return name(i); | 220 if (entry->contains(pc)) return name(i); |
| 182 } | 221 } |
| 183 } | 222 } |
| 184 return NULL; | 223 return NULL; |
| 185 } | 224 } |
| 186 | 225 |
| 187 const char* Builtins::name(int index) { | 226 const char* Builtins::name(int index) { |
| 188 switch (index) { | 227 switch (index) { |
| 189 #define CASE(Name, ...) \ | 228 #define CASE(Name, ...) \ |
| 190 case k##Name: \ | 229 case k##Name: \ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 218 if (responsible_context.is_null()) { | 257 if (responsible_context.is_null()) { |
| 219 return true; | 258 return true; |
| 220 } | 259 } |
| 221 } | 260 } |
| 222 if (*responsible_context == target->context()) return true; | 261 if (*responsible_context == target->context()) return true; |
| 223 return isolate->MayAccess(responsible_context, target_global_proxy); | 262 return isolate->MayAccess(responsible_context, target_global_proxy); |
| 224 } | 263 } |
| 225 | 264 |
| 226 } // namespace internal | 265 } // namespace internal |
| 227 } // namespace v8 | 266 } // namespace v8 |
| OLD | NEW |