Commit d1987177 authored by verwaest's avatar verwaest Committed by Commit bot

[runtime] More LookupIterator / Transition related performance tweaks

Minor improvements measured through by https://github.com/kpdecker/six-speed/blob/master/tests/object-assign/object-assign.es6. Mostly due to inlining of NowContains on the FieldType

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

Cr-Commit-Position: refs/heads/master@{#34060}
parent 4fbca26c
......@@ -45,17 +45,6 @@ FieldType* FieldType::cast(Object* object) {
return reinterpret_cast<FieldType*>(object);
}
bool FieldType::NowContains(Object* value) {
if (this == Any()) return true;
if (this == None()) return false;
if (!value->IsHeapObject()) return false;
return HeapObject::cast(value)->map() == Map::cast(this);
}
bool FieldType::NowContains(Handle<Object> value) {
return NowContains(*value);
}
bool FieldType::IsClass() { return this->IsMap(); }
Handle<i::Map> FieldType::AsClass() {
......
......@@ -22,8 +22,15 @@ class FieldType : public Object {
static Handle<FieldType> Class(i::Handle<i::Map> map, Isolate* isolate);
static FieldType* cast(Object* object);
bool NowContains(Object* value);
bool NowContains(Handle<Object> value);
bool NowContains(Object* value) {
if (this == Any()) return true;
if (this == None()) return false;
if (!value->IsHeapObject()) return false;
return HeapObject::cast(value)->map() == Map::cast(this);
}
bool NowContains(Handle<Object> value) { return NowContains(*value); }
bool IsClass();
Handle<i::Map> AsClass();
bool IsNone() { return this == None(); }
......
......@@ -181,8 +181,9 @@ void LookupIterator::PrepareForDataProperty(Handle<Object> value) {
if (kind == to) return;
} else if (holder_map_->is_dictionary_map()) {
return;
} else {
if (holder_map_->is_dictionary_map()) return;
holder_map_ =
Map::PrepareForDataProperty(holder_map_, descriptor_number(), value);
......@@ -247,19 +248,30 @@ void LookupIterator::PrepareTransitionToDataProperty(
DCHECK_NE(INTEGER_INDEXED_EXOTIC, state_);
DCHECK(state_ == NOT_FOUND || !HolderIsReceiverOrHiddenPrototype());
auto transition = Map::TransitionToDataProperty(
handle(receiver->map(), isolate_), name_, value, attributes, store_mode);
Handle<Map> map(receiver->map(), isolate_);
// Dictionary maps can always have additional data properties.
if (map->is_dictionary_map()) {
state_ = TRANSITION;
if (map->IsJSGlobalObjectMap()) {
// Install a property cell.
InternalizeName();
auto cell = JSGlobalObject::EnsurePropertyCell(
Handle<JSGlobalObject>::cast(receiver), name());
DCHECK(cell->value()->IsTheHole());
transition_ = cell;
} else {
transition_ = map;
}
return;
}
Handle<Map> transition =
Map::TransitionToDataProperty(map, name_, value, attributes, store_mode);
state_ = TRANSITION;
transition_ = transition;
if (receiver->IsJSGlobalObject()) {
// Install a property cell.
InternalizeName();
auto cell = JSGlobalObject::EnsurePropertyCell(
Handle<JSGlobalObject>::cast(receiver), name());
DCHECK(cell->value()->IsTheHole());
transition_ = cell;
} else if (!transition->is_dictionary_map()) {
if (!transition->is_dictionary_map()) {
property_details_ = transition->GetLastDescriptorDetails();
has_property_ = true;
}
......
......@@ -6608,9 +6608,8 @@ bool JSObject::HasSlowStringWrapperElements() {
}
bool JSObject::HasFixedTypedArrayElements() {
HeapObject* array = elements();
DCHECK(array != NULL);
return array->IsFixedTypedArrayBase();
DCHECK_NOT_NULL(elements());
return map()->has_fixed_typed_array_elements();
}
#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \
......
......@@ -9844,17 +9844,19 @@ FieldType* DescriptorArray::GetFieldType(int descriptor_number) {
return FieldType::cast(value);
}
bool DescriptorArray::CanHoldValue(int descriptor, Object* value) {
PropertyDetails details = GetDetails(descriptor);
namespace {
bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) {
PropertyDetails details = descriptors->GetDetails(descriptor);
switch (details.type()) {
case DATA:
return value->FitsRepresentation(details.representation()) &&
GetFieldType(descriptor)->NowContains(value);
descriptors->GetFieldType(descriptor)->NowContains(value);
case DATA_CONSTANT:
DCHECK(GetConstant(descriptor) != value ||
DCHECK(descriptors->GetConstant(descriptor) != value ||
value->FitsRepresentation(details.representation()));
return GetConstant(descriptor) == value;
return descriptors->GetConstant(descriptor) == value;
case ACCESSOR:
case ACCESSOR_CONSTANT:
......@@ -9865,11 +9867,9 @@ bool DescriptorArray::CanHoldValue(int descriptor, Object* value) {
return false;
}
namespace {
Handle<Map> UpdateDescriptorForValue(Handle<Map> map, int descriptor,
Handle<Object> value) {
if (map->instance_descriptors()->CanHoldValue(descriptor, *value)) return map;
if (CanHoldValue(map->instance_descriptors(), descriptor, *value)) return map;
Isolate* isolate = map->GetIsolate();
PropertyAttributes attributes =
......@@ -9887,8 +9887,7 @@ Handle<Map> UpdateDescriptorForValue(Handle<Map> map, int descriptor,
Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor,
Handle<Object> value) {
// Dictionaries can store any property value.
if (map->is_dictionary_map()) return map;
DCHECK(!map->is_dictionary_map());
// Update to the newest map before storing the property.
return UpdateDescriptorForValue(Update(map), descriptor, value);
}
......@@ -9898,8 +9897,7 @@ Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name,
Handle<Object> value,
PropertyAttributes attributes,
StoreFromKeyed store_mode) {
// Dictionary maps can always have additional data properties.
if (map->is_dictionary_map()) return map;
DCHECK(!map->is_dictionary_map());
// Migrate to the newest map before storing the property.
map = Update(map);
......
......@@ -2958,8 +2958,6 @@ class DescriptorArray: public FixedArray {
Isolate* isolate, Handle<FixedArray> new_cache,
Handle<FixedArray> new_index_cache);
bool CanHoldValue(int descriptor, Object* value);
// Accessors for fetching instance descriptor at descriptor number.
inline Name* GetKey(int descriptor_number);
inline Object** GetKeySlot(int descriptor_number);
......
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