Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

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: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/profiler/cpu-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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...) Expand 10 before | Expand all | Expand 10 after
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, API, 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
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.
160 CHECK_EQ(builtin_count, index); 168
161 for (int i = 0; i < builtin_count; i++) { 169 CHECK_EQ(BUILTIN_COUNT, index);
162 Code::cast(builtins_[i])->set_builtin_index(i); 170
171 if (create_heap_objects) {
172 for (int i = 0; i < BUILTIN_COUNT; i++) {
173 Code::cast(builtins_[i].code)->set_builtin_index(i);
163 } 174 }
164 } 175 }
165 176
166 // Mark as initialized. 177 // Mark as initialized.
167 initialized_ = true; 178 initialized_ = true;
168 } 179 }
169 180
170 void Builtins::TearDown() { initialized_ = false; } 181 void Builtins::TearDown() { initialized_ = false; }
171 182
172 void Builtins::IterateBuiltins(ObjectVisitor* v) { 183 void Builtins::IterateBuiltins(ObjectVisitor* v) {
173 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); 184 for (int i = 0; i < BUILTIN_COUNT; i++) {
185 v->VisitPointer(&builtins_[i].code);
186 }
174 } 187 }
175 188
176 const char* Builtins::Lookup(byte* pc) { 189 const char* Builtins::Lookup(byte* pc) {
177 // may be called during initialization (disassembler!) 190 // may be called during initialization (disassembler!)
178 if (initialized_) { 191 if (initialized_) {
179 for (int i = 0; i < builtin_count; i++) { 192 for (int i = 0; i < BUILTIN_COUNT; i++) {
180 Code* entry = Code::cast(builtins_[i]); 193 Code* entry = Code::cast(builtins_[i].code);
181 if (entry->contains(pc)) return name(i); 194 if (entry->contains(pc)) return name(i);
182 } 195 }
183 } 196 }
184 return NULL; 197 return NULL;
185 } 198 }
186 199
187 const char* Builtins::name(int index) { 200 const char* Builtins::name(int index) {
188 switch (index) { 201 switch (index) {
189 #define CASE(Name, ...) \ 202 #define CASE(Name, ...) \
190 case k##Name: \ 203 case k##Name: \
(...skipping 27 matching lines...) Expand all
218 if (responsible_context.is_null()) { 231 if (responsible_context.is_null()) {
219 return true; 232 return true;
220 } 233 }
221 } 234 }
222 if (*responsible_context == target->context()) return true; 235 if (*responsible_context == target->context()) return true;
223 return isolate->MayAccess(responsible_context, target_global_proxy); 236 return isolate->MayAccess(responsible_context, target_global_proxy);
224 } 237 }
225 238
226 } // namespace internal 239 } // namespace internal
227 } // namespace v8 240 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/profiler/cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698