Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1092)

Unified Diff: src/objects.cc

Issue 15681004: Revert "Make Object.freeze fast" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 2c8c339d996bd6429c7dc534605971893ed48be0..527028a31409b3c5385659d82dd68afe297d7e49 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4507,42 +4507,6 @@ MaybeObject* JSObject::TransformToFastProperties(int unused_property_fields) {
}
-static MUST_USE_RESULT MaybeObject* CopyFastElementsToDictionary(
- Isolate* isolate,
- FixedArrayBase* array,
- int length,
- SeededNumberDictionary* dictionary) {
- Heap* heap = isolate->heap();
- bool has_double_elements = array->IsFixedDoubleArray();
- for (int i = 0; i < length; i++) {
- Object* value = NULL;
- if (has_double_elements) {
- FixedDoubleArray* double_array = FixedDoubleArray::cast(array);
- if (double_array->is_the_hole(i)) {
- value = isolate->heap()->the_hole_value();
- } else {
- // Objects must be allocated in the old object space, since the
- // overall number of HeapNumbers needed for the conversion might
- // exceed the capacity of new space, and we would fail repeatedly
- // trying to convert the FixedDoubleArray.
- MaybeObject* maybe_value_object =
- heap->AllocateHeapNumber(double_array->get_scalar(i), TENURED);
- if (!maybe_value_object->ToObject(&value)) return maybe_value_object;
- }
- } else {
- value = FixedArray::cast(array)->get(i);
- }
- if (!value->IsTheHole()) {
- PropertyDetails details = PropertyDetails(NONE, NORMAL, 0);
- MaybeObject* maybe_result =
- dictionary->AddNumberEntry(i, value, details);
- if (!maybe_result->To(&dictionary)) return maybe_result;
- }
- }
- return dictionary;
-}
-
-
Handle<SeededNumberDictionary> JSObject::NormalizeElements(
Handle<JSObject> object) {
CALL_HEAP_FUNCTION(object->GetIsolate(),
@@ -4574,14 +4538,44 @@ MaybeObject* JSObject::NormalizeElements() {
int old_capacity = 0;
int used_elements = 0;
GetElementsCapacityAndUsage(&old_capacity, &used_elements);
- SeededNumberDictionary* dictionary;
- MaybeObject* maybe_dictionary =
- SeededNumberDictionary::Allocate(GetHeap(), used_elements);
- if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
+ SeededNumberDictionary* dictionary = NULL;
+ { Object* object;
+ MaybeObject* maybe =
+ SeededNumberDictionary::Allocate(GetHeap(), used_elements);
+ if (!maybe->ToObject(&object)) return maybe;
+ dictionary = SeededNumberDictionary::cast(object);
+ }
- maybe_dictionary = CopyFastElementsToDictionary(
- GetIsolate(), array, length, dictionary);
- if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
+ // Copy the elements to the new backing store.
+ bool has_double_elements = array->IsFixedDoubleArray();
+ for (int i = 0; i < length; i++) {
+ Object* value = NULL;
+ if (has_double_elements) {
+ FixedDoubleArray* double_array = FixedDoubleArray::cast(array);
+ if (double_array->is_the_hole(i)) {
+ value = GetIsolate()->heap()->the_hole_value();
+ } else {
+ // Objects must be allocated in the old object space, since the
+ // overall number of HeapNumbers needed for the conversion might
+ // exceed the capacity of new space, and we would fail repeatedly
+ // trying to convert the FixedDoubleArray.
+ MaybeObject* maybe_value_object =
+ GetHeap()->AllocateHeapNumber(double_array->get_scalar(i), TENURED);
+ if (!maybe_value_object->ToObject(&value)) return maybe_value_object;
+ }
+ } else {
+ ASSERT(old_map->has_fast_smi_or_object_elements());
+ value = FixedArray::cast(array)->get(i);
+ }
+ PropertyDetails details = PropertyDetails(NONE, NORMAL, 0);
+ if (!value->IsTheHole()) {
+ Object* result;
+ MaybeObject* maybe_result =
+ dictionary->AddNumberEntry(i, value, details);
+ if (!maybe_result->ToObject(&result)) return maybe_result;
+ dictionary = SeededNumberDictionary::cast(result);
+ }
+ }
// Switch to using the dictionary as the backing storage for elements.
if (is_arguments) {
@@ -4589,11 +4583,11 @@ MaybeObject* JSObject::NormalizeElements() {
} else {
// Set the new map first to satify the elements type assert in
// set_elements().
- Map* new_map;
+ Object* new_map;
MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(),
DICTIONARY_ELEMENTS);
- if (!maybe->To(&new_map)) return maybe;
- set_map(new_map);
+ if (!maybe->ToObject(&new_map)) return maybe;
+ set_map(Map::cast(new_map));
set_elements(dictionary);
}
@@ -5337,7 +5331,6 @@ MaybeObject* JSObject::PreventExtensions() {
// Do a map transition, other objects with this map may still
// be extensible.
- // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps.
Map* new_map;
MaybeObject* maybe = map()->Copy();
if (!maybe->To(&new_map)) return maybe;
@@ -5349,138 +5342,6 @@ MaybeObject* JSObject::PreventExtensions() {
}
-template<typename Dictionary>
-static void FreezeDictionary(Dictionary* dictionary) {
- int capacity = dictionary->Capacity();
- for (int i = 0; i < capacity; i++) {
- Object* k = dictionary->KeyAt(i);
- if (dictionary->IsKey(k)) {
- PropertyDetails details = dictionary->DetailsAt(i);
- details = details.CopyAddAttributes(FROZEN);
- dictionary->DetailsAtPut(i, details);
- }
- }
-}
-
-
-MUST_USE_RESULT MaybeObject* JSObject::Freeze(Isolate* isolate) {
- // Freezing non-strict arguments should be handled elsewhere.
- ASSERT(!HasNonStrictArgumentsElements());
-
- Heap* heap = isolate->heap();
-
- if (map()->is_frozen()) return this;
-
- if (IsAccessCheckNeeded() &&
- !isolate->MayNamedAccess(this,
- heap->undefined_value(),
- v8::ACCESS_KEYS)) {
- isolate->ReportFailedAccessCheck(this, v8::ACCESS_KEYS);
- return heap->false_value();
- }
-
- if (IsJSGlobalProxy()) {
- Object* proto = GetPrototype();
- if (proto->IsNull()) return this;
- ASSERT(proto->IsJSGlobalObject());
- return JSObject::cast(proto)->Freeze(isolate);
- }
-
- // It's not possible to freeze objects with external array elements
- if (HasExternalArrayElements()) {
- HandleScope scope(isolate);
- Handle<Object> object(this, isolate);
- Handle<Object> error =
- isolate->factory()->NewTypeError(
- "cant_prevent_ext_external_array_elements",
- HandleVector(&object, 1));
- return isolate->Throw(*error);
- }
-
- SeededNumberDictionary* new_element_dictionary = NULL;
- if (!elements()->IsDictionary()) {
- int length = IsJSArray()
- ? Smi::cast(JSArray::cast(this)->length())->value()
- : elements()->length();
- if (length > 0) {
- int capacity = 0;
- int used = 0;
- GetElementsCapacityAndUsage(&capacity, &used);
- MaybeObject* maybe_dict = SeededNumberDictionary::Allocate(heap, used);
- if (!maybe_dict->To(&new_element_dictionary)) return maybe_dict;
-
- // Move elements to a dictionary; avoid calling NormalizeElements to avoid
- // unnecessary transitions.
- maybe_dict = CopyFastElementsToDictionary(isolate, elements(), length,
- new_element_dictionary);
- if (!maybe_dict->To(&new_element_dictionary)) return maybe_dict;
- } else {
- // No existing elements, use a pre-allocated empty backing store
- new_element_dictionary = heap->empty_slow_element_dictionary();
- }
- }
-
- LookupResult result(isolate);
- map()->LookupTransition(this, heap->frozen_symbol(), &result);
- if (result.IsTransition()) {
- Map* transition_map = result.GetTransitionTarget();
- ASSERT(transition_map->has_dictionary_elements());
- ASSERT(transition_map->is_frozen());
- ASSERT(!transition_map->is_extensible());
- set_map(transition_map);
- } else if (HasFastProperties() && map()->CanHaveMoreTransitions()) {
- // Create a new descriptor array with fully-frozen properties
- int num_descriptors = map()->NumberOfOwnDescriptors();
- DescriptorArray* new_descriptors;
- MaybeObject* maybe_descriptors =
- map()->instance_descriptors()->CopyUpToAddAttributes(num_descriptors,
- FROZEN);
- if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors;
-
- Map* new_map;
- MaybeObject* maybe_new_map = map()->CopyReplaceDescriptors(
- new_descriptors, INSERT_TRANSITION, heap->frozen_symbol());
- if (!maybe_new_map->To(&new_map)) return maybe_new_map;
- new_map->freeze();
- new_map->set_is_extensible(false);
- new_map->set_elements_kind(DICTIONARY_ELEMENTS);
- set_map(new_map);
- } else {
- // Slow path: need to normalize properties for safety
- MaybeObject* maybe = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
- if (maybe->IsFailure()) return maybe;
-
- // Create a new map, since other objects with this map may be extensible.
- // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps.
- Map* new_map;
- MaybeObject* maybe_copy = map()->Copy();
- if (!maybe_copy->To(&new_map)) return maybe_copy;
- new_map->freeze();
- new_map->set_is_extensible(false);
- new_map->set_elements_kind(DICTIONARY_ELEMENTS);
- set_map(new_map);
-
- // Freeze dictionary-mode properties
- FreezeDictionary(property_dictionary());
- }
-
- ASSERT(map()->has_dictionary_elements());
- if (new_element_dictionary != NULL) {
- set_elements(new_element_dictionary);
- }
-
- if (elements() != heap->empty_slow_element_dictionary()) {
- SeededNumberDictionary* dictionary = element_dictionary();
- // Make sure we never go back to the fast case
- dictionary->set_requires_slow_elements();
- // Freeze all elements in the dictionary
- FreezeDictionary(dictionary);
- }
-
- return this;
-}
-
-
MUST_USE_RESULT MaybeObject* JSObject::DeepCopy(Isolate* isolate) {
StackLimitCheck check(isolate);
if (check.HasOverflowed()) return isolate->StackOverflow();
@@ -6505,9 +6366,9 @@ MaybeObject* Map::ShareDescriptor(DescriptorArray* descriptors,
MaybeObject* Map::CopyReplaceDescriptors(DescriptorArray* descriptors,
- TransitionFlag flag,
Name* name,
- SimpleTransitionFlag simple_flag) {
+ TransitionFlag flag,
+ int descriptor_index) {
ASSERT(descriptors->IsSortedNoDuplicates());
Map* result;
@@ -6518,8 +6379,14 @@ MaybeObject* Map::CopyReplaceDescriptors(DescriptorArray* descriptors,
if (flag == INSERT_TRANSITION && CanHaveMoreTransitions()) {
TransitionArray* transitions;
+ SimpleTransitionFlag simple_flag =
+ (descriptor_index == descriptors->number_of_descriptors() - 1)
+ ? SIMPLE_TRANSITION
+ : FULL_TRANSITION;
+ ASSERT(name == descriptors->GetKey(descriptor_index));
MaybeObject* maybe_transitions = AddTransition(name, result, simple_flag);
if (!maybe_transitions->To(&transitions)) return maybe_transitions;
+
set_transitions(transitions);
result->SetBackPointer(this);
} else if (flag != OMIT_TRANSITION_KEEP_REPRESENTATIONS) {
@@ -6635,7 +6502,7 @@ MaybeObject* Map::CopyWithPreallocatedFieldDescriptors() {
descriptors->CopyUpTo(number_of_own_descriptors);
if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors;
- return CopyReplaceDescriptors(new_descriptors, OMIT_TRANSITION);
+ return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION, 0);
}
@@ -6647,7 +6514,7 @@ MaybeObject* Map::Copy() {
descriptors->CopyUpTo(number_of_own_descriptors);
if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors;
- return CopyReplaceDescriptors(new_descriptors, OMIT_TRANSITION);
+ return CopyReplaceDescriptors(new_descriptors, NULL, OMIT_TRANSITION, 0);
}
@@ -6688,7 +6555,9 @@ MaybeObject* Map::CopyAddDescriptor(Descriptor* descriptor,
}
Name* key = descriptor->GetKey();
- return CopyReplaceDescriptors(new_descriptors, flag, key, SIMPLE_TRANSITION);
+ int insertion_index = new_descriptors->number_of_descriptors() - 1;
+
+ return CopyReplaceDescriptors(new_descriptors, key, flag, insertion_index);
}
@@ -6709,8 +6578,7 @@ MaybeObject* Map::CopyInsertDescriptor(Descriptor* descriptor,
}
-MaybeObject* DescriptorArray::CopyUpToAddAttributes(
- int enumeration_index, PropertyAttributes attributes) {
+MaybeObject* DescriptorArray::CopyUpTo(int enumeration_index) {
if (enumeration_index == 0) return GetHeap()->empty_descriptor_array();
int size = enumeration_index;
@@ -6720,16 +6588,8 @@ MaybeObject* DescriptorArray::CopyUpToAddAttributes(
if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;
DescriptorArray::WhitenessWitness witness(descriptors);
- if (attributes != NONE) {
- for (int i = 0; i < size; ++i) {
- PropertyDetails details = GetDetails(i).CopyAddAttributes(attributes);
- Descriptor desc(GetKey(i), GetValue(i), details);
- descriptors->Set(i, &desc, witness);
- }
- } else {
- for (int i = 0; i < size; ++i) {
- descriptors->CopyFrom(i, this, i, witness);
- }
+ for (int i = 0; i < size; ++i) {
+ descriptors->CopyFrom(i, this, i, witness);
}
if (number_of_descriptors() != enumeration_index) descriptors->Sort();
@@ -6770,11 +6630,7 @@ MaybeObject* Map::CopyReplaceDescriptor(DescriptorArray* descriptors,
// Re-sort if descriptors were removed.
if (new_size != descriptors->length()) new_descriptors->Sort();
- SimpleTransitionFlag simple_flag =
- (insertion_index == descriptors->number_of_descriptors() - 1)
- ? SIMPLE_TRANSITION
- : FULL_TRANSITION;
- return CopyReplaceDescriptors(new_descriptors, flag, key, simple_flag);
+ return CopyReplaceDescriptors(new_descriptors, key, flag, insertion_index);
}
@@ -13527,13 +13383,13 @@ template class Dictionary<SeededNumberDictionaryShape, uint32_t>;
template class Dictionary<UnseededNumberDictionaryShape, uint32_t>;
template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::
- Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure);
+ Allocate(Heap* heap, int at_least_space_for);
template MaybeObject* Dictionary<UnseededNumberDictionaryShape, uint32_t>::
- Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure);
+ Allocate(Heap* heap, int at_least_space_for);
template MaybeObject* Dictionary<NameDictionaryShape, Name*>::
- Allocate(Heap* heap, int n, PretenureFlag pretenure);
+ Allocate(Heap* heap, int n);
template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::AtPut(
uint32_t, Object*);
@@ -14477,15 +14333,10 @@ MaybeObject* MapCache::Put(FixedArray* array, Map* value) {
template<typename Shape, typename Key>
MaybeObject* Dictionary<Shape, Key>::Allocate(Heap* heap,
- int at_least_space_for,
- PretenureFlag pretenure) {
+ int at_least_space_for) {
Object* obj;
{ MaybeObject* maybe_obj =
- HashTable<Shape, Key>::Allocate(
- heap,
- at_least_space_for,
- HashTable<Shape, Key>::USE_DEFAULT_MINIMUM_CAPACITY,
- pretenure);
+ HashTable<Shape, Key>::Allocate(heap, at_least_space_for);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
// Initialize the next enumeration index.
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698