v8  3.14.5(node0.10.28)
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 list of builtins implemented in C++.
42 #define BUILTIN_LIST_C(V) \
43  V(Illegal, NO_EXTRA_ARGUMENTS) \
44  \
45  V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
46  \
47  V(InternalArrayCodeGeneric, NO_EXTRA_ARGUMENTS) \
48  V(ArrayCodeGeneric, NO_EXTRA_ARGUMENTS) \
49  \
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) \
57  \
58  V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
59  V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
60  V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
61  V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS) \
62  \
63  V(StrictModePoisonPill, NO_EXTRA_ARGUMENTS)
64 
65 // Define list of builtins implemented in assembly.
66 #define BUILTIN_LIST_A(V) \
67  V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED, \
68  Code::kNoExtraICState) \
69  V(InRecompileQueue, BUILTIN, UNINITIALIZED, \
70  Code::kNoExtraICState) \
71  V(JSConstructStubCountdown, BUILTIN, UNINITIALIZED, \
72  Code::kNoExtraICState) \
73  V(JSConstructStubGeneric, BUILTIN, UNINITIALIZED, \
74  Code::kNoExtraICState) \
75  V(JSConstructStubApi, BUILTIN, UNINITIALIZED, \
76  Code::kNoExtraICState) \
77  V(JSEntryTrampoline, BUILTIN, UNINITIALIZED, \
78  Code::kNoExtraICState) \
79  V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED, \
80  Code::kNoExtraICState) \
81  V(LazyCompile, BUILTIN, UNINITIALIZED, \
82  Code::kNoExtraICState) \
83  V(LazyRecompile, BUILTIN, UNINITIALIZED, \
84  Code::kNoExtraICState) \
85  V(ParallelRecompile, BUILTIN, UNINITIALIZED, \
86  Code::kNoExtraICState) \
87  V(NotifyDeoptimized, BUILTIN, UNINITIALIZED, \
88  Code::kNoExtraICState) \
89  V(NotifyLazyDeoptimized, BUILTIN, UNINITIALIZED, \
90  Code::kNoExtraICState) \
91  V(NotifyOSR, BUILTIN, UNINITIALIZED, \
92  Code::kNoExtraICState) \
93  \
94  V(LoadIC_Miss, BUILTIN, UNINITIALIZED, \
95  Code::kNoExtraICState) \
96  V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED, \
97  Code::kNoExtraICState) \
98  V(KeyedLoadIC_MissForceGeneric, BUILTIN, UNINITIALIZED, \
99  Code::kNoExtraICState) \
100  V(KeyedLoadIC_Slow, BUILTIN, UNINITIALIZED, \
101  Code::kNoExtraICState) \
102  V(StoreIC_Miss, BUILTIN, UNINITIALIZED, \
103  Code::kNoExtraICState) \
104  V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED, \
105  Code::kNoExtraICState) \
106  V(KeyedStoreIC_MissForceGeneric, BUILTIN, UNINITIALIZED, \
107  Code::kNoExtraICState) \
108  V(KeyedStoreIC_Slow, BUILTIN, UNINITIALIZED, \
109  Code::kNoExtraICState) \
110  V(LoadIC_Initialize, LOAD_IC, UNINITIALIZED, \
111  Code::kNoExtraICState) \
112  V(LoadIC_PreMonomorphic, LOAD_IC, PREMONOMORPHIC, \
113  Code::kNoExtraICState) \
114  V(LoadIC_Normal, LOAD_IC, MONOMORPHIC, \
115  Code::kNoExtraICState) \
116  V(LoadIC_ArrayLength, LOAD_IC, MONOMORPHIC, \
117  Code::kNoExtraICState) \
118  V(LoadIC_StringLength, LOAD_IC, MONOMORPHIC, \
119  Code::kNoExtraICState) \
120  V(LoadIC_StringWrapperLength, LOAD_IC, MONOMORPHIC, \
121  Code::kNoExtraICState) \
122  V(LoadIC_FunctionPrototype, LOAD_IC, MONOMORPHIC, \
123  Code::kNoExtraICState) \
124  V(LoadIC_Megamorphic, LOAD_IC, MEGAMORPHIC, \
125  Code::kNoExtraICState) \
126  V(LoadIC_Getter_ForDeopt, LOAD_IC, MONOMORPHIC, \
127  Code::kNoExtraICState) \
128  \
129  V(KeyedLoadIC_Initialize, KEYED_LOAD_IC, UNINITIALIZED, \
130  Code::kNoExtraICState) \
131  V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC, \
132  Code::kNoExtraICState) \
133  V(KeyedLoadIC_Generic, KEYED_LOAD_IC, MEGAMORPHIC, \
134  Code::kNoExtraICState) \
135  V(KeyedLoadIC_String, KEYED_LOAD_IC, MEGAMORPHIC, \
136  Code::kNoExtraICState) \
137  V(KeyedLoadIC_IndexedInterceptor, KEYED_LOAD_IC, MEGAMORPHIC, \
138  Code::kNoExtraICState) \
139  V(KeyedLoadIC_NonStrictArguments, KEYED_LOAD_IC, MEGAMORPHIC, \
140  Code::kNoExtraICState) \
141  \
142  V(StoreIC_Initialize, STORE_IC, UNINITIALIZED, \
143  Code::kNoExtraICState) \
144  V(StoreIC_ArrayLength, STORE_IC, MONOMORPHIC, \
145  Code::kNoExtraICState) \
146  V(StoreIC_Normal, STORE_IC, MONOMORPHIC, \
147  Code::kNoExtraICState) \
148  V(StoreIC_Megamorphic, STORE_IC, MEGAMORPHIC, \
149  Code::kNoExtraICState) \
150  V(StoreIC_GlobalProxy, STORE_IC, MEGAMORPHIC, \
151  Code::kNoExtraICState) \
152  V(StoreIC_Initialize_Strict, STORE_IC, UNINITIALIZED, \
153  kStrictMode) \
154  V(StoreIC_ArrayLength_Strict, STORE_IC, MONOMORPHIC, \
155  kStrictMode) \
156  V(StoreIC_Normal_Strict, STORE_IC, MONOMORPHIC, \
157  kStrictMode) \
158  V(StoreIC_Megamorphic_Strict, STORE_IC, MEGAMORPHIC, \
159  kStrictMode) \
160  V(StoreIC_GlobalProxy_Strict, STORE_IC, MEGAMORPHIC, \
161  kStrictMode) \
162  V(StoreIC_Setter_ForDeopt, STORE_IC, MONOMORPHIC, \
163  kStrictMode) \
164  \
165  V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED, \
166  Code::kNoExtraICState) \
167  V(KeyedStoreIC_Generic, KEYED_STORE_IC, MEGAMORPHIC, \
168  Code::kNoExtraICState) \
169  \
170  V(KeyedStoreIC_Initialize_Strict, KEYED_STORE_IC, UNINITIALIZED, \
171  kStrictMode) \
172  V(KeyedStoreIC_Generic_Strict, KEYED_STORE_IC, MEGAMORPHIC, \
173  kStrictMode) \
174  V(KeyedStoreIC_NonStrictArguments, KEYED_STORE_IC, MEGAMORPHIC, \
175  Code::kNoExtraICState) \
176  V(TransitionElementsSmiToDouble, BUILTIN, UNINITIALIZED, \
177  Code::kNoExtraICState) \
178  V(TransitionElementsDoubleToObject, BUILTIN, UNINITIALIZED, \
179  Code::kNoExtraICState) \
180  \
181  /* Uses KeyedLoadIC_Initialize; must be after in list. */ \
182  V(FunctionCall, BUILTIN, UNINITIALIZED, \
183  Code::kNoExtraICState) \
184  V(FunctionApply, BUILTIN, UNINITIALIZED, \
185  Code::kNoExtraICState) \
186  \
187  V(InternalArrayCode, BUILTIN, UNINITIALIZED, \
188  Code::kNoExtraICState) \
189  V(ArrayCode, BUILTIN, UNINITIALIZED, \
190  Code::kNoExtraICState) \
191  V(ArrayConstructCode, BUILTIN, UNINITIALIZED, \
192  Code::kNoExtraICState) \
193  \
194  V(StringConstructCode, BUILTIN, UNINITIALIZED, \
195  Code::kNoExtraICState) \
196  \
197  V(OnStackReplacement, BUILTIN, UNINITIALIZED, \
198  Code::kNoExtraICState)
199 
200 
201 #ifdef ENABLE_DEBUGGER_SUPPORT
202 // Define list of builtins used by the debugger implemented in assembly.
203 #define BUILTIN_LIST_DEBUG_A(V) \
204  V(Return_DebugBreak, BUILTIN, DEBUG_BREAK, \
205  Code::kNoExtraICState) \
206  V(CallFunctionStub_DebugBreak, BUILTIN, DEBUG_BREAK, \
207  Code::kNoExtraICState) \
208  V(CallFunctionStub_Recording_DebugBreak, BUILTIN, DEBUG_BREAK, \
209  Code::kNoExtraICState) \
210  V(CallConstructStub_DebugBreak, BUILTIN, DEBUG_BREAK, \
211  Code::kNoExtraICState) \
212  V(CallConstructStub_Recording_DebugBreak, BUILTIN, DEBUG_BREAK, \
213  Code::kNoExtraICState) \
214  V(LoadIC_DebugBreak, LOAD_IC, DEBUG_BREAK, \
215  Code::kNoExtraICState) \
216  V(KeyedLoadIC_DebugBreak, KEYED_LOAD_IC, DEBUG_BREAK, \
217  Code::kNoExtraICState) \
218  V(StoreIC_DebugBreak, STORE_IC, DEBUG_BREAK, \
219  Code::kNoExtraICState) \
220  V(KeyedStoreIC_DebugBreak, KEYED_STORE_IC, DEBUG_BREAK, \
221  Code::kNoExtraICState) \
222  V(Slot_DebugBreak, BUILTIN, DEBUG_BREAK, \
223  Code::kNoExtraICState) \
224  V(PlainReturn_LiveEdit, BUILTIN, DEBUG_BREAK, \
225  Code::kNoExtraICState) \
226  V(FrameDropper_LiveEdit, BUILTIN, DEBUG_BREAK, \
227  Code::kNoExtraICState)
228 #else
229 #define BUILTIN_LIST_DEBUG_A(V)
230 #endif
231 
232 // Define list of builtins implemented in JavaScript.
233 #define BUILTINS_LIST_JS(V) \
234  V(EQUALS, 1) \
235  V(STRICT_EQUALS, 1) \
236  V(COMPARE, 2) \
237  V(ADD, 1) \
238  V(SUB, 1) \
239  V(MUL, 1) \
240  V(DIV, 1) \
241  V(MOD, 1) \
242  V(BIT_OR, 1) \
243  V(BIT_AND, 1) \
244  V(BIT_XOR, 1) \
245  V(UNARY_MINUS, 0) \
246  V(BIT_NOT, 0) \
247  V(SHL, 1) \
248  V(SAR, 1) \
249  V(SHR, 1) \
250  V(DELETE, 2) \
251  V(IN, 1) \
252  V(INSTANCE_OF, 1) \
253  V(FILTER_KEY, 1) \
254  V(CALL_NON_FUNCTION, 0) \
255  V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \
256  V(CALL_FUNCTION_PROXY, 1) \
257  V(CALL_FUNCTION_PROXY_AS_CONSTRUCTOR, 1) \
258  V(TO_OBJECT, 0) \
259  V(TO_NUMBER, 0) \
260  V(TO_STRING, 0) \
261  V(STRING_ADD_LEFT, 1) \
262  V(STRING_ADD_RIGHT, 1) \
263  V(APPLY_PREPARE, 1) \
264  V(APPLY_OVERFLOW, 1)
265 
266 
267 class BuiltinFunctionTable;
268 class ObjectVisitor;
269 
270 
271 class Builtins {
272  public:
273  ~Builtins();
274 
275  // Generate all builtin code objects. Should be called once during
276  // isolate initialization.
277  void SetUp(bool create_heap_objects);
278  void TearDown();
279 
280  // Garbage collection support.
281  void IterateBuiltins(ObjectVisitor* v);
282 
283  // Disassembler support.
284  const char* Lookup(byte* pc);
285 
286  enum Name {
287 #define DEF_ENUM_C(name, ignore) k##name,
288 #define DEF_ENUM_A(name, kind, state, extra) 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();
317 #undef DECLARE_BUILTIN_ACCESSOR_C
318 #undef DECLARE_BUILTIN_ACCESSOR_A
319 
320  Code* builtin(Name name) {
321  // Code::cast cannot be used here since we access builtins
322  // during the marking phase of mark sweep. See IC::Clear.
323  return reinterpret_cast<Code*>(builtins_[name]);
324  }
325 
327  return reinterpret_cast<Address>(&builtins_[name]);
328  }
329 
331  return c_functions_[id];
332  }
333 
334  static const char* GetName(JavaScript id) { return javascript_names_[id]; }
335  static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
336  Handle<Code> GetCode(JavaScript id, bool* resolved);
337  static int NumberOfJavaScriptBuiltins() { return id_count; }
338 
339  bool is_initialized() const { return initialized_; }
340 
341  private:
342  Builtins();
343 
344  // The external C++ functions called from the code.
345  static Address const c_functions_[cfunction_count];
346 
347  // Note: These are always Code objects, but to conform with
348  // IterateBuiltins() above which assumes Object**'s for the callback
349  // function f, we use an Object* array here.
350  Object* builtins_[builtin_count];
351  const char* names_[builtin_count];
352  static const char* const javascript_names_[id_count];
353  static int const javascript_argc_[id_count];
354 
355  static void Generate_Adaptor(MacroAssembler* masm,
356  CFunctionId id,
357  BuiltinExtraArguments extra_args);
358  static void Generate_InRecompileQueue(MacroAssembler* masm);
359  static void Generate_ParallelRecompile(MacroAssembler* masm);
360  static void Generate_JSConstructStubCountdown(MacroAssembler* masm);
361  static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
362  static void Generate_JSConstructStubApi(MacroAssembler* masm);
363  static void Generate_JSEntryTrampoline(MacroAssembler* masm);
364  static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
365  static void Generate_LazyCompile(MacroAssembler* masm);
366  static void Generate_LazyRecompile(MacroAssembler* masm);
367  static void Generate_NotifyDeoptimized(MacroAssembler* masm);
368  static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm);
369  static void Generate_NotifyOSR(MacroAssembler* masm);
370  static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
371 
372  static void Generate_FunctionCall(MacroAssembler* masm);
373  static void Generate_FunctionApply(MacroAssembler* masm);
374 
375  static void Generate_InternalArrayCode(MacroAssembler* masm);
376  static void Generate_ArrayCode(MacroAssembler* masm);
377  static void Generate_ArrayConstructCode(MacroAssembler* masm);
378 
379  static void Generate_StringConstructCode(MacroAssembler* masm);
380  static void Generate_OnStackReplacement(MacroAssembler* masm);
381 
382  static void InitBuiltinFunctionTable();
383 
384  bool initialized_;
385 
386  friend class BuiltinFunctionTable;
387  friend class Isolate;
388 
390 };
391 
392 } } // namespace v8::internal
393 
394 #endif // V8_BUILTINS_H_
byte * Address
Definition: globals.h:157
Code * builtin(Name name)
Definition: builtins.h:320
#define DEF_ENUM(name, ignore)
Definition: builtins.h:305
#define BUILTINS_LIST_JS(V)
Definition: builtins.h:233
bool is_initialized() const
Definition: builtins.h:339
#define DECLARE_BUILTIN_ACCESSOR_C(name, ignore)
Definition: builtins.h:311
static const char * GetName(JavaScript id)
Definition: builtins.h:334
#define DEF_ENUM_A(name, kind, state, extra)
Definition: builtins.h:288
#define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra)
Definition: builtins.h:312
static Address c_function_address(CFunctionId id)
Definition: builtins.h:330
uint8_t byte
Definition: globals.h:156
void SetUp(bool create_heap_objects)
Definition: builtins.cc:1610
static int GetArgumentsCount(JavaScript id)
Definition: builtins.h:335
BuiltinExtraArguments
Definition: builtins.h:35
#define DEF_ENUM_C(name, ignore)
Definition: builtins.h:298
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:307
const Register pc
Address builtin_address(Name name)
Definition: builtins.h:326
static int NumberOfJavaScriptBuiltins()
Definition: builtins.h:337
const char * Lookup(byte *pc)
Definition: builtins.cc:1692
#define BUILTIN_LIST_DEBUG_A(V)
Definition: builtins.h:229
Handle< Code > GetCode(JavaScript id, bool *resolved)
void IterateBuiltins(ObjectVisitor *v)
Definition: builtins.cc:1687
#define BUILTIN_LIST_C(V)
Definition: builtins.h:42
#define BUILTIN_LIST_A(V)
Definition: builtins.h:66