| 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 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 | 1581 |
| 1582 struct BuiltinDesc { | 1582 struct BuiltinDesc { |
| 1583 byte* generator; | 1583 byte* generator; |
| 1584 byte* c_code; | 1584 byte* c_code; |
| 1585 const char* s_name; // name is only used for generating log information. | 1585 const char* s_name; // name is only used for generating log information. |
| 1586 int name; | 1586 int name; |
| 1587 Code::Flags flags; | 1587 Code::Flags flags; |
| 1588 BuiltinExtraArguments extra_args; | 1588 BuiltinExtraArguments extra_args; |
| 1589 }; | 1589 }; |
| 1590 | 1590 |
| 1591 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } |
| 1592 |
| 1591 class BuiltinFunctionTable { | 1593 class BuiltinFunctionTable { |
| 1592 public: | 1594 public: |
| 1593 BuiltinFunctionTable() { | 1595 BuiltinDesc* functions() { |
| 1594 Builtins::InitBuiltinFunctionTable(); | 1596 CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); |
| 1597 return functions_; |
| 1595 } | 1598 } |
| 1596 | 1599 |
| 1597 static const BuiltinDesc* functions() { return functions_; } | 1600 OnceType once_; |
| 1598 | 1601 BuiltinDesc functions_[Builtins::builtin_count + 1]; |
| 1599 private: | |
| 1600 static BuiltinDesc functions_[Builtins::builtin_count + 1]; | |
| 1601 | 1602 |
| 1602 friend class Builtins; | 1603 friend class Builtins; |
| 1603 }; | 1604 }; |
| 1604 | 1605 |
| 1605 BuiltinDesc BuiltinFunctionTable::functions_[Builtins::builtin_count + 1]; | 1606 static BuiltinFunctionTable builtin_function_table = |
| 1606 | 1607 BUILTIN_FUNCTION_TABLE_INIT; |
| 1607 static const BuiltinFunctionTable builtin_function_table_init; | |
| 1608 | 1608 |
| 1609 // Define array of pointers to generators and C builtin functions. | 1609 // Define array of pointers to generators and C builtin functions. |
| 1610 // We do this in a sort of roundabout way so that we can do the initialization | 1610 // We do this in a sort of roundabout way so that we can do the initialization |
| 1611 // within the lexical scope of Builtins:: and within a context where | 1611 // within the lexical scope of Builtins:: and within a context where |
| 1612 // Code::Flags names a non-abstract type. | 1612 // Code::Flags names a non-abstract type. |
| 1613 void Builtins::InitBuiltinFunctionTable() { | 1613 void Builtins::InitBuiltinFunctionTable() { |
| 1614 BuiltinDesc* functions = BuiltinFunctionTable::functions_; | 1614 BuiltinDesc* functions = builtin_function_table.functions_; |
| 1615 functions[builtin_count].generator = NULL; | 1615 functions[builtin_count].generator = NULL; |
| 1616 functions[builtin_count].c_code = NULL; | 1616 functions[builtin_count].c_code = NULL; |
| 1617 functions[builtin_count].s_name = NULL; | 1617 functions[builtin_count].s_name = NULL; |
| 1618 functions[builtin_count].name = builtin_count; | 1618 functions[builtin_count].name = builtin_count; |
| 1619 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 1619 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
| 1620 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; | 1620 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; |
| 1621 | 1621 |
| 1622 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ | 1622 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ |
| 1623 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 1623 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
| 1624 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 1624 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1648 } | 1648 } |
| 1649 | 1649 |
| 1650 void Builtins::SetUp(bool create_heap_objects) { | 1650 void Builtins::SetUp(bool create_heap_objects) { |
| 1651 ASSERT(!initialized_); | 1651 ASSERT(!initialized_); |
| 1652 Isolate* isolate = Isolate::Current(); | 1652 Isolate* isolate = Isolate::Current(); |
| 1653 Heap* heap = isolate->heap(); | 1653 Heap* heap = isolate->heap(); |
| 1654 | 1654 |
| 1655 // Create a scope for the handles in the builtins. | 1655 // Create a scope for the handles in the builtins. |
| 1656 HandleScope scope(isolate); | 1656 HandleScope scope(isolate); |
| 1657 | 1657 |
| 1658 const BuiltinDesc* functions = BuiltinFunctionTable::functions(); | 1658 const BuiltinDesc* functions = builtin_function_table.functions(); |
| 1659 | 1659 |
| 1660 // For now we generate builtin adaptor code into a stack-allocated | 1660 // For now we generate builtin adaptor code into a stack-allocated |
| 1661 // buffer, before copying it into individual code objects. Be careful | 1661 // buffer, before copying it into individual code objects. Be careful |
| 1662 // with alignment, some platforms don't like unaligned code. | 1662 // with alignment, some platforms don't like unaligned code. |
| 1663 union { int force_alignment; byte buffer[4*KB]; } u; | 1663 union { int force_alignment; byte buffer[4*KB]; } u; |
| 1664 | 1664 |
| 1665 // Traverse the list of builtins and generate an adaptor in a | 1665 // Traverse the list of builtins and generate an adaptor in a |
| 1666 // separate code object for each one. | 1666 // separate code object for each one. |
| 1667 for (int i = 0; i < builtin_count; i++) { | 1667 for (int i = 0; i < builtin_count; i++) { |
| 1668 if (create_heap_objects) { | 1668 if (create_heap_objects) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 return Handle<Code>(code_address); \ | 1756 return Handle<Code>(code_address); \ |
| 1757 } | 1757 } |
| 1758 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1758 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1759 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1759 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1760 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1760 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1761 #undef DEFINE_BUILTIN_ACCESSOR_C | 1761 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1762 #undef DEFINE_BUILTIN_ACCESSOR_A | 1762 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1763 | 1763 |
| 1764 | 1764 |
| 1765 } } // namespace v8::internal | 1765 } } // namespace v8::internal |
| OLD | NEW |