Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Unified Diff: src/mips64/builtins-mips64.cc

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mips/builtins-mips.cc ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/mips64/builtins-mips64.cc
diff --git a/src/mips64/builtins-mips64.cc b/src/mips64/builtins-mips64.cc
index 6d719081a4103b4d807b4afaf804f23271e140ca..2f63123a3d63fe1cee1353f6dd9d7df63a43b258 100644
--- a/src/mips64/builtins-mips64.cc
+++ b/src/mips64/builtins-mips64.cc
@@ -348,7 +348,8 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
static void Generate_JSConstructStubHelper(MacroAssembler* masm,
- bool is_api_function) {
+ bool is_api_function,
+ bool create_implicit_receiver) {
// ----------- S t a t e -------------
// -- a0 : number of arguments
// -- a1 : constructor function
@@ -367,164 +368,183 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(a2, t0);
__ SmiTag(a0);
- __ Push(a2, a0, a1, a3);
-
- // 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.
- __ GetObjectType(a3, a5, a4);
- __ Branch(&rt_call, ne, a4, Operand(JS_FUNCTION_TYPE));
-
- // Load the initial map and verify that it is in fact a map.
- // a3: new target
- __ ld(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset));
- __ JumpIfSmi(a2, &rt_call);
- __ GetObjectType(a2, t1, t0);
- __ Branch(&rt_call, ne, t0, Operand(MAP_TYPE));
-
- // Fall back to runtime if the expected base constructor and base
- // constructor differ.
- __ ld(a5, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset));
- __ Branch(&rt_call, ne, a1, Operand(a5));
-
- // 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.
- // a1: constructor function
- // a2: initial map
- __ lbu(t1, FieldMemOperand(a2, Map::kInstanceTypeOffset));
- __ Branch(&rt_call, eq, t1, Operand(JS_FUNCTION_TYPE));
-
- if (!is_api_function) {
- Label allocate;
- MemOperand bit_field3 = FieldMemOperand(a2, Map::kBitField3Offset);
- // Check if slack tracking is enabled.
- __ lwu(a4, bit_field3);
- __ DecodeField<Map::Counter>(a6, a4);
- __ Branch(&allocate, lt, a6,
- Operand(static_cast<int64_t>(Map::kSlackTrackingCounterEnd)));
- // Decrease generous allocation count.
- __ Dsubu(a4, a4, Operand(1 << Map::Counter::kShift));
- __ Branch(USE_DELAY_SLOT, &allocate, ne, a6,
- Operand(Map::kSlackTrackingCounterEnd));
- __ sw(a4, bit_field3); // In delay slot.
-
- __ Push(a1, a2, a2); // a2 = Initial map.
- __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
-
- __ Pop(a1, a2);
- __ li(a6, Operand(Map::kSlackTrackingCounterEnd - 1));
-
- __ bind(&allocate);
- }
-
- // Now allocate the JSObject on the heap.
- // a1: constructor function
- // a2: initial map
- Label rt_call_reload_new_target;
- __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
-
- __ Allocate(a3, t0, t1, t2, &rt_call_reload_new_target, SIZE_IN_WORDS);
+ if (create_implicit_receiver) {
+ __ Push(a2, a0, a1, a3);
+ } else {
+ __ Push(a2, a0);
+ }
- // Allocated the JSObject, now initialize the fields. Map is set to
- // initial map and properties and elements are set to empty fixed array.
- // a1: constructor function
- // a2: initial map
- // a3: object size
- // t0: JSObject (not tagged)
- __ LoadRoot(t2, Heap::kEmptyFixedArrayRootIndex);
- __ mov(t1, t0);
- __ sd(a2, MemOperand(t1, JSObject::kMapOffset));
- __ sd(t2, MemOperand(t1, JSObject::kPropertiesOffset));
- __ sd(t2, MemOperand(t1, JSObject::kElementsOffset));
- __ Daddu(t1, t1, Operand(3*kPointerSize));
- DCHECK_EQ(0 * kPointerSize, JSObject::kMapOffset);
- DCHECK_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
- DCHECK_EQ(2 * kPointerSize, JSObject::kElementsOffset);
-
- // Fill all the in-object properties with appropriate filler.
- // a1: constructor function
- // a2: initial map
- // a3: object size (in words)
- // t0: JSObject (not tagged)
- // t1: First in-object property of JSObject (not tagged)
- // a6: slack tracking counter (non-API function case)
- DCHECK_EQ(3 * kPointerSize, JSObject::kHeaderSize);
-
- // Use t3 to hold undefined, which is used in several places below.
- __ LoadRoot(t3, Heap::kUndefinedValueRootIndex);
-
- if (!is_api_function) {
- Label no_inobject_slack_tracking;
-
- // Check if slack tracking is enabled.
- __ Branch(&no_inobject_slack_tracking, lt, a6,
- Operand(static_cast<int64_t>(Map::kSlackTrackingCounterEnd)));
-
- // Allocate object with a slack.
- __ lbu(
- a0,
- FieldMemOperand(
- a2, Map::kInObjectPropertiesOrConstructorFunctionIndexOffset));
- __ lbu(a2, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset));
- __ dsubu(a0, a0, a2);
- __ dsll(at, a0, kPointerSizeLog2);
- __ daddu(a0, t1, at);
- // a0: offset of first field after pre-allocated fields
- if (FLAG_debug_code) {
- __ dsll(at, a3, kPointerSizeLog2);
- __ Daddu(t2, t0, Operand(at)); // End of object.
- __ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields,
- a0, Operand(t2));
+ if (create_implicit_receiver) {
+ // 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.
+ __ GetObjectType(a3, a5, a4);
+ __ Branch(&rt_call, ne, a4, Operand(JS_FUNCTION_TYPE));
+
+ // Load the initial map and verify that it is in fact a map.
+ // a3: new target
+ __ ld(a2,
+ FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset));
+ __ JumpIfSmi(a2, &rt_call);
+ __ GetObjectType(a2, t1, t0);
+ __ Branch(&rt_call, ne, t0, Operand(MAP_TYPE));
+
+ // Fall back to runtime if the expected base constructor and base
+ // constructor differ.
+ __ ld(a5, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset));
+ __ Branch(&rt_call, ne, a1, Operand(a5));
+
+ // 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.
+ // a1: constructor function
+ // a2: initial map
+ __ lbu(t1, FieldMemOperand(a2, Map::kInstanceTypeOffset));
+ __ Branch(&rt_call, eq, t1, Operand(JS_FUNCTION_TYPE));
+
+ if (!is_api_function) {
+ Label allocate;
+ MemOperand bit_field3 = FieldMemOperand(a2, Map::kBitField3Offset);
+ // Check if slack tracking is enabled.
+ __ lwu(a4, bit_field3);
+ __ DecodeField<Map::Counter>(a6, a4);
+ __ Branch(
+ &allocate, lt, a6,
+ Operand(static_cast<int64_t>(Map::kSlackTrackingCounterEnd)));
+ // Decrease generous allocation count.
+ __ Dsubu(a4, a4, Operand(1 << Map::Counter::kShift));
+ __ Branch(USE_DELAY_SLOT, &allocate, ne, a6,
+ Operand(Map::kSlackTrackingCounterEnd));
+ __ sw(a4, bit_field3); // In delay slot.
+
+ __ Push(a1, a2, a2); // a2 = Initial map.
+ __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
+
+ __ Pop(a1, a2);
+ __ li(a6, Operand(Map::kSlackTrackingCounterEnd - 1));
+
+ __ bind(&allocate);
}
- __ InitializeFieldsWithFiller(t1, a0, t3);
- // To allow for truncation.
- __ LoadRoot(t3, Heap::kOnePointerFillerMapRootIndex);
- // Fill the remaining fields with one pointer filler map.
- __ bind(&no_inobject_slack_tracking);
- }
+ // Now allocate the JSObject on the heap.
+ // a1: constructor function
+ // a2: initial map
+ Label rt_call_reload_new_target;
+ __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
+
+ __ Allocate(a3, t0, t1, t2, &rt_call_reload_new_target, 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.
+ // a1: constructor function
+ // a2: initial map
+ // a3: object size
+ // t0: JSObject (not tagged)
+ __ LoadRoot(t2, Heap::kEmptyFixedArrayRootIndex);
+ __ mov(t1, t0);
+ __ sd(a2, MemOperand(t1, JSObject::kMapOffset));
+ __ sd(t2, MemOperand(t1, JSObject::kPropertiesOffset));
+ __ sd(t2, MemOperand(t1, JSObject::kElementsOffset));
+ __ Daddu(t1, t1, Operand(3 * kPointerSize));
+ DCHECK_EQ(0 * kPointerSize, JSObject::kMapOffset);
+ DCHECK_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
+ DCHECK_EQ(2 * kPointerSize, JSObject::kElementsOffset);
+
+ // Fill all the in-object properties with appropriate filler.
+ // a1: constructor function
+ // a2: initial map
+ // a3: object size (in words)
+ // t0: JSObject (not tagged)
+ // t1: First in-object property of JSObject (not tagged)
+ // a6: slack tracking counter (non-API function case)
+ DCHECK_EQ(3 * kPointerSize, JSObject::kHeaderSize);
+
+ // Use t3 to hold undefined, which is used in several places below.
+ __ LoadRoot(t3, Heap::kUndefinedValueRootIndex);
+
+ if (!is_api_function) {
+ Label no_inobject_slack_tracking;
+
+ // Check if slack tracking is enabled.
+ __ Branch(
+ &no_inobject_slack_tracking, lt, a6,
+ Operand(static_cast<int64_t>(Map::kSlackTrackingCounterEnd)));
+
+ // Allocate object with a slack.
+ __ lbu(a0,
+ FieldMemOperand(
+ a2,
+ Map::kInObjectPropertiesOrConstructorFunctionIndexOffset));
+ __ lbu(a2, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset));
+ __ dsubu(a0, a0, a2);
+ __ dsll(at, a0, kPointerSizeLog2);
+ __ daddu(a0, t1, at);
+ // a0: offset of first field after pre-allocated fields
+ if (FLAG_debug_code) {
+ __ dsll(at, a3, kPointerSizeLog2);
+ __ Daddu(t2, t0, Operand(at)); // End of object.
+ __ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields, a0,
+ Operand(t2));
+ }
+ __ InitializeFieldsWithFiller(t1, a0, t3);
+ // To allow for truncation.
+ __ LoadRoot(t3, Heap::kOnePointerFillerMapRootIndex);
+ // Fill the remaining fields with one pointer filler map.
+
+ __ bind(&no_inobject_slack_tracking);
+ }
- __ dsll(at, a3, kPointerSizeLog2);
- __ Daddu(a0, t0, Operand(at)); // End of object.
- __ InitializeFieldsWithFiller(t1, a0, t3);
+ __ dsll(at, a3, kPointerSizeLog2);
+ __ Daddu(a0, t0, Operand(at)); // End of object.
+ __ InitializeFieldsWithFiller(t1, a0, t3);
- // 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.
- __ Daddu(t0, t0, Operand(kHeapObjectTag));
+ // 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.
+ __ Daddu(t0, t0, Operand(kHeapObjectTag));
- // Continue with JSObject being successfully allocated.
- // a4: JSObject
- __ jmp(&allocated);
+ // Continue with JSObject being successfully allocated.
+ // a4: JSObject
+ __ jmp(&allocated);
- // Reload the new target and fall-through.
- __ bind(&rt_call_reload_new_target);
- __ ld(a3, MemOperand(sp, 0 * kPointerSize));
- }
+ // Reload the new target and fall-through.
+ __ bind(&rt_call_reload_new_target);
+ __ ld(a3, MemOperand(sp, 0 * kPointerSize));
+ }
- // Allocate the new receiver object using the runtime call.
- // a1: constructor function
- // a3: new target
- __ bind(&rt_call);
+ // Allocate the new receiver object using the runtime call.
+ // a1: constructor function
+ // a3: new target
+ __ bind(&rt_call);
- __ Push(a1, a3); // constructor function, new target
- __ CallRuntime(Runtime::kNewObject, 2);
- __ mov(t0, v0);
+ __ Push(a1, a3); // constructor function, new target
+ __ CallRuntime(Runtime::kNewObject, 2);
+ __ mov(t0, v0);
- // Receiver for constructor call allocated.
- // t0: JSObject
- __ bind(&allocated);
+ // Receiver for constructor call allocated.
+ // t0: JSObject
+ __ bind(&allocated);
- // Restore the parameters.
- __ Pop(a3); // new.target
- __ Pop(a1);
+ // Restore the parameters.
+ __ Pop(a3); // new.target
+ __ Pop(a1);
- __ ld(a0, MemOperand(sp));
+ __ ld(a0, MemOperand(sp));
+ }
__ SmiUntag(a0);
- __ Push(a3, t0, t0);
+ // Push new.target onto the construct frame. This is stored just below the
+ // receiver on the stack.
+ if (create_implicit_receiver) {
+ // Push the allocated receiver to the stack. We need two copies
+ // because we may have to return the original one and the calling
+ // conventions dictate that the called function pops the receiver.
+ __ Push(a3, t0, t0);
+ } else {
+ __ push(a3);
+ __ PushRoot(Heap::kTheHoleValueRootIndex);
+ }
// Set up pointer to last argument.
__ Daddu(a2, fp, Operand(StandardFrameConstants::kCallerSPOffset));
@@ -564,43 +584,47 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
}
// Store offset of return address for deoptimizer.
- if (!is_api_function) {
+ if (create_implicit_receiver && !is_api_function) {
masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
}
// Restore context from the frame.
__ ld(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
- // If the result is an object (in the ECMA sense), we should get rid
- // of the receiver and use the result; see ECMA-262 section 13.2.2-7
- // on page 74.
- Label use_receiver, exit;
-
- // If the result is a smi, it is *not* an object in the ECMA sense.
- // v0: result
- // sp[0]: receiver (newly allocated object)
- // sp[1]: new.target
- // sp[2]: number of arguments (smi-tagged)
- __ JumpIfSmi(v0, &use_receiver);
-
- // If the type of the result (stored in its map) is less than
- // FIRST_SPEC_OBJECT_TYPE, it is not an object in the ECMA sense.
- __ GetObjectType(v0, a1, a3);
- __ Branch(&exit, greater_equal, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
-
- // Throw away the result of the constructor invocation and use the
- // on-stack receiver as the result.
- __ bind(&use_receiver);
- __ ld(v0, MemOperand(sp));
-
- // Remove receiver from the stack, remove caller arguments, and
- // return.
- __ bind(&exit);
- // v0: result
- // sp[0]: receiver (newly allocated object)
- // sp[1]: new target
- // sp[2]: number of arguments (smi-tagged)
- __ ld(a1, MemOperand(sp, 2 * kPointerSize));
+ if (create_implicit_receiver) {
+ // If the result is an object (in the ECMA sense), we should get rid
+ // of the receiver and use the result; see ECMA-262 section 13.2.2-7
+ // on page 74.
+ Label use_receiver, exit;
+
+ // If the result is a smi, it is *not* an object in the ECMA sense.
+ // v0: result
+ // sp[0]: receiver (newly allocated object)
+ // sp[1]: new.target
+ // sp[2]: number of arguments (smi-tagged)
+ __ JumpIfSmi(v0, &use_receiver);
+
+ // If the type of the result (stored in its map) is less than
+ // FIRST_SPEC_OBJECT_TYPE, it is not an object in the ECMA sense.
+ __ GetObjectType(v0, a1, a3);
+ __ Branch(&exit, greater_equal, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
+
+ // Throw away the result of the constructor invocation and use the
+ // on-stack receiver as the result.
+ __ bind(&use_receiver);
+ __ ld(v0, MemOperand(sp));
+
+ // Remove receiver from the stack, remove caller arguments, and
+ // return.
+ __ bind(&exit);
+ // v0: result
+ // sp[0]: receiver (newly allocated object)
+ // sp[1]: new target
+ // sp[2]: number of arguments (smi-tagged)
+ __ ld(a1, MemOperand(sp, 2 * kPointerSize));
+ } else {
+ __ ld(a1, MemOperand(sp, kPointerSize));
+ }
// Leave construct frame.
}
@@ -608,91 +632,25 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ SmiScale(a4, a1, kPointerSizeLog2);
__ Daddu(sp, sp, a4);
__ Daddu(sp, sp, kPointerSize);
- __ IncrementCounter(isolate->counters()->constructed_objects(), 1, a1, a2);
+ if (create_implicit_receiver) {
+ __ IncrementCounter(isolate->counters()->constructed_objects(), 1, a1, a2);
+ }
__ Ret();
}
void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
- Generate_JSConstructStubHelper(masm, false);
+ Generate_JSConstructStubHelper(masm, false, true);
}
void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
- Generate_JSConstructStubHelper(masm, true);
+ Generate_JSConstructStubHelper(masm, true, true);
}
-void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- a0 : number of arguments
- // -- a1 : constructor function
- // -- a2 : allocation site or undefined
- // -- a3 : new target
- // -- ra : return address
- // -- sp[...]: constructor arguments
- // -----------------------------------
-
- {
- FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
-
- __ AssertUndefinedOrAllocationSite(a2, t0);
- __ push(a2);
-
- __ mov(a4, a0);
- __ SmiTag(a4);
- __ push(a4); // Smi-tagged arguments count.
-
- // Push new.target.
- __ push(a3);
-
- // receiver is the hole.
- __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
- __ push(at);
-
- // Set up pointer to last argument.
- __ Daddu(a2, fp, Operand(StandardFrameConstants::kCallerSPOffset));
-
- // Copy arguments and receiver to the expression stack.
- // a0: number of arguments
- // a1: constructor function
- // a2: address of last argument (caller sp)
- // a4: number of arguments (smi-tagged)
- // sp[0]: receiver
- // sp[1]: new.target
- // sp[2]: number of arguments (smi-tagged)
- Label loop, entry;
- __ SmiUntag(a4);
- __ jmp(&entry);
- __ bind(&loop);
- __ dsll(at, a4, kPointerSizeLog2);
- __ Daddu(at, a2, Operand(at));
- __ ld(at, MemOperand(at));
- __ push(at);
- __ bind(&entry);
- __ Daddu(a4, a4, Operand(-1));
- __ Branch(&loop, ge, a4, Operand(zero_reg));
-
- // Call the function.
- // a0: number of arguments
- // a1: constructor function
- ParameterCount actual(a0);
- __ InvokeFunction(a1, actual, CALL_FUNCTION, NullCallWrapper());
-
- // Restore context from the frame.
- // v0: result
- // sp[0]: new.target
- // sp[1]: number of arguments (smi-tagged)
- __ ld(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
- __ ld(a1, MemOperand(sp, kPointerSize));
-
- // Leave construct frame.
- }
-
- __ SmiScale(at, a1, kPointerSizeLog2);
- __ Daddu(sp, sp, Operand(at));
- __ Daddu(sp, sp, Operand(kPointerSize));
- __ Jump(ra);
+void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
+ Generate_JSConstructStubHelper(masm, false, false);
}
« no previous file with comments | « src/mips/builtins-mips.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698