v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
builtins.h
Go to the documentation of this file.
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_BUILTINS_H_
29 #define V8_BUILTINS_H_
30 
31 namespace v8 {
32 namespace internal {
33 
34 // Specifies extra arguments required by a C++ builtin.
38 };
39 
40 
41 #define CODE_AGE_LIST_WITH_ARG(V, A) \
42  V(Quadragenarian, A) \
43  V(Quinquagenarian, A) \
44  V(Sexagenarian, A) \
45  V(Septuagenarian, A) \
46  V(Octogenarian, A)
47 
48 #define CODE_AGE_LIST_IGNORE_ARG(X, V) V(X)
49 
50 #define CODE_AGE_LIST(V) \
51  CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
52 
53 #define CODE_AGE_LIST_COMPLETE(V) \
54  V(NotExecuted) \
55  V(ExecutedOnce) \
56  V(NoAge) \
57  CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
58 
59 #define DECLARE_CODE_AGE_BUILTIN(C, V) \
60  V(Make##C##CodeYoungAgainOddMarking, BUILTIN, \
61  UNINITIALIZED, kNoExtraICState) \
62  V(Make##C##CodeYoungAgainEvenMarking, BUILTIN, \
63  UNINITIALIZED, kNoExtraICState)
64 
65 
66 // Define list of builtins implemented in C++.
67 #define BUILTIN_LIST_C(V) \
68  V(Illegal, NO_EXTRA_ARGUMENTS) \
69  \
70  V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
71  \
72  V(ArrayPush, NO_EXTRA_ARGUMENTS) \
73  V(ArrayPop, NO_EXTRA_ARGUMENTS) \
74  V(ArrayShift, NO_EXTRA_ARGUMENTS) \
75  V(ArrayUnshift, NO_EXTRA_ARGUMENTS) \
76  V(ArraySlice, NO_EXTRA_ARGUMENTS) \
77  V(ArraySplice, NO_EXTRA_ARGUMENTS) \
78  V(ArrayConcat, NO_EXTRA_ARGUMENTS) \
79  \
80  V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
81  V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
82  V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
83  V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS) \
84  \
85  V(StrictModePoisonPill, NO_EXTRA_ARGUMENTS)
86 
87 // Define list of builtins implemented in assembly.
88 #define BUILTIN_LIST_A(V) \
89  V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED, \
90  kNoExtraICState) \
91  V(InOptimizationQueue, BUILTIN, UNINITIALIZED, \
92  kNoExtraICState) \
93  V(JSConstructStubCountdown, BUILTIN, UNINITIALIZED, \
94  kNoExtraICState) \
95  V(JSConstructStubGeneric, BUILTIN, UNINITIALIZED, \
96  kNoExtraICState) \
97  V(JSConstructStubApi, BUILTIN, UNINITIALIZED, \
98  kNoExtraICState) \
99  V(JSEntryTrampoline, BUILTIN, UNINITIALIZED, \
100  kNoExtraICState) \
101  V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED, \
102  kNoExtraICState) \
103  V(CompileUnoptimized, BUILTIN, UNINITIALIZED, \
104  kNoExtraICState) \
105  V(CompileOptimized, BUILTIN, UNINITIALIZED, \
106  kNoExtraICState) \
107  V(CompileOptimizedConcurrent, BUILTIN, UNINITIALIZED, \
108  kNoExtraICState) \
109  V(NotifyDeoptimized, BUILTIN, UNINITIALIZED, \
110  kNoExtraICState) \
111  V(NotifySoftDeoptimized, BUILTIN, UNINITIALIZED, \
112  kNoExtraICState) \
113  V(NotifyLazyDeoptimized, BUILTIN, UNINITIALIZED, \
114  kNoExtraICState) \
115  V(NotifyStubFailure, BUILTIN, UNINITIALIZED, \
116  kNoExtraICState) \
117  V(NotifyStubFailureSaveDoubles, BUILTIN, UNINITIALIZED, \
118  kNoExtraICState) \
119  \
120  V(LoadIC_Miss, BUILTIN, UNINITIALIZED, \
121  kNoExtraICState) \
122  V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED, \
123  kNoExtraICState) \
124  V(StoreIC_Miss, BUILTIN, UNINITIALIZED, \
125  kNoExtraICState) \
126  V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED, \
127  kNoExtraICState) \
128  V(LoadIC_Getter_ForDeopt, LOAD_IC, MONOMORPHIC, \
129  kNoExtraICState) \
130  V(KeyedLoadIC_Initialize, KEYED_LOAD_IC, UNINITIALIZED, \
131  kNoExtraICState) \
132  V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC, \
133  kNoExtraICState) \
134  V(KeyedLoadIC_Generic, KEYED_LOAD_IC, GENERIC, \
135  kNoExtraICState) \
136  V(KeyedLoadIC_String, KEYED_LOAD_IC, MEGAMORPHIC, \
137  kNoExtraICState) \
138  V(KeyedLoadIC_IndexedInterceptor, KEYED_LOAD_IC, MONOMORPHIC, \
139  kNoExtraICState) \
140  V(KeyedLoadIC_SloppyArguments, KEYED_LOAD_IC, MONOMORPHIC, \
141  kNoExtraICState) \
142  \
143  V(StoreIC_Setter_ForDeopt, STORE_IC, MONOMORPHIC, \
144  StoreIC::kStrictModeState) \
145  \
146  V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED, \
147  kNoExtraICState) \
148  V(KeyedStoreIC_PreMonomorphic, KEYED_STORE_IC, PREMONOMORPHIC, \
149  kNoExtraICState) \
150  V(KeyedStoreIC_Generic, KEYED_STORE_IC, GENERIC, \
151  kNoExtraICState) \
152  \
153  V(KeyedStoreIC_Initialize_Strict, KEYED_STORE_IC, UNINITIALIZED, \
154  StoreIC::kStrictModeState) \
155  V(KeyedStoreIC_PreMonomorphic_Strict, KEYED_STORE_IC, PREMONOMORPHIC, \
156  StoreIC::kStrictModeState) \
157  V(KeyedStoreIC_Generic_Strict, KEYED_STORE_IC, GENERIC, \
158  StoreIC::kStrictModeState) \
159  V(KeyedStoreIC_SloppyArguments, KEYED_STORE_IC, MONOMORPHIC, \
160  kNoExtraICState) \
161  \
162  /* Uses KeyedLoadIC_Initialize; must be after in list. */ \
163  V(FunctionCall, BUILTIN, UNINITIALIZED, \
164  kNoExtraICState) \
165  V(FunctionApply, BUILTIN, UNINITIALIZED, \
166  kNoExtraICState) \
167  \
168  V(InternalArrayCode, BUILTIN, UNINITIALIZED, \
169  kNoExtraICState) \
170  V(ArrayCode, BUILTIN, UNINITIALIZED, \
171  kNoExtraICState) \
172  \
173  V(StringConstructCode, BUILTIN, UNINITIALIZED, \
174  kNoExtraICState) \
175  \
176  V(OnStackReplacement, BUILTIN, UNINITIALIZED, \
177  kNoExtraICState) \
178  V(InterruptCheck, BUILTIN, UNINITIALIZED, \
179  kNoExtraICState) \
180  V(OsrAfterStackCheck, BUILTIN, UNINITIALIZED, \
181  kNoExtraICState) \
182  V(StackCheck, BUILTIN, UNINITIALIZED, \
183  kNoExtraICState) \
184  \
185  V(MarkCodeAsExecutedOnce, BUILTIN, UNINITIALIZED, \
186  kNoExtraICState) \
187  V(MarkCodeAsExecutedTwice, BUILTIN, UNINITIALIZED, \
188  kNoExtraICState) \
189  CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, V)
190 
191 // Define list of builtin handlers implemented in assembly.
192 #define BUILTIN_LIST_H(V) \
193  V(LoadIC_Slow, LOAD_IC) \
194  V(KeyedLoadIC_Slow, KEYED_LOAD_IC) \
195  V(StoreIC_Slow, STORE_IC) \
196  V(KeyedStoreIC_Slow, KEYED_STORE_IC) \
197  V(LoadIC_Normal, LOAD_IC) \
198  V(StoreIC_Normal, STORE_IC)
199 
200 #ifdef ENABLE_DEBUGGER_SUPPORT
201 // Define list of builtins used by the debugger implemented in assembly.
202 #define BUILTIN_LIST_DEBUG_A(V) \
203  V(Return_DebugBreak, BUILTIN, DEBUG_STUB, \
204  DEBUG_BREAK) \
205  V(CallFunctionStub_DebugBreak, BUILTIN, DEBUG_STUB, \
206  DEBUG_BREAK) \
207  V(CallFunctionStub_Recording_DebugBreak, BUILTIN, DEBUG_STUB, \
208  DEBUG_BREAK) \
209  V(CallConstructStub_DebugBreak, BUILTIN, DEBUG_STUB, \
210  DEBUG_BREAK) \
211  V(CallConstructStub_Recording_DebugBreak, BUILTIN, DEBUG_STUB, \
212  DEBUG_BREAK) \
213  V(LoadIC_DebugBreak, LOAD_IC, DEBUG_STUB, \
214  DEBUG_BREAK) \
215  V(KeyedLoadIC_DebugBreak, KEYED_LOAD_IC, DEBUG_STUB, \
216  DEBUG_BREAK) \
217  V(StoreIC_DebugBreak, STORE_IC, DEBUG_STUB, \
218  DEBUG_BREAK) \
219  V(KeyedStoreIC_DebugBreak, KEYED_STORE_IC, DEBUG_STUB, \
220  DEBUG_BREAK) \
221  V(CompareNilIC_DebugBreak, COMPARE_NIL_IC, DEBUG_STUB, \
222  DEBUG_BREAK) \
223  V(Slot_DebugBreak, BUILTIN, DEBUG_STUB, \
224  DEBUG_BREAK) \
225  V(PlainReturn_LiveEdit, BUILTIN, DEBUG_STUB, \
226  DEBUG_BREAK) \
227  V(FrameDropper_LiveEdit, BUILTIN, DEBUG_STUB, \
228  DEBUG_BREAK)
229 #else
230 #define BUILTIN_LIST_DEBUG_A(V)
231 #endif
232 
233 // Define list of builtins implemented in JavaScript.
234 #define BUILTINS_LIST_JS(V) \
235  V(EQUALS, 1) \
236  V(STRICT_EQUALS, 1) \
237  V(COMPARE, 2) \
238  V(ADD, 1) \
239  V(SUB, 1) \
240  V(MUL, 1) \
241  V(DIV, 1) \
242  V(MOD, 1) \
243  V(BIT_OR, 1) \
244  V(BIT_AND, 1) \
245  V(BIT_XOR, 1) \
246  V(SHL, 1) \
247  V(SAR, 1) \
248  V(SHR, 1) \
249  V(DELETE, 2) \
250  V(IN, 1) \
251  V(INSTANCE_OF, 1) \
252  V(FILTER_KEY, 1) \
253  V(CALL_NON_FUNCTION, 0) \
254  V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \
255  V(CALL_FUNCTION_PROXY, 1) \
256  V(CALL_FUNCTION_PROXY_AS_CONSTRUCTOR, 1) \
257  V(TO_OBJECT, 0) \
258  V(TO_NUMBER, 0) \
259  V(TO_STRING, 0) \
260  V(STRING_ADD_LEFT, 1) \
261  V(STRING_ADD_RIGHT, 1) \
262  V(APPLY_PREPARE, 1) \
263  V(APPLY_OVERFLOW, 1)
264 
265 class BuiltinFunctionTable;
266 class ObjectVisitor;
267 
268 
269 class Builtins {
270  public:
271  ~Builtins();
272 
273  // Generate all builtin code objects. Should be called once during
274  // isolate initialization.
275  void SetUp(Isolate* isolate, bool create_heap_objects);
276  void TearDown();
277 
278  // Garbage collection support.
279  void IterateBuiltins(ObjectVisitor* v);
280 
281  // Disassembler support.
282  const char* Lookup(byte* pc);
283 
284  enum Name {
285 #define DEF_ENUM_C(name, ignore) k##name,
286 #define DEF_ENUM_A(name, kind, state, extra) k##name,
287 #define DEF_ENUM_H(name, kind) k##name,
292 #undef DEF_ENUM_C
293 #undef DEF_ENUM_A
295  };
296 
297  enum CFunctionId {
298 #define DEF_ENUM_C(name, ignore) c_##name,
300 #undef DEF_ENUM_C
302  };
303 
304  enum JavaScript {
305 #define DEF_ENUM(name, ignore) name,
307 #undef DEF_ENUM
309  };
310 
311 #define DECLARE_BUILTIN_ACCESSOR_C(name, ignore) Handle<Code> name();
312 #define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \
313  Handle<Code> name();
314 #define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name();
319 #undef DECLARE_BUILTIN_ACCESSOR_C
320 #undef DECLARE_BUILTIN_ACCESSOR_A
321 
323  // Code::cast cannot be used here since we access builtins
324  // during the marking phase of mark sweep. See IC::Clear.
325  return reinterpret_cast<Code*>(builtins_[name]);
326  }
327 
329  return reinterpret_cast<Address>(&builtins_[name]);
330  }
331 
333  return c_functions_[id];
334  }
335 
336  static const char* GetName(JavaScript id) { return javascript_names_[id]; }
337  const char* name(int index) {
338  ASSERT(index >= 0);
339  ASSERT(index < builtin_count);
340  return names_[index];
341  }
342  static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
343  Handle<Code> GetCode(JavaScript id, bool* resolved);
344  static int NumberOfJavaScriptBuiltins() { return id_count; }
345 
346  bool is_initialized() const { return initialized_; }
347 
348  private:
349  Builtins();
350 
351  // The external C++ functions called from the code.
352  static Address const c_functions_[cfunction_count];
353 
354  // Note: These are always Code objects, but to conform with
355  // IterateBuiltins() above which assumes Object**'s for the callback
356  // function f, we use an Object* array here.
357  Object* builtins_[builtin_count];
358  const char* names_[builtin_count];
359  static const char* const javascript_names_[id_count];
360  static int const javascript_argc_[id_count];
361 
362  static void Generate_Adaptor(MacroAssembler* masm,
363  CFunctionId id,
364  BuiltinExtraArguments extra_args);
365  static void Generate_CompileUnoptimized(MacroAssembler* masm);
366  static void Generate_InOptimizationQueue(MacroAssembler* masm);
367  static void Generate_CompileOptimized(MacroAssembler* masm);
368  static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm);
369  static void Generate_JSConstructStubCountdown(MacroAssembler* masm);
370  static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
371  static void Generate_JSConstructStubApi(MacroAssembler* masm);
372  static void Generate_JSEntryTrampoline(MacroAssembler* masm);
373  static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
374  static void Generate_NotifyDeoptimized(MacroAssembler* masm);
375  static void Generate_NotifySoftDeoptimized(MacroAssembler* masm);
376  static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm);
377  static void Generate_NotifyStubFailure(MacroAssembler* masm);
378  static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm);
379  static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
380 
381  static void Generate_FunctionCall(MacroAssembler* masm);
382  static void Generate_FunctionApply(MacroAssembler* masm);
383 
384  static void Generate_InternalArrayCode(MacroAssembler* masm);
385  static void Generate_ArrayCode(MacroAssembler* masm);
386 
387  static void Generate_StringConstructCode(MacroAssembler* masm);
388  static void Generate_OnStackReplacement(MacroAssembler* masm);
389  static void Generate_OsrAfterStackCheck(MacroAssembler* masm);
390  static void Generate_InterruptCheck(MacroAssembler* masm);
391  static void Generate_StackCheck(MacroAssembler* masm);
392 
393 #define DECLARE_CODE_AGE_BUILTIN_GENERATOR(C) \
394  static void Generate_Make##C##CodeYoungAgainEvenMarking( \
395  MacroAssembler* masm); \
396  static void Generate_Make##C##CodeYoungAgainOddMarking( \
397  MacroAssembler* masm);
399 #undef DECLARE_CODE_AGE_BUILTIN_GENERATOR
400 
401  static void Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm);
402  static void Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm);
403 
404  static void InitBuiltinFunctionTable();
405 
406  bool initialized_;
407 
408  friend class BuiltinFunctionTable;
409  friend class Isolate;
410 
412 };
413 
414 } } // namespace v8::internal
415 
416 #endif // V8_BUILTINS_H_
byte * Address
Definition: globals.h:186
Code * builtin(Name name)
Definition: builtins.h:322
#define DEF_ENUM(name, ignore)
Definition: builtins.h:305
#define BUILTINS_LIST_JS(V)
Definition: builtins.h:234
bool is_initialized() const
Definition: builtins.h:346
#define BUILTIN_LIST_H(V)
Definition: builtins.h:192
void SetUp(Isolate *isolate, bool create_heap_objects)
Definition: builtins.cc:1603
#define ASSERT(condition)
Definition: checks.h:329
#define DECLARE_BUILTIN_ACCESSOR_C(name, ignore)
Definition: builtins.h:311
static const char * GetName(JavaScript id)
Definition: builtins.h:336
#define DEF_ENUM_A(name, kind, state, extra)
Definition: builtins.h:286
#define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra)
Definition: builtins.h:312
#define DECLARE_BUILTIN_ACCESSOR_H(name, kind)
Definition: builtins.h:314
static Address c_function_address(CFunctionId id)
Definition: builtins.h:332
#define DEF_ENUM_H(name, kind)
Definition: builtins.h:287
uint8_t byte
Definition: globals.h:185
static int GetArgumentsCount(JavaScript id)
Definition: builtins.h:342
BuiltinExtraArguments
Definition: builtins.h:35
#define DEF_ENUM_C(name, ignore)
Definition: builtins.h:298
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:359
const Register pc
Address builtin_address(Name name)
Definition: builtins.h:328
#define DECLARE_CODE_AGE_BUILTIN_GENERATOR(C)
Definition: builtins.h:393
static int NumberOfJavaScriptBuiltins()
Definition: builtins.h:344
const char * Lookup(byte *pc)
Definition: builtins.cc:1687
#define BUILTIN_LIST_DEBUG_A(V)
Definition: builtins.h:230
Handle< Code > GetCode(JavaScript id, bool *resolved)
const char * name(int index)
Definition: builtins.h:337
#define CODE_AGE_LIST(V)
Definition: builtins.h:50
void IterateBuiltins(ObjectVisitor *v)
Definition: builtins.cc:1682
#define BUILTIN_LIST_C(V)
Definition: builtins.h:67
#define BUILTIN_LIST_A(V)
Definition: builtins.h:88