Commit 9fa206e1 authored by ishell's avatar ishell Committed by Commit bot

[runtime] Ensure that all elements kind transitions are chained to the root map.

This CL also updates the elements kind transition lookup logic:
1) First we go back to the root map,
2) Follow elements kind transitions,
3) Replay the property transitions.

BUG=v8:5009
LOG=Y
TBR=bmeurer@chromium.org

Review-Url: https://codereview.chromium.org/2015513002
Cr-Commit-Position: refs/heads/master@{#36652}
parent fa9756d0
......@@ -192,12 +192,12 @@ bool AccessInfoFactory::ComputeElementAccessInfos(
MapTransitionList transitions(maps.length());
for (Handle<Map> map : maps) {
if (Map::TryUpdate(map).ToHandle(&map)) {
Handle<Map> transition_target =
Map::FindTransitionedMap(map, &possible_transition_targets);
if (transition_target.is_null()) {
Map* transition_target =
map->FindElementsKindTransitionedMap(&possible_transition_targets);
if (transition_target == nullptr) {
receiver_maps.Add(map);
} else {
transitions.push_back(std::make_pair(map, transition_target));
transitions.push_back(std::make_pair(map, handle(transition_target)));
}
}
}
......
......@@ -7670,9 +7670,13 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
// Get transition target for each map (NULL == no transition).
for (int i = 0; i < maps->length(); ++i) {
Handle<Map> map = maps->at(i);
Handle<Map> transitioned_map =
Map::FindTransitionedMap(map, &possible_transitioned_maps);
transition_target.Add(transitioned_map);
Map* transitioned_map =
map->FindElementsKindTransitionedMap(&possible_transitioned_maps);
if (transitioned_map != nullptr) {
transition_target.Add(handle(transitioned_map));
} else {
transition_target.Add(Handle<Map>());
}
}
MapHandleList untransitionable_maps(maps->length());
......
......@@ -83,8 +83,11 @@ void PropertyICCompiler::CompileKeyedStorePolymorphicHandlers(
for (int i = 0; i < receiver_maps->length(); ++i) {
Handle<Map> receiver_map(receiver_maps->at(i));
Handle<Code> cached_stub;
Handle<Map> transitioned_map =
Map::FindTransitionedMap(receiver_map, receiver_maps);
Handle<Map> transitioned_map;
{
Map* tmap = receiver_map->FindElementsKindTransitionedMap(receiver_maps);
if (tmap != nullptr) transitioned_map = handle(tmap);
}
// TODO(mvstanton): The code below is doing pessimistic elements
// transitions. I would like to stop doing that and rely on Allocation Site
......
......@@ -762,11 +762,12 @@ bool IC::IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map) {
ElementsKind target_elements_kind = target_map->elements_kind();
bool more_general_transition = IsMoreGeneralElementsKindTransition(
source_map->elements_kind(), target_elements_kind);
Map* transitioned_map =
more_general_transition
? source_map->LookupElementsTransitionMap(target_elements_kind)
: NULL;
Map* transitioned_map = nullptr;
if (more_general_transition) {
MapHandleList map_list;
map_list.Add(handle(target_map));
transitioned_map = source_map->FindElementsKindTransitionedMap(&map_list);
}
return transitioned_map == target_map;
}
......
......@@ -18,6 +18,7 @@
#include "src/conversions-inl.h"
#include "src/factory.h"
#include "src/field-index-inl.h"
#include "src/field-type.h"
#include "src/handles-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
......@@ -2811,6 +2812,25 @@ FixedArrayBase* Map::GetInitialElements() {
return result;
}
// static
Handle<Map> Map::ReconfigureProperty(Handle<Map> map, int modify_index,
PropertyKind new_kind,
PropertyAttributes new_attributes,
Representation new_representation,
Handle<FieldType> new_field_type,
StoreMode store_mode) {
return Reconfigure(map, map->elements_kind(), modify_index, new_kind,
new_attributes, new_representation, new_field_type,
store_mode);
}
// static
Handle<Map> Map::ReconfigureElementsKind(Handle<Map> map,
ElementsKind new_elements_kind) {
return Reconfigure(map, new_elements_kind, -1, kData, NONE,
Representation::None(), FieldType::None(map->GetIsolate()),
ALLOW_IN_DESCRIPTOR);
}
Object** DescriptorArray::GetKeySlot(int descriptor_number) {
DCHECK(descriptor_number < number_of_descriptors());
......
This diff is collapsed.
......@@ -5769,15 +5769,14 @@ class Map: public HeapObject {
static void GeneralizeFieldType(Handle<Map> map, int modify_index,
Representation new_representation,
Handle<FieldType> new_field_type);
static Handle<Map> ReconfigureProperty(Handle<Map> map, int modify_index,
PropertyKind new_kind,
PropertyAttributes new_attributes,
Representation new_representation,
Handle<FieldType> new_field_type,
StoreMode store_mode);
static Handle<Map> CopyGeneralizeAllRepresentations(
Handle<Map> map, int modify_index, StoreMode store_mode,
PropertyKind kind, PropertyAttributes attributes, const char* reason);
static inline Handle<Map> ReconfigureProperty(
Handle<Map> map, int modify_index, PropertyKind new_kind,
PropertyAttributes new_attributes, Representation new_representation,
Handle<FieldType> new_field_type, StoreMode store_mode);
static inline Handle<Map> ReconfigureElementsKind(
Handle<Map> map, ElementsKind new_elements_kind);
static Handle<Map> PrepareForDataProperty(Handle<Map> old_map,
int descriptor_number,
......@@ -5998,17 +5997,10 @@ class Map: public HeapObject {
// Computes a hash value for this map, to be used in HashTables and such.
int Hash();
// Returns the map that this map transitions to if its elements_kind
// is changed to |elements_kind|, or NULL if no such map is cached yet.
// |safe_to_add_transitions| is set to false if adding transitions is not
// allowed.
Map* LookupElementsTransitionMap(ElementsKind elements_kind);
// Returns the transitioned map for this map with the most generic
// elements_kind that's found in |candidates|, or null handle if no match is
// elements_kind that's found in |candidates|, or |nullptr| if no match is
// found at all.
static Handle<Map> FindTransitionedMap(Handle<Map> map,
MapHandleList* candidates);
Map* FindElementsKindTransitionedMap(MapHandleList* candidates);
inline bool CanTransition();
......@@ -6167,6 +6159,17 @@ class Map: public HeapObject {
Handle<LayoutDescriptor> full_layout_descriptor);
private:
// Returns the map that this (root) map transitions to if its elements_kind
// is changed to |elements_kind|, or |nullptr| if no such map is cached yet.
Map* LookupElementsTransitionMap(ElementsKind elements_kind);
// Tries to replay property transitions starting from this (root) map using
// the descriptor array of the |map|. The |root_map| is expected to have
// proper elements kind and therefore elements kinds transitions are not
// taken by this function. Returns |nullptr| if matching transition map is
// not found.
Map* TryReplayPropertyTransitions(Map* map);
static void ConnectTransition(Handle<Map> parent, Handle<Map> child,
Handle<Name> name, SimpleTransitionFlag flag);
......@@ -6203,6 +6206,19 @@ class Map: public HeapObject {
static Handle<Map> CopyNormalized(Handle<Map> map,
PropertyNormalizationMode mode);
static Handle<Map> Reconfigure(Handle<Map> map,
ElementsKind new_elements_kind,
int modify_index, PropertyKind new_kind,
PropertyAttributes new_attributes,
Representation new_representation,
Handle<FieldType> new_field_type,
StoreMode store_mode);
static Handle<Map> CopyGeneralizeAllRepresentations(
Handle<Map> map, ElementsKind elements_kind, int modify_index,
StoreMode store_mode, PropertyKind kind, PropertyAttributes attributes,
const char* reason);
// Fires when the layout of an object with a leaf map changes.
// This includes adding transitions to the leaf map or changing
// the descriptor array.
......
This diff is collapsed.
// Copyright 2016 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.
function fn1() {
}
function fn2() {
}
function fn3() {
}
function create(id) {
// Just some `FunctionTemplate` to hang on
var o = new version();
o.id = id;
o[0] = null;
return o;
}
function setM1(o) {
o.m1 = fn1;
}
function setM2(o) {
o.m2 = fn2;
}
function setAltM2(o) {
// Failing StoreIC happens here
o.m2 = fn3;
}
function setAltM1(o) {
o.m1 = null;
}
function test(o) {
o.m2();
o.m1();
}
var p0 = create(0);
var p1 = create(1);
var p2 = create(2);
setM1(p0);
setM1(p1);
setM1(p2);
setM2(p0);
setAltM2(p0);
setAltM1(p0);
setAltM2(p1);
setAltM2(p2);
test(p2);
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