| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 5188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5199 FastCloneShallowArrayStub::Mode mode = | 5199 FastCloneShallowArrayStub::Mode mode = |
| 5200 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS | 5200 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
| 5201 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 5201 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 5202 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | 5202 : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 5203 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); | 5203 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
| 5204 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); | 5204 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 5205 } | 5205 } |
| 5206 } | 5206 } |
| 5207 | 5207 |
| 5208 | 5208 |
| 5209 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | |
| 5210 Register result, | |
| 5211 Register source, | |
| 5212 int* offset, | |
| 5213 AllocationSiteMode mode) { | |
| 5214 ASSERT(!source.is(rcx)); | |
| 5215 ASSERT(!result.is(rcx)); | |
| 5216 | |
| 5217 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE && | |
| 5218 object->map()->CanTrackAllocationSite(); | |
| 5219 | |
| 5220 // Only elements backing stores for non-COW arrays need to be copied. | |
| 5221 Handle<FixedArrayBase> elements(object->elements()); | |
| 5222 bool has_elements = elements->length() > 0 && | |
| 5223 elements->map() != isolate()->heap()->fixed_cow_array_map(); | |
| 5224 | |
| 5225 // Increase the offset so that subsequent objects end up right after | |
| 5226 // this object and its backing store. | |
| 5227 int object_offset = *offset; | |
| 5228 int object_size = object->map()->instance_size(); | |
| 5229 int elements_size = has_elements ? elements->Size() : 0; | |
| 5230 int elements_offset = *offset + object_size; | |
| 5231 if (create_allocation_site_info) { | |
| 5232 elements_offset += AllocationSiteInfo::kSize; | |
| 5233 *offset += AllocationSiteInfo::kSize; | |
| 5234 } | |
| 5235 | |
| 5236 *offset += object_size + elements_size; | |
| 5237 | |
| 5238 // Copy object header. | |
| 5239 ASSERT(object->properties()->length() == 0); | |
| 5240 int inobject_properties = object->map()->inobject_properties(); | |
| 5241 int header_size = object_size - inobject_properties * kPointerSize; | |
| 5242 for (int i = 0; i < header_size; i += kPointerSize) { | |
| 5243 if (has_elements && i == JSObject::kElementsOffset) { | |
| 5244 __ lea(rcx, Operand(result, elements_offset)); | |
| 5245 } else { | |
| 5246 __ movq(rcx, FieldOperand(source, i)); | |
| 5247 } | |
| 5248 __ movq(FieldOperand(result, object_offset + i), rcx); | |
| 5249 } | |
| 5250 | |
| 5251 // Copy in-object properties. | |
| 5252 for (int i = 0; i < inobject_properties; i++) { | |
| 5253 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); | |
| 5254 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i), | |
| 5255 isolate()); | |
| 5256 if (value->IsJSObject()) { | |
| 5257 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | |
| 5258 __ lea(rcx, Operand(result, *offset)); | |
| 5259 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5260 __ LoadHeapObject(source, value_object); | |
| 5261 EmitDeepCopy(value_object, result, source, offset, | |
| 5262 DONT_TRACK_ALLOCATION_SITE); | |
| 5263 } else if (value->IsHeapObject()) { | |
| 5264 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | |
| 5265 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5266 } else { | |
| 5267 __ movq(rcx, value, RelocInfo::NONE64); | |
| 5268 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5269 } | |
| 5270 } | |
| 5271 | |
| 5272 // Build Allocation Site Info if desired | |
| 5273 if (create_allocation_site_info) { | |
| 5274 __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex); | |
| 5275 __ movq(FieldOperand(result, object_size), kScratchRegister); | |
| 5276 __ movq(FieldOperand(result, object_size + kPointerSize), source); | |
| 5277 } | |
| 5278 | |
| 5279 if (has_elements) { | |
| 5280 // Copy elements backing store header. | |
| 5281 __ LoadHeapObject(source, elements); | |
| 5282 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | |
| 5283 __ movq(rcx, FieldOperand(source, i)); | |
| 5284 __ movq(FieldOperand(result, elements_offset + i), rcx); | |
| 5285 } | |
| 5286 | |
| 5287 // Copy elements backing store content. | |
| 5288 int elements_length = elements->length(); | |
| 5289 if (elements->IsFixedDoubleArray()) { | |
| 5290 Handle<FixedDoubleArray> double_array = | |
| 5291 Handle<FixedDoubleArray>::cast(elements); | |
| 5292 for (int i = 0; i < elements_length; i++) { | |
| 5293 int64_t value = double_array->get_representation(i); | |
| 5294 int total_offset = | |
| 5295 elements_offset + FixedDoubleArray::OffsetOfElementAt(i); | |
| 5296 __ movq(rcx, value, RelocInfo::NONE64); | |
| 5297 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5298 } | |
| 5299 } else if (elements->IsFixedArray()) { | |
| 5300 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements); | |
| 5301 for (int i = 0; i < elements_length; i++) { | |
| 5302 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); | |
| 5303 Handle<Object> value(fast_elements->get(i), isolate()); | |
| 5304 if (value->IsJSObject()) { | |
| 5305 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | |
| 5306 __ lea(rcx, Operand(result, *offset)); | |
| 5307 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5308 __ LoadHeapObject(source, value_object); | |
| 5309 EmitDeepCopy(value_object, result, source, offset, | |
| 5310 DONT_TRACK_ALLOCATION_SITE); | |
| 5311 } else if (value->IsHeapObject()) { | |
| 5312 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | |
| 5313 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5314 } else { | |
| 5315 __ movq(rcx, value, RelocInfo::NONE64); | |
| 5316 __ movq(FieldOperand(result, total_offset), rcx); | |
| 5317 } | |
| 5318 } | |
| 5319 } else { | |
| 5320 UNREACHABLE(); | |
| 5321 } | |
| 5322 } | |
| 5323 } | |
| 5324 | |
| 5325 | |
| 5326 void LCodeGen::DoFastLiteral(LFastLiteral* instr) { | |
| 5327 int size = instr->hydrogen()->total_size(); | |
| 5328 ElementsKind boilerplate_elements_kind = | |
| 5329 instr->hydrogen()->boilerplate()->GetElementsKind(); | |
| 5330 | |
| 5331 // Deopt if the array literal boilerplate ElementsKind is of a type different | |
| 5332 // than the expected one. The check isn't necessary if the boilerplate has | |
| 5333 // already been converted to TERMINAL_FAST_ELEMENTS_KIND. | |
| 5334 if (CanTransitionToMoreGeneralFastElementsKind( | |
| 5335 boilerplate_elements_kind, true)) { | |
| 5336 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); | |
| 5337 __ movq(rcx, FieldOperand(rbx, HeapObject::kMapOffset)); | |
| 5338 // Load the map's "bit field 2". | |
| 5339 __ movb(rcx, FieldOperand(rcx, Map::kBitField2Offset)); | |
| 5340 // Retrieve elements_kind from bit field 2. | |
| 5341 __ and_(rcx, Immediate(Map::kElementsKindMask)); | |
| 5342 __ cmpb(rcx, Immediate(boilerplate_elements_kind << | |
| 5343 Map::kElementsKindShift)); | |
| 5344 DeoptimizeIf(not_equal, instr->environment()); | |
| 5345 } | |
| 5346 | |
| 5347 // Allocate all objects that are part of the literal in one big | |
| 5348 // allocation. This avoids multiple limit checks. | |
| 5349 Label allocated, runtime_allocate; | |
| 5350 __ Allocate(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); | |
| 5351 __ jmp(&allocated); | |
| 5352 | |
| 5353 __ bind(&runtime_allocate); | |
| 5354 __ Push(Smi::FromInt(size)); | |
| 5355 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | |
| 5356 | |
| 5357 __ bind(&allocated); | |
| 5358 int offset = 0; | |
| 5359 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); | |
| 5360 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset, | |
| 5361 instr->hydrogen()->allocation_site_mode()); | |
| 5362 ASSERT_EQ(size, offset); | |
| 5363 } | |
| 5364 | |
| 5365 | |
| 5366 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { | 5209 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
| 5367 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 5210 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
| 5368 Handle<FixedArray> constant_properties = | 5211 Handle<FixedArray> constant_properties = |
| 5369 instr->hydrogen()->constant_properties(); | 5212 instr->hydrogen()->constant_properties(); |
| 5370 | 5213 |
| 5371 int flags = instr->hydrogen()->fast_elements() | 5214 int flags = instr->hydrogen()->fast_elements() |
| 5372 ? ObjectLiteral::kFastElements | 5215 ? ObjectLiteral::kFastElements |
| 5373 : ObjectLiteral::kNoFlags; | 5216 : ObjectLiteral::kNoFlags; |
| 5374 flags |= instr->hydrogen()->has_function() | 5217 flags |= instr->hydrogen()->has_function() |
| 5375 ? ObjectLiteral::kHasFunction | 5218 ? ObjectLiteral::kHasFunction |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5847 FixedArray::kHeaderSize - kPointerSize)); | 5690 FixedArray::kHeaderSize - kPointerSize)); |
| 5848 __ bind(&done); | 5691 __ bind(&done); |
| 5849 } | 5692 } |
| 5850 | 5693 |
| 5851 | 5694 |
| 5852 #undef __ | 5695 #undef __ |
| 5853 | 5696 |
| 5854 } } // namespace v8::internal | 5697 } } // namespace v8::internal |
| 5855 | 5698 |
| 5856 #endif // V8_TARGET_ARCH_X64 | 5699 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |