OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 5282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5293 Runtime::kAllocateInNewSpace, 1, instr, instr->context()); | 5293 Runtime::kAllocateInNewSpace, 1, instr, instr->context()); |
5294 __ StoreToSafepointRegisterSlot(result, eax); | 5294 __ StoreToSafepointRegisterSlot(result, eax); |
5295 } | 5295 } |
5296 | 5296 |
5297 | 5297 |
5298 void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { | 5298 void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
5299 ASSERT(ToRegister(instr->context()).is(esi)); | 5299 ASSERT(ToRegister(instr->context()).is(esi)); |
5300 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 5300 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
5301 ElementsKind boilerplate_elements_kind = | 5301 ElementsKind boilerplate_elements_kind = |
5302 instr->hydrogen()->boilerplate_elements_kind(); | 5302 instr->hydrogen()->boilerplate_elements_kind(); |
5303 AllocationSiteInfoMode allocation_site_info_mode = instr->hydrogen()-> | |
5304 allocation_site_info_mode(); | |
5303 | 5305 |
5304 // Deopt if the array literal boilerplate ElementsKind is of a type different | 5306 // Deopt if the array literal boilerplate ElementsKind is of a type different |
5305 // than the expected one. The check isn't necessary if the boilerplate has | 5307 // than the expected one. The check isn't necessary if the boilerplate has |
5306 // already been converted to TERMINAL_FAST_ELEMENTS_KIND. | 5308 // already been converted to TERMINAL_FAST_ELEMENTS_KIND. |
5307 if (CanTransitionToMoreGeneralFastElementsKind( | 5309 if (CanTransitionToMoreGeneralFastElementsKind( |
5308 boilerplate_elements_kind, true)) { | 5310 boilerplate_elements_kind, true)) { |
5309 __ LoadHeapObject(eax, instr->hydrogen()->boilerplate_object()); | 5311 __ LoadHeapObject(eax, instr->hydrogen()->boilerplate_object()); |
5310 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | 5312 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
5311 // Load the map's "bit field 2". We only need the first byte, | 5313 // Load the map's "bit field 2". We only need the first byte, |
5312 // but the following masking takes care of that anyway. | 5314 // but the following masking takes care of that anyway. |
(...skipping 10 matching lines...) Expand all Loading... | |
5323 // Boilerplate already exists, constant elements are never accessed. | 5325 // Boilerplate already exists, constant elements are never accessed. |
5324 // Pass an empty fixed array. | 5326 // Pass an empty fixed array. |
5325 __ push(Immediate(isolate()->factory()->empty_fixed_array())); | 5327 __ push(Immediate(isolate()->factory()->empty_fixed_array())); |
5326 | 5328 |
5327 // Pick the right runtime function or stub to call. | 5329 // Pick the right runtime function or stub to call. |
5328 int length = instr->hydrogen()->length(); | 5330 int length = instr->hydrogen()->length(); |
5329 if (instr->hydrogen()->IsCopyOnWrite()) { | 5331 if (instr->hydrogen()->IsCopyOnWrite()) { |
5330 ASSERT(instr->hydrogen()->depth() == 1); | 5332 ASSERT(instr->hydrogen()->depth() == 1); |
5331 FastCloneShallowArrayStub::Mode mode = | 5333 FastCloneShallowArrayStub::Mode mode = |
5332 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; | 5334 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
5333 FastCloneShallowArrayStub stub(mode, length); | 5335 FastCloneShallowArrayStub stub(mode, DONT_TRACK_ALLOCATION_SITE_INFO, |
Toon Verwaest
2013/01/16 10:53:42
Without _INFO it probably fits on one line; but th
mvstanton
2013/01/16 13:01:56
thx, now it does fit on one line.
| |
5336 length); | |
5334 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 5337 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
5335 } else if (instr->hydrogen()->depth() > 1) { | 5338 } else if (instr->hydrogen()->depth() > 1) { |
5336 CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); | 5339 CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
5337 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 5340 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
5338 CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); | 5341 CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
5339 } else { | 5342 } else { |
5340 FastCloneShallowArrayStub::Mode mode = | 5343 FastCloneShallowArrayStub::Mode mode = |
5341 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS | 5344 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
5342 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 5345 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
5343 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | 5346 : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
5344 FastCloneShallowArrayStub stub(mode, length); | 5347 FastCloneShallowArrayStub stub(mode, allocation_site_info_mode, length); |
5345 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 5348 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
5346 } | 5349 } |
5347 } | 5350 } |
5348 | 5351 |
5349 | 5352 |
5350 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | 5353 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
5351 Register result, | 5354 Register result, |
5352 Register source, | 5355 Register source, |
5353 int* offset) { | 5356 int* offset, |
5357 AllocationSiteInfoMode mode) { | |
5354 ASSERT(!source.is(ecx)); | 5358 ASSERT(!source.is(ecx)); |
5355 ASSERT(!result.is(ecx)); | 5359 ASSERT(!result.is(ecx)); |
5356 | 5360 |
5361 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE_INFO && | |
5362 object->map()->CanTrackAllocationSite(); | |
5363 | |
5357 if (FLAG_debug_code) { | 5364 if (FLAG_debug_code) { |
5358 __ LoadHeapObject(ecx, object); | 5365 __ LoadHeapObject(ecx, object); |
5359 __ cmp(source, ecx); | 5366 __ cmp(source, ecx); |
5360 __ Assert(equal, "Unexpected object literal boilerplate"); | 5367 __ Assert(equal, "Unexpected object literal boilerplate"); |
5361 __ mov(ecx, FieldOperand(source, HeapObject::kMapOffset)); | 5368 __ mov(ecx, FieldOperand(source, HeapObject::kMapOffset)); |
5362 __ cmp(ecx, Handle<Map>(object->map())); | 5369 __ cmp(ecx, Handle<Map>(object->map())); |
5363 __ Assert(equal, "Unexpected boilerplate map"); | 5370 __ Assert(equal, "Unexpected boilerplate map"); |
5364 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); | 5371 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
5365 __ and_(ecx, Map::kElementsKindMask); | 5372 __ and_(ecx, Map::kElementsKindMask); |
5366 __ cmp(ecx, object->GetElementsKind() << Map::kElementsKindShift); | 5373 __ cmp(ecx, object->GetElementsKind() << Map::kElementsKindShift); |
5367 __ Assert(equal, "Unexpected boilerplate elements kind"); | 5374 __ Assert(equal, "Unexpected boilerplate elements kind"); |
5368 } | 5375 } |
5369 | 5376 |
5370 // Only elements backing stores for non-COW arrays need to be copied. | 5377 // Only elements backing stores for non-COW arrays need to be copied. |
5371 Handle<FixedArrayBase> elements(object->elements()); | 5378 Handle<FixedArrayBase> elements(object->elements()); |
5372 bool has_elements = elements->length() > 0 && | 5379 bool has_elements = elements->length() > 0 && |
5373 elements->map() != isolate()->heap()->fixed_cow_array_map(); | 5380 elements->map() != isolate()->heap()->fixed_cow_array_map(); |
5374 | 5381 |
5375 // Increase the offset so that subsequent objects end up right after | 5382 // Increase the offset so that subsequent objects end up right after |
5376 // this object and its backing store. | 5383 // this object and its backing store. |
5377 int object_offset = *offset; | 5384 int object_offset = *offset; |
5378 int object_size = object->map()->instance_size(); | 5385 int object_size = object->map()->instance_size(); |
5379 int elements_offset = *offset + object_size; | 5386 int elements_offset = *offset + object_size; |
5387 if (create_allocation_site_info) { | |
5388 elements_offset += AllocationSiteInfo::kSize; | |
5389 } | |
5380 int elements_size = has_elements ? elements->Size() : 0; | 5390 int elements_size = has_elements ? elements->Size() : 0; |
5381 *offset += object_size + elements_size; | 5391 *offset += object_size + elements_size; |
5392 if (create_allocation_site_info) { | |
Toon Verwaest
2013/01/16 10:53:42
I think it's cleaner to just merge both if branche
mvstanton
2013/01/16 13:01:56
big time, thx.
| |
5393 *offset += AllocationSiteInfo::kSize; | |
5394 } | |
5382 | 5395 |
5383 // Copy object header. | 5396 // Copy object header. |
5384 ASSERT(object->properties()->length() == 0); | 5397 ASSERT(object->properties()->length() == 0); |
5385 int inobject_properties = object->map()->inobject_properties(); | 5398 int inobject_properties = object->map()->inobject_properties(); |
5386 int header_size = object_size - inobject_properties * kPointerSize; | 5399 int header_size = object_size - inobject_properties * kPointerSize; |
5387 for (int i = 0; i < header_size; i += kPointerSize) { | 5400 for (int i = 0; i < header_size; i += kPointerSize) { |
5388 if (has_elements && i == JSObject::kElementsOffset) { | 5401 if (has_elements && i == JSObject::kElementsOffset) { |
5389 __ lea(ecx, Operand(result, elements_offset)); | 5402 __ lea(ecx, Operand(result, elements_offset)); |
5390 } else { | 5403 } else { |
5391 __ mov(ecx, FieldOperand(source, i)); | 5404 __ mov(ecx, FieldOperand(source, i)); |
5392 } | 5405 } |
5393 __ mov(FieldOperand(result, object_offset + i), ecx); | 5406 __ mov(FieldOperand(result, object_offset + i), ecx); |
5394 } | 5407 } |
5395 | 5408 |
5396 // Copy in-object properties. | 5409 // Copy in-object properties. |
5397 for (int i = 0; i < inobject_properties; i++) { | 5410 for (int i = 0; i < inobject_properties; i++) { |
5398 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); | 5411 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
5399 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); | 5412 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
5400 if (value->IsJSObject()) { | 5413 if (value->IsJSObject()) { |
5401 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 5414 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
5402 __ lea(ecx, Operand(result, *offset)); | 5415 __ lea(ecx, Operand(result, *offset)); |
5403 __ mov(FieldOperand(result, total_offset), ecx); | 5416 __ mov(FieldOperand(result, total_offset), ecx); |
5404 __ LoadHeapObject(source, value_object); | 5417 __ LoadHeapObject(source, value_object); |
5405 EmitDeepCopy(value_object, result, source, offset); | 5418 EmitDeepCopy(value_object, result, source, offset, |
5419 DONT_TRACK_ALLOCATION_SITE_INFO); | |
5406 } else if (value->IsHeapObject()) { | 5420 } else if (value->IsHeapObject()) { |
5407 __ LoadHeapObject(ecx, Handle<HeapObject>::cast(value)); | 5421 __ LoadHeapObject(ecx, Handle<HeapObject>::cast(value)); |
5408 __ mov(FieldOperand(result, total_offset), ecx); | 5422 __ mov(FieldOperand(result, total_offset), ecx); |
5409 } else { | 5423 } else { |
5410 __ mov(FieldOperand(result, total_offset), Immediate(value)); | 5424 __ mov(FieldOperand(result, total_offset), Immediate(value)); |
5411 } | 5425 } |
5412 } | 5426 } |
5413 | 5427 |
5428 // Build Allocation Site Info if desired | |
5429 if (create_allocation_site_info) { | |
5430 __ mov(FieldOperand(result, object_size), | |
5431 Immediate(Handle<Map>(isolate()->heap()-> | |
5432 allocation_site_info_map()))); | |
5433 __ mov(FieldOperand(result, object_size + kPointerSize), source); | |
5434 } | |
5435 | |
5414 if (has_elements) { | 5436 if (has_elements) { |
5415 // Copy elements backing store header. | 5437 // Copy elements backing store header. |
5416 __ LoadHeapObject(source, elements); | 5438 __ LoadHeapObject(source, elements); |
5417 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | 5439 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { |
5418 __ mov(ecx, FieldOperand(source, i)); | 5440 __ mov(ecx, FieldOperand(source, i)); |
5419 __ mov(FieldOperand(result, elements_offset + i), ecx); | 5441 __ mov(FieldOperand(result, elements_offset + i), ecx); |
5420 } | 5442 } |
5421 | 5443 |
5422 // Copy elements backing store content. | 5444 // Copy elements backing store content. |
5423 int elements_length = elements->length(); | 5445 int elements_length = elements->length(); |
(...skipping 12 matching lines...) Expand all Loading... | |
5436 } else if (elements->IsFixedArray()) { | 5458 } else if (elements->IsFixedArray()) { |
5437 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements); | 5459 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements); |
5438 for (int i = 0; i < elements_length; i++) { | 5460 for (int i = 0; i < elements_length; i++) { |
5439 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); | 5461 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); |
5440 Handle<Object> value(fast_elements->get(i)); | 5462 Handle<Object> value(fast_elements->get(i)); |
5441 if (value->IsJSObject()) { | 5463 if (value->IsJSObject()) { |
5442 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 5464 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
5443 __ lea(ecx, Operand(result, *offset)); | 5465 __ lea(ecx, Operand(result, *offset)); |
5444 __ mov(FieldOperand(result, total_offset), ecx); | 5466 __ mov(FieldOperand(result, total_offset), ecx); |
5445 __ LoadHeapObject(source, value_object); | 5467 __ LoadHeapObject(source, value_object); |
5446 EmitDeepCopy(value_object, result, source, offset); | 5468 EmitDeepCopy(value_object, result, source, offset, |
5469 DONT_TRACK_ALLOCATION_SITE_INFO); | |
5447 } else if (value->IsHeapObject()) { | 5470 } else if (value->IsHeapObject()) { |
5448 __ LoadHeapObject(ecx, Handle<HeapObject>::cast(value)); | 5471 __ LoadHeapObject(ecx, Handle<HeapObject>::cast(value)); |
5449 __ mov(FieldOperand(result, total_offset), ecx); | 5472 __ mov(FieldOperand(result, total_offset), ecx); |
5450 } else { | 5473 } else { |
5451 __ mov(FieldOperand(result, total_offset), Immediate(value)); | 5474 __ mov(FieldOperand(result, total_offset), Immediate(value)); |
5452 } | 5475 } |
5453 } | 5476 } |
5454 } else { | 5477 } else { |
5455 UNREACHABLE(); | 5478 UNREACHABLE(); |
5456 } | 5479 } |
(...skipping 29 matching lines...) Expand all Loading... | |
5486 __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); | 5509 __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
5487 __ jmp(&allocated); | 5510 __ jmp(&allocated); |
5488 | 5511 |
5489 __ bind(&runtime_allocate); | 5512 __ bind(&runtime_allocate); |
5490 __ push(Immediate(Smi::FromInt(size))); | 5513 __ push(Immediate(Smi::FromInt(size))); |
5491 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 5514 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
5492 | 5515 |
5493 __ bind(&allocated); | 5516 __ bind(&allocated); |
5494 int offset = 0; | 5517 int offset = 0; |
5495 __ LoadHeapObject(ebx, instr->hydrogen()->boilerplate()); | 5518 __ LoadHeapObject(ebx, instr->hydrogen()->boilerplate()); |
5496 EmitDeepCopy(instr->hydrogen()->boilerplate(), eax, ebx, &offset); | 5519 EmitDeepCopy(instr->hydrogen()->boilerplate(), eax, ebx, &offset, |
5520 instr->hydrogen()->allocation_site_info_mode()); | |
5497 ASSERT_EQ(size, offset); | 5521 ASSERT_EQ(size, offset); |
5498 } | 5522 } |
5499 | 5523 |
5500 | 5524 |
5501 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { | 5525 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
5502 ASSERT(ToRegister(instr->context()).is(esi)); | 5526 ASSERT(ToRegister(instr->context()).is(esi)); |
5503 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 5527 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
5504 Handle<FixedArray> constant_properties = | 5528 Handle<FixedArray> constant_properties = |
5505 instr->hydrogen()->constant_properties(); | 5529 instr->hydrogen()->constant_properties(); |
5506 | 5530 |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5955 FixedArray::kHeaderSize - kPointerSize)); | 5979 FixedArray::kHeaderSize - kPointerSize)); |
5956 __ bind(&done); | 5980 __ bind(&done); |
5957 } | 5981 } |
5958 | 5982 |
5959 | 5983 |
5960 #undef __ | 5984 #undef __ |
5961 | 5985 |
5962 } } // namespace v8::internal | 5986 } } // namespace v8::internal |
5963 | 5987 |
5964 #endif // V8_TARGET_ARCH_IA32 | 5988 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |