OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 4255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4266 | 4266 |
4267 // Fall back to %NewStrictArguments. | 4267 // Fall back to %NewStrictArguments. |
4268 __ bind(&too_big_for_new_space); | 4268 __ bind(&too_big_for_new_space); |
4269 __ PopReturnAddressTo(kScratchRegister); | 4269 __ PopReturnAddressTo(kScratchRegister); |
4270 __ Push(rdi); | 4270 __ Push(rdi); |
4271 __ PushReturnAddressFrom(kScratchRegister); | 4271 __ PushReturnAddressFrom(kScratchRegister); |
4272 __ TailCallRuntime(Runtime::kNewStrictArguments); | 4272 __ TailCallRuntime(Runtime::kNewStrictArguments); |
4273 } | 4273 } |
4274 | 4274 |
4275 | 4275 |
4276 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { | |
4277 Register context_reg = rsi; | |
4278 Register slot_reg = rbx; | |
4279 Register value_reg = rax; | |
4280 Register cell_reg = r8; | |
4281 Register cell_details_reg = rdx; | |
4282 Register cell_value_reg = r9; | |
4283 Label fast_heapobject_case, fast_smi_case, slow_case; | |
4284 | |
4285 if (FLAG_debug_code) { | |
4286 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex); | |
4287 __ Check(not_equal, kUnexpectedValue); | |
4288 } | |
4289 | |
4290 // Go up context chain to the script context. | |
4291 for (int i = 0; i < depth(); ++i) { | |
4292 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); | |
4293 context_reg = rdi; | |
4294 } | |
4295 | |
4296 // Load the PropertyCell at the specified slot. | |
4297 __ movp(cell_reg, ContextOperand(context_reg, slot_reg)); | |
4298 | |
4299 // Load PropertyDetails for the cell (actually only the cell_type, kind and | |
4300 // READ_ONLY bit of attributes). | |
4301 __ SmiToInteger32(cell_details_reg, | |
4302 FieldOperand(cell_reg, PropertyCell::kDetailsOffset)); | |
4303 __ andl(cell_details_reg, | |
4304 Immediate(PropertyDetails::PropertyCellTypeField::kMask | | |
4305 PropertyDetails::KindField::kMask | | |
4306 PropertyDetails::kAttributesReadOnlyMask)); | |
4307 | |
4308 // Check if PropertyCell holds mutable data. | |
4309 Label not_mutable_data; | |
4310 __ cmpl(cell_details_reg, | |
4311 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
4312 PropertyCellType::kMutable) | | |
4313 PropertyDetails::KindField::encode(kData))); | |
4314 __ j(not_equal, ¬_mutable_data); | |
4315 __ JumpIfSmi(value_reg, &fast_smi_case); | |
4316 __ bind(&fast_heapobject_case); | |
4317 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); | |
4318 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, | |
4319 cell_value_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET, | |
4320 OMIT_SMI_CHECK); | |
4321 // RecordWriteField clobbers the value register, so we need to reload. | |
4322 __ movp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); | |
4323 __ Ret(); | |
4324 __ bind(¬_mutable_data); | |
4325 | |
4326 // Check if PropertyCell value matches the new value (relevant for Constant, | |
4327 // ConstantType and Undefined cells). | |
4328 Label not_same_value; | |
4329 __ movp(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); | |
4330 __ cmpp(cell_value_reg, value_reg); | |
4331 __ j(not_equal, ¬_same_value, | |
4332 FLAG_debug_code ? Label::kFar : Label::kNear); | |
4333 // Make sure the PropertyCell is not marked READ_ONLY. | |
4334 __ testl(cell_details_reg, | |
4335 Immediate(PropertyDetails::kAttributesReadOnlyMask)); | |
4336 __ j(not_zero, &slow_case); | |
4337 if (FLAG_debug_code) { | |
4338 Label done; | |
4339 // This can only be true for Constant, ConstantType and Undefined cells, | |
4340 // because we never store the_hole via this stub. | |
4341 __ cmpl(cell_details_reg, | |
4342 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
4343 PropertyCellType::kConstant) | | |
4344 PropertyDetails::KindField::encode(kData))); | |
4345 __ j(equal, &done); | |
4346 __ cmpl(cell_details_reg, | |
4347 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
4348 PropertyCellType::kConstantType) | | |
4349 PropertyDetails::KindField::encode(kData))); | |
4350 __ j(equal, &done); | |
4351 __ cmpl(cell_details_reg, | |
4352 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
4353 PropertyCellType::kUndefined) | | |
4354 PropertyDetails::KindField::encode(kData))); | |
4355 __ Check(equal, kUnexpectedValue); | |
4356 __ bind(&done); | |
4357 } | |
4358 __ Ret(); | |
4359 __ bind(¬_same_value); | |
4360 | |
4361 // Check if PropertyCell contains data with constant type (and is not | |
4362 // READ_ONLY). | |
4363 __ cmpl(cell_details_reg, | |
4364 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
4365 PropertyCellType::kConstantType) | | |
4366 PropertyDetails::KindField::encode(kData))); | |
4367 __ j(not_equal, &slow_case, Label::kNear); | |
4368 | |
4369 // Now either both old and new values must be SMIs or both must be heap | |
4370 // objects with same map. | |
4371 Label value_is_heap_object; | |
4372 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear); | |
4373 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear); | |
4374 // Old and new values are SMIs, no need for a write barrier here. | |
4375 __ bind(&fast_smi_case); | |
4376 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); | |
4377 __ Ret(); | |
4378 __ bind(&value_is_heap_object); | |
4379 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear); | |
4380 Register cell_value_map_reg = cell_value_reg; | |
4381 __ movp(cell_value_map_reg, | |
4382 FieldOperand(cell_value_reg, HeapObject::kMapOffset)); | |
4383 __ cmpp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset)); | |
4384 __ j(equal, &fast_heapobject_case); | |
4385 | |
4386 // Fallback to the runtime. | |
4387 __ bind(&slow_case); | |
4388 __ Integer32ToSmi(slot_reg, slot_reg); | |
4389 __ PopReturnAddressTo(kScratchRegister); | |
4390 __ Push(slot_reg); | |
4391 __ Push(value_reg); | |
4392 __ Push(kScratchRegister); | |
4393 __ TailCallRuntime(is_strict(language_mode()) | |
4394 ? Runtime::kStoreGlobalViaContext_Strict | |
4395 : Runtime::kStoreGlobalViaContext_Sloppy); | |
4396 } | |
4397 | |
4398 | |
4399 static int Offset(ExternalReference ref0, ExternalReference ref1) { | 4276 static int Offset(ExternalReference ref0, ExternalReference ref1) { |
4400 int64_t offset = (ref0.address() - ref1.address()); | 4277 int64_t offset = (ref0.address() - ref1.address()); |
4401 // Check that fits into int. | 4278 // Check that fits into int. |
4402 DCHECK(static_cast<int>(offset) == offset); | 4279 DCHECK(static_cast<int>(offset) == offset); |
4403 return static_cast<int>(offset); | 4280 return static_cast<int>(offset); |
4404 } | 4281 } |
4405 | 4282 |
4406 | 4283 |
4407 // Prepares stack to put arguments (aligns and so on). WIN64 calling | 4284 // Prepares stack to put arguments (aligns and so on). WIN64 calling |
4408 // convention requires to put the pointer to the return value slot into | 4285 // convention requires to put the pointer to the return value slot into |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4780 kStackUnwindSpace, nullptr, return_value_operand, | 4657 kStackUnwindSpace, nullptr, return_value_operand, |
4781 NULL); | 4658 NULL); |
4782 } | 4659 } |
4783 | 4660 |
4784 #undef __ | 4661 #undef __ |
4785 | 4662 |
4786 } // namespace internal | 4663 } // namespace internal |
4787 } // namespace v8 | 4664 } // namespace v8 |
4788 | 4665 |
4789 #endif // V8_TARGET_ARCH_X64 | 4666 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |