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 #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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 5019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5030 Label fast_elements_case; | 5030 Label fast_elements_case; |
5031 __ cmpl(rcx, Immediate(FAST_ELEMENTS)); | 5031 __ cmpl(rcx, Immediate(FAST_ELEMENTS)); |
5032 __ j(equal, &fast_elements_case); | 5032 __ j(equal, &fast_elements_case); |
5033 GenerateCase(masm, FAST_HOLEY_ELEMENTS); | 5033 GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
5034 | 5034 |
5035 __ bind(&fast_elements_case); | 5035 __ bind(&fast_elements_case); |
5036 GenerateCase(masm, FAST_ELEMENTS); | 5036 GenerateCase(masm, FAST_ELEMENTS); |
5037 } | 5037 } |
5038 | 5038 |
5039 | 5039 |
5040 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { | |
5041 Register context_reg = rsi; | |
Igor Sheludko
2015/07/18 20:52:44
What about using LoadGlobalViaContextDescriptor::S
Benedikt Meurer
2015/07/24 05:18:29
I explicitly changed it to not use those functions
| |
5042 Register slot_reg = rbx; | |
5043 Register name_reg = rcx; | |
5044 Register result_reg = rax; | |
5045 Label slow_case; | |
5046 | |
5047 // Go up context chain to the script context. | |
5048 for (int i = 0; i < depth(); ++i) { | |
5049 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); | |
5050 context_reg = rdi; | |
Igor Sheludko
2015/07/18 20:52:44
Nice!
Benedikt Meurer
2015/07/24 05:18:29
Acknowledged.
| |
5051 } | |
5052 | |
5053 // Load the PropertyCell value at the specified slot. | |
5054 __ movp(result_reg, ContextOperand(context_reg, slot_reg)); | |
5055 __ movp(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset)); | |
5056 | |
5057 // Check that value is not the_hole. | |
5058 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex); | |
5059 __ j(equal, &slow_case, Label::kNear); | |
5060 __ Ret(); | |
5061 | |
5062 // Fallback to the runtime. | |
5063 __ bind(&slow_case); | |
5064 __ Integer32ToSmi(slot_reg, slot_reg); | |
5065 __ PopReturnAddressTo(kScratchRegister); | |
5066 __ Push(slot_reg); | |
5067 __ Push(name_reg); | |
5068 __ Push(kScratchRegister); | |
5069 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 2, 1); | |
5070 } | |
5071 | |
5072 | |
5073 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { | |
5074 Register context_reg = rsi; | |
Igor Sheludko
2015/07/18 20:52:44
Same here.
Benedikt Meurer
2015/07/24 05:18:29
See above.
| |
5075 Register slot_reg = rbx; | |
5076 Register name_reg = rcx; | |
5077 Register value_reg = rax; | |
5078 Register cell_reg = r8; | |
5079 Register cell_details_reg = rdx; | |
5080 Register cell_value_reg = r9; | |
5081 Label fast_case, slow_case; | |
5082 | |
5083 if (FLAG_debug_code) { | |
5084 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex); | |
5085 __ Check(not_equal, kUnexpectedValue); | |
5086 __ AssertName(name_reg); | |
5087 } | |
5088 | |
5089 // Go up context chain to the script context. | |
5090 for (int i = 0; i < depth(); ++i) { | |
5091 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); | |
5092 context_reg = rdi; | |
5093 } | |
5094 | |
5095 // Load the PropertyCell at the specified slot. | |
5096 __ movp(cell_reg, ContextOperand(context_reg, slot_reg)); | |
5097 | |
5098 // Load PropertyDetails for the cell (actually only the cell_type and kind). | |
5099 __ SmiToInteger32(cell_details_reg, | |
5100 FieldOperand(cell_reg, PropertyCell::kDetailsOffset)); | |
5101 __ andl(cell_details_reg, | |
5102 Immediate(PropertyDetails::PropertyCellTypeField::kMask | | |
5103 PropertyDetails::KindField::kMask)); | |
5104 | |
5105 | |
5106 // Check if PropertyCell holds mutable data. | |
5107 Label not_mutable_data; | |
5108 __ cmpl(cell_details_reg, | |
5109 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
5110 PropertyCellType::kMutable) | | |
5111 PropertyDetails::KindField::encode(kData))); | |
5112 __ j(not_equal, ¬_mutable_data); | |
5113 __ bind(&fast_case); | |
5114 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); | |
5115 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, | |
5116 cell_value_reg, kDontSaveFPRegs); | |
5117 // RecordWriteField clobbers the value register, so we need to reload. | |
5118 __ movp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); | |
5119 __ Ret(); | |
5120 __ bind(¬_mutable_data); | |
5121 | |
5122 // Check if PropertyCell value matches the new value (relevant for Constant | |
5123 // and ConstantType cells). | |
5124 Label not_same_value; | |
5125 __ movp(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); | |
5126 __ cmpp(cell_value_reg, value_reg); | |
5127 __ j(not_equal, ¬_same_value, | |
5128 FLAG_debug_code ? Label::kFar : Label::kNear); | |
5129 if (FLAG_debug_code) { | |
5130 Label done; | |
5131 // This can only be true for Constant and ConstantType cells, because we | |
Igor Sheludko
2015/07/18 20:52:44
We could probably get here for PropertyCellType::k
Benedikt Meurer
2015/07/24 05:18:29
Acknowledged.
| |
5132 // never store the_hole via this stub. | |
5133 __ cmpl(cell_details_reg, | |
5134 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
5135 PropertyCellType::kConstant) | | |
5136 PropertyDetails::KindField::encode(kData))); | |
5137 __ j(equal, &done); | |
5138 __ cmpl(cell_details_reg, | |
5139 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
5140 PropertyCellType::kConstantType) | | |
5141 PropertyDetails::KindField::encode(kData))); | |
5142 __ Check(equal, kUnexpectedValue); | |
5143 __ bind(&done); | |
5144 } | |
5145 __ Ret(); | |
5146 __ bind(¬_same_value); | |
5147 | |
5148 // Check if PropertyCell contains data with constant type. | |
5149 __ cmpl(cell_details_reg, | |
5150 Immediate(PropertyDetails::PropertyCellTypeField::encode( | |
5151 PropertyCellType::kConstantType) | | |
5152 PropertyDetails::KindField::encode(kData))); | |
5153 __ j(not_equal, &slow_case, Label::kNear); | |
5154 | |
5155 // Now either both old and new values must be SMIs or both must be heap | |
5156 // objects with same map. | |
5157 Label value_is_heap_object; | |
5158 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear); | |
5159 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear); | |
5160 // Old and new values are SMIs, no need for a write barrier here. | |
5161 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); | |
5162 __ Ret(); | |
5163 __ bind(&value_is_heap_object); | |
5164 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear); | |
5165 Register cell_value_map_reg = cell_value_reg; | |
5166 __ movp(cell_value_map_reg, | |
5167 FieldOperand(cell_value_reg, HeapObject::kMapOffset)); | |
5168 __ cmpp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset)); | |
5169 __ j(equal, &fast_case); | |
Igor Sheludko
2015/07/19 20:29:29
I think it is better to write field and RecordWrit
Igor Sheludko
2015/07/20 09:01:16
Even better idea: we could add an explicit smi che
Benedikt Meurer
2015/07/24 05:18:29
Acknowledged.
Benedikt Meurer
2015/07/24 05:18:29
Done.
| |
5170 | |
5171 // Fallback to the runtime. | |
5172 __ bind(&slow_case); | |
5173 __ Integer32ToSmi(slot_reg, slot_reg); | |
5174 __ PopReturnAddressTo(kScratchRegister); | |
5175 __ Push(slot_reg); | |
5176 __ Push(name_reg); | |
5177 __ Push(value_reg); | |
5178 __ Push(kScratchRegister); | |
5179 __ TailCallRuntime(is_strict(language_mode()) | |
5180 ? Runtime::kStoreGlobalViaContext_Strict | |
5181 : Runtime::kStoreGlobalViaContext_Sloppy, | |
5182 3, 1); | |
5183 } | |
5184 | |
5185 | |
5040 static int Offset(ExternalReference ref0, ExternalReference ref1) { | 5186 static int Offset(ExternalReference ref0, ExternalReference ref1) { |
5041 int64_t offset = (ref0.address() - ref1.address()); | 5187 int64_t offset = (ref0.address() - ref1.address()); |
5042 // Check that fits into int. | 5188 // Check that fits into int. |
5043 DCHECK(static_cast<int>(offset) == offset); | 5189 DCHECK(static_cast<int>(offset) == offset); |
5044 return static_cast<int>(offset); | 5190 return static_cast<int>(offset); |
5045 } | 5191 } |
5046 | 5192 |
5047 | 5193 |
5048 // Prepares stack to put arguments (aligns and so on). WIN64 calling | 5194 // Prepares stack to put arguments (aligns and so on). WIN64 calling |
5049 // convention requires to put the pointer to the return value slot into | 5195 // convention requires to put the pointer to the return value slot into |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5432 kStackSpace, nullptr, return_value_operand, NULL); | 5578 kStackSpace, nullptr, return_value_operand, NULL); |
5433 } | 5579 } |
5434 | 5580 |
5435 | 5581 |
5436 #undef __ | 5582 #undef __ |
5437 | 5583 |
5438 } // namespace internal | 5584 } // namespace internal |
5439 } // namespace v8 | 5585 } // namespace v8 |
5440 | 5586 |
5441 #endif // V8_TARGET_ARCH_X64 | 5587 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |