Chromium Code Reviews| Index: src/ia32/macro-assembler-ia32.cc |
| diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc |
| index 5e4f21129159cf5334e1ef9c82dc9f0532abee74..2bc50dc7110a237bba3499ce51b65b8433d735c0 100644 |
| --- a/src/ia32/macro-assembler-ia32.cc |
| +++ b/src/ia32/macro-assembler-ia32.cc |
| @@ -1188,11 +1188,31 @@ void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| } |
| +ExternalReference MacroAssembler::GetTopAddress(AllocationTarget target) { |
| + if (target == NEW_SPACE) { |
| + return ExternalReference::new_space_allocation_top_address(isolate()); |
| + } else { |
| + return ExternalReference::old_pointer_space_allocation_top_address( |
| + isolate()); |
| + } |
| +} |
| + |
| + |
| +ExternalReference MacroAssembler::GetLimitAddress(AllocationTarget target) { |
| + if (target == NEW_SPACE) { |
| + return ExternalReference::new_space_allocation_limit_address(isolate()); |
| + } else { |
| + return ExternalReference::old_pointer_space_allocation_limit_address( |
| + isolate()); |
| + } |
| +} |
| + |
| + |
| void MacroAssembler::LoadAllocationTopHelper(Register result, |
| Register scratch, |
| - AllocationFlags flags) { |
| - ExternalReference new_space_allocation_top = |
| - ExternalReference::new_space_allocation_top_address(isolate()); |
| + AllocationFlags flags, |
| + AllocationTarget target) { |
| + ExternalReference allocation_top = GetTopAddress(target); |
| // Just return if allocation top is already known. |
| if ((flags & RESULT_CONTAINS_TOP) != 0) { |
| @@ -1200,7 +1220,7 @@ void MacroAssembler::LoadAllocationTopHelper(Register result, |
| ASSERT(scratch.is(no_reg)); |
| #ifdef DEBUG |
| // Assert that result actually contains top on entry. |
| - cmp(result, Operand::StaticVariable(new_space_allocation_top)); |
| + cmp(result, Operand::StaticVariable(allocation_top)); |
| Check(equal, "Unexpected allocation top"); |
| #endif |
| return; |
| @@ -1208,104 +1228,33 @@ void MacroAssembler::LoadAllocationTopHelper(Register result, |
| // Move address of new object to result. Use scratch register if available. |
| if (scratch.is(no_reg)) { |
| - mov(result, Operand::StaticVariable(new_space_allocation_top)); |
| + mov(result, Operand::StaticVariable(allocation_top)); |
| } else { |
| - mov(scratch, Immediate(new_space_allocation_top)); |
| + mov(scratch, Immediate(allocation_top)); |
| mov(result, Operand(scratch, 0)); |
| } |
| } |
| void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| - Register scratch) { |
| + Register scratch, |
| + AllocationTarget target) { |
| if (emit_debug_code()) { |
| test(result_end, Immediate(kObjectAlignmentMask)); |
| Check(zero, "Unaligned allocation in new space"); |
| } |
| - ExternalReference new_space_allocation_top = |
| - ExternalReference::new_space_allocation_top_address(isolate()); |
| + ExternalReference allocation_top = GetTopAddress(target); |
| // Update new top. Use scratch if available. |
| if (scratch.is(no_reg)) { |
| - mov(Operand::StaticVariable(new_space_allocation_top), result_end); |
| + mov(Operand::StaticVariable(allocation_top), result_end); |
| } else { |
| mov(Operand(scratch, 0), result_end); |
| } |
| } |
| -void MacroAssembler::AllocateInNewSpace(int object_size, |
| - Register result, |
| - Register result_end, |
| - Register scratch, |
| - Label* gc_required, |
| - AllocationFlags flags) { |
| - ASSERT((flags & (RESULT_CONTAINS_TOP | SIZE_IN_WORDS)) == 0); |
| - if (!FLAG_inline_new) { |
| - if (emit_debug_code()) { |
| - // Trash the registers to simulate an allocation failure. |
| - mov(result, Immediate(0x7091)); |
| - if (result_end.is_valid()) { |
| - mov(result_end, Immediate(0x7191)); |
| - } |
| - if (scratch.is_valid()) { |
| - mov(scratch, Immediate(0x7291)); |
| - } |
| - } |
| - jmp(gc_required); |
| - return; |
| - } |
| - ASSERT(!result.is(result_end)); |
| - |
| - // Load address of new object into result. |
| - LoadAllocationTopHelper(result, scratch, flags); |
| - |
| - // Align the next allocation. Storing the filler map without checking top is |
| - // always safe because the limit of the heap is always aligned. |
| - if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| - ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| - Label aligned; |
| - test(result, Immediate(kDoubleAlignmentMask)); |
| - j(zero, &aligned, Label::kNear); |
| - mov(Operand(result, 0), |
| - Immediate(isolate()->factory()->one_pointer_filler_map())); |
| - add(result, Immediate(kDoubleSize / 2)); |
| - bind(&aligned); |
| - } |
| - |
| - Register top_reg = result_end.is_valid() ? result_end : result; |
| - |
| - // Calculate new top and bail out if new space is exhausted. |
| - ExternalReference new_space_allocation_limit = |
| - ExternalReference::new_space_allocation_limit_address(isolate()); |
| - |
| - if (!top_reg.is(result)) { |
| - mov(top_reg, result); |
| - } |
| - add(top_reg, Immediate(object_size)); |
| - j(carry, gc_required); |
| - cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); |
| - j(above, gc_required); |
| - |
| - // Update allocation top. |
| - UpdateAllocationTopHelper(top_reg, scratch); |
| - |
| - // Tag result if requested. |
| - bool tag_result = (flags & TAG_OBJECT) != 0; |
| - if (top_reg.is(result)) { |
| - if (tag_result) { |
| - sub(result, Immediate(object_size - kHeapObjectTag)); |
| - } else { |
| - sub(result, Immediate(object_size)); |
| - } |
| - } else if (tag_result) { |
| - ASSERT(kHeapObjectTag == 1); |
| - inc(result); |
| - } |
| -} |
| - |
| - |
| void MacroAssembler::AllocateInNewSpace( |
| int header_size, |
| ScaleFactor element_size, |
| @@ -1333,7 +1282,7 @@ void MacroAssembler::AllocateInNewSpace( |
| ASSERT(!result.is(result_end)); |
| // Load address of new object into result. |
| - LoadAllocationTopHelper(result, scratch, flags); |
| + LoadAllocationTopHelper(result, scratch, flags, NEW_SPACE); |
| // Align the next allocation. Storing the filler map without checking top is |
| // always safe because the limit of the heap is always aligned. |
| @@ -1376,7 +1325,7 @@ void MacroAssembler::AllocateInNewSpace( |
| } |
| // Update allocation top. |
| - UpdateAllocationTopHelper(result_end, scratch); |
| + UpdateAllocationTopHelper(result_end, scratch, NEW_SPACE); |
| } |
| @@ -1403,7 +1352,7 @@ void MacroAssembler::AllocateInNewSpace(Register object_size, |
| ASSERT(!result.is(result_end)); |
| // Load address of new object into result. |
| - LoadAllocationTopHelper(result, scratch, flags); |
| + LoadAllocationTopHelper(result, scratch, flags, NEW_SPACE); |
| // Align the next allocation. Storing the filler map without checking top is |
| // always safe because the limit of the heap is always aligned. |
| @@ -1436,7 +1385,78 @@ void MacroAssembler::AllocateInNewSpace(Register object_size, |
| } |
| // Update allocation top. |
| - UpdateAllocationTopHelper(result_end, scratch); |
| + UpdateAllocationTopHelper(result_end, scratch, NEW_SPACE); |
| +} |
| + |
| + |
| +void MacroAssembler::Allocate(int object_size, |
| + Register result, |
| + Register result_end, |
| + Register scratch, |
| + Label* gc_required, |
| + AllocationFlags flags, |
| + AllocationTarget target) { |
| + ASSERT((flags & (RESULT_CONTAINS_TOP | SIZE_IN_WORDS)) == 0); |
| + if (!FLAG_inline_new) { |
| + if (emit_debug_code()) { |
| + // Trash the registers to simulate an allocation failure. |
| + mov(result, Immediate(0x7091)); |
| + if (result_end.is_valid()) { |
| + mov(result_end, Immediate(0x7191)); |
| + } |
| + if (scratch.is_valid()) { |
| + mov(scratch, Immediate(0x7291)); |
| + } |
| + } |
| + jmp(gc_required); |
| + return; |
| + } |
| + ASSERT(!result.is(result_end)); |
| + |
| + // Load address of new object into result. |
| + LoadAllocationTopHelper(result, scratch, flags, target); |
| + |
| + // Align the next allocation. Storing the filler map without checking top is |
| + // always safe because the limit of the heap is always aligned. |
|
danno
2013/03/05 12:18:18
Is the limit of the heap also still aligned in the
Hannes Payer (out of office)
2013/03/11 17:16:31
Done.
|
| + if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| + ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| + Label aligned; |
| + test(result, Immediate(kDoubleAlignmentMask)); |
| + j(zero, &aligned, Label::kNear); |
| + mov(Operand(result, 0), |
| + Immediate(isolate()->factory()->one_pointer_filler_map())); |
| + add(result, Immediate(kDoubleSize / 2)); |
| + bind(&aligned); |
| + } |
| + |
| + Register top_reg = result_end.is_valid() ? result_end : result; |
| + |
| + // Calculate new top and bail out if space is exhausted. |
| + ExternalReference allocation_limit = GetLimitAddress(target); |
| + |
| + if (!top_reg.is(result)) { |
| + mov(top_reg, result); |
| + } |
| + add(top_reg, Immediate(object_size)); |
| + j(carry, gc_required); |
| + cmp(top_reg, Operand::StaticVariable(allocation_limit)); |
| + j(above, gc_required); |
| + |
| + // Update allocation top. |
| + UpdateAllocationTopHelper(top_reg, scratch, target); |
| + |
| + // Tag result if requested. |
| + bool tag_result = (flags & TAG_OBJECT) != 0; |
| + if (top_reg.is(result)) { |
| + if (tag_result) { |
| + sub(result, Immediate(object_size - kHeapObjectTag)); |
| + } else { |
| + sub(result, Immediate(object_size)); |
| + } |
| + } else if (tag_result) { |
| + ASSERT(kHeapObjectTag == 1); |
| + inc(result); |
| + } |
| } |
|
danno
2013/03/05 12:18:18
nit: Can you move this up to where AllocationInNew
Hannes Payer (out of office)
2013/03/11 17:16:31
Done.
|
| @@ -1459,12 +1479,8 @@ void MacroAssembler::AllocateHeapNumber(Register result, |
| Register scratch2, |
| Label* gc_required) { |
| // Allocate heap number in new space. |
| - AllocateInNewSpace(HeapNumber::kSize, |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required, |
| + TAG_OBJECT, NEW_SPACE); |
| // Set the map. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |
| @@ -1552,12 +1568,8 @@ void MacroAssembler::AllocateAsciiString(Register result, |
| ASSERT(length > 0); |
| // Allocate ASCII string in new space. |
| - AllocateInNewSpace(SeqOneByteString::SizeFor(length), |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(SeqOneByteString::SizeFor(length), result, scratch1, scratch2, |
| + gc_required, TAG_OBJECT, NEW_SPACE); |
| // Set the map, length and hash field. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |
| @@ -1574,12 +1586,8 @@ void MacroAssembler::AllocateTwoByteConsString(Register result, |
| Register scratch2, |
| Label* gc_required) { |
| // Allocate heap number in new space. |
| - AllocateInNewSpace(ConsString::kSize, |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| + TAG_OBJECT, NEW_SPACE); |
| // Set the map. The other fields are left uninitialized. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |
| @@ -1592,12 +1600,8 @@ void MacroAssembler::AllocateAsciiConsString(Register result, |
| Register scratch2, |
| Label* gc_required) { |
| // Allocate heap number in new space. |
| - AllocateInNewSpace(ConsString::kSize, |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| + TAG_OBJECT, NEW_SPACE); |
| // Set the map. The other fields are left uninitialized. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |
| @@ -1610,12 +1614,8 @@ void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
| Register scratch2, |
| Label* gc_required) { |
| // Allocate heap number in new space. |
| - AllocateInNewSpace(SlicedString::kSize, |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| + TAG_OBJECT, NEW_SPACE); |
| // Set the map. The other fields are left uninitialized. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |
| @@ -1628,12 +1628,8 @@ void MacroAssembler::AllocateAsciiSlicedString(Register result, |
| Register scratch2, |
| Label* gc_required) { |
| // Allocate heap number in new space. |
| - AllocateInNewSpace(SlicedString::kSize, |
| - result, |
| - scratch1, |
| - scratch2, |
| - gc_required, |
| - TAG_OBJECT); |
| + Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| + TAG_OBJECT, NEW_SPACE); |
| // Set the map. The other fields are left uninitialized. |
| mov(FieldOperand(result, HeapObject::kMapOffset), |