From b56466f4da9c38d197343746c43444792e98d3fd Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 27 Oct 2011 11:11:59 +0000 Subject: [PATCH] Fixing dead code in empty array init. TEST=set JSArray::kPreallocatedArrayElements to larger than 4. Review URL: http://codereview.chromium.org/8381014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9816 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/builtins-arm.cc | 18 ++++++++++++------ src/ia32/builtins-ia32.cc | 12 ++++++++---- src/mips/builtins-mips.cc | 17 ++++++++++++----- src/x64/builtins-x64.cc | 12 ++++++++---- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/arm/builtins-arm.cc b/src/arm/builtins-arm.cc index 29bf190..d0136f5 100644 --- a/src/arm/builtins-arm.cc +++ b/src/arm/builtins-arm.cc @@ -104,7 +104,10 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, // Allocate the JSArray object together with space for a fixed array with the // requested elements. - int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); + int size = JSArray::kSize; + if (initial_capacity > 0) { + size += FixedArray::SizeFor(initial_capacity); + } __ AllocateInNewSpace(size, result, scratch2, @@ -124,6 +127,11 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, __ mov(scratch3, Operand(0, RelocInfo::NONE)); __ str(scratch3, FieldMemOperand(result, JSArray::kLengthOffset)); + if (initial_capacity == 0) { + __ str(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); + return; + } + // Calculate the location of the elements array and set elements array member // of the JSArray. // result: JSObject @@ -132,7 +140,6 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, __ str(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); // Clear the heap tag on the elements array. - STATIC_ASSERT(kSmiTag == 0); __ sub(scratch1, scratch1, Operand(kHeapObjectTag)); // Initialize the FixedArray and fill it with holes. FixedArray length is @@ -141,15 +148,14 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, // scratch1: elements array (untagged) // scratch2: start of next object __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); - ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); + STATIC_ASSERT(0 * kPointerSize == FixedArray::kMapOffset); __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); __ mov(scratch3, Operand(Smi::FromInt(initial_capacity))); - ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); + STATIC_ASSERT(1 * kPointerSize == FixedArray::kLengthOffset); __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); // Fill the FixedArray with the hole value. Inline the code if short. - if (initial_capacity == 0) return; - ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); + STATIC_ASSERT(2 * kPointerSize == FixedArray::kHeaderSize); __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); static const int kLoopUnfoldLimit = 4; if (initial_capacity <= kLoopUnfoldLimit) { diff --git a/src/ia32/builtins-ia32.cc b/src/ia32/builtins-ia32.cc index 70e342d..ac4da4c 100644 --- a/src/ia32/builtins-ia32.cc +++ b/src/ia32/builtins-ia32.cc @@ -996,13 +996,17 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, } } else { Label loop, entry; + __ mov(scratch2, Immediate(initial_capacity)); __ jmp(&entry); __ bind(&loop); - __ mov(Operand(scratch1, 0), factory->the_hole_value()); - __ add(scratch1, Immediate(kPointerSize)); + __ mov(FieldOperand(scratch1, + scratch2, + times_pointer_size, + FixedArray::kHeaderSize), + factory->the_hole_value()); __ bind(&entry); - __ cmp(scratch1, scratch2); - __ j(below, &loop); + __ dec(scratch2); + __ j(not_sign, &loop); } } diff --git a/src/mips/builtins-mips.cc b/src/mips/builtins-mips.cc index 1687abe..17975fe 100644 --- a/src/mips/builtins-mips.cc +++ b/src/mips/builtins-mips.cc @@ -106,7 +106,10 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, // Allocate the JSArray object together with space for a fixed array with the // requested elements. - int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); + int size = JSArray::kSize; + if (initial_capacity > 0) { + size += FixedArray::SizeFor(initial_capacity); + } __ AllocateInNewSpace(size, result, scratch2, @@ -125,6 +128,11 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, __ mov(scratch3, zero_reg); __ sw(scratch3, FieldMemOperand(result, JSArray::kLengthOffset)); + if (initial_capacity == 0) { + __ sw(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); + return; + } + // Calculate the location of the elements array and set elements array member // of the JSArray. // result: JSObject @@ -141,17 +149,16 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, // scratch1: elements array (untagged) // scratch2: start of next object __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); - ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); + STATIC_ASSERT(0 * kPointerSize == FixedArray::kMapOffset); __ sw(scratch3, MemOperand(scratch1)); __ Addu(scratch1, scratch1, kPointerSize); __ li(scratch3, Operand(Smi::FromInt(initial_capacity))); - ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); + STATIC_ASSERT(1 * kPointerSize == FixedArray::kLengthOffset); __ sw(scratch3, MemOperand(scratch1)); __ Addu(scratch1, scratch1, kPointerSize); // Fill the FixedArray with the hole value. Inline the code if short. - if (initial_capacity == 0) return; - ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); + STATIC_ASSERT(2 * kPointerSize == FixedArray::kHeaderSize); __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); static const int kLoopUnfoldLimit = 4; if (initial_capacity <= kLoopUnfoldLimit) { diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc index 8baa2f3..e423ae3 100644 --- a/src/x64/builtins-x64.cc +++ b/src/x64/builtins-x64.cc @@ -1075,13 +1075,17 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, } } else { Label loop, entry; + __ movq(scratch2, Immediate(initial_capacity)); __ jmp(&entry); __ bind(&loop); - __ movq(Operand(scratch1, 0), scratch3); - __ addq(scratch1, Immediate(kPointerSize)); + __ movq(FieldOperand(scratch1, + scratch2, + times_pointer_size, + FixedArray::kHeaderSize), + scratch3); __ bind(&entry); - __ cmpq(scratch1, scratch2); - __ j(below, &loop); + __ decq(scratch2); + __ j(not_sign, &loop); } } -- 2.7.4