1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 // Specifies extra arguments required by a C++ builtin.
12 enum BuiltinExtraArguments {
13 NO_EXTRA_ARGUMENTS = 0,
14 NEEDS_CALLED_FUNCTION = 1
18 #define CODE_AGE_LIST_WITH_ARG(V, A) \
19 V(Quadragenarian, A) \
20 V(Quinquagenarian, A) \
22 V(Septuagenarian, A) \
25 #define CODE_AGE_LIST_IGNORE_ARG(X, V) V(X)
27 #define CODE_AGE_LIST(V) \
28 CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
30 #define CODE_AGE_LIST_COMPLETE(V) \
35 CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
37 #define DECLARE_CODE_AGE_BUILTIN(C, V) \
38 V(Make##C##CodeYoungAgainOddMarking, BUILTIN, \
39 UNINITIALIZED, kNoExtraICState) \
40 V(Make##C##CodeYoungAgainEvenMarking, BUILTIN, \
41 UNINITIALIZED, kNoExtraICState)
44 // Define list of builtins implemented in C++.
45 #define BUILTIN_LIST_C(V) \
46 V(Illegal, NO_EXTRA_ARGUMENTS) \
48 V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
50 V(ArrayPush, NO_EXTRA_ARGUMENTS) \
51 V(ArrayPop, NO_EXTRA_ARGUMENTS) \
52 V(ArrayShift, NO_EXTRA_ARGUMENTS) \
53 V(ArrayUnshift, NO_EXTRA_ARGUMENTS) \
54 V(ArraySlice, NO_EXTRA_ARGUMENTS) \
55 V(ArraySplice, NO_EXTRA_ARGUMENTS) \
56 V(ArrayConcat, NO_EXTRA_ARGUMENTS) \
58 V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
59 V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
60 V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
61 V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS) \
63 V(RestrictedFunctionPropertiesThrower, NO_EXTRA_ARGUMENTS) \
64 V(RestrictedStrictArgumentsPropertiesThrower, NO_EXTRA_ARGUMENTS)
66 // Define list of builtins implemented in assembly.
67 #define BUILTIN_LIST_A(V) \
68 V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState) \
69 V(InOptimizationQueue, BUILTIN, UNINITIALIZED, kNoExtraICState) \
70 V(JSConstructStubGeneric, BUILTIN, UNINITIALIZED, kNoExtraICState) \
71 V(JSConstructStubForDerived, BUILTIN, UNINITIALIZED, kNoExtraICState) \
72 V(JSConstructStubApi, BUILTIN, UNINITIALIZED, kNoExtraICState) \
73 V(JSEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState) \
74 V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState) \
75 V(InterpreterEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState) \
76 V(InterpreterExitTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState) \
77 V(CompileLazy, BUILTIN, UNINITIALIZED, kNoExtraICState) \
78 V(CompileOptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
79 V(CompileOptimizedConcurrent, BUILTIN, UNINITIALIZED, kNoExtraICState) \
80 V(NotifyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
81 V(NotifySoftDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
82 V(NotifyLazyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
83 V(NotifyStubFailure, BUILTIN, UNINITIALIZED, kNoExtraICState) \
84 V(NotifyStubFailureSaveDoubles, BUILTIN, UNINITIALIZED, kNoExtraICState) \
86 V(LoadIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState) \
87 V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState) \
88 V(StoreIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState) \
89 V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState) \
90 V(LoadIC_Getter_ForDeopt, LOAD_IC, MONOMORPHIC, kNoExtraICState) \
91 V(KeyedLoadIC_Megamorphic, KEYED_LOAD_IC, MEGAMORPHIC, kNoExtraICState) \
93 V(KeyedLoadIC_Megamorphic_Strong, KEYED_LOAD_IC, MEGAMORPHIC, \
94 LoadICState::kStrongModeState) \
96 V(StoreIC_Setter_ForDeopt, STORE_IC, MONOMORPHIC, \
97 StoreICState::kStrictModeState) \
99 V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED, kNoExtraICState) \
100 V(KeyedStoreIC_PreMonomorphic, KEYED_STORE_IC, PREMONOMORPHIC, \
102 V(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, MEGAMORPHIC, kNoExtraICState) \
104 V(KeyedStoreIC_Initialize_Strict, KEYED_STORE_IC, UNINITIALIZED, \
105 StoreICState::kStrictModeState) \
106 V(KeyedStoreIC_PreMonomorphic_Strict, KEYED_STORE_IC, PREMONOMORPHIC, \
107 StoreICState::kStrictModeState) \
108 V(KeyedStoreIC_Megamorphic_Strict, KEYED_STORE_IC, MEGAMORPHIC, \
109 StoreICState::kStrictModeState) \
111 V(FunctionCall, BUILTIN, UNINITIALIZED, kNoExtraICState) \
112 V(FunctionApply, BUILTIN, UNINITIALIZED, kNoExtraICState) \
113 V(ReflectApply, BUILTIN, UNINITIALIZED, kNoExtraICState) \
114 V(ReflectConstruct, BUILTIN, UNINITIALIZED, kNoExtraICState) \
116 V(InternalArrayCode, BUILTIN, UNINITIALIZED, kNoExtraICState) \
117 V(ArrayCode, BUILTIN, UNINITIALIZED, kNoExtraICState) \
119 V(StringConstructCode, BUILTIN, UNINITIALIZED, kNoExtraICState) \
121 V(OnStackReplacement, BUILTIN, UNINITIALIZED, kNoExtraICState) \
122 V(InterruptCheck, BUILTIN, UNINITIALIZED, kNoExtraICState) \
123 V(OsrAfterStackCheck, BUILTIN, UNINITIALIZED, kNoExtraICState) \
124 V(StackCheck, BUILTIN, UNINITIALIZED, kNoExtraICState) \
126 V(MarkCodeAsToBeExecutedOnce, BUILTIN, UNINITIALIZED, kNoExtraICState) \
127 V(MarkCodeAsExecutedOnce, BUILTIN, UNINITIALIZED, kNoExtraICState) \
128 V(MarkCodeAsExecutedTwice, BUILTIN, UNINITIALIZED, kNoExtraICState) \
129 CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, V)
131 // Define list of builtin handlers implemented in assembly.
132 #define BUILTIN_LIST_H(V) \
133 V(LoadIC_Slow, LOAD_IC) \
134 V(LoadIC_Slow_Strong, LOAD_IC) \
135 V(KeyedLoadIC_Slow, KEYED_LOAD_IC) \
136 V(KeyedLoadIC_Slow_Strong, KEYED_LOAD_IC) \
137 V(StoreIC_Slow, STORE_IC) \
138 V(KeyedStoreIC_Slow, KEYED_STORE_IC) \
139 V(LoadIC_Normal, LOAD_IC) \
140 V(LoadIC_Normal_Strong, LOAD_IC) \
141 V(StoreIC_Normal, STORE_IC)
143 // Define list of builtins used by the debugger implemented in assembly.
144 #define BUILTIN_LIST_DEBUG_A(V) \
145 V(Return_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \
146 V(Slot_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \
147 V(PlainReturn_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState) \
148 V(FrameDropper_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState)
150 // Define list of builtins implemented in JavaScript.
151 #define BUILTINS_LIST_JS(V) \
153 V(STRICT_EQUALS, 1) \
155 V(COMPARE_STRONG, 2) \
167 V(BIT_OR_STRONG, 1) \
169 V(BIT_AND_STRONG, 1) \
171 V(BIT_XOR_STRONG, 1) \
181 V(CALL_NON_FUNCTION, 0) \
182 V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \
183 V(CALL_FUNCTION_PROXY, 1) \
184 V(CALL_FUNCTION_PROXY_AS_CONSTRUCTOR, 1) \
189 V(STRING_ADD_LEFT, 1) \
190 V(STRING_ADD_LEFT_STRONG, 1) \
191 V(STRING_ADD_RIGHT, 1) \
192 V(STRING_ADD_RIGHT_STRONG, 1) \
193 V(APPLY_PREPARE, 1) \
194 V(REFLECT_APPLY_PREPARE, 1) \
195 V(REFLECT_CONSTRUCT_PREPARE, 2) \
196 V(CONCAT_ITERABLE_TO_ARRAY, 1) \
199 class BuiltinFunctionTable;
207 // Generate all builtin code objects. Should be called once during
208 // isolate initialization.
209 void SetUp(Isolate* isolate, bool create_heap_objects);
212 // Garbage collection support.
213 void IterateBuiltins(ObjectVisitor* v);
215 // Disassembler support.
216 const char* Lookup(byte* pc);
219 #define DEF_ENUM_C(name, ignore) k##name,
220 #define DEF_ENUM_A(name, kind, state, extra) k##name,
221 #define DEF_ENUM_H(name, kind) k##name,
222 BUILTIN_LIST_C(DEF_ENUM_C)
223 BUILTIN_LIST_A(DEF_ENUM_A)
224 BUILTIN_LIST_H(DEF_ENUM_H)
225 BUILTIN_LIST_DEBUG_A(DEF_ENUM_A)
232 #define DEF_ENUM_C(name, ignore) c_##name,
233 BUILTIN_LIST_C(DEF_ENUM_C)
239 #define DEF_ENUM(name, ignore) name,
240 BUILTINS_LIST_JS(DEF_ENUM)
245 #define DECLARE_BUILTIN_ACCESSOR_C(name, ignore) Handle<Code> name();
246 #define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \
248 #define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name();
249 BUILTIN_LIST_C(DECLARE_BUILTIN_ACCESSOR_C)
250 BUILTIN_LIST_A(DECLARE_BUILTIN_ACCESSOR_A)
251 BUILTIN_LIST_H(DECLARE_BUILTIN_ACCESSOR_H)
252 BUILTIN_LIST_DEBUG_A(DECLARE_BUILTIN_ACCESSOR_A)
253 #undef DECLARE_BUILTIN_ACCESSOR_C
254 #undef DECLARE_BUILTIN_ACCESSOR_A
256 Code* builtin(Name name) {
257 // Code::cast cannot be used here since we access builtins
258 // during the marking phase of mark sweep. See IC::Clear.
259 return reinterpret_cast<Code*>(builtins_[name]);
262 Address builtin_address(Name name) {
263 return reinterpret_cast<Address>(&builtins_[name]);
266 static Address c_function_address(CFunctionId id) {
267 return c_functions_[id];
270 static const char* GetName(JavaScript id) { return javascript_names_[id]; }
271 const char* name(int index) {
273 DCHECK(index < builtin_count);
274 return names_[index];
276 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
277 static int NumberOfJavaScriptBuiltins() { return id_count; }
279 bool is_initialized() const { return initialized_; }
281 MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction(
282 Handle<JSFunction> function, Handle<Object> receiver, int argc,
283 Handle<Object> args[]);
288 // The external C++ functions called from the code.
289 static Address const c_functions_[cfunction_count];
291 // Note: These are always Code objects, but to conform with
292 // IterateBuiltins() above which assumes Object**'s for the callback
293 // function f, we use an Object* array here.
294 Object* builtins_[builtin_count];
295 const char* names_[builtin_count];
296 static const char* const javascript_names_[id_count];
297 static int const javascript_argc_[id_count];
299 static void Generate_Adaptor(MacroAssembler* masm,
301 BuiltinExtraArguments extra_args);
302 static void Generate_CompileLazy(MacroAssembler* masm);
303 static void Generate_InOptimizationQueue(MacroAssembler* masm);
304 static void Generate_CompileOptimized(MacroAssembler* masm);
305 static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm);
306 static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
307 static void Generate_JSConstructStubForDerived(MacroAssembler* masm);
308 static void Generate_JSConstructStubApi(MacroAssembler* masm);
309 static void Generate_JSEntryTrampoline(MacroAssembler* masm);
310 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
311 static void Generate_InterpreterEntryTrampoline(MacroAssembler* masm);
312 static void Generate_InterpreterExitTrampoline(MacroAssembler* masm);
313 static void Generate_NotifyDeoptimized(MacroAssembler* masm);
314 static void Generate_NotifySoftDeoptimized(MacroAssembler* masm);
315 static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm);
316 static void Generate_NotifyStubFailure(MacroAssembler* masm);
317 static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm);
318 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
320 static void Generate_FunctionCall(MacroAssembler* masm);
321 static void Generate_FunctionApply(MacroAssembler* masm);
322 static void Generate_ReflectApply(MacroAssembler* masm);
323 static void Generate_ReflectConstruct(MacroAssembler* masm);
325 static void Generate_InternalArrayCode(MacroAssembler* masm);
326 static void Generate_ArrayCode(MacroAssembler* masm);
328 static void Generate_StringConstructCode(MacroAssembler* masm);
329 static void Generate_OnStackReplacement(MacroAssembler* masm);
330 static void Generate_OsrAfterStackCheck(MacroAssembler* masm);
331 static void Generate_InterruptCheck(MacroAssembler* masm);
332 static void Generate_StackCheck(MacroAssembler* masm);
334 #define DECLARE_CODE_AGE_BUILTIN_GENERATOR(C) \
335 static void Generate_Make##C##CodeYoungAgainEvenMarking( \
336 MacroAssembler* masm); \
337 static void Generate_Make##C##CodeYoungAgainOddMarking( \
338 MacroAssembler* masm);
339 CODE_AGE_LIST(DECLARE_CODE_AGE_BUILTIN_GENERATOR)
340 #undef DECLARE_CODE_AGE_BUILTIN_GENERATOR
342 static void Generate_MarkCodeAsToBeExecutedOnce(MacroAssembler* masm);
343 static void Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm);
344 static void Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm);
346 static void InitBuiltinFunctionTable();
350 friend class BuiltinFunctionTable;
351 friend class Isolate;
353 DISALLOW_COPY_AND_ASSIGN(Builtins);
356 } } // namespace v8::internal
358 #endif // V8_BUILTINS_H_