| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/base/ieee754.h" | 10 #include "src/base/ieee754.h" |
| (...skipping 5578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5589 | 5589 |
| 5590 Builtins::Builtins() : initialized_(false) { | 5590 Builtins::Builtins() : initialized_(false) { |
| 5591 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); | 5591 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); |
| 5592 memset(names_, 0, sizeof(names_[0]) * builtin_count); | 5592 memset(names_, 0, sizeof(names_[0]) * builtin_count); |
| 5593 } | 5593 } |
| 5594 | 5594 |
| 5595 | 5595 |
| 5596 Builtins::~Builtins() { | 5596 Builtins::~Builtins() { |
| 5597 } | 5597 } |
| 5598 | 5598 |
| 5599 #define DEF_ENUM_C(name) FUNCTION_ADDR(Builtin_##name), | 5599 #define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name), |
| 5600 Address const Builtins::c_functions_[cfunction_count] = { | 5600 Address const Builtins::c_functions_[cfunction_count] = { |
| 5601 BUILTIN_LIST_C(DEF_ENUM_C) | 5601 BUILTIN_LIST_C(DEF_ENUM_C) |
| 5602 }; | 5602 }; |
| 5603 #undef DEF_ENUM_C | 5603 #undef DEF_ENUM_C |
| 5604 | 5604 |
| 5605 | 5605 |
| 5606 struct BuiltinDesc { | 5606 struct BuiltinDesc { |
| 5607 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); | 5607 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); |
| 5608 byte* generator; | 5608 byte* generator; |
| 5609 byte* c_code; | 5609 byte* c_code; |
| 5610 const char* s_name; // name is only used for generating log information. | 5610 const char* s_name; // name is only used for generating log information. |
| 5611 int name; | 5611 int name; |
| 5612 Code::Flags flags; | 5612 Code::Flags flags; |
| 5613 bool builtin_exit_frame; |
| 5613 int argc; | 5614 int argc; |
| 5614 }; | 5615 }; |
| 5615 | 5616 |
| 5616 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } | 5617 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } |
| 5617 | 5618 |
| 5618 class BuiltinFunctionTable { | 5619 class BuiltinFunctionTable { |
| 5619 public: | 5620 public: |
| 5620 BuiltinDesc* functions() { | 5621 BuiltinDesc* functions() { |
| 5621 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); | 5622 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); |
| 5622 return functions_; | 5623 return functions_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5647 const size_t buffer_size = 8 * KB; | 5648 const size_t buffer_size = 8 * KB; |
| 5648 #endif | 5649 #endif |
| 5649 union { | 5650 union { |
| 5650 int force_alignment; | 5651 int force_alignment; |
| 5651 byte buffer[buffer_size]; // NOLINT(runtime/arrays) | 5652 byte buffer[buffer_size]; // NOLINT(runtime/arrays) |
| 5652 } u; | 5653 } u; |
| 5653 | 5654 |
| 5654 MacroAssembler masm(isolate, u.buffer, sizeof(u.buffer), | 5655 MacroAssembler masm(isolate, u.buffer, sizeof(u.buffer), |
| 5655 CodeObjectRequired::kYes); | 5656 CodeObjectRequired::kYes); |
| 5656 // Generate the code/adaptor. | 5657 // Generate the code/adaptor. |
| 5657 typedef void (*Generator)(MacroAssembler*, int); | 5658 typedef void (*Generator)(MacroAssembler*, int, bool); |
| 5658 Generator g = FUNCTION_CAST<Generator>(builtin_desc->generator); | 5659 Generator g = FUNCTION_CAST<Generator>(builtin_desc->generator); |
| 5659 // We pass all arguments to the generator, but it may not use all of | 5660 // We pass all arguments to the generator, but it may not use all of |
| 5660 // them. This works because the first arguments are on top of the | 5661 // them. This works because the first arguments are on top of the |
| 5661 // stack. | 5662 // stack. |
| 5662 DCHECK(!masm.has_frame()); | 5663 DCHECK(!masm.has_frame()); |
| 5663 g(&masm, builtin_desc->name); | 5664 g(&masm, builtin_desc->name, builtin_desc->builtin_exit_frame); |
| 5664 // Move the code into the object heap. | 5665 // Move the code into the object heap. |
| 5665 CodeDesc desc; | 5666 CodeDesc desc; |
| 5666 masm.GetCode(&desc); | 5667 masm.GetCode(&desc); |
| 5667 Code::Flags flags = builtin_desc->flags; | 5668 Code::Flags flags = builtin_desc->flags; |
| 5668 return isolate->factory()->NewCode(desc, flags, masm.CodeObject()); | 5669 return isolate->factory()->NewCode(desc, flags, masm.CodeObject()); |
| 5669 } | 5670 } |
| 5670 | 5671 |
| 5671 // Builder for builtins implemented in TurboFan with JS linkage. | 5672 // Builder for builtins implemented in TurboFan with JS linkage. |
| 5672 Handle<Code> CodeStubAssemblerBuilderJS(Isolate* isolate, | 5673 Handle<Code> CodeStubAssemblerBuilderJS(Isolate* isolate, |
| 5673 BuiltinDesc const* builtin_desc) { | 5674 BuiltinDesc const* builtin_desc) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5707 // within the lexical scope of Builtins:: and within a context where | 5708 // within the lexical scope of Builtins:: and within a context where |
| 5708 // Code::Flags names a non-abstract type. | 5709 // Code::Flags names a non-abstract type. |
| 5709 void Builtins::InitBuiltinFunctionTable() { | 5710 void Builtins::InitBuiltinFunctionTable() { |
| 5710 BuiltinDesc* functions = builtin_function_table.functions_; | 5711 BuiltinDesc* functions = builtin_function_table.functions_; |
| 5711 functions[builtin_count].builder = nullptr; | 5712 functions[builtin_count].builder = nullptr; |
| 5712 functions[builtin_count].generator = nullptr; | 5713 functions[builtin_count].generator = nullptr; |
| 5713 functions[builtin_count].c_code = nullptr; | 5714 functions[builtin_count].c_code = nullptr; |
| 5714 functions[builtin_count].s_name = nullptr; | 5715 functions[builtin_count].s_name = nullptr; |
| 5715 functions[builtin_count].name = builtin_count; | 5716 functions[builtin_count].name = builtin_count; |
| 5716 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 5717 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
| 5718 functions[builtin_count].builtin_exit_frame = false; |
| 5717 functions[builtin_count].argc = 0; | 5719 functions[builtin_count].argc = 0; |
| 5718 | 5720 |
| 5719 #define DEF_FUNCTION_PTR_C(aname) \ | 5721 #define DEF_FUNCTION_PTR_C(aname, is_builtin_exit_frame) \ |
| 5720 functions->builder = &MacroAssemblerBuilder; \ | 5722 functions->builder = &MacroAssemblerBuilder; \ |
| 5721 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 5723 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
| 5722 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 5724 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ |
| 5723 functions->s_name = #aname; \ | 5725 functions->s_name = #aname; \ |
| 5724 functions->name = c_##aname; \ | 5726 functions->name = c_##aname; \ |
| 5725 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 5727 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
| 5728 functions->builtin_exit_frame = is_builtin_exit_frame; \ |
| 5726 functions->argc = 0; \ | 5729 functions->argc = 0; \ |
| 5727 ++functions; | 5730 ++functions; |
| 5728 | 5731 |
| 5729 #define DEF_FUNCTION_PTR_A(aname, kind, extra) \ | 5732 #define DEF_FUNCTION_PTR_A(aname, kind, extra) \ |
| 5730 functions->builder = &MacroAssemblerBuilder; \ | 5733 functions->builder = &MacroAssemblerBuilder; \ |
| 5731 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5734 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
| 5732 functions->c_code = NULL; \ | 5735 functions->c_code = NULL; \ |
| 5733 functions->s_name = #aname; \ | 5736 functions->s_name = #aname; \ |
| 5734 functions->name = k##aname; \ | 5737 functions->name = k##aname; \ |
| 5735 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | 5738 functions->flags = Code::ComputeFlags(Code::kind, extra); \ |
| 5739 functions->builtin_exit_frame = false; \ |
| 5736 functions->argc = 0; \ | 5740 functions->argc = 0; \ |
| 5737 ++functions; | 5741 ++functions; |
| 5738 | 5742 |
| 5739 #define DEF_FUNCTION_PTR_T(aname, aargc) \ | 5743 #define DEF_FUNCTION_PTR_T(aname, aargc) \ |
| 5740 functions->builder = &CodeStubAssemblerBuilderJS; \ | 5744 functions->builder = &CodeStubAssemblerBuilderJS; \ |
| 5741 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5745 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
| 5742 functions->c_code = NULL; \ | 5746 functions->c_code = NULL; \ |
| 5743 functions->s_name = #aname; \ | 5747 functions->s_name = #aname; \ |
| 5744 functions->name = k##aname; \ | 5748 functions->name = k##aname; \ |
| 5745 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 5749 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
| 5750 functions->builtin_exit_frame = false; \ |
| 5746 functions->argc = aargc; \ | 5751 functions->argc = aargc; \ |
| 5747 ++functions; | 5752 ++functions; |
| 5748 | 5753 |
| 5749 #define DEF_FUNCTION_PTR_S(aname, kind, extra, interface_descriptor) \ | 5754 #define DEF_FUNCTION_PTR_S(aname, kind, extra, interface_descriptor) \ |
| 5750 functions->builder = &CodeStubAssemblerBuilderCS; \ | 5755 functions->builder = &CodeStubAssemblerBuilderCS; \ |
| 5751 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5756 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
| 5752 functions->c_code = NULL; \ | 5757 functions->c_code = NULL; \ |
| 5753 functions->s_name = #aname; \ | 5758 functions->s_name = #aname; \ |
| 5754 functions->name = k##aname; \ | 5759 functions->name = k##aname; \ |
| 5755 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | 5760 functions->flags = Code::ComputeFlags(Code::kind, extra); \ |
| 5761 functions->builtin_exit_frame = false; \ |
| 5756 functions->argc = CallDescriptors::interface_descriptor; \ | 5762 functions->argc = CallDescriptors::interface_descriptor; \ |
| 5757 ++functions; | 5763 ++functions; |
| 5758 | 5764 |
| 5759 #define DEF_FUNCTION_PTR_H(aname, kind) \ | 5765 #define DEF_FUNCTION_PTR_H(aname, kind) \ |
| 5760 functions->builder = &MacroAssemblerBuilder; \ | 5766 functions->builder = &MacroAssemblerBuilder; \ |
| 5761 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5767 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
| 5762 functions->c_code = NULL; \ | 5768 functions->c_code = NULL; \ |
| 5763 functions->s_name = #aname; \ | 5769 functions->s_name = #aname; \ |
| 5764 functions->name = k##aname; \ | 5770 functions->name = k##aname; \ |
| 5765 functions->flags = Code::ComputeHandlerFlags(Code::kind); \ | 5771 functions->flags = Code::ComputeHandlerFlags(Code::kind); \ |
| 5772 functions->builtin_exit_frame = false; \ |
| 5766 functions->argc = 0; \ | 5773 functions->argc = 0; \ |
| 5767 ++functions; | 5774 ++functions; |
| 5768 | 5775 |
| 5769 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) | 5776 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) |
| 5770 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) | 5777 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) |
| 5771 BUILTIN_LIST_T(DEF_FUNCTION_PTR_T) | 5778 BUILTIN_LIST_T(DEF_FUNCTION_PTR_T) |
| 5772 BUILTIN_LIST_S(DEF_FUNCTION_PTR_S) | 5779 BUILTIN_LIST_S(DEF_FUNCTION_PTR_S) |
| 5773 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) | 5780 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) |
| 5774 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | 5781 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) |
| 5775 | 5782 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6089 a->Bind(&u32); | 6096 a->Bind(&u32); |
| 6090 a->AtomicStore(MachineRepresentation::kWord32, backing_store, | 6097 a->AtomicStore(MachineRepresentation::kWord32, backing_store, |
| 6091 a->WordShl(index_word, 2), value_word32); | 6098 a->WordShl(index_word, 2), value_word32); |
| 6092 a->Return(value_integer); | 6099 a->Return(value_integer); |
| 6093 | 6100 |
| 6094 // This shouldn't happen, we've already validated the type. | 6101 // This shouldn't happen, we've already validated the type. |
| 6095 a->Bind(&other); | 6102 a->Bind(&other); |
| 6096 a->Return(a->Int32Constant(0)); | 6103 a->Return(a->Int32Constant(0)); |
| 6097 } | 6104 } |
| 6098 | 6105 |
| 6099 #define DEFINE_BUILTIN_ACCESSOR_C(name) \ | 6106 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ |
| 6100 Handle<Code> Builtins::name() { \ | 6107 Handle<Code> Builtins::name() { \ |
| 6101 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6108 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 6102 return Handle<Code>(code_address); \ | 6109 return Handle<Code>(code_address); \ |
| 6103 } | 6110 } |
| 6104 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, extra) \ | 6111 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, extra) \ |
| 6105 Handle<Code> Builtins::name() { \ | 6112 Handle<Code> Builtins::name() { \ |
| 6106 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6113 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 6107 return Handle<Code>(code_address); \ | 6114 return Handle<Code>(code_address); \ |
| 6108 } | 6115 } |
| 6109 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ | 6116 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6129 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 6136 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 6130 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 6137 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 6131 #undef DEFINE_BUILTIN_ACCESSOR_C | 6138 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 6132 #undef DEFINE_BUILTIN_ACCESSOR_A | 6139 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 6133 #undef DEFINE_BUILTIN_ACCESSOR_T | 6140 #undef DEFINE_BUILTIN_ACCESSOR_T |
| 6134 #undef DEFINE_BUILTIN_ACCESSOR_S | 6141 #undef DEFINE_BUILTIN_ACCESSOR_S |
| 6135 #undef DEFINE_BUILTIN_ACCESSOR_H | 6142 #undef DEFINE_BUILTIN_ACCESSOR_H |
| 6136 | 6143 |
| 6137 } // namespace internal | 6144 } // namespace internal |
| 6138 } // namespace v8 | 6145 } // namespace v8 |
| OLD | NEW |