Commit 04419d4d authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[builtins] Migrate the Object constructor from JS to CSA.

This speeds up the baseline performance of Object by 20%.

With this change, the callViaObject when run with --noopt
goes from 10718ms to 8577ms on the benchmark from:
http://benediktmeurer.de/2017/08/31/object-constructor-calls-in-webpack-bundles

Bug: v8:6772
Change-Id: Id0e54ba44204a1700885185ec360e1c56834fb73
Reviewed-on: https://chromium-review.googlesource.com/654900Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47888}
parent 238b3c96
......@@ -691,9 +691,13 @@ void Genesis::CreateObjectFunction(Handle<JSFunction> empty_function) {
int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount;
int instance_size = JSObject::kHeaderSize + kPointerSize * unused;
Handle<JSFunction> object_fun =
CreateFunction(isolate_, factory->Object_string(), JS_OBJECT_TYPE,
instance_size, factory->null_value(), Builtins::kIllegal);
Handle<JSFunction> object_fun = CreateFunction(
isolate_, factory->Object_string(), JS_OBJECT_TYPE, instance_size,
factory->null_value(), Builtins::kObjectConstructor);
object_fun->shared()->set_length(1);
object_fun->shared()->DontAdaptArguments();
object_fun->shared()->set_construct_stub(
*BUILTIN_CODE(isolate_, ObjectConstructor_ConstructStub));
native_context()->set_object_function(*object_fun);
{
......
......@@ -795,5 +795,51 @@ TF_BUILTIN(CreateEmptyObjectLiteral, ConstructorBuiltinsAssembler) {
Node* result = EmitCreateEmptyObjectLiteral(context);
Return(result);
}
TF_BUILTIN(ObjectConstructor, ConstructorBuiltinsAssembler) {
int const kValueArg = 0;
Node* argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc);
Node* value = args.GetOptionalArgumentValue(kValueArg);
Node* context = Parameter(BuiltinDescriptor::kContext);
CSA_ASSERT(this, IsUndefined(Parameter(BuiltinDescriptor::kNewTarget)));
Label return_to_object(this);
GotoIf(Word32And(IsNotUndefined(value), IsNotNull(value)), &return_to_object);
args.PopAndReturn(EmitCreateEmptyObjectLiteral(context));
BIND(&return_to_object);
args.PopAndReturn(CallBuiltin(Builtins::kToObject, context, value));
}
TF_BUILTIN(ObjectConstructor_ConstructStub, ConstructorBuiltinsAssembler) {
int const kValueArg = 0;
Node* argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc);
Node* value = args.GetOptionalArgumentValue(kValueArg);
Node* target = LoadFromFrame(StandardFrameConstants::kFunctionOffset,
MachineType::TaggedPointer());
Node* new_target = Parameter(BuiltinDescriptor::kNewTarget);
Node* context = Parameter(BuiltinDescriptor::kContext);
CSA_ASSERT(this, IsNotUndefined(new_target));
Label return_to_object(this);
GotoIf(Word32And(WordEqual(target, new_target),
Word32And(IsNotUndefined(value), IsNotNull(value))),
&return_to_object);
args.PopAndReturn(EmitFastNewObject(context, target, new_target));
BIND(&return_to_object);
args.PopAndReturn(CallBuiltin(Builtins::kToObject, context, value));
}
} // namespace internal
} // namespace v8
......@@ -683,6 +683,9 @@ namespace internal {
TFC(StrictEqual, Compare, 1) \
\
/* Object */ \
TFJ(ObjectConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
TFJ(ObjectConstructor_ConstructStub, \
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
CPP(ObjectAssign) \
/* ES #sec-object.create */ \
TFJ(ObjectCreate, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
......
......@@ -448,6 +448,7 @@ bool BuiltinHasNoSideEffect(Builtins::Name id) {
switch (id) {
// Whitelist for builtins.
// Object builtins.
case Builtins::kObjectConstructor:
case Builtins::kObjectCreate:
case Builtins::kObjectEntries:
case Builtins::kObjectGetOwnPropertyDescriptor:
......
......@@ -35,23 +35,6 @@ function GetMethod(obj, p) {
throw %make_type_error(kCalledNonCallable, typeof func);
}
// ES6 19.1.1.1
function ObjectConstructor(x) {
if (GlobalObject != new.target && !IS_UNDEFINED(new.target)) {
return this;
}
if (IS_NULL(x) || IS_UNDEFINED(x)) return {};
return TO_OBJECT(x);
}
// ----------------------------------------------------------------------------
// Object
%SetNativeFlag(GlobalObject);
%SetCode(GlobalObject, ObjectConstructor);
// ----------------------------------------------------------------------------
// Iterator related spec functions.
......
......@@ -93,7 +93,7 @@ TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedMapped) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Handle<SharedFunctionInfo> shared(isolate()->script_function()->shared());
Node* const frame_state_outer = FrameState(shared, graph()->start());
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
Reduction r = Reduce(graph()->NewNode(
......@@ -111,7 +111,7 @@ TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedUnmapped) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Handle<SharedFunctionInfo> shared(isolate()->script_function()->shared());
Node* const frame_state_outer = FrameState(shared, graph()->start());
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
Reduction r = Reduce(graph()->NewNode(
......@@ -129,7 +129,7 @@ TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedRestArray) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Handle<SharedFunctionInfo> shared(isolate()->script_function()->shared());
Node* const frame_state_outer = FrameState(shared, graph()->start());
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
Reduction r = Reduce(graph()->NewNode(
......
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