Chromium Code Reviews

Side by Side Diff: src/builtins/builtins.cc

Issue 2246333003: Store information about builtins in descriptors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix typo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 76 matching lines...)
110 return *code; 110 return *code;
111 } 111 }
112 } // anonymous namespace 112 } // anonymous namespace
113 113
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 int index = 0;
121 int index = 0; 121 const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN);
122 const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN); 122 Code* code;
123 Code* code; 123 Address entry;
124 #define BUILD_CPP(Name) \ 124
125 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), BUILTIN_EXIT, \ 125 // If setting up a snapshot (or running without a snapshot), the code objects
126 kBuiltinFlags, #Name); \ 126 // are created here. Otherwise, we simply leave the code pointer unset as it
127 builtins_[index++] = code; 127 // will be written later by the deserializer.
128 #define BUILD_API(Name) \ 128
129 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), EXIT, \ 129 #define MAYBE_CODE(call) (create_heap_objects ? (call) : nullptr)
130 kBuiltinFlags, #Name); \ 130 #define BUILD_CPP(Name) \
131 builtins_[index++] = code; 131 entry = FUNCTION_ADDR(Builtin_##Name); \
132 #define BUILD_TFJ(Name, Argc) \ 132 code = MAYBE_CODE( \
133 code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \ 133 BuildAdaptor(isolate, entry, BUILTIN_EXIT, kBuiltinFlags, #Name)); \
134 kBuiltinFlags, #Name); \ 134 builtins_[index++] = Descriptor(k##Name, CPP, entry, code, #Name);
135 builtins_[index++] = code; 135 #define BUILD_API(Name) \
136 entry = FUNCTION_ADDR(Builtin_##Name); \
137 code = MAYBE_CODE(BuildAdaptor(isolate, entry, EXIT, kBuiltinFlags, #Name)); \
138 builtins_[index++] = Descriptor(k##Name, API, entry, code, #Name);
139 #define BUILD_TFJ(Name, Argc) \
140 code = MAYBE_CODE(BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, \
141 Argc, kBuiltinFlags, #Name)); \
142 builtins_[index++] = Descriptor(k##Name, TFJ, nullptr, code, #Name);
136 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \ 143 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor) \
137 { InterfaceDescriptor##Descriptor descriptor(isolate); } \ 144 { InterfaceDescriptor##Descriptor descriptor(isolate); } \
138 code = BuildWithCodeStubAssemblerCS( \ 145 code = MAYBE_CODE(BuildWithCodeStubAssemblerCS( \
139 isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \ 146 isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \
140 Code::ComputeFlags(Code::Kind, Extra), #Name); \ 147 Code::ComputeFlags(Code::Kind, Extra), #Name)); \
141 builtins_[index++] = code; 148 builtins_[index++] = Descriptor(k##Name, TFS, nullptr, code, #Name);
142 #define BUILD_ASM(Name) \ 149 #define BUILD_ASM(Name) \
143 code = \ 150 code = MAYBE_CODE(BuildWithMacroAssembler(isolate, Generate_##Name, \
144 BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \ 151 kBuiltinFlags, #Name)); \
145 builtins_[index++] = code; 152 builtins_[index++] = Descriptor(k##Name, ASM, nullptr, code, #Name);
146 #define BUILD_ASH(Name, Kind, Extra) \ 153 #define BUILD_ASH(Name, Kind, Extra) \
147 code = BuildWithMacroAssembler( \ 154 code = MAYBE_CODE( \
148 isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \ 155 BuildWithMacroAssembler(isolate, Generate_##Name, \
149 builtins_[index++] = code; 156 Code::ComputeFlags(Code::Kind, Extra), #Name)); \
157 builtins_[index++] = Descriptor(k##Name, ASH, nullptr, code, #Name);
150 158
151 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, 159 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM, BUILD_ASH,
152 BUILD_ASH, BUILD_ASM); 160 BUILD_ASM);
153 161
154 #undef BUILD_CPP 162 #undef BUILD_CPP
155 #undef BUILD_API 163 #undef BUILD_API
156 #undef BUILD_TFJ 164 #undef BUILD_TFJ
157 #undef BUILD_TFS 165 #undef BUILD_TFS
158 #undef BUILD_ASM 166 #undef BUILD_ASM
159 #undef BUILD_ASH 167 #undef BUILD_ASH
160 CHECK_EQ(builtin_count, index); 168 #undef MAYBE_CODE
161 for (int i = 0; i < builtin_count; i++) { 169
162 Code::cast(builtins_[i])->set_builtin_index(i); 170 CHECK_EQ(BUILTIN_COUNT, index);
171
172 if (create_heap_objects) {
173 for (int i = 0; i < BUILTIN_COUNT; i++) {
174 Code::cast(builtins_[i].code)->set_builtin_index(i);
Toon Verwaest 2016/08/19 11:58:15 drop cast
163 } 175 }
164 } 176 }
165 177
166 // Mark as initialized. 178 // Mark as initialized.
167 initialized_ = true; 179 initialized_ = true;
168 } 180 }
169 181
170 void Builtins::TearDown() { initialized_ = false; } 182 void Builtins::TearDown() { initialized_ = false; }
171 183
172 void Builtins::IterateBuiltins(ObjectVisitor* v) { 184 void Builtins::IterateBuiltins(ObjectVisitor* v) {
173 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); 185 for (int i = 0; i < BUILTIN_COUNT; i++) {
186 v->VisitPointer(&builtins_[i].code);
187 }
174 } 188 }
175 189
176 const char* Builtins::Lookup(byte* pc) { 190 const char* Builtins::Lookup(byte* pc) {
177 // may be called during initialization (disassembler!) 191 // may be called during initialization (disassembler!)
178 if (initialized_) { 192 if (initialized_) {
179 for (int i = 0; i < builtin_count; i++) { 193 for (int i = 0; i < BUILTIN_COUNT; i++) {
180 Code* entry = Code::cast(builtins_[i]); 194 Code* entry = Code::cast(builtins_[i].code);
181 if (entry->contains(pc)) return name(i); 195 if (entry->contains(pc)) return name(i);
182 } 196 }
183 } 197 }
184 return NULL; 198 return NULL;
185 } 199 }
186 200
187 const char* Builtins::name(int index) { 201 const char* Builtins::name(int index) {
188 switch (index) { 202 switch (index) {
189 #define CASE(Name, ...) \ 203 #define CASE(Name, ...) \
190 case k##Name: \ 204 case k##Name: \
(...skipping 27 matching lines...)
218 if (responsible_context.is_null()) { 232 if (responsible_context.is_null()) {
219 return true; 233 return true;
220 } 234 }
221 } 235 }
222 if (*responsible_context == target->context()) return true; 236 if (*responsible_context == target->context()) return true;
223 return isolate->MayAccess(responsible_context, target_global_proxy); 237 return isolate->MayAccess(responsible_context, target_global_proxy);
224 } 238 }
225 239
226 } // namespace internal 240 } // namespace internal
227 } // namespace v8 241 } // namespace v8
OLDNEW

Powered by Google App Engine