| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| 11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
| 12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
| 13 #include "src/debug.h" | 13 #include "src/debug.h" |
| 14 #include "src/full-codegen.h" | 14 #include "src/full-codegen.h" |
| 15 #include "src/ic/ic.h" | 15 #include "src/ic/ic.h" |
| 16 #include "src/isolate-inl.h" | 16 #include "src/isolate-inl.h" |
| 17 #include "src/parser.h" | 17 #include "src/parser.h" |
| 18 #include "src/scopes.h" | 18 #include "src/scopes.h" |
| 19 | 19 |
| 20 namespace v8 { | 20 namespace v8 { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 #define __ ACCESS_MASM(masm_) | 23 #define __ ACCESS_MASM(masm_) |
| 24 | 24 |
| 25 | 25 |
| 26 class JumpPatchSite BASE_EMBEDDED { | 26 class JumpPatchSite BASE_EMBEDDED { |
| 27 public: | 27 public: |
| 28 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { | 28 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { |
| 29 #ifdef DEBUG | 29 #if DCHECK_IS_ON |
| 30 info_emitted_ = false; | 30 info_emitted_ = false; |
| 31 #endif | 31 #endif |
| 32 } | 32 } |
| 33 | 33 |
| 34 ~JumpPatchSite() { | 34 ~JumpPatchSite() { |
| 35 DCHECK(patch_site_.is_bound() == info_emitted_); | 35 DCHECK(patch_site_.is_bound() == info_emitted_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void EmitJumpIfNotSmi(Register reg, | 38 void EmitJumpIfNotSmi(Register reg, |
| 39 Label* target, | 39 Label* target, |
| 40 Label::Distance near_jump = Label::kFar) { | 40 Label::Distance near_jump = Label::kFar) { |
| 41 __ testb(reg, Immediate(kSmiTagMask)); | 41 __ testb(reg, Immediate(kSmiTagMask)); |
| 42 EmitJump(not_carry, target, near_jump); // Always taken before patched. | 42 EmitJump(not_carry, target, near_jump); // Always taken before patched. |
| 43 } | 43 } |
| 44 | 44 |
| 45 void EmitJumpIfSmi(Register reg, | 45 void EmitJumpIfSmi(Register reg, |
| 46 Label* target, | 46 Label* target, |
| 47 Label::Distance near_jump = Label::kFar) { | 47 Label::Distance near_jump = Label::kFar) { |
| 48 __ testb(reg, Immediate(kSmiTagMask)); | 48 __ testb(reg, Immediate(kSmiTagMask)); |
| 49 EmitJump(carry, target, near_jump); // Never taken before patched. | 49 EmitJump(carry, target, near_jump); // Never taken before patched. |
| 50 } | 50 } |
| 51 | 51 |
| 52 void EmitPatchInfo() { | 52 void EmitPatchInfo() { |
| 53 if (patch_site_.is_bound()) { | 53 if (patch_site_.is_bound()) { |
| 54 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); | 54 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
| 55 DCHECK(is_uint8(delta_to_patch_site)); | 55 DCHECK(is_uint8(delta_to_patch_site)); |
| 56 __ testl(rax, Immediate(delta_to_patch_site)); | 56 __ testl(rax, Immediate(delta_to_patch_site)); |
| 57 #ifdef DEBUG | 57 #if DCHECK_IS_ON |
| 58 info_emitted_ = true; | 58 info_emitted_ = true; |
| 59 #endif | 59 #endif |
| 60 } else { | 60 } else { |
| 61 __ nop(); // Signals no inlined code. | 61 __ nop(); // Signals no inlined code. |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 // jc will be patched with jz, jnc will become jnz. | 66 // jc will be patched with jz, jnc will become jnz. |
| 67 void EmitJump(Condition cc, Label* target, Label::Distance near_jump) { | 67 void EmitJump(Condition cc, Label* target, Label::Distance near_jump) { |
| 68 DCHECK(!patch_site_.is_bound() && !info_emitted_); | 68 DCHECK(!patch_site_.is_bound() && !info_emitted_); |
| 69 DCHECK(cc == carry || cc == not_carry); | 69 DCHECK(cc == carry || cc == not_carry); |
| 70 __ bind(&patch_site_); | 70 __ bind(&patch_site_); |
| 71 __ j(cc, target, near_jump); | 71 __ j(cc, target, near_jump); |
| 72 } | 72 } |
| 73 | 73 |
| 74 MacroAssembler* masm_; | 74 MacroAssembler* masm_; |
| 75 Label patch_site_; | 75 Label patch_site_; |
| 76 #ifdef DEBUG | 76 #if DCHECK_IS_ON |
| 77 bool info_emitted_; | 77 bool info_emitted_; |
| 78 #endif | 78 #endif |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 | 81 |
| 82 // Generate code for a JS function. On entry to the function the receiver | 82 // Generate code for a JS function. On entry to the function the receiver |
| 83 // and arguments have been pushed on the stack left to right, with the | 83 // and arguments have been pushed on the stack left to right, with the |
| 84 // return address on top of them. The actual argument count matches the | 84 // return address on top of them. The actual argument count matches the |
| 85 // formal parameter count expected by the function. | 85 // formal parameter count expected by the function. |
| 86 // | 86 // |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 396 } |
| 397 EmitProfilingCounterDecrement(weight); | 397 EmitProfilingCounterDecrement(weight); |
| 398 Label ok; | 398 Label ok; |
| 399 __ j(positive, &ok, Label::kNear); | 399 __ j(positive, &ok, Label::kNear); |
| 400 __ Push(rax); | 400 __ Push(rax); |
| 401 __ call(isolate()->builtins()->InterruptCheck(), | 401 __ call(isolate()->builtins()->InterruptCheck(), |
| 402 RelocInfo::CODE_TARGET); | 402 RelocInfo::CODE_TARGET); |
| 403 __ Pop(rax); | 403 __ Pop(rax); |
| 404 EmitProfilingCounterReset(); | 404 EmitProfilingCounterReset(); |
| 405 __ bind(&ok); | 405 __ bind(&ok); |
| 406 #ifdef DEBUG | 406 #if DCHECK_IS_ON |
| 407 // Add a label for checking the size of the code used for returning. | 407 // Add a label for checking the size of the code used for returning. |
| 408 Label check_exit_codesize; | 408 Label check_exit_codesize; |
| 409 masm_->bind(&check_exit_codesize); | 409 masm_->bind(&check_exit_codesize); |
| 410 #endif | 410 #endif |
| 411 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); | 411 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
| 412 __ RecordJSReturn(); | 412 __ RecordJSReturn(); |
| 413 // Do not use the leave instruction here because it is too short to | 413 // Do not use the leave instruction here because it is too short to |
| 414 // patch with the code required by the debugger. | 414 // patch with the code required by the debugger. |
| 415 __ movp(rsp, rbp); | 415 __ movp(rsp, rbp); |
| 416 __ popq(rbp); | 416 __ popq(rbp); |
| (...skipping 4699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5116 return previous_; | 5116 return previous_; |
| 5117 } | 5117 } |
| 5118 | 5118 |
| 5119 | 5119 |
| 5120 #undef __ | 5120 #undef __ |
| 5121 | 5121 |
| 5122 | 5122 |
| 5123 static const byte kJnsInstruction = 0x79; | 5123 static const byte kJnsInstruction = 0x79; |
| 5124 static const byte kNopByteOne = 0x66; | 5124 static const byte kNopByteOne = 0x66; |
| 5125 static const byte kNopByteTwo = 0x90; | 5125 static const byte kNopByteTwo = 0x90; |
| 5126 #ifdef DEBUG | 5126 #if DCHECK_IS_ON |
| 5127 static const byte kCallInstruction = 0xe8; | 5127 static const byte kCallInstruction = 0xe8; |
| 5128 #endif | 5128 #endif |
| 5129 | 5129 |
| 5130 | 5130 |
| 5131 void BackEdgeTable::PatchAt(Code* unoptimized_code, | 5131 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 5132 Address pc, | 5132 Address pc, |
| 5133 BackEdgeState target_state, | 5133 BackEdgeState target_state, |
| 5134 Code* replacement_code) { | 5134 Code* replacement_code) { |
| 5135 Address call_target_address = pc - kIntSize; | 5135 Address call_target_address = pc - kIntSize; |
| 5136 Address jns_instr_address = call_target_address - 3; | 5136 Address jns_instr_address = call_target_address - 3; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5193 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5193 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5194 Assembler::target_address_at(call_target_address, | 5194 Assembler::target_address_at(call_target_address, |
| 5195 unoptimized_code)); | 5195 unoptimized_code)); |
| 5196 return OSR_AFTER_STACK_CHECK; | 5196 return OSR_AFTER_STACK_CHECK; |
| 5197 } | 5197 } |
| 5198 | 5198 |
| 5199 | 5199 |
| 5200 } } // namespace v8::internal | 5200 } } // namespace v8::internal |
| 5201 | 5201 |
| 5202 #endif // V8_TARGET_ARCH_X64 | 5202 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |