Commit a509b105 authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: [stubs] Introduce a dedicated FastNewObjectStub.

Port ba2077aa

Original commit message:
    Move the already existing fast case for %NewObject into a dedicated
    FastNewObjectStub that we can utilize in places where we would otherwise
    fallback to %NewObject immediately, which is rather expensive.

    Also use FastNewObjectStub as the generic implementation of JSCreate,
    which should make constructor inlining based on SharedFunctionInfo (w/o
    specializing to a concrete closure) viable soon.

R=bmeurer@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=

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

Cr-Commit-Position: refs/heads/master@{#34169}
parent c1f653be
......@@ -331,8 +331,9 @@ void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) {
__ bind(&new_object);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r5, r4, r6); // first argument, constructor, new target
__ CallRuntime(Runtime::kNewObject);
__ Push(r5); // first argument
FastNewObjectStub stub(masm->isolate());
__ CallStub(&stub);
__ Pop(r5);
}
__ StoreP(r5, FieldMemOperand(r3, JSValue::kValueOffset), r0);
......@@ -460,8 +461,9 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ bind(&new_object);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r5, r4, r6); // first argument, constructor, new target
__ CallRuntime(Runtime::kNewObject);
__ Push(r5); // first argument
FastNewObjectStub stub(masm->isolate());
__ CallStub(&stub);
__ Pop(r5);
}
__ StoreP(r5, FieldMemOperand(r3, JSValue::kValueOffset), r0);
......@@ -551,142 +553,18 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ SmiTag(r3);
__ Push(r5, r3);
// Try to allocate the object without transitioning into C code. If any of
// the preconditions is not met, the code bails out to the runtime call.
Label rt_call, allocated;
if (FLAG_inline_new) {
// Verify that the new target is a JSFunction.
__ CompareObjectType(r6, r8, r7, JS_FUNCTION_TYPE);
__ bne(&rt_call);
// Load the initial map and verify that it is in fact a map.
// r6: new target
__ LoadP(r5,
FieldMemOperand(r6, JSFunction::kPrototypeOrInitialMapOffset));
__ JumpIfSmi(r5, &rt_call);
__ CompareObjectType(r5, r8, r7, MAP_TYPE);
__ bne(&rt_call);
// Fall back to runtime if the expected base constructor and base
// constructor differ.
__ LoadP(r8, FieldMemOperand(r5, Map::kConstructorOrBackPointerOffset));
__ cmp(r4, r8);
__ bne(&rt_call);
// Check that the constructor is not constructing a JSFunction (see
// comments in Runtime_NewObject in runtime.cc). In which case the
// initial map's instance type would be JS_FUNCTION_TYPE.
// r4: constructor function
// r5: initial map
// r6: new target
__ CompareInstanceType(r5, r8, JS_FUNCTION_TYPE);
__ beq(&rt_call);
// Now allocate the JSObject on the heap.
// r4: constructor function
// r5: initial map
// r6: new target
__ lbz(r10, FieldMemOperand(r5, Map::kInstanceSizeOffset));
__ Allocate(r10, r7, r10, r9, &rt_call, SIZE_IN_WORDS);
// Allocated the JSObject, now initialize the fields. Map is set to
// initial map and properties and elements are set to empty fixed array.
// r4: constructor function
// r5: initial map
// r6: new target
// r7: JSObject (not HeapObject tagged - the actual address).
// r10: start of next object
__ LoadRoot(r9, Heap::kEmptyFixedArrayRootIndex);
__ StoreP(r5, MemOperand(r7, JSObject::kMapOffset));
__ StoreP(r9, MemOperand(r7, JSObject::kPropertiesOffset));
__ StoreP(r9, MemOperand(r7, JSObject::kElementsOffset));
__ addi(r8, r7, Operand(JSObject::kElementsOffset + kPointerSize));
// Add the object tag to make the JSObject real, so that we can continue
// and jump into the continuation code at any time from now on.
__ addi(r7, r7, Operand(kHeapObjectTag));
// Fill all the in-object properties with the appropriate filler.
// r7: JSObject (tagged)
// r8: First in-object property of JSObject (not tagged)
__ LoadRoot(r9, Heap::kUndefinedValueRootIndex);
if (!is_api_function) {
Label no_inobject_slack_tracking;
MemOperand bit_field3 = FieldMemOperand(r5, Map::kBitField3Offset);
// Check if slack tracking is enabled.
__ lwz(r3, bit_field3);
__ DecodeField<Map::ConstructionCounter>(r11, r3);
// r11: slack tracking counter
__ cmpi(r11, Operand(Map::kSlackTrackingCounterEnd));
__ blt(&no_inobject_slack_tracking);
// Decrease generous allocation count.
__ Add(r3, r3, -(1 << Map::ConstructionCounter::kShift), r0);
__ stw(r3, bit_field3);
// Allocate object with a slack.
__ lbz(r3, FieldMemOperand(r5, Map::kUnusedPropertyFieldsOffset));
__ ShiftLeftImm(r3, r3, Operand(kPointerSizeLog2));
__ sub(r3, r10, r3);
// r3: offset of first field after pre-allocated fields
if (FLAG_debug_code) {
__ cmp(r8, r3);
__ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields);
}
__ InitializeFieldsWithFiller(r8, r3, r9);
// To allow truncation fill the remaining fields with one pointer
// filler map.
__ LoadRoot(r9, Heap::kOnePointerFillerMapRootIndex);
__ InitializeFieldsWithFiller(r8, r10, r9);
// r11: slack tracking counter value before decreasing.
__ cmpi(r11, Operand(Map::kSlackTrackingCounterEnd));
__ bne(&allocated);
// Push the constructor, new_target and the object to the stack,
// and then the initial map as an argument to the runtime call.
__ Push(r4, r6, r7, r5);
__ CallRuntime(Runtime::kFinalizeInstanceSize);
__ Pop(r4, r6, r7);
// Continue with JSObject being successfully allocated
// r4: constructor function
// r6: new target
// r7: JSObject
__ b(&allocated);
__ bind(&no_inobject_slack_tracking);
}
__ InitializeFieldsWithFiller(r8, r10, r9);
// Continue with JSObject being successfully allocated
// r4: constructor function
// r6: new target
// r7: JSObject
__ b(&allocated);
}
// Allocate the new receiver object using the runtime call.
// r4: constructor function
// r6: new target
__ bind(&rt_call);
// Push the constructor and new_target twice, second pair as arguments
// to the runtime call.
__ Push(r4, r6, r4, r6);
__ CallRuntime(Runtime::kNewObject);
// Allocate the new receiver object.
__ Push(r4, r6);
FastNewObjectStub stub(masm->isolate());
__ CallStub(&stub);
__ mr(r7, r3);
__ Pop(r4, r6);
// Receiver for constructor call allocated.
// r4: constructor function
// r6: new target
// r7: JSObject
__ bind(&allocated);
// ----------- S t a t e -------------
// -- r4: constructor function
// -- r6: new target
// -- r7: newly allocated object
// -----------------------------------
// Retrieve smi-tagged arguments count from the stack.
__ LoadP(r3, MemOperand(sp));
......
......@@ -4704,6 +4704,128 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
GenerateCase(masm, FAST_ELEMENTS);
}
void FastNewObjectStub::Generate(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r4 : target
// -- r6 : new target
// -- cp : context
// -- lr : return address
// -----------------------------------
__ AssertFunction(r4);
__ AssertReceiver(r6);
// Verify that the new target is a JSFunction.
Label new_object;
__ CompareObjectType(r6, r5, r5, JS_FUNCTION_TYPE);
__ bne(&new_object);
// Load the initial map and verify that it's in fact a map.
__ LoadP(r5, FieldMemOperand(r6, JSFunction::kPrototypeOrInitialMapOffset));
__ JumpIfSmi(r5, &new_object);
__ CompareObjectType(r5, r3, r3, MAP_TYPE);
__ bne(&new_object);
// Fall back to runtime if the target differs from the new target's
// initial map constructor.
__ LoadP(r3, FieldMemOperand(r5, Map::kConstructorOrBackPointerOffset));
__ cmp(r3, r4);
__ bne(&new_object);
// Allocate the JSObject on the heap.
Label allocate, done_allocate;
__ lbz(r7, FieldMemOperand(r5, Map::kInstanceSizeOffset));
__ Allocate(r7, r3, r8, r9, &allocate, SIZE_IN_WORDS);
__ bind(&done_allocate);
// Initialize the JSObject fields.
__ StoreP(r5, MemOperand(r3, JSObject::kMapOffset));
__ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
__ StoreP(r6, MemOperand(r3, JSObject::kPropertiesOffset));
__ StoreP(r6, MemOperand(r3, JSObject::kElementsOffset));
STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
__ addi(r4, r3, Operand(JSObject::kHeaderSize));
// ----------- S t a t e -------------
// -- r3 : result (untagged)
// -- r4 : result fields (untagged)
// -- r8 : result end (untagged)
// -- r5 : initial map
// -- cp : context
// -- lr : return address
// -----------------------------------
// Perform in-object slack tracking if requested.
Label slack_tracking;
STATIC_ASSERT(Map::kNoSlackTracking == 0);
__ LoadRoot(r9, Heap::kUndefinedValueRootIndex);
__ lwz(r6, FieldMemOperand(r5, Map::kBitField3Offset));
__ DecodeField<Map::ConstructionCounter>(r10, r6, SetRC);
__ bne(&slack_tracking, cr0);
{
// Initialize all in-object fields with undefined.
__ InitializeFieldsWithFiller(r4, r8, r9);
// Add the object tag to make the JSObject real.
__ addi(r3, r3, Operand(kHeapObjectTag));
__ Ret();
}
__ bind(&slack_tracking);
{
// Decrease generous allocation count.
STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
__ Add(r6, r6, -(1 << Map::ConstructionCounter::kShift), r0);
__ stw(r6, FieldMemOperand(r5, Map::kBitField3Offset));
// Initialize the in-object fields with undefined.
__ lbz(r7, FieldMemOperand(r5, Map::kUnusedPropertyFieldsOffset));
__ ShiftLeftImm(r7, r7, Operand(kPointerSizeLog2));
__ sub(r7, r8, r7);
__ InitializeFieldsWithFiller(r4, r7, r9);
// Initialize the remaining (reserved) fields with one pointer filler map.
__ LoadRoot(r9, Heap::kOnePointerFillerMapRootIndex);
__ InitializeFieldsWithFiller(r4, r8, r9);
// Add the object tag to make the JSObject real.
__ addi(r3, r3, Operand(kHeapObjectTag));
// Check if we can finalize the instance size.
__ cmpi(r10, Operand(Map::kSlackTrackingCounterEnd));
__ Ret(ne);
// Finalize the instance size.
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r3, r5);
__ CallRuntime(Runtime::kFinalizeInstanceSize);
__ Pop(r3);
}
__ Ret();
}
// Fall back to %AllocateInNewSpace.
__ bind(&allocate);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
STATIC_ASSERT(kSmiTag == 0);
__ ShiftLeftImm(r7, r7,
Operand(kPointerSizeLog2 + kSmiTagSize + kSmiShiftSize));
__ Push(r5, r7);
__ CallRuntime(Runtime::kAllocateInNewSpace);
__ Pop(r5);
}
__ subi(r3, r3, Operand(kHeapObjectTag));
__ lbz(r8, FieldMemOperand(r5, Map::kInstanceSizeOffset));
__ ShiftLeftImm(r8, r8, Operand(kPointerSizeLog2));
__ add(r8, r3, r8);
__ b(&done_allocate);
// Fall back to %NewObject.
__ bind(&new_object);
__ Push(r4, r6);
__ TailCallRuntime(Runtime::kNewObject);
}
void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r4 : function
......
......@@ -82,6 +82,12 @@ void FastNewContextDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void FastNewObjectDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {r4, r6};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void FastNewRestParameterDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {r4};
......
......@@ -2751,6 +2751,18 @@ void MacroAssembler::AssertBoundFunction(Register object) {
}
}
void MacroAssembler::AssertReceiver(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object, r0);
Check(ne, kOperandIsASmiAndNotAReceiver, cr0);
push(object);
STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
CompareObjectType(object, object, object, FIRST_JS_RECEIVER_TYPE);
pop(object);
Check(ge, kOperandIsNotAReceiver);
}
}
void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
Register scratch) {
......
......@@ -1352,6 +1352,9 @@ class MacroAssembler : public Assembler {
// enabled via --debug-code.
void AssertBoundFunction(Register object);
// Abort execution if argument is not a JSReceiver, enabled via --debug-code.
void AssertReceiver(Register object);
// Abort execution if argument is not undefined or an AllocationSite, enabled
// via --debug-code.
void AssertUndefinedOrAllocationSite(Register object, Register scratch);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment