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