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 5699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5710 | 5710 |
5711 Builtins::Builtins() : initialized_(false) { | 5711 Builtins::Builtins() : initialized_(false) { |
5712 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); | 5712 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); |
5713 memset(names_, 0, sizeof(names_[0]) * builtin_count); | 5713 memset(names_, 0, sizeof(names_[0]) * builtin_count); |
5714 } | 5714 } |
5715 | 5715 |
5716 | 5716 |
5717 Builtins::~Builtins() { | 5717 Builtins::~Builtins() { |
5718 } | 5718 } |
5719 | 5719 |
5720 #define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name), | 5720 #define DEF_ENUM_C(name) FUNCTION_ADDR(Builtin_##name), |
5721 Address const Builtins::c_functions_[cfunction_count] = { | 5721 Address const Builtins::c_functions_[cfunction_count] = { |
5722 BUILTIN_LIST_C(DEF_ENUM_C) | 5722 BUILTIN_LIST_C(DEF_ENUM_C) |
5723 }; | 5723 }; |
5724 #undef DEF_ENUM_C | 5724 #undef DEF_ENUM_C |
5725 | 5725 |
5726 | 5726 |
5727 struct BuiltinDesc { | 5727 struct BuiltinDesc { |
5728 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); | 5728 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); |
5729 byte* generator; | 5729 byte* generator; |
5730 byte* c_code; | 5730 byte* c_code; |
5731 const char* s_name; // name is only used for generating log information. | 5731 const char* s_name; // name is only used for generating log information. |
5732 int name; | 5732 int name; |
5733 Code::Flags flags; | 5733 Code::Flags flags; |
5734 Builtins::ExitFrameType exit_frame_type; | |
5735 int argc; | 5734 int argc; |
5736 }; | 5735 }; |
5737 | 5736 |
5738 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } | 5737 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } |
5739 | 5738 |
5740 class BuiltinFunctionTable { | 5739 class BuiltinFunctionTable { |
5741 public: | 5740 public: |
5742 BuiltinDesc* functions() { | 5741 BuiltinDesc* functions() { |
5743 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); | 5742 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); |
5744 return functions_; | 5743 return functions_; |
(...skipping 24 matching lines...) Expand all Loading... |
5769 const size_t buffer_size = 8 * KB; | 5768 const size_t buffer_size = 8 * KB; |
5770 #endif | 5769 #endif |
5771 union { | 5770 union { |
5772 int force_alignment; | 5771 int force_alignment; |
5773 byte buffer[buffer_size]; // NOLINT(runtime/arrays) | 5772 byte buffer[buffer_size]; // NOLINT(runtime/arrays) |
5774 } u; | 5773 } u; |
5775 | 5774 |
5776 MacroAssembler masm(isolate, u.buffer, sizeof(u.buffer), | 5775 MacroAssembler masm(isolate, u.buffer, sizeof(u.buffer), |
5777 CodeObjectRequired::kYes); | 5776 CodeObjectRequired::kYes); |
5778 // Generate the code/adaptor. | 5777 // Generate the code/adaptor. |
5779 typedef void (*Generator)(MacroAssembler*, int, Builtins::ExitFrameType); | 5778 typedef void (*Generator)(MacroAssembler*, int); |
5780 Generator g = FUNCTION_CAST<Generator>(builtin_desc->generator); | 5779 Generator g = FUNCTION_CAST<Generator>(builtin_desc->generator); |
5781 // We pass all arguments to the generator, but it may not use all of | 5780 // We pass all arguments to the generator, but it may not use all of |
5782 // them. This works because the first arguments are on top of the | 5781 // them. This works because the first arguments are on top of the |
5783 // stack. | 5782 // stack. |
5784 DCHECK(!masm.has_frame()); | 5783 DCHECK(!masm.has_frame()); |
5785 g(&masm, builtin_desc->name, builtin_desc->exit_frame_type); | 5784 g(&masm, builtin_desc->name); |
5786 // Move the code into the object heap. | 5785 // Move the code into the object heap. |
5787 CodeDesc desc; | 5786 CodeDesc desc; |
5788 masm.GetCode(&desc); | 5787 masm.GetCode(&desc); |
5789 Code::Flags flags = builtin_desc->flags; | 5788 Code::Flags flags = builtin_desc->flags; |
5790 return isolate->factory()->NewCode(desc, flags, masm.CodeObject()); | 5789 return isolate->factory()->NewCode(desc, flags, masm.CodeObject()); |
5791 } | 5790 } |
5792 | 5791 |
5793 // Builder for builtins implemented in TurboFan with JS linkage. | 5792 // Builder for builtins implemented in TurboFan with JS linkage. |
5794 Handle<Code> CodeStubAssemblerBuilderJS(Isolate* isolate, | 5793 Handle<Code> CodeStubAssemblerBuilderJS(Isolate* isolate, |
5795 BuiltinDesc const* builtin_desc) { | 5794 BuiltinDesc const* builtin_desc) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5829 // within the lexical scope of Builtins:: and within a context where | 5828 // within the lexical scope of Builtins:: and within a context where |
5830 // Code::Flags names a non-abstract type. | 5829 // Code::Flags names a non-abstract type. |
5831 void Builtins::InitBuiltinFunctionTable() { | 5830 void Builtins::InitBuiltinFunctionTable() { |
5832 BuiltinDesc* functions = builtin_function_table.functions_; | 5831 BuiltinDesc* functions = builtin_function_table.functions_; |
5833 functions[builtin_count].builder = nullptr; | 5832 functions[builtin_count].builder = nullptr; |
5834 functions[builtin_count].generator = nullptr; | 5833 functions[builtin_count].generator = nullptr; |
5835 functions[builtin_count].c_code = nullptr; | 5834 functions[builtin_count].c_code = nullptr; |
5836 functions[builtin_count].s_name = nullptr; | 5835 functions[builtin_count].s_name = nullptr; |
5837 functions[builtin_count].name = builtin_count; | 5836 functions[builtin_count].name = builtin_count; |
5838 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 5837 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
5839 functions[builtin_count].exit_frame_type = EXIT; | |
5840 functions[builtin_count].argc = 0; | 5838 functions[builtin_count].argc = 0; |
5841 | 5839 |
5842 #define DEF_FUNCTION_PTR_C(aname, aexit_frame_type) \ | 5840 #define DEF_FUNCTION_PTR_C(aname) \ |
5843 functions->builder = &MacroAssemblerBuilder; \ | 5841 functions->builder = &MacroAssemblerBuilder; \ |
5844 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 5842 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
5845 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 5843 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ |
5846 functions->s_name = #aname; \ | 5844 functions->s_name = #aname; \ |
5847 functions->name = c_##aname; \ | 5845 functions->name = c_##aname; \ |
5848 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 5846 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
5849 functions->exit_frame_type = aexit_frame_type; \ | |
5850 functions->argc = 0; \ | 5847 functions->argc = 0; \ |
5851 ++functions; | 5848 ++functions; |
5852 | 5849 |
5853 #define DEF_FUNCTION_PTR_A(aname, kind, extra) \ | 5850 #define DEF_FUNCTION_PTR_A(aname, kind, extra) \ |
5854 functions->builder = &MacroAssemblerBuilder; \ | 5851 functions->builder = &MacroAssemblerBuilder; \ |
5855 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5852 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
5856 functions->c_code = NULL; \ | 5853 functions->c_code = NULL; \ |
5857 functions->s_name = #aname; \ | 5854 functions->s_name = #aname; \ |
5858 functions->name = k##aname; \ | 5855 functions->name = k##aname; \ |
5859 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | 5856 functions->flags = Code::ComputeFlags(Code::kind, extra); \ |
5860 functions->exit_frame_type = EXIT; \ | |
5861 functions->argc = 0; \ | 5857 functions->argc = 0; \ |
5862 ++functions; | 5858 ++functions; |
5863 | 5859 |
5864 #define DEF_FUNCTION_PTR_T(aname, aargc) \ | 5860 #define DEF_FUNCTION_PTR_T(aname, aargc) \ |
5865 functions->builder = &CodeStubAssemblerBuilderJS; \ | 5861 functions->builder = &CodeStubAssemblerBuilderJS; \ |
5866 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5862 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
5867 functions->c_code = NULL; \ | 5863 functions->c_code = NULL; \ |
5868 functions->s_name = #aname; \ | 5864 functions->s_name = #aname; \ |
5869 functions->name = k##aname; \ | 5865 functions->name = k##aname; \ |
5870 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 5866 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
5871 functions->exit_frame_type = EXIT; \ | |
5872 functions->argc = aargc; \ | 5867 functions->argc = aargc; \ |
5873 ++functions; | 5868 ++functions; |
5874 | 5869 |
5875 #define DEF_FUNCTION_PTR_S(aname, kind, extra, interface_descriptor) \ | 5870 #define DEF_FUNCTION_PTR_S(aname, kind, extra, interface_descriptor) \ |
5876 functions->builder = &CodeStubAssemblerBuilderCS; \ | 5871 functions->builder = &CodeStubAssemblerBuilderCS; \ |
5877 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5872 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
5878 functions->c_code = NULL; \ | 5873 functions->c_code = NULL; \ |
5879 functions->s_name = #aname; \ | 5874 functions->s_name = #aname; \ |
5880 functions->name = k##aname; \ | 5875 functions->name = k##aname; \ |
5881 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | 5876 functions->flags = Code::ComputeFlags(Code::kind, extra); \ |
5882 functions->exit_frame_type = EXIT; \ | |
5883 functions->argc = CallDescriptors::interface_descriptor; \ | 5877 functions->argc = CallDescriptors::interface_descriptor; \ |
5884 ++functions; | 5878 ++functions; |
5885 | 5879 |
5886 #define DEF_FUNCTION_PTR_H(aname, kind) \ | 5880 #define DEF_FUNCTION_PTR_H(aname, kind) \ |
5887 functions->builder = &MacroAssemblerBuilder; \ | 5881 functions->builder = &MacroAssemblerBuilder; \ |
5888 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 5882 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
5889 functions->c_code = NULL; \ | 5883 functions->c_code = NULL; \ |
5890 functions->s_name = #aname; \ | 5884 functions->s_name = #aname; \ |
5891 functions->name = k##aname; \ | 5885 functions->name = k##aname; \ |
5892 functions->flags = Code::ComputeHandlerFlags(Code::kind); \ | 5886 functions->flags = Code::ComputeHandlerFlags(Code::kind); \ |
5893 functions->exit_frame_type = EXIT; \ | |
5894 functions->argc = 0; \ | 5887 functions->argc = 0; \ |
5895 ++functions; | 5888 ++functions; |
5896 | 5889 |
5897 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) | 5890 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) |
5898 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) | 5891 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) |
5899 BUILTIN_LIST_T(DEF_FUNCTION_PTR_T) | 5892 BUILTIN_LIST_T(DEF_FUNCTION_PTR_T) |
5900 BUILTIN_LIST_S(DEF_FUNCTION_PTR_S) | 5893 BUILTIN_LIST_S(DEF_FUNCTION_PTR_S) |
5901 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) | 5894 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) |
5902 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | 5895 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) |
5903 | 5896 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6217 a->Bind(&u32); | 6210 a->Bind(&u32); |
6218 a->AtomicStore(MachineRepresentation::kWord32, backing_store, | 6211 a->AtomicStore(MachineRepresentation::kWord32, backing_store, |
6219 a->WordShl(index_word, 2), value_word32); | 6212 a->WordShl(index_word, 2), value_word32); |
6220 a->Return(value_integer); | 6213 a->Return(value_integer); |
6221 | 6214 |
6222 // This shouldn't happen, we've already validated the type. | 6215 // This shouldn't happen, we've already validated the type. |
6223 a->Bind(&other); | 6216 a->Bind(&other); |
6224 a->Return(a->Int32Constant(0)); | 6217 a->Return(a->Int32Constant(0)); |
6225 } | 6218 } |
6226 | 6219 |
6227 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 6220 #define DEFINE_BUILTIN_ACCESSOR_C(name) \ |
6228 Handle<Code> Builtins::name() { \ | 6221 Handle<Code> Builtins::name() { \ |
6229 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6222 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
6230 return Handle<Code>(code_address); \ | 6223 return Handle<Code>(code_address); \ |
6231 } | 6224 } |
6232 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, extra) \ | 6225 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, extra) \ |
6233 Handle<Code> Builtins::name() { \ | 6226 Handle<Code> Builtins::name() { \ |
6234 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6227 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
6235 return Handle<Code>(code_address); \ | 6228 return Handle<Code>(code_address); \ |
6236 } | 6229 } |
6237 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ | 6230 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ |
(...skipping 19 matching lines...) Expand all Loading... |
6257 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 6250 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
6258 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 6251 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
6259 #undef DEFINE_BUILTIN_ACCESSOR_C | 6252 #undef DEFINE_BUILTIN_ACCESSOR_C |
6260 #undef DEFINE_BUILTIN_ACCESSOR_A | 6253 #undef DEFINE_BUILTIN_ACCESSOR_A |
6261 #undef DEFINE_BUILTIN_ACCESSOR_T | 6254 #undef DEFINE_BUILTIN_ACCESSOR_T |
6262 #undef DEFINE_BUILTIN_ACCESSOR_S | 6255 #undef DEFINE_BUILTIN_ACCESSOR_S |
6263 #undef DEFINE_BUILTIN_ACCESSOR_H | 6256 #undef DEFINE_BUILTIN_ACCESSOR_H |
6264 | 6257 |
6265 } // namespace internal | 6258 } // namespace internal |
6266 } // namespace v8 | 6259 } // namespace v8 |
OLD | NEW |