OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \ | 233 V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \ |
234 V(TO_OBJECT, 0) \ | 234 V(TO_OBJECT, 0) \ |
235 V(TO_NUMBER, 0) \ | 235 V(TO_NUMBER, 0) \ |
236 V(TO_STRING, 0) \ | 236 V(TO_STRING, 0) \ |
237 V(STRING_ADD_LEFT, 1) \ | 237 V(STRING_ADD_LEFT, 1) \ |
238 V(STRING_ADD_RIGHT, 1) \ | 238 V(STRING_ADD_RIGHT, 1) \ |
239 V(APPLY_PREPARE, 1) \ | 239 V(APPLY_PREPARE, 1) \ |
240 V(APPLY_OVERFLOW, 1) | 240 V(APPLY_OVERFLOW, 1) |
241 | 241 |
242 | 242 |
| 243 class BuiltinFunctionTable; |
243 class ObjectVisitor; | 244 class ObjectVisitor; |
244 | 245 |
245 | 246 |
246 class Builtins : public AllStatic { | 247 class Builtins { |
247 public: | 248 public: |
| 249 ~Builtins(); |
| 250 |
248 // Generate all builtin code objects. Should be called once during | 251 // Generate all builtin code objects. Should be called once during |
249 // VM initialization. | 252 // isolate initialization. |
250 static void Setup(bool create_heap_objects); | 253 void Setup(bool create_heap_objects); |
251 static void TearDown(); | 254 void TearDown(); |
252 | 255 |
253 // Garbage collection support. | 256 // Garbage collection support. |
254 static void IterateBuiltins(ObjectVisitor* v); | 257 void IterateBuiltins(ObjectVisitor* v); |
255 | 258 |
256 // Disassembler support. | 259 // Disassembler support. |
257 static const char* Lookup(byte* pc); | 260 const char* Lookup(byte* pc); |
258 | 261 |
259 enum Name { | 262 enum Name { |
260 #define DEF_ENUM_C(name, ignore) name, | 263 #define DEF_ENUM_C(name, ignore) name, |
261 #define DEF_ENUM_A(name, kind, state, extra) name, | 264 #define DEF_ENUM_A(name, kind, state, extra) name, |
262 BUILTIN_LIST_C(DEF_ENUM_C) | 265 BUILTIN_LIST_C(DEF_ENUM_C) |
263 BUILTIN_LIST_A(DEF_ENUM_A) | 266 BUILTIN_LIST_A(DEF_ENUM_A) |
264 BUILTIN_LIST_DEBUG_A(DEF_ENUM_A) | 267 BUILTIN_LIST_DEBUG_A(DEF_ENUM_A) |
265 #undef DEF_ENUM_C | 268 #undef DEF_ENUM_C |
266 #undef DEF_ENUM_A | 269 #undef DEF_ENUM_A |
267 builtin_count | 270 builtin_count |
268 }; | 271 }; |
269 | 272 |
270 enum CFunctionId { | 273 enum CFunctionId { |
271 #define DEF_ENUM_C(name, ignore) c_##name, | 274 #define DEF_ENUM_C(name, ignore) c_##name, |
272 BUILTIN_LIST_C(DEF_ENUM_C) | 275 BUILTIN_LIST_C(DEF_ENUM_C) |
273 #undef DEF_ENUM_C | 276 #undef DEF_ENUM_C |
274 cfunction_count | 277 cfunction_count |
275 }; | 278 }; |
276 | 279 |
277 enum JavaScript { | 280 enum JavaScript { |
278 #define DEF_ENUM(name, ignore) name, | 281 #define DEF_ENUM(name, ignore) name, |
279 BUILTINS_LIST_JS(DEF_ENUM) | 282 BUILTINS_LIST_JS(DEF_ENUM) |
280 #undef DEF_ENUM | 283 #undef DEF_ENUM |
281 id_count | 284 id_count |
282 }; | 285 }; |
283 | 286 |
284 static Code* builtin(Name name) { | 287 Code* builtin(Name name) { |
285 // Code::cast cannot be used here since we access builtins | 288 // Code::cast cannot be used here since we access builtins |
286 // during the marking phase of mark sweep. See IC::Clear. | 289 // during the marking phase of mark sweep. See IC::Clear. |
287 return reinterpret_cast<Code*>(builtins_[name]); | 290 return reinterpret_cast<Code*>(builtins_[name]); |
288 } | 291 } |
289 | 292 |
290 static Address builtin_address(Name name) { | 293 Address builtin_address(Name name) { |
291 return reinterpret_cast<Address>(&builtins_[name]); | 294 return reinterpret_cast<Address>(&builtins_[name]); |
292 } | 295 } |
293 | 296 |
294 static Address c_function_address(CFunctionId id) { | 297 static Address c_function_address(CFunctionId id) { |
295 return c_functions_[id]; | 298 return c_functions_[id]; |
296 } | 299 } |
297 | 300 |
298 static const char* GetName(JavaScript id) { return javascript_names_[id]; } | 301 static const char* GetName(JavaScript id) { return javascript_names_[id]; } |
299 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; } | 302 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; } |
300 static Handle<Code> GetCode(JavaScript id, bool* resolved); | 303 Handle<Code> GetCode(JavaScript id, bool* resolved); |
301 static int NumberOfJavaScriptBuiltins() { return id_count; } | 304 static int NumberOfJavaScriptBuiltins() { return id_count; } |
302 | 305 |
| 306 bool is_initialized() const { return initialized_; } |
| 307 |
303 private: | 308 private: |
| 309 Builtins(); |
| 310 |
304 // The external C++ functions called from the code. | 311 // The external C++ functions called from the code. |
305 static Address c_functions_[cfunction_count]; | 312 static Address const c_functions_[cfunction_count]; |
306 | 313 |
307 // Note: These are always Code objects, but to conform with | 314 // Note: These are always Code objects, but to conform with |
308 // IterateBuiltins() above which assumes Object**'s for the callback | 315 // IterateBuiltins() above which assumes Object**'s for the callback |
309 // function f, we use an Object* array here. | 316 // function f, we use an Object* array here. |
310 static Object* builtins_[builtin_count]; | 317 Object* builtins_[builtin_count]; |
311 static const char* names_[builtin_count]; | 318 const char* names_[builtin_count]; |
312 static const char* javascript_names_[id_count]; | 319 static const char* const javascript_names_[id_count]; |
313 static int javascript_argc_[id_count]; | 320 static int const javascript_argc_[id_count]; |
314 | 321 |
315 static void Generate_Adaptor(MacroAssembler* masm, | 322 static void Generate_Adaptor(MacroAssembler* masm, |
316 CFunctionId id, | 323 CFunctionId id, |
317 BuiltinExtraArguments extra_args); | 324 BuiltinExtraArguments extra_args); |
318 static void Generate_JSConstructCall(MacroAssembler* masm); | 325 static void Generate_JSConstructCall(MacroAssembler* masm); |
319 static void Generate_JSConstructStubCountdown(MacroAssembler* masm); | 326 static void Generate_JSConstructStubCountdown(MacroAssembler* masm); |
320 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); | 327 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); |
321 static void Generate_JSConstructStubApi(MacroAssembler* masm); | 328 static void Generate_JSConstructStubApi(MacroAssembler* masm); |
322 static void Generate_JSEntryTrampoline(MacroAssembler* masm); | 329 static void Generate_JSEntryTrampoline(MacroAssembler* masm); |
323 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm); | 330 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm); |
324 static void Generate_LazyCompile(MacroAssembler* masm); | 331 static void Generate_LazyCompile(MacroAssembler* masm); |
325 static void Generate_LazyRecompile(MacroAssembler* masm); | 332 static void Generate_LazyRecompile(MacroAssembler* masm); |
326 static void Generate_NotifyDeoptimized(MacroAssembler* masm); | 333 static void Generate_NotifyDeoptimized(MacroAssembler* masm); |
327 static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm); | 334 static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm); |
328 static void Generate_NotifyOSR(MacroAssembler* masm); | 335 static void Generate_NotifyOSR(MacroAssembler* masm); |
329 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm); | 336 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm); |
330 | 337 |
331 static void Generate_FunctionCall(MacroAssembler* masm); | 338 static void Generate_FunctionCall(MacroAssembler* masm); |
332 static void Generate_FunctionApply(MacroAssembler* masm); | 339 static void Generate_FunctionApply(MacroAssembler* masm); |
333 | 340 |
334 static void Generate_ArrayCode(MacroAssembler* masm); | 341 static void Generate_ArrayCode(MacroAssembler* masm); |
335 static void Generate_ArrayConstructCode(MacroAssembler* masm); | 342 static void Generate_ArrayConstructCode(MacroAssembler* masm); |
336 | 343 |
337 static void Generate_StringConstructCode(MacroAssembler* masm); | 344 static void Generate_StringConstructCode(MacroAssembler* masm); |
| 345 static void Generate_OnStackReplacement(MacroAssembler* masm); |
338 | 346 |
339 static void Generate_OnStackReplacement(MacroAssembler* masm); | 347 static void InitBuiltinFunctionTable(); |
| 348 |
| 349 bool initialized_; |
| 350 |
| 351 friend class BuiltinFunctionTable; |
| 352 friend class Isolate; |
| 353 |
| 354 DISALLOW_COPY_AND_ASSIGN(Builtins); |
340 }; | 355 }; |
341 | 356 |
342 } } // namespace v8::internal | 357 } } // namespace v8::internal |
343 | 358 |
344 #endif // V8_BUILTINS_H_ | 359 #endif // V8_BUILTINS_H_ |
OLD | NEW |