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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 5098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5109 Label fast_elements_case; | 5109 Label fast_elements_case; |
5110 __ cmp(ecx, Immediate(FAST_ELEMENTS)); | 5110 __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
5111 __ j(equal, &fast_elements_case); | 5111 __ j(equal, &fast_elements_case); |
5112 GenerateCase(masm, FAST_HOLEY_ELEMENTS); | 5112 GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
5113 | 5113 |
5114 __ bind(&fast_elements_case); | 5114 __ bind(&fast_elements_case); |
5115 GenerateCase(masm, FAST_ELEMENTS); | 5115 GenerateCase(masm, FAST_ELEMENTS); |
5116 } | 5116 } |
5117 | 5117 |
5118 | 5118 |
| 5119 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5120 Register context_reg = esi; |
| 5121 Register slot_reg = ebx; |
| 5122 Register name_reg = ecx; |
| 5123 Register result_reg = eax; |
| 5124 Label slow_case; |
| 5125 |
| 5126 // Go up context chain to the script context. |
| 5127 for (int i = 0; i < depth(); ++i) { |
| 5128 __ mov(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5129 context_reg = result_reg; |
| 5130 } |
| 5131 |
| 5132 // Load the PropertyCell value at the specified slot. |
| 5133 __ mov(result_reg, ContextOperand(context_reg, slot_reg)); |
| 5134 __ mov(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset)); |
| 5135 |
| 5136 // Check that value is not the_hole. |
| 5137 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex); |
| 5138 __ j(equal, &slow_case, Label::kNear); |
| 5139 __ Ret(); |
| 5140 |
| 5141 // Fallback to the runtime. |
| 5142 __ bind(&slow_case); |
| 5143 __ SmiTag(slot_reg); |
| 5144 __ Pop(result_reg); // Pop return address. |
| 5145 __ Push(slot_reg); |
| 5146 __ Push(name_reg); |
| 5147 __ Push(result_reg); // Push return address. |
| 5148 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 2, 1); |
| 5149 } |
| 5150 |
| 5151 |
| 5152 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5153 Register context_reg = esi; |
| 5154 Register slot_reg = ebx; |
| 5155 Register name_reg = ecx; |
| 5156 Register value_reg = eax; |
| 5157 Register cell_reg = edi; |
| 5158 Register cell_details_reg = edx; |
| 5159 Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5160 |
| 5161 if (FLAG_debug_code) { |
| 5162 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex); |
| 5163 __ Check(not_equal, kUnexpectedValue); |
| 5164 __ AssertName(name_reg); |
| 5165 } |
| 5166 |
| 5167 // Go up context chain to the script context. |
| 5168 for (int i = 0; i < depth(); ++i) { |
| 5169 __ mov(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5170 context_reg = cell_reg; |
| 5171 } |
| 5172 |
| 5173 // Load the PropertyCell at the specified slot. |
| 5174 __ mov(cell_reg, ContextOperand(context_reg, slot_reg)); |
| 5175 |
| 5176 // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5177 __ mov(cell_details_reg, |
| 5178 FieldOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5179 __ SmiUntag(cell_details_reg); |
| 5180 __ and_(cell_details_reg, |
| 5181 Immediate(PropertyDetails::PropertyCellTypeField::kMask | |
| 5182 PropertyDetails::KindField::kMask)); |
| 5183 |
| 5184 |
| 5185 // Check if PropertyCell holds mutable data. |
| 5186 Label not_mutable_data; |
| 5187 __ cmp(cell_details_reg, |
| 5188 Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5189 PropertyCellType::kMutable) | |
| 5190 PropertyDetails::KindField::encode(kData))); |
| 5191 __ j(not_equal, ¬_mutable_data); |
| 5192 __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5193 __ bind(&fast_heapobject_case); |
| 5194 __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); |
| 5195 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5196 cell_details_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 5197 OMIT_SMI_CHECK); |
| 5198 // RecordWriteField clobbers the value register, so we need to reload. |
| 5199 __ mov(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5200 __ Ret(); |
| 5201 __ bind(¬_mutable_data); |
| 5202 |
| 5203 // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5204 // ConstantType and Undefined cells). |
| 5205 Label not_same_value; |
| 5206 __ cmp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5207 __ j(not_equal, ¬_same_value, |
| 5208 FLAG_debug_code ? Label::kFar : Label::kNear); |
| 5209 if (FLAG_debug_code) { |
| 5210 Label done; |
| 5211 // This can only be true for Constant, ConstantType and Undefined cells, |
| 5212 // because we never store the_hole via this stub. |
| 5213 __ cmp(cell_details_reg, |
| 5214 Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5215 PropertyCellType::kConstant) | |
| 5216 PropertyDetails::KindField::encode(kData))); |
| 5217 __ j(equal, &done); |
| 5218 __ cmp(cell_details_reg, |
| 5219 Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5220 PropertyCellType::kConstantType) | |
| 5221 PropertyDetails::KindField::encode(kData))); |
| 5222 __ j(equal, &done); |
| 5223 __ cmp(cell_details_reg, |
| 5224 Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5225 PropertyCellType::kUndefined) | |
| 5226 PropertyDetails::KindField::encode(kData))); |
| 5227 __ Check(equal, kUnexpectedValue); |
| 5228 __ bind(&done); |
| 5229 } |
| 5230 __ Ret(); |
| 5231 __ bind(¬_same_value); |
| 5232 |
| 5233 // Check if PropertyCell contains data with constant type. |
| 5234 __ cmp(cell_details_reg, |
| 5235 Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5236 PropertyCellType::kConstantType) | |
| 5237 PropertyDetails::KindField::encode(kData))); |
| 5238 __ j(not_equal, &slow_case, Label::kNear); |
| 5239 |
| 5240 // Now either both old and new values must be SMIs or both must be heap |
| 5241 // objects with same map. |
| 5242 Label value_is_heap_object; |
| 5243 Register cell_value_reg = cell_details_reg; |
| 5244 __ mov(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5245 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear); |
| 5246 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear); |
| 5247 // Old and new values are SMIs, no need for a write barrier here. |
| 5248 __ bind(&fast_smi_case); |
| 5249 __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); |
| 5250 __ Ret(); |
| 5251 __ bind(&value_is_heap_object); |
| 5252 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear); |
| 5253 Register cell_value_map_reg = cell_value_reg; |
| 5254 __ mov(cell_value_map_reg, |
| 5255 FieldOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5256 __ cmp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset)); |
| 5257 __ j(equal, &fast_heapobject_case); |
| 5258 |
| 5259 // Fallback to the runtime. |
| 5260 __ bind(&slow_case); |
| 5261 __ SmiTag(slot_reg); |
| 5262 __ Pop(cell_reg); // Pop return address. |
| 5263 __ Push(slot_reg); |
| 5264 __ Push(name_reg); |
| 5265 __ Push(value_reg); |
| 5266 __ Push(cell_reg); // Push return address. |
| 5267 __ TailCallRuntime(is_strict(language_mode()) |
| 5268 ? Runtime::kStoreGlobalViaContext_Strict |
| 5269 : Runtime::kStoreGlobalViaContext_Sloppy, |
| 5270 3, 1); |
| 5271 } |
| 5272 |
| 5273 |
5119 // Generates an Operand for saving parameters after PrepareCallApiFunction. | 5274 // Generates an Operand for saving parameters after PrepareCallApiFunction. |
5120 static Operand ApiParameterOperand(int index) { | 5275 static Operand ApiParameterOperand(int index) { |
5121 return Operand(esp, index * kPointerSize); | 5276 return Operand(esp, index * kPointerSize); |
5122 } | 5277 } |
5123 | 5278 |
5124 | 5279 |
5125 // Prepares stack to put arguments (aligns and so on). Reserves | 5280 // Prepares stack to put arguments (aligns and so on). Reserves |
5126 // space for return value if needed (assumes the return value is a handle). | 5281 // space for return value if needed (assumes the return value is a handle). |
5127 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1) | 5282 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1) |
5128 // etc. Saves context (esi). If space was reserved for return value then | 5283 // etc. Saves context (esi). If space was reserved for return value then |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 Operand(ebp, 7 * kPointerSize), NULL); | 5654 Operand(ebp, 7 * kPointerSize), NULL); |
5500 } | 5655 } |
5501 | 5656 |
5502 | 5657 |
5503 #undef __ | 5658 #undef __ |
5504 | 5659 |
5505 } // namespace internal | 5660 } // namespace internal |
5506 } // namespace v8 | 5661 } // namespace v8 |
5507 | 5662 |
5508 #endif // V8_TARGET_ARCH_IA32 | 5663 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |