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

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

Issue 2760233005: [snapshot] Move builtins generation into mksnapshot (Closed)
Patch Set: Created 3 years, 9 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
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/api.h" 6 #include "src/api.h"
7 #include "src/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/callable.h" 8 #include "src/callable.h"
9 #include "src/code-events.h"
10 #include "src/compiler/code-assembler.h"
11 #include "src/ic/ic-state.h"
12 #include "src/interface-descriptors.h"
13 #include "src/isolate.h" 9 #include "src/isolate.h"
14 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
15 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
16 12
17 namespace v8 { 13 namespace v8 {
18 namespace internal { 14 namespace internal {
19 15
20 // Forward declarations for C++ builtins. 16 // Forward declarations for C++ builtins.
21 #define FORWARD_DECLARE(Name) \ 17 #define FORWARD_DECLARE(Name) \
22 Object* Builtin_##Name(int argc, Object** args, Isolate* isolate); 18 Object* Builtin_##Name(int argc, Object** args, Isolate* isolate);
23 BUILTIN_LIST_C(FORWARD_DECLARE) 19 BUILTIN_LIST_C(FORWARD_DECLARE)
24 20
25 Builtins::Builtins() : initialized_(false) { 21 Builtins::Builtins() : initialized_(false) {
26 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); 22 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count);
27 } 23 }
28 24
29 Builtins::~Builtins() {} 25 Builtins::~Builtins() {}
30 26
31 namespace {
Jakob Kummerow 2017/03/21 16:38:00 all this stuff moved to setup-builtins-internal.cc
32 void PostBuildProfileAndTracing(Isolate* isolate, Code* code,
33 const char* name) {
34 PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG,
35 AbstractCode::cast(code), name));
36 #ifdef ENABLE_DISASSEMBLER
37 if (FLAG_print_builtin_code) {
38 CodeTracer::Scope trace_scope(isolate->GetCodeTracer());
39 OFStream os(trace_scope.file());
40 os << "Builtin: " << name << "\n";
41 code->Disassemble(name, os);
42 os << "\n";
43 }
44 #endif
45 }
46
47 typedef void (*MacroAssemblerGenerator)(MacroAssembler*);
48 typedef void (*CodeAssemblerGenerator)(compiler::CodeAssemblerState*);
49
50 Code* BuildWithMacroAssembler(Isolate* isolate,
51 MacroAssemblerGenerator generator,
52 Code::Flags flags, const char* s_name) {
53 HandleScope scope(isolate);
54 const size_t buffer_size = 32 * KB;
55 byte buffer[buffer_size]; // NOLINT(runtime/arrays)
56 MacroAssembler masm(isolate, buffer, buffer_size, CodeObjectRequired::kYes);
57 DCHECK(!masm.has_frame());
58 generator(&masm);
59 CodeDesc desc;
60 masm.GetCode(&desc);
61 Handle<Code> code =
62 isolate->factory()->NewCode(desc, flags, masm.CodeObject());
63 PostBuildProfileAndTracing(isolate, *code, s_name);
64 return *code;
65 }
66
67 Code* BuildAdaptor(Isolate* isolate, Address builtin_address,
68 Builtins::ExitFrameType exit_frame_type, Code::Flags flags,
69 const char* name) {
70 HandleScope scope(isolate);
71 const size_t buffer_size = 32 * KB;
72 byte buffer[buffer_size]; // NOLINT(runtime/arrays)
73 MacroAssembler masm(isolate, buffer, buffer_size, CodeObjectRequired::kYes);
74 DCHECK(!masm.has_frame());
75 Builtins::Generate_Adaptor(&masm, builtin_address, exit_frame_type);
76 CodeDesc desc;
77 masm.GetCode(&desc);
78 Handle<Code> code =
79 isolate->factory()->NewCode(desc, flags, masm.CodeObject());
80 PostBuildProfileAndTracing(isolate, *code, name);
81 return *code;
82 }
83
84 // Builder for builtins implemented in TurboFan with JS linkage.
85 Code* BuildWithCodeStubAssemblerJS(Isolate* isolate,
86 CodeAssemblerGenerator generator, int argc,
87 Code::Flags flags, const char* name) {
88 HandleScope scope(isolate);
89 Zone zone(isolate->allocator(), ZONE_NAME);
90 const int argc_with_recv =
91 (argc == SharedFunctionInfo::kDontAdaptArgumentsSentinel) ? 0 : argc + 1;
92 compiler::CodeAssemblerState state(isolate, &zone, argc_with_recv, flags,
93 name);
94 generator(&state);
95 Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state);
96 PostBuildProfileAndTracing(isolate, *code, name);
97 return *code;
98 }
99
100 // Builder for builtins implemented in TurboFan with CallStub linkage.
101 Code* BuildWithCodeStubAssemblerCS(Isolate* isolate,
102 CodeAssemblerGenerator generator,
103 CallDescriptors::Key interface_descriptor,
104 Code::Flags flags, const char* name,
105 int result_size) {
106 HandleScope scope(isolate);
107 Zone zone(isolate->allocator(), ZONE_NAME);
108 // The interface descriptor with given key must be initialized at this point
109 // and this construction just queries the details from the descriptors table.
110 CallInterfaceDescriptor descriptor(isolate, interface_descriptor);
111 // Ensure descriptor is already initialized.
112 DCHECK_LE(0, descriptor.GetRegisterParameterCount());
113 compiler::CodeAssemblerState state(isolate, &zone, descriptor, flags, name,
114 result_size);
115 generator(&state);
116 Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state);
117 PostBuildProfileAndTracing(isolate, *code, name);
118 return *code;
119 }
120 } // anonymous namespace
121
122 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) {
123 DCHECK(!initialized_);
124
125 // Create a scope for the handles in the builtins.
126 HandleScope scope(isolate);
127
128 if (create_heap_objects) {
129 int index = 0;
130 const Code::Flags kBuiltinFlags = Code::ComputeFlags(Code::BUILTIN);
131 Code* code;
132 #define BUILD_CPP(Name) \
133 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), BUILTIN_EXIT, \
134 kBuiltinFlags, #Name); \
135 builtins_[index++] = code;
136 #define BUILD_API(Name) \
137 code = BuildAdaptor(isolate, FUNCTION_ADDR(Builtin_##Name), EXIT, \
138 kBuiltinFlags, #Name); \
139 builtins_[index++] = code;
140 #define BUILD_TFJ(Name, Argc, ...) \
141 code = BuildWithCodeStubAssemblerJS(isolate, &Generate_##Name, Argc, \
142 kBuiltinFlags, #Name); \
143 builtins_[index++] = code;
144 #define BUILD_TFS(Name, Kind, Extra, InterfaceDescriptor, result_size) \
145 { InterfaceDescriptor##Descriptor descriptor(isolate); } \
146 code = BuildWithCodeStubAssemblerCS( \
147 isolate, &Generate_##Name, CallDescriptors::InterfaceDescriptor, \
148 Code::ComputeFlags(Code::Kind, Extra), #Name, result_size); \
149 builtins_[index++] = code;
150 #define BUILD_ASM(Name) \
151 code = \
152 BuildWithMacroAssembler(isolate, Generate_##Name, kBuiltinFlags, #Name); \
153 builtins_[index++] = code;
154 #define BUILD_ASH(Name, Kind, Extra) \
155 code = BuildWithMacroAssembler( \
156 isolate, Generate_##Name, Code::ComputeFlags(Code::Kind, Extra), #Name); \
157 builtins_[index++] = code;
158
159 BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFS, BUILD_ASM,
160 BUILD_ASH, BUILD_ASM);
161
162 #undef BUILD_CPP
163 #undef BUILD_API
164 #undef BUILD_TFJ
165 #undef BUILD_TFS
166 #undef BUILD_ASM
167 #undef BUILD_ASH
168 CHECK_EQ(builtin_count, index);
169 for (int i = 0; i < builtin_count; i++) {
170 Code::cast(builtins_[i])->set_builtin_index(i);
171 }
172
173 #define SET_PROMISE_REJECTION_PREDICTION(Name) \
174 Code::cast(builtins_[k##Name])->set_is_promise_rejection(true);
175
176 BUILTIN_PROMISE_REJECTION_PREDICTION_LIST(SET_PROMISE_REJECTION_PREDICTION)
177 #undef SET_PROMISE_REJECTION_PREDICTION
178
179 #define SET_EXCEPTION_CAUGHT_PREDICTION(Name) \
180 Code::cast(builtins_[k##Name])->set_is_exception_caught(true);
181
182 BUILTIN_EXCEPTION_CAUGHT_PREDICTION_LIST(SET_EXCEPTION_CAUGHT_PREDICTION)
183 #undef SET_EXCEPTION_CAUGHT_PREDICTION
184
185 #define SET_CODE_NON_TAGGED_PARAMS(Name) \
186 Code::cast(builtins_[k##Name])->set_has_tagged_params(false);
187 BUILTINS_WITH_UNTAGGED_PARAMS(SET_CODE_NON_TAGGED_PARAMS)
188 #undef SET_CODE_NON_TAGGED_PARAMS
189 }
190
191 // Mark as initialized.
192 initialized_ = true;
193 }
194
195 void Builtins::TearDown() { initialized_ = false; } 27 void Builtins::TearDown() { initialized_ = false; }
196 28
197 void Builtins::IterateBuiltins(ObjectVisitor* v) { 29 void Builtins::IterateBuiltins(ObjectVisitor* v) {
198 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); 30 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count);
199 } 31 }
200 32
201 const char* Builtins::Lookup(byte* pc) { 33 const char* Builtins::Lookup(byte* pc) {
202 // may be called during initialization (disassembler!) 34 // may be called during initialization (disassembler!)
203 if (initialized_) { 35 if (initialized_) {
204 for (int i = 0; i < builtin_count; i++) { 36 for (int i = 0; i < builtin_count; i++) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // TODO(jochen): Remove this. 231 // TODO(jochen): Remove this.
400 if (responsible_context.is_null()) { 232 if (responsible_context.is_null()) {
401 return true; 233 return true;
402 } 234 }
403 if (*responsible_context == target->context()) return true; 235 if (*responsible_context == target->context()) return true;
404 return isolate->MayAccess(responsible_context, target_global_proxy); 236 return isolate->MayAccess(responsible_context, target_global_proxy);
405 } 237 }
406 238
407 } // namespace internal 239 } // namespace internal
408 } // namespace v8 240 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698