| 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" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } else if (FLAG_debug_code) { | 225 } else if (FLAG_debug_code) { |
| 226 Label done; | 226 Label done; |
| 227 __ JumpIfInNewSpace(rsi, rax, &done, Label::kNear); | 227 __ JumpIfInNewSpace(rsi, rax, &done, Label::kNear); |
| 228 __ Abort(kExpectedNewSpaceObject); | 228 __ Abort(kExpectedNewSpaceObject); |
| 229 __ bind(&done); | 229 __ bind(&done); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 Variable* new_target_var = scope()->new_target_var(); |
| 236 if (new_target_var != nullptr) { |
| 237 EmitAssignNewTarget(new_target_var); |
| 238 new_target_var->set_initializer_position(scope()->start_position()); |
| 239 } |
| 240 |
| 241 // TODO(arv): Remove ArgumentsAccessStub::HasNewTarget |
| 235 ArgumentsAccessStub::HasNewTarget has_new_target = | 242 ArgumentsAccessStub::HasNewTarget has_new_target = |
| 236 IsSubclassConstructor(info->function()->kind()) | 243 ArgumentsAccessStub::NO_NEW_TARGET; |
| 237 ? ArgumentsAccessStub::HAS_NEW_TARGET | |
| 238 : ArgumentsAccessStub::NO_NEW_TARGET; | |
| 239 | 244 |
| 240 // Possibly allocate RestParameters | 245 // Possibly allocate RestParameters |
| 241 int rest_index; | 246 int rest_index; |
| 242 Variable* rest_param = scope()->rest_parameter(&rest_index); | 247 Variable* rest_param = scope()->rest_parameter(&rest_index); |
| 243 if (rest_param) { | 248 if (rest_param) { |
| 244 Comment cmnt(masm_, "[ Allocate rest parameter array"); | 249 Comment cmnt(masm_, "[ Allocate rest parameter array"); |
| 245 | 250 |
| 246 int num_parameters = info->scope()->num_parameters(); | 251 int num_parameters = info->scope()->num_parameters(); |
| 247 int offset = num_parameters * kPointerSize; | 252 int offset = num_parameters * kPointerSize; |
| 248 if (has_new_target == ArgumentsAccessStub::HAS_NEW_TARGET) { | 253 if (has_new_target == ArgumentsAccessStub::HAS_NEW_TARGET) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 masm_->bind(&check_exit_codesize); | 445 masm_->bind(&check_exit_codesize); |
| 441 #endif | 446 #endif |
| 442 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); | 447 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
| 443 __ RecordJSReturn(); | 448 __ RecordJSReturn(); |
| 444 // Do not use the leave instruction here because it is too short to | 449 // Do not use the leave instruction here because it is too short to |
| 445 // patch with the code required by the debugger. | 450 // patch with the code required by the debugger. |
| 446 __ movp(rsp, rbp); | 451 __ movp(rsp, rbp); |
| 447 __ popq(rbp); | 452 __ popq(rbp); |
| 448 int no_frame_start = masm_->pc_offset(); | 453 int no_frame_start = masm_->pc_offset(); |
| 449 | 454 |
| 450 int arg_count = info_->scope()->num_parameters() + 1; | 455 int offset = info_->scope()->num_parameters() + 1; |
| 451 if (IsSubclassConstructor(info_->function()->kind())) { | 456 if (scope()->uses_new_target()) { |
| 452 arg_count++; | 457 offset++; |
| 453 } | 458 } |
| 454 int arguments_bytes = arg_count * kPointerSize; | 459 __ Ret(offset * kPointerSize, rcx); |
| 455 __ Ret(arguments_bytes, rcx); | |
| 456 | 460 |
| 457 // Add padding that will be overwritten by a debugger breakpoint. We | 461 // Add padding that will be overwritten by a debugger breakpoint. We |
| 458 // have just generated at least 7 bytes: "movp rsp, rbp; pop rbp; ret k" | 462 // have just generated at least 7 bytes: "movp rsp, rbp; pop rbp; ret k" |
| 459 // (3 + 1 + 3) for x64 and at least 6 (2 + 1 + 3) bytes for x32. | 463 // (3 + 1 + 3) for x64 and at least 6 (2 + 1 + 3) bytes for x32. |
| 460 const int kPadding = Assembler::kJSReturnSequenceLength - | 464 const int kPadding = Assembler::kJSReturnSequenceLength - |
| 461 kPointerSize == kInt64Size ? 7 : 6; | 465 kPointerSize == kInt64Size ? 7 : 6; |
| 462 for (int i = 0; i < kPadding; ++i) { | 466 for (int i = 0; i < kPadding; ++i) { |
| 463 masm_->int3(); | 467 masm_->int3(); |
| 464 } | 468 } |
| 465 // Check that the size of the code used for returning is large enough | 469 // Check that the size of the code used for returning is large enough |
| (...skipping 2550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3016 Label uninitialized_this; | 3020 Label uninitialized_this; |
| 3017 __ j(equal, &uninitialized_this); | 3021 __ j(equal, &uninitialized_this); |
| 3018 __ Push(this_var->name()); | 3022 __ Push(this_var->name()); |
| 3019 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 3023 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 3020 __ bind(&uninitialized_this); | 3024 __ bind(&uninitialized_this); |
| 3021 | 3025 |
| 3022 EmitVariableAssignment(this_var, Token::INIT_CONST); | 3026 EmitVariableAssignment(this_var, Token::INIT_CONST); |
| 3023 } | 3027 } |
| 3024 | 3028 |
| 3025 | 3029 |
| 3030 void FullCodeGenerator::EmitAssignNewTarget(Variable* new_target_var) { |
| 3031 __ CallRuntime(Runtime::kGetNewTarget, 0); |
| 3032 |
| 3033 // Register fp = rax; |
| 3034 // // Register count = rbx; |
| 3035 // // Register scratch = rcx; |
| 3036 |
| 3037 // // Get the frame pointer for the calling frame. |
| 3038 // __ movp(fp, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
| 3039 |
| 3040 // // Skip the arguments adaptor frame if it exists. |
| 3041 // Label check_frame_marker, construct_frame, assign; |
| 3042 |
| 3043 // __ Cmp(Operand(fp, StandardFrameConstants::kContextOffset), |
| 3044 // Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 3045 // __ j(not_equal, &check_frame_marker, Label::kNear); |
| 3046 // __ movp(fp, Operand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3047 |
| 3048 // // Check the marker in the calling frame. |
| 3049 // __ bind(&check_frame_marker); |
| 3050 // __ Cmp(Operand(fp, StandardFrameConstants::kMarkerOffset), |
| 3051 // Smi::FromInt(StackFrame::CONSTRUCT)); |
| 3052 // __ j(equal, &construct_frame, Label::kNear); |
| 3053 |
| 3054 // // [[Call]] always return undefined |
| 3055 // __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 3056 // __ jmp(&assign, Label::kNear); |
| 3057 |
| 3058 // // [[Construct]] get new.target from stack. |
| 3059 // __ bind(&construct_frame); |
| 3060 |
| 3061 // // Get the number of formal parameters. |
| 3062 // // __ Move(count, Smi::FromInt(info_->scope()->num_parameters())); |
| 3063 |
| 3064 // // Label length_done; |
| 3065 // // // TODO(arv): Don't check this again... |
| 3066 // // // Check if the calling frame is an arguments adaptor frame. |
| 3067 // // __ movp(scratch, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
| 3068 // // __ Cmp(Operand(scratch, StandardFrameConstants::kContextOffset), |
| 3069 // // Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 3070 // // __ j(not_equal, &length_done, Label::kNear); |
| 3071 |
| 3072 // // // Arguments adaptor case: Read the arguments length from the |
| 3073 // // // adaptor frame. |
| 3074 // // __ movp(count, Operand(rbx, |
| 3075 // ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3076 |
| 3077 // // __ bind(&length_done); |
| 3078 |
| 3079 // // // static const int kNewTargetOffset = kFPOnStackSize + kPCOnStackSize; |
| 3080 // // static const int kNewTargetOffset = 3 * kPointerSize; |
| 3081 |
| 3082 // // __ leap(rax, Operand(fp, count, times_pointer_size, kNewTargetOffset)); |
| 3083 |
| 3084 // __ movp(rax, Operand(fp, (3 + info_->scope()->num_parameters()) * |
| 3085 // kPointerSize)); |
| 3086 |
| 3087 // __ bind(&assign); |
| 3088 EmitVariableAssignment(new_target_var, Token::INIT_CONST); |
| 3089 } |
| 3090 |
| 3091 |
| 3026 void FullCodeGenerator::VisitCall(Call* expr) { | 3092 void FullCodeGenerator::VisitCall(Call* expr) { |
| 3027 #ifdef DEBUG | 3093 #ifdef DEBUG |
| 3028 // We want to verify that RecordJSReturnSite gets called on all paths | 3094 // We want to verify that RecordJSReturnSite gets called on all paths |
| 3029 // through this function. Avoid early returns. | 3095 // through this function. Avoid early returns. |
| 3030 expr->return_is_recorded_ = false; | 3096 expr->return_is_recorded_ = false; |
| 3031 #endif | 3097 #endif |
| 3032 | 3098 |
| 3033 Comment cmnt(masm_, "[ Call"); | 3099 Comment cmnt(masm_, "[ Call"); |
| 3034 Expression* callee = expr->expression(); | 3100 Expression* callee = expr->expression(); |
| 3035 Call::CallType call_type = expr->GetCallType(isolate()); | 3101 Call::CallType call_type = expr->GetCallType(isolate()); |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4121 __ movp(rax, Immediate(0)); | 4187 __ movp(rax, Immediate(0)); |
| 4122 __ jmp(&args_set_up); | 4188 __ jmp(&args_set_up); |
| 4123 | 4189 |
| 4124 // Copy arguments from adaptor frame. | 4190 // Copy arguments from adaptor frame. |
| 4125 { | 4191 { |
| 4126 __ bind(&adaptor_frame); | 4192 __ bind(&adaptor_frame); |
| 4127 __ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 4193 __ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4128 __ SmiToInteger64(rcx, rcx); | 4194 __ SmiToInteger64(rcx, rcx); |
| 4129 | 4195 |
| 4130 // Subtract 1 from arguments count, for new.target. | 4196 // Subtract 1 from arguments count, for new.target. |
| 4131 __ subp(rcx, Immediate(1)); | 4197 // TODO(arv): FIXME! |
| 4198 // __ subp(rcx, Immediate(1)); |
| 4132 __ movp(rax, rcx); | 4199 __ movp(rax, rcx); |
| 4133 __ leap(rdx, Operand(rdx, rcx, times_pointer_size, | 4200 __ leap(rdx, Operand(rdx, rcx, times_pointer_size, |
| 4134 StandardFrameConstants::kCallerSPOffset)); | 4201 StandardFrameConstants::kCallerSPOffset)); |
| 4135 Label loop; | 4202 Label loop; |
| 4136 __ bind(&loop); | 4203 __ bind(&loop); |
| 4137 __ Push(Operand(rdx, -1 * kPointerSize)); | 4204 __ Push(Operand(rdx, -1 * kPointerSize)); |
| 4138 __ subp(rdx, Immediate(kPointerSize)); | 4205 __ subp(rdx, Immediate(kPointerSize)); |
| 4139 __ decp(rcx); | 4206 __ decp(rcx); |
| 4140 __ j(not_zero, &loop); | 4207 __ j(not_zero, &loop); |
| 4141 } | 4208 } |
| (...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5417 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5484 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5418 Assembler::target_address_at(call_target_address, | 5485 Assembler::target_address_at(call_target_address, |
| 5419 unoptimized_code)); | 5486 unoptimized_code)); |
| 5420 return OSR_AFTER_STACK_CHECK; | 5487 return OSR_AFTER_STACK_CHECK; |
| 5421 } | 5488 } |
| 5422 | 5489 |
| 5423 | 5490 |
| 5424 } } // namespace v8::internal | 5491 } } // namespace v8::internal |
| 5425 | 5492 |
| 5426 #endif // V8_TARGET_ARCH_X64 | 5493 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |