| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 22 matching lines...) Expand all Loading... |
| 33 #include "codegen-inl.h" | 33 #include "codegen-inl.h" |
| 34 #include "assembler-x64.h" | 34 #include "assembler-x64.h" |
| 35 #include "macro-assembler-x64.h" | 35 #include "macro-assembler-x64.h" |
| 36 #include "serialize.h" | 36 #include "serialize.h" |
| 37 #include "debug.h" | 37 #include "debug.h" |
| 38 #include "heap.h" | 38 #include "heap.h" |
| 39 | 39 |
| 40 namespace v8 { | 40 namespace v8 { |
| 41 namespace internal { | 41 namespace internal { |
| 42 | 42 |
| 43 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) | 43 MacroAssembler::MacroAssembler(void* buffer, int size) |
| 44 : Assembler(arg_isolate, buffer, size), | 44 : Assembler(buffer, size), |
| 45 generating_stub_(false), | 45 generating_stub_(false), |
| 46 allow_stub_calls_(true), | 46 allow_stub_calls_(true), |
| 47 root_array_available_(true) { | 47 root_array_available_(true), |
| 48 if (isolate() != NULL) { | 48 code_object_(isolate()->heap()->undefined_value()) { |
| 49 code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), | |
| 50 isolate()); | |
| 51 } | |
| 52 } | 49 } |
| 53 | 50 |
| 54 | 51 |
| 55 static intptr_t RootRegisterDelta(ExternalReference other, Isolate* isolate) { | 52 static intptr_t RootRegisterDelta(ExternalReference other, Isolate* isolate) { |
| 56 Address roots_register_value = kRootRegisterBias + | 53 Address roots_register_value = kRootRegisterBias + |
| 57 reinterpret_cast<Address>(isolate->heap()->roots_address()); | 54 reinterpret_cast<Address>(isolate->heap()->roots_address()); |
| 58 intptr_t delta = other.address() - roots_register_value; | 55 intptr_t delta = other.address() - roots_register_value; |
| 59 return delta; | 56 return delta; |
| 60 } | 57 } |
| 61 | 58 |
| (...skipping 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2847 return num_arguments - kRegisterPassedArguments; | 2844 return num_arguments - kRegisterPassedArguments; |
| 2848 #endif | 2845 #endif |
| 2849 } | 2846 } |
| 2850 | 2847 |
| 2851 | 2848 |
| 2852 void MacroAssembler::PrepareCallCFunction(int num_arguments) { | 2849 void MacroAssembler::PrepareCallCFunction(int num_arguments) { |
| 2853 int frame_alignment = OS::ActivationFrameAlignment(); | 2850 int frame_alignment = OS::ActivationFrameAlignment(); |
| 2854 ASSERT(frame_alignment != 0); | 2851 ASSERT(frame_alignment != 0); |
| 2855 ASSERT(num_arguments >= 0); | 2852 ASSERT(num_arguments >= 0); |
| 2856 | 2853 |
| 2854 // Reserve space for Isolate address which is always passed as last parameter |
| 2855 num_arguments += 1; |
| 2856 |
| 2857 // Make stack end at alignment and allocate space for arguments and old rsp. | 2857 // Make stack end at alignment and allocate space for arguments and old rsp. |
| 2858 movq(kScratchRegister, rsp); | 2858 movq(kScratchRegister, rsp); |
| 2859 ASSERT(IsPowerOf2(frame_alignment)); | 2859 ASSERT(IsPowerOf2(frame_alignment)); |
| 2860 int argument_slots_on_stack = | 2860 int argument_slots_on_stack = |
| 2861 ArgumentStackSlotsForCFunctionCall(num_arguments); | 2861 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2862 subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); | 2862 subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); |
| 2863 and_(rsp, Immediate(-frame_alignment)); | 2863 and_(rsp, Immediate(-frame_alignment)); |
| 2864 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); | 2864 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); |
| 2865 } | 2865 } |
| 2866 | 2866 |
| 2867 | 2867 |
| 2868 void MacroAssembler::CallCFunction(ExternalReference function, | 2868 void MacroAssembler::CallCFunction(ExternalReference function, |
| 2869 int num_arguments) { | 2869 int num_arguments) { |
| 2870 LoadAddress(rax, function); | 2870 LoadAddress(rax, function); |
| 2871 CallCFunction(rax, num_arguments); | 2871 CallCFunction(rax, num_arguments); |
| 2872 } | 2872 } |
| 2873 | 2873 |
| 2874 | 2874 |
| 2875 void MacroAssembler::CallCFunction(Register function, int num_arguments) { | 2875 void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
| 2876 // Pass current isolate address as additional parameter. |
| 2877 if (num_arguments < kRegisterPassedArguments) { |
| 2878 #ifdef _WIN64 |
| 2879 // First four arguments are passed in registers on Windows. |
| 2880 Register arg_to_reg[] = {rcx, rdx, r8, r9}; |
| 2881 #else |
| 2882 // First six arguments are passed in registers on other platforms. |
| 2883 Register arg_to_reg[] = {rdi, rsi, rdx, rcx, r8, r9}; |
| 2884 #endif |
| 2885 Register reg = arg_to_reg[num_arguments]; |
| 2886 LoadAddress(reg, ExternalReference::isolate_address()); |
| 2887 } else { |
| 2888 // Push Isolate pointer after all parameters. |
| 2889 int argument_slots_on_stack = |
| 2890 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2891 LoadAddress(kScratchRegister, ExternalReference::isolate_address()); |
| 2892 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), |
| 2893 kScratchRegister); |
| 2894 } |
| 2895 |
| 2876 // Check stack alignment. | 2896 // Check stack alignment. |
| 2877 if (emit_debug_code()) { | 2897 if (emit_debug_code()) { |
| 2878 CheckStackAlignment(); | 2898 CheckStackAlignment(); |
| 2879 } | 2899 } |
| 2880 | 2900 |
| 2881 call(function); | 2901 call(function); |
| 2882 ASSERT(OS::ActivationFrameAlignment() != 0); | 2902 ASSERT(OS::ActivationFrameAlignment() != 0); |
| 2883 ASSERT(num_arguments >= 0); | 2903 ASSERT(num_arguments >= 0); |
| 2904 num_arguments += 1; |
| 2884 int argument_slots_on_stack = | 2905 int argument_slots_on_stack = |
| 2885 ArgumentStackSlotsForCFunctionCall(num_arguments); | 2906 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2886 movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); | 2907 movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); |
| 2887 } | 2908 } |
| 2888 | 2909 |
| 2889 | 2910 |
| 2890 CodePatcher::CodePatcher(byte* address, int size) | 2911 CodePatcher::CodePatcher(byte* address, int size) |
| 2891 : address_(address), | 2912 : address_(address), size_(size), masm_(address, size + Assembler::kGap) { |
| 2892 size_(size), | |
| 2893 masm_(Isolate::Current(), address, size + Assembler::kGap) { | |
| 2894 // Create a new macro assembler pointing to the address of the code to patch. | 2913 // Create a new macro assembler pointing to the address of the code to patch. |
| 2895 // The size is adjusted with kGap on order for the assembler to generate size | 2914 // The size is adjusted with kGap on order for the assembler to generate size |
| 2896 // bytes of instructions without failing with buffer size constraints. | 2915 // bytes of instructions without failing with buffer size constraints. |
| 2897 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2916 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2898 } | 2917 } |
| 2899 | 2918 |
| 2900 | 2919 |
| 2901 CodePatcher::~CodePatcher() { | 2920 CodePatcher::~CodePatcher() { |
| 2902 // Indicate that code has changed. | 2921 // Indicate that code has changed. |
| 2903 CPU::FlushICache(address_, size_); | 2922 CPU::FlushICache(address_, size_); |
| 2904 | 2923 |
| 2905 // Check that the code was patched as expected. | 2924 // Check that the code was patched as expected. |
| 2906 ASSERT(masm_.pc_ == address_ + size_); | 2925 ASSERT(masm_.pc_ == address_ + size_); |
| 2907 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2926 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2908 } | 2927 } |
| 2909 | 2928 |
| 2910 } } // namespace v8::internal | 2929 } } // namespace v8::internal |
| 2911 | 2930 |
| 2912 #endif // V8_TARGET_ARCH_X64 | 2931 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |