Commit 1377cd37 authored by Z Duong Nguyen-Huu's avatar Z Duong Nguyen-Huu Committed by Commit Bot

Put sealed, frozen elements kind behind flag

Per suggestion, we put this behind runtime flag in the mean time.
Refactor some codes.

Bug: v8:6831
Change-Id: Ibeb2a62b2a132971f8bc51c045bf0d2594eec198
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1566238
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60927}
parent 875046c7
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/checks.h" #include "src/checks.h"
#include "src/flags.h"
#include "src/utils.h" #include "src/utils.h"
namespace v8 { namespace v8 {
...@@ -154,13 +155,24 @@ inline bool IsDoubleOrFloatElementsKind(ElementsKind kind) { ...@@ -154,13 +155,24 @@ inline bool IsDoubleOrFloatElementsKind(ElementsKind kind) {
} }
inline bool IsPackedFrozenOrSealedElementsKind(ElementsKind kind) { inline bool IsPackedFrozenOrSealedElementsKind(ElementsKind kind) {
DCHECK_IMPLIES(
IsInRange(kind, PACKED_SEALED_ELEMENTS, PACKED_FROZEN_ELEMENTS),
FLAG_enable_sealed_frozen_elements_kind);
return IsInRange(kind, PACKED_SEALED_ELEMENTS, PACKED_FROZEN_ELEMENTS); return IsInRange(kind, PACKED_SEALED_ELEMENTS, PACKED_FROZEN_ELEMENTS);
} }
inline bool IsSealedElementsKind(ElementsKind kind) { inline bool IsSealedElementsKind(ElementsKind kind) {
DCHECK_IMPLIES(kind == PACKED_SEALED_ELEMENTS,
FLAG_enable_sealed_frozen_elements_kind);
return kind == PACKED_SEALED_ELEMENTS; return kind == PACKED_SEALED_ELEMENTS;
} }
inline bool IsFrozenElementsKind(ElementsKind kind) {
DCHECK_IMPLIES(kind == PACKED_FROZEN_ELEMENTS,
FLAG_enable_sealed_frozen_elements_kind);
return kind == PACKED_FROZEN_ELEMENTS;
}
inline bool IsSmiOrObjectElementsKind(ElementsKind kind) { inline bool IsSmiOrObjectElementsKind(ElementsKind kind) {
return kind == PACKED_SMI_ELEMENTS || kind == HOLEY_SMI_ELEMENTS || return kind == PACKED_SMI_ELEMENTS || kind == HOLEY_SMI_ELEMENTS ||
kind == PACKED_ELEMENTS || kind == HOLEY_ELEMENTS; kind == PACKED_ELEMENTS || kind == HOLEY_ELEMENTS;
......
...@@ -354,6 +354,9 @@ DEFINE_BOOL(enable_one_shot_optimization, true, ...@@ -354,6 +354,9 @@ DEFINE_BOOL(enable_one_shot_optimization, true,
"Enable size optimizations for the code that will " "Enable size optimizations for the code that will "
"only be executed once") "only be executed once")
// Flag for sealed, frozen elements kind instead of dictionary elements kind
DEFINE_BOOL(enable_sealed_frozen_elements_kind, true,
"Enable sealed, frozen elements kind")
// Flags for data representation optimizations // Flags for data representation optimizations
DEFINE_BOOL(unbox_double_arrays, true, "automatically unbox arrays of doubles") DEFINE_BOOL(unbox_double_arrays, true, "automatically unbox arrays of doubles")
......
...@@ -1948,7 +1948,7 @@ Handle<Object> KeyedStoreIC::StoreElementHandler( ...@@ -1948,7 +1948,7 @@ Handle<Object> KeyedStoreIC::StoreElementHandler(
code = code =
CodeFactory::KeyedStoreIC_SloppyArguments(isolate(), store_mode).code(); CodeFactory::KeyedStoreIC_SloppyArguments(isolate(), store_mode).code();
} else if (receiver_map->has_fast_elements() || } else if (receiver_map->has_fast_elements() ||
PACKED_SEALED_ELEMENTS == receiver_map->elements_kind() || receiver_map->has_sealed_elements() ||
receiver_map->has_fixed_typed_array_elements()) { receiver_map->has_fixed_typed_array_elements()) {
TRACE_HANDLER_STATS(isolate(), KeyedStoreIC_StoreFastElementStub); TRACE_HANDLER_STATS(isolate(), KeyedStoreIC_StoreFastElementStub);
code = CodeFactory::StoreFastElementIC(isolate(), store_mode).code(); code = CodeFactory::StoreFastElementIC(isolate(), store_mode).code();
...@@ -1962,7 +1962,7 @@ Handle<Object> KeyedStoreIC::StoreElementHandler( ...@@ -1962,7 +1962,7 @@ Handle<Object> KeyedStoreIC::StoreElementHandler(
// TODO(jgruber): Update counter name. // TODO(jgruber): Update counter name.
TRACE_HANDLER_STATS(isolate(), KeyedStoreIC_StoreElementStub); TRACE_HANDLER_STATS(isolate(), KeyedStoreIC_StoreElementStub);
DCHECK(DICTIONARY_ELEMENTS == receiver_map->elements_kind() || DCHECK(DICTIONARY_ELEMENTS == receiver_map->elements_kind() ||
PACKED_FROZEN_ELEMENTS == receiver_map->elements_kind()); receiver_map->has_frozen_elements());
code = CodeFactory::KeyedStoreIC_Slow(isolate(), store_mode).code(); code = CodeFactory::KeyedStoreIC_Slow(isolate(), store_mode).code();
} }
......
...@@ -1167,9 +1167,8 @@ LookupIterator::State LookupIterator::LookupInRegularHolder( ...@@ -1167,9 +1167,8 @@ LookupIterator::State LookupIterator::LookupInRegularHolder(
return holder->IsJSTypedArray() ? INTEGER_INDEXED_EXOTIC : NOT_FOUND; return holder->IsJSTypedArray() ? INTEGER_INDEXED_EXOTIC : NOT_FOUND;
} }
property_details_ = accessor->GetDetails(js_object, number_); property_details_ = accessor->GetDetails(js_object, number_);
if (map->is_frozen_or_sealed_elements()) { if (map->has_frozen_or_sealed_elements()) {
PropertyAttributes attrs = PropertyAttributes attrs = map->has_sealed_elements() ? SEALED : FROZEN;
map->elements_kind() == PACKED_SEALED_ELEMENTS ? SEALED : FROZEN;
property_details_ = property_details_.CopyAddAttributes(attrs); property_details_ = property_details_.CopyAddAttributes(attrs);
} }
} else if (!map->is_dictionary_map()) { } else if (!map->is_dictionary_map()) {
......
...@@ -645,7 +645,7 @@ void JSObject::JSObjectVerify(Isolate* isolate) { ...@@ -645,7 +645,7 @@ void JSObject::JSObjectVerify(Isolate* isolate) {
// pointer may point to a one pointer filler map. // pointer may point to a one pointer filler map.
if (ElementsAreSafeToExamine()) { if (ElementsAreSafeToExamine()) {
CHECK_EQ((map()->has_fast_smi_or_object_elements() || CHECK_EQ((map()->has_fast_smi_or_object_elements() ||
map()->is_frozen_or_sealed_elements() || map()->has_frozen_or_sealed_elements() ||
(elements() == GetReadOnlyRoots().empty_fixed_array()) || (elements() == GetReadOnlyRoots().empty_fixed_array()) ||
HasFastStringWrapperElements()), HasFastStringWrapperElements()),
(elements()->map() == GetReadOnlyRoots().fixed_array_map() || (elements()->map() == GetReadOnlyRoots().fixed_array_map() ||
......
...@@ -3673,8 +3673,8 @@ bool TestElementsIntegrityLevel(JSObject object, PropertyAttributes level) { ...@@ -3673,8 +3673,8 @@ bool TestElementsIntegrityLevel(JSObject object, PropertyAttributes level) {
return false; // TypedArrays with elements can't be frozen. return false; // TypedArrays with elements can't be frozen.
return TestPropertiesIntegrityLevel(object, level); return TestPropertiesIntegrityLevel(object, level);
} }
if (kind == PACKED_FROZEN_ELEMENTS) return true; if (IsFrozenElementsKind(kind)) return true;
if (kind == PACKED_SEALED_ELEMENTS && level != FROZEN) return true; if (IsSealedElementsKind(kind) && level != FROZEN) return true;
ElementsAccessor* accessor = ElementsAccessor::ForKind(kind); ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
// Only DICTIONARY_ELEMENTS and SLOW_SLOPPY_ARGUMENTS_ELEMENTS have // Only DICTIONARY_ELEMENTS and SLOW_SLOPPY_ARGUMENTS_ELEMENTS have
...@@ -3813,7 +3813,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition( ...@@ -3813,7 +3813,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
if (attrs == NONE && !object->map()->is_extensible()) return Just(true); if (attrs == NONE && !object->map()->is_extensible()) return Just(true);
ElementsKind old_elements_kind = object->map()->elements_kind(); ElementsKind old_elements_kind = object->map()->elements_kind();
if (attrs != FROZEN && old_elements_kind == PACKED_SEALED_ELEMENTS) if (attrs != FROZEN && IsSealedElementsKind(old_elements_kind))
return Just(true); return Just(true);
if (old_elements_kind == PACKED_FROZEN_ELEMENTS) return Just(true); if (old_elements_kind == PACKED_FROZEN_ELEMENTS) return Just(true);
...@@ -3874,7 +3874,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition( ...@@ -3874,7 +3874,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
DCHECK(transition_map->has_dictionary_elements() || DCHECK(transition_map->has_dictionary_elements() ||
transition_map->has_fixed_typed_array_elements() || transition_map->has_fixed_typed_array_elements() ||
transition_map->elements_kind() == SLOW_STRING_WRAPPER_ELEMENTS || transition_map->elements_kind() == SLOW_STRING_WRAPPER_ELEMENTS ||
transition_map->is_frozen_or_sealed_elements()); transition_map->has_frozen_or_sealed_elements());
DCHECK(!transition_map->is_extensible()); DCHECK(!transition_map->is_extensible());
JSObject::MigrateToMap(object, transition_map); JSObject::MigrateToMap(object, transition_map);
} else if (transitions.CanHaveMoreTransitions()) { } else if (transitions.CanHaveMoreTransitions()) {
...@@ -3918,7 +3918,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition( ...@@ -3918,7 +3918,7 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
} }
} }
if (object->map()->is_frozen_or_sealed_elements()) { if (object->map()->has_frozen_or_sealed_elements()) {
return Just(true); return Just(true);
} }
......
...@@ -500,10 +500,18 @@ bool Map::has_dictionary_elements() const { ...@@ -500,10 +500,18 @@ bool Map::has_dictionary_elements() const {
return IsDictionaryElementsKind(elements_kind()); return IsDictionaryElementsKind(elements_kind());
} }
bool Map::is_frozen_or_sealed_elements() const { bool Map::has_frozen_or_sealed_elements() const {
return IsPackedFrozenOrSealedElementsKind(elements_kind()); return IsPackedFrozenOrSealedElementsKind(elements_kind());
} }
bool Map::has_sealed_elements() const {
return IsSealedElementsKind(elements_kind());
}
bool Map::has_frozen_elements() const {
return IsFrozenElementsKind(elements_kind());
}
void Map::set_is_dictionary_map(bool value) { void Map::set_is_dictionary_map(bool value) {
uint32_t new_bit_field3 = IsDictionaryMapBit::update(bit_field3(), value); uint32_t new_bit_field3 = IsDictionaryMapBit::update(bit_field3(), value);
new_bit_field3 = IsUnstableBit::update(new_bit_field3, value); new_bit_field3 = IsUnstableBit::update(new_bit_field3, value);
......
...@@ -2043,21 +2043,23 @@ Handle<Map> Map::CopyForPreventExtensions(Isolate* isolate, Handle<Map> map, ...@@ -2043,21 +2043,23 @@ Handle<Map> Map::CopyForPreventExtensions(Isolate* isolate, Handle<Map> map,
ElementsKind new_kind = IsStringWrapperElementsKind(map->elements_kind()) ElementsKind new_kind = IsStringWrapperElementsKind(map->elements_kind())
? SLOW_STRING_WRAPPER_ELEMENTS ? SLOW_STRING_WRAPPER_ELEMENTS
: DICTIONARY_ELEMENTS; : DICTIONARY_ELEMENTS;
switch (map->elements_kind()) { if (FLAG_enable_sealed_frozen_elements_kind) {
case PACKED_ELEMENTS: switch (map->elements_kind()) {
if (attrs_to_add == SEALED) { case PACKED_ELEMENTS:
new_kind = PACKED_SEALED_ELEMENTS; if (attrs_to_add == SEALED) {
} else if (attrs_to_add == FROZEN) { new_kind = PACKED_SEALED_ELEMENTS;
new_kind = PACKED_FROZEN_ELEMENTS; } else if (attrs_to_add == FROZEN) {
} new_kind = PACKED_FROZEN_ELEMENTS;
break; }
case PACKED_SEALED_ELEMENTS: break;
if (attrs_to_add == FROZEN) { case PACKED_SEALED_ELEMENTS:
new_kind = PACKED_FROZEN_ELEMENTS; if (attrs_to_add == FROZEN) {
} new_kind = PACKED_FROZEN_ELEMENTS;
break; }
default: break;
break; default:
break;
}
} }
new_map->set_elements_kind(new_kind); new_map->set_elements_kind(new_kind);
} }
......
...@@ -421,7 +421,9 @@ class Map : public HeapObject { ...@@ -421,7 +421,9 @@ class Map : public HeapObject {
inline bool has_fast_string_wrapper_elements() const; inline bool has_fast_string_wrapper_elements() const;
inline bool has_fixed_typed_array_elements() const; inline bool has_fixed_typed_array_elements() const;
inline bool has_dictionary_elements() const; inline bool has_dictionary_elements() const;
inline bool is_frozen_or_sealed_elements() const; inline bool has_frozen_or_sealed_elements() const;
inline bool has_sealed_elements() const;
inline bool has_frozen_elements() const;
// Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a
// map with DICTIONARY_ELEMENTS was found in the prototype chain. // map with DICTIONARY_ELEMENTS was found in the prototype chain.
......
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