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 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) | 1615 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) |
1616 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | 1616 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) |
1617 | 1617 |
1618 #undef DEF_FUNCTION_PTR_C | 1618 #undef DEF_FUNCTION_PTR_C |
1619 #undef DEF_FUNCTION_PTR_A | 1619 #undef DEF_FUNCTION_PTR_A |
1620 } | 1620 } |
1621 | 1621 |
1622 | 1622 |
1623 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { | 1623 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
1624 ASSERT(!initialized_); | 1624 ASSERT(!initialized_); |
1625 Heap* heap = isolate->heap(); | |
1626 | 1625 |
1627 // Create a scope for the handles in the builtins. | 1626 // Create a scope for the handles in the builtins. |
1628 HandleScope scope(isolate); | 1627 HandleScope scope(isolate); |
1629 | 1628 |
1630 const BuiltinDesc* functions = builtin_function_table.functions(); | 1629 const BuiltinDesc* functions = builtin_function_table.functions(); |
1631 | 1630 |
1632 // For now we generate builtin adaptor code into a stack-allocated | 1631 // For now we generate builtin adaptor code into a stack-allocated |
1633 // buffer, before copying it into individual code objects. Be careful | 1632 // buffer, before copying it into individual code objects. Be careful |
1634 // with alignment, some platforms don't like unaligned code. | 1633 // with alignment, some platforms don't like unaligned code. |
1635 // TODO(jbramley): I had to increase the size of this buffer from 8KB because | 1634 // TODO(jbramley): I had to increase the size of this buffer from 8KB because |
(...skipping 10 matching lines...) Expand all Loading... |
1646 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); | 1645 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); |
1647 // We pass all arguments to the generator, but it may not use all of | 1646 // We pass all arguments to the generator, but it may not use all of |
1648 // them. This works because the first arguments are on top of the | 1647 // them. This works because the first arguments are on top of the |
1649 // stack. | 1648 // stack. |
1650 ASSERT(!masm.has_frame()); | 1649 ASSERT(!masm.has_frame()); |
1651 g(&masm, functions[i].name, functions[i].extra_args); | 1650 g(&masm, functions[i].name, functions[i].extra_args); |
1652 // Move the code into the object heap. | 1651 // Move the code into the object heap. |
1653 CodeDesc desc; | 1652 CodeDesc desc; |
1654 masm.GetCode(&desc); | 1653 masm.GetCode(&desc); |
1655 Code::Flags flags = functions[i].flags; | 1654 Code::Flags flags = functions[i].flags; |
1656 Object* code = NULL; | 1655 Handle<Code> code = |
1657 { | 1656 isolate->factory()->NewCode(desc, flags, masm.CodeObject()); |
1658 // During startup it's OK to always allocate and defer GC to later. | |
1659 // This simplifies things because we don't need to retry. | |
1660 AlwaysAllocateScope __scope__(isolate); | |
1661 { MaybeObject* maybe_code = | |
1662 heap->CreateCode(desc, flags, masm.CodeObject()); | |
1663 if (!maybe_code->ToObject(&code)) { | |
1664 v8::internal::V8::FatalProcessOutOfMemory("CreateCode"); | |
1665 } | |
1666 } | |
1667 } | |
1668 // Log the event and add the code to the builtins array. | 1657 // Log the event and add the code to the builtins array. |
1669 PROFILE(isolate, | 1658 PROFILE(isolate, |
1670 CodeCreateEvent(Logger::BUILTIN_TAG, | 1659 CodeCreateEvent(Logger::BUILTIN_TAG, *code, functions[i].s_name)); |
1671 Code::cast(code), | 1660 GDBJIT(AddCode(GDBJITInterface::BUILTIN, functions[i].s_name, *code)); |
1672 functions[i].s_name)); | 1661 builtins_[i] = *code; |
1673 GDBJIT(AddCode(GDBJITInterface::BUILTIN, | |
1674 functions[i].s_name, | |
1675 Code::cast(code))); | |
1676 builtins_[i] = code; | |
1677 #ifdef ENABLE_DISASSEMBLER | 1662 #ifdef ENABLE_DISASSEMBLER |
1678 if (FLAG_print_builtin_code) { | 1663 if (FLAG_print_builtin_code) { |
1679 CodeTracer::Scope trace_scope(isolate->GetCodeTracer()); | 1664 CodeTracer::Scope trace_scope(isolate->GetCodeTracer()); |
1680 PrintF(trace_scope.file(), "Builtin: %s\n", functions[i].s_name); | 1665 PrintF(trace_scope.file(), "Builtin: %s\n", functions[i].s_name); |
1681 Code::cast(code)->Disassemble(functions[i].s_name, trace_scope.file()); | 1666 code->Disassemble(functions[i].s_name, trace_scope.file()); |
1682 PrintF(trace_scope.file(), "\n"); | 1667 PrintF(trace_scope.file(), "\n"); |
1683 } | 1668 } |
1684 #endif | 1669 #endif |
1685 } else { | 1670 } else { |
1686 // Deserializing. The values will be filled in during IterateBuiltins. | 1671 // Deserializing. The values will be filled in during IterateBuiltins. |
1687 builtins_[i] = NULL; | 1672 builtins_[i] = NULL; |
1688 } | 1673 } |
1689 names_[i] = functions[i].s_name; | 1674 names_[i] = functions[i].s_name; |
1690 } | 1675 } |
1691 | 1676 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 } | 1733 } |
1749 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1734 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1750 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1735 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1751 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1736 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
1752 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1737 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1753 #undef DEFINE_BUILTIN_ACCESSOR_C | 1738 #undef DEFINE_BUILTIN_ACCESSOR_C |
1754 #undef DEFINE_BUILTIN_ACCESSOR_A | 1739 #undef DEFINE_BUILTIN_ACCESSOR_A |
1755 | 1740 |
1756 | 1741 |
1757 } } // namespace v8::internal | 1742 } } // namespace v8::internal |
OLD | NEW |