Commit 1f3a863b authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[turbofan] Fix traversal order of boilerplate objects.

This fixes {JSCreateLowering} to traverse boilerplate objects in the
same order the runtime uses (i.e. properties first, elements second).
That order is hard-coded in the nesting of {AllocationSite} objects.

R=bmeurer@chromium.org
TEST=mjsunit/regress/regress-crbug-709537
BUG=chromium:709537

Change-Id: I8f446a0880448ea88a3e242e92d11d611581a42b
Reviewed-on: https://chromium-review.googlesource.com/474028Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44563}
parent b213f239
......@@ -1144,11 +1144,6 @@ Node* JSCreateLowering::AllocateFastLiteral(
// Setup the properties backing store.
Node* properties = jsgraph()->EmptyFixedArrayConstant();
// Setup the elements backing store.
Node* elements = AllocateFastLiteralElements(effect, control, boilerplate,
pretenure, site_context);
if (elements->op()->EffectOutputCount() > 0) effect = elements;
// Compute the in-object properties to store first (might have effects).
Handle<Map> boilerplate_map(boilerplate->map(), isolate());
ZoneVector<std::pair<FieldAccess, Node*>> inobject_fields(zone());
......@@ -1213,6 +1208,11 @@ Node* JSCreateLowering::AllocateFastLiteral(
inobject_fields.push_back(std::make_pair(access, value));
}
// Setup the elements backing store.
Node* elements = AllocateFastLiteralElements(effect, control, boilerplate,
pretenure, site_context);
if (elements->op()->EffectOutputCount() > 0) effect = elements;
// Actually allocate and initialize the object.
AllocationBuilder builder(jsgraph(), effect, control);
builder.Allocate(boilerplate_map->instance_size(), pretenure,
......
......@@ -11307,6 +11307,14 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
// properties to a safe value.
BuildInitializeInobjectProperties(object, initial_map);
// Copy in-object properties.
if (initial_map->NumberOfFields() != 0 ||
initial_map->unused_property_fields() > 0) {
BuildEmitInObjectProperties(boilerplate_object, object, site_context,
pretenure_flag);
}
// Copy elements.
Handle<FixedArrayBase> elements(boilerplate_object->elements());
int elements_size = (elements->length() > 0 &&
elements->map() != isolate()->heap()->fixed_cow_array_map()) ?
......@@ -11344,12 +11352,6 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
object_elements_cow);
}
// Copy in-object properties.
if (initial_map->NumberOfFields() != 0 ||
initial_map->unused_property_fields() > 0) {
BuildEmitInObjectProperties(boilerplate_object, object, site_context,
pretenure_flag);
}
return object;
}
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
function foo() {
return { 0: {}, x: {} };
}
var ref = foo();
assertEquals(ref, foo());
assertEquals(ref, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(ref, foo());
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