MIPS: Bugfix: array constructors that expect a type feedback cell that points to an AllocationSite were being passed the undefined object in some cases. Clearly separate the cases where we have an AllocationSite and where we don't in the general ArrayConstructorStub.

Port r16693 (0852d4ab)

BUG=
R=gergely@homejinni.com

Review URL: https://codereview.chromium.org/23451057

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16698 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
palfia@homejinni.com 2013-09-13 00:10:24 +00:00
parent 617f7546a7
commit 2cec3754da

View File

@ -6968,87 +6968,125 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
template<class T> template<class T>
static void CreateArrayDispatch(MacroAssembler* masm) { static void CreateArrayDispatch(MacroAssembler* masm,
int last_index = GetSequenceIndexFromFastElementsKind( AllocationSiteOverrideMode mode) {
TERMINAL_FAST_ELEMENTS_KIND); if (mode == DISABLE_ALLOCATION_SITES) {
for (int i = 0; i <= last_index; ++i) { T stub(GetInitialFastElementsKind(),
Label next; CONTEXT_CHECK_REQUIRED,
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); mode);
__ Branch(&next, ne, a3, Operand(kind));
T stub(kind);
__ TailCallStub(&stub); __ TailCallStub(&stub);
__ bind(&next); } else if (mode == DONT_OVERRIDE) {
} int last_index = GetSequenceIndexFromFastElementsKind(
TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
Label next;
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ Branch(&next, ne, a3, Operand(kind));
T stub(kind);
__ TailCallStub(&stub);
__ bind(&next);
}
// If we reached this point there is a problem. // If we reached this point there is a problem.
__ Abort(kUnexpectedElementsKindInArrayConstructor); __ Abort(kUnexpectedElementsKindInArrayConstructor);
} else {
UNREACHABLE();
}
} }
static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
// a2 - type info cell AllocationSiteOverrideMode mode) {
// a3 - kind // a2 - type info cell (if mode != DISABLE_ALLOCATION_SITES)
// a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
// a0 - number of arguments // a0 - number of arguments
// a1 - constructor? // a1 - constructor?
// sp[0] - last argument // sp[0] - last argument
ASSERT(FAST_SMI_ELEMENTS == 0);
ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
ASSERT(FAST_ELEMENTS == 2);
ASSERT(FAST_HOLEY_ELEMENTS == 3);
ASSERT(FAST_DOUBLE_ELEMENTS == 4);
ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence; Label normal_sequence;
__ And(at, a3, Operand(1)); if (mode == DONT_OVERRIDE) {
__ Branch(&normal_sequence, ne, at, Operand(zero_reg)); ASSERT(FAST_SMI_ELEMENTS == 0);
ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
ASSERT(FAST_ELEMENTS == 2);
ASSERT(FAST_HOLEY_ELEMENTS == 3);
ASSERT(FAST_DOUBLE_ELEMENTS == 4);
ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
// is the low bit set? If so, we are holey and that is good.
__ And(at, a3, Operand(1));
__ Branch(&normal_sequence, ne, at, Operand(zero_reg));
}
// look at the first argument // look at the first argument
__ lw(t1, MemOperand(sp, 0)); __ lw(t1, MemOperand(sp, 0));
__ Branch(&normal_sequence, eq, t1, Operand(zero_reg)); __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
// We are going to create a holey array, but our kind is non-holey. if (mode == DISABLE_ALLOCATION_SITES) {
// Fix kind and retry (only if we have an allocation site in the cell). ElementsKind initial = GetInitialFastElementsKind();
__ Addu(a3, a3, Operand(1)); ElementsKind holey_initial = GetHoleyElementsKind(initial);
__ LoadRoot(at, Heap::kUndefinedValueRootIndex);
__ Branch(&normal_sequence, eq, a2, Operand(at));
__ lw(t1, FieldMemOperand(a2, Cell::kValueOffset));
__ lw(t1, FieldMemOperand(t1, 0));
__ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
__ Branch(&normal_sequence, ne, t1, Operand(at));
// Save the resulting elements kind in type info ArraySingleArgumentConstructorStub stub_holey(holey_initial,
__ SmiTag(a3); CONTEXT_CHECK_REQUIRED,
__ lw(t1, FieldMemOperand(a2, Cell::kValueOffset)); DISABLE_ALLOCATION_SITES);
__ sw(a3, FieldMemOperand(t1, AllocationSite::kTransitionInfoOffset)); __ TailCallStub(&stub_holey);
__ SmiUntag(a3);
__ bind(&normal_sequence); __ bind(&normal_sequence);
int last_index = GetSequenceIndexFromFastElementsKind( ArraySingleArgumentConstructorStub stub(initial,
TERMINAL_FAST_ELEMENTS_KIND); CONTEXT_CHECK_REQUIRED,
for (int i = 0; i <= last_index; ++i) { DISABLE_ALLOCATION_SITES);
Label next;
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ Branch(&next, ne, a3, Operand(kind));
ArraySingleArgumentConstructorStub stub(kind);
__ TailCallStub(&stub); __ TailCallStub(&stub);
__ bind(&next); } else if (mode == DONT_OVERRIDE) {
} // We are going to create a holey array, but our kind is non-holey.
// Fix kind and retry (only if we have an allocation site in the cell).
__ Addu(a3, a3, Operand(1));
__ lw(t1, FieldMemOperand(a2, Cell::kValueOffset));
// If we reached this point there is a problem. if (FLAG_debug_code) {
__ Abort(kUnexpectedElementsKindInArrayConstructor); __ lw(t1, FieldMemOperand(t1, 0));
__ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
__ Assert(eq, kExpectedAllocationSiteInCell, t1, Operand(at));
__ lw(t1, FieldMemOperand(a2, Cell::kValueOffset));
}
// Save the resulting elements kind in type info
__ SmiTag(a3);
__ lw(t1, FieldMemOperand(a2, Cell::kValueOffset));
__ sw(a3, FieldMemOperand(t1, AllocationSite::kTransitionInfoOffset));
__ SmiUntag(a3);
__ bind(&normal_sequence);
int last_index = GetSequenceIndexFromFastElementsKind(
TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
Label next;
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ Branch(&next, ne, a3, Operand(kind));
ArraySingleArgumentConstructorStub stub(kind);
__ TailCallStub(&stub);
__ bind(&next);
}
// If we reached this point there is a problem.
__ Abort(kUnexpectedElementsKindInArrayConstructor);
} else {
UNREACHABLE();
}
} }
template<class T> template<class T>
static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
ElementsKind initial_kind = GetInitialFastElementsKind();
ElementsKind initial_holey_kind = GetHoleyElementsKind(initial_kind);
int to_index = GetSequenceIndexFromFastElementsKind( int to_index = GetSequenceIndexFromFastElementsKind(
TERMINAL_FAST_ELEMENTS_KIND); TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= to_index; ++i) { for (int i = 0; i <= to_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
T stub(kind); T stub(kind);
stub.GetCode(isolate)->set_is_pregenerated(true); stub.GetCode(isolate)->set_is_pregenerated(true);
if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE ||
(!FLAG_track_allocation_sites &&
(kind == initial_kind || kind == initial_holey_kind))) {
T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES);
stub1.GetCode(isolate)->set_is_pregenerated(true); stub1.GetCode(isolate)->set_is_pregenerated(true);
} }
@ -7081,6 +7119,33 @@ void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
} }
void ArrayConstructorStub::GenerateDispatchToArrayStub(
MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (argument_count_ == ANY) {
Label not_zero_case, not_one_case;
__ And(at, a0, a0);
__ Branch(&not_zero_case, ne, at, Operand(zero_reg));
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
__ bind(&not_zero_case);
__ Branch(&not_one_case, gt, a0, Operand(1));
CreateArrayDispatchOneArgument(masm, mode);
__ bind(&not_one_case);
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
} else if (argument_count_ == NONE) {
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
} else if (argument_count_ == ONE) {
CreateArrayDispatchOneArgument(masm, mode);
} else if (argument_count_ == MORE_THAN_ONE) {
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
} else {
UNREACHABLE();
}
}
void ArrayConstructorStub::Generate(MacroAssembler* masm) { void ArrayConstructorStub::Generate(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- a0 : argc (only if argument_count_ == ANY) // -- a0 : argc (only if argument_count_ == ANY)
@ -7114,49 +7179,24 @@ void ArrayConstructorStub::Generate(MacroAssembler* masm) {
__ bind(&okay_here); __ bind(&okay_here);
} }
Label no_info, switch_ready; Label no_info;
// Get the elements kind and case on that. // Get the elements kind and case on that.
__ LoadRoot(at, Heap::kUndefinedValueRootIndex); __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
__ Branch(&no_info, eq, a2, Operand(at)); __ Branch(&no_info, eq, a2, Operand(at));
__ lw(a3, FieldMemOperand(a2, Cell::kValueOffset)); __ lw(a3, FieldMemOperand(a2, Cell::kValueOffset));
// The type cell may have undefined in its value. // If the type cell is undefined, or contains anything other than an
__ LoadRoot(at, Heap::kUndefinedValueRootIndex); // AllocationSite, call an array constructor that doesn't use AllocationSites.
__ Branch(&no_info, eq, a3, Operand(at));
// The type cell has either an AllocationSite or a JSFunction.
__ lw(t0, FieldMemOperand(a3, 0)); __ lw(t0, FieldMemOperand(a3, 0));
__ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
__ Branch(&no_info, ne, t0, Operand(at)); __ Branch(&no_info, ne, t0, Operand(at));
__ lw(a3, FieldMemOperand(a3, AllocationSite::kTransitionInfoOffset)); __ lw(a3, FieldMemOperand(a3, AllocationSite::kTransitionInfoOffset));
__ SmiUntag(a3); __ SmiUntag(a3);
__ jmp(&switch_ready); GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
__ bind(&no_info); __ bind(&no_info);
__ li(a3, Operand(GetInitialFastElementsKind())); GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
__ bind(&switch_ready);
if (argument_count_ == ANY) {
Label not_zero_case, not_one_case;
__ And(at, a0, a0);
__ Branch(&not_zero_case, ne, at, Operand(zero_reg));
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
__ bind(&not_zero_case);
__ Branch(&not_one_case, gt, a0, Operand(1));
CreateArrayDispatchOneArgument(masm);
__ bind(&not_one_case);
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
} else if (argument_count_ == NONE) {
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
} else if (argument_count_ == ONE) {
CreateArrayDispatchOneArgument(masm);
} else if (argument_count_ == MORE_THAN_ONE) {
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
} else {
UNREACHABLE();
}
} }