OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 | 1560 |
1561 struct BuiltinDesc { | 1561 struct BuiltinDesc { |
1562 byte* generator; | 1562 byte* generator; |
1563 byte* c_code; | 1563 byte* c_code; |
1564 const char* s_name; // name is only used for generating log information. | 1564 const char* s_name; // name is only used for generating log information. |
1565 int name; | 1565 int name; |
1566 Code::Flags flags; | 1566 Code::Flags flags; |
1567 BuiltinExtraArguments extra_args; | 1567 BuiltinExtraArguments extra_args; |
1568 }; | 1568 }; |
1569 | 1569 |
1570 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } | |
1571 | |
1572 class BuiltinFunctionTable { | 1570 class BuiltinFunctionTable { |
1573 public: | 1571 public: |
1574 BuiltinDesc* functions() { | 1572 BuiltinFunctionTable() { |
1575 CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); | 1573 Builtins::InitBuiltinFunctionTable(); |
1576 return functions_; | |
1577 } | 1574 } |
1578 | 1575 |
1579 OnceType once_; | 1576 static const BuiltinDesc* functions() { return functions_; } |
1580 BuiltinDesc functions_[Builtins::builtin_count + 1]; | 1577 |
| 1578 private: |
| 1579 static BuiltinDesc functions_[Builtins::builtin_count + 1]; |
1581 | 1580 |
1582 friend class Builtins; | 1581 friend class Builtins; |
1583 }; | 1582 }; |
1584 | 1583 |
1585 static BuiltinFunctionTable builtin_function_table = | 1584 BuiltinDesc BuiltinFunctionTable::functions_[Builtins::builtin_count + 1]; |
1586 BUILTIN_FUNCTION_TABLE_INIT; | 1585 |
| 1586 static const BuiltinFunctionTable builtin_function_table_init; |
1587 | 1587 |
1588 // Define array of pointers to generators and C builtin functions. | 1588 // Define array of pointers to generators and C builtin functions. |
1589 // We do this in a sort of roundabout way so that we can do the initialization | 1589 // We do this in a sort of roundabout way so that we can do the initialization |
1590 // within the lexical scope of Builtins:: and within a context where | 1590 // within the lexical scope of Builtins:: and within a context where |
1591 // Code::Flags names a non-abstract type. | 1591 // Code::Flags names a non-abstract type. |
1592 void Builtins::InitBuiltinFunctionTable() { | 1592 void Builtins::InitBuiltinFunctionTable() { |
1593 BuiltinDesc* functions = builtin_function_table.functions_; | 1593 BuiltinDesc* functions = BuiltinFunctionTable::functions_; |
1594 functions[builtin_count].generator = NULL; | 1594 functions[builtin_count].generator = NULL; |
1595 functions[builtin_count].c_code = NULL; | 1595 functions[builtin_count].c_code = NULL; |
1596 functions[builtin_count].s_name = NULL; | 1596 functions[builtin_count].s_name = NULL; |
1597 functions[builtin_count].name = builtin_count; | 1597 functions[builtin_count].name = builtin_count; |
1598 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 1598 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
1599 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; | 1599 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; |
1600 | 1600 |
1601 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ | 1601 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ |
1602 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 1602 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
1603 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 1603 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ |
(...skipping 23 matching lines...) Expand all Loading... |
1627 } | 1627 } |
1628 | 1628 |
1629 void Builtins::SetUp(bool create_heap_objects) { | 1629 void Builtins::SetUp(bool create_heap_objects) { |
1630 ASSERT(!initialized_); | 1630 ASSERT(!initialized_); |
1631 Isolate* isolate = Isolate::Current(); | 1631 Isolate* isolate = Isolate::Current(); |
1632 Heap* heap = isolate->heap(); | 1632 Heap* heap = isolate->heap(); |
1633 | 1633 |
1634 // Create a scope for the handles in the builtins. | 1634 // Create a scope for the handles in the builtins. |
1635 HandleScope scope(isolate); | 1635 HandleScope scope(isolate); |
1636 | 1636 |
1637 const BuiltinDesc* functions = builtin_function_table.functions(); | 1637 const BuiltinDesc* functions = BuiltinFunctionTable::functions(); |
1638 | 1638 |
1639 // For now we generate builtin adaptor code into a stack-allocated | 1639 // For now we generate builtin adaptor code into a stack-allocated |
1640 // buffer, before copying it into individual code objects. Be careful | 1640 // buffer, before copying it into individual code objects. Be careful |
1641 // with alignment, some platforms don't like unaligned code. | 1641 // with alignment, some platforms don't like unaligned code. |
1642 union { int force_alignment; byte buffer[4*KB]; } u; | 1642 union { int force_alignment; byte buffer[4*KB]; } u; |
1643 | 1643 |
1644 // Traverse the list of builtins and generate an adaptor in a | 1644 // Traverse the list of builtins and generate an adaptor in a |
1645 // separate code object for each one. | 1645 // separate code object for each one. |
1646 for (int i = 0; i < builtin_count; i++) { | 1646 for (int i = 0; i < builtin_count; i++) { |
1647 if (create_heap_objects) { | 1647 if (create_heap_objects) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 return Handle<Code>(code_address); \ | 1735 return Handle<Code>(code_address); \ |
1736 } | 1736 } |
1737 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1737 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1738 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1738 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1739 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1739 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1740 #undef DEFINE_BUILTIN_ACCESSOR_C | 1740 #undef DEFINE_BUILTIN_ACCESSOR_C |
1741 #undef DEFINE_BUILTIN_ACCESSOR_A | 1741 #undef DEFINE_BUILTIN_ACCESSOR_A |
1742 | 1742 |
1743 | 1743 |
1744 } } // namespace v8::internal | 1744 } } // namespace v8::internal |
OLD | NEW |