Commit 309bf937 authored by ishell@chromium.org's avatar ishell@chromium.org

Revert "JSObject::NormalizeElements() handlified."

This reverts commit r20146 which broke V8 GC Stress, Mjsunit tests.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20154 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e79ff827
...@@ -4711,59 +4711,70 @@ static Handle<SeededNumberDictionary> CopyFastElementsToDictionary( ...@@ -4711,59 +4711,70 @@ static Handle<SeededNumberDictionary> CopyFastElementsToDictionary(
Handle<SeededNumberDictionary> JSObject::NormalizeElements( Handle<SeededNumberDictionary> JSObject::NormalizeElements(
Handle<JSObject> object) { Handle<JSObject> object) {
ASSERT(!object->HasExternalArrayElements()); CALL_HEAP_FUNCTION(object->GetIsolate(),
Isolate* isolate = object->GetIsolate(); object->NormalizeElements(),
Factory* factory = isolate->factory(); SeededNumberDictionary);
}
MaybeObject* JSObject::NormalizeElements() {
ASSERT(!HasExternalArrayElements());
// Find the backing store. // Find the backing store.
Handle<FixedArrayBase> array(FixedArrayBase::cast(object->elements())); FixedArrayBase* array = FixedArrayBase::cast(elements());
Map* old_map = array->map();
bool is_arguments = bool is_arguments =
(array->map() == isolate->heap()->sloppy_arguments_elements_map()); (old_map == old_map->GetHeap()->sloppy_arguments_elements_map());
if (is_arguments) { if (is_arguments) {
array = handle(FixedArrayBase::cast( array = FixedArrayBase::cast(FixedArray::cast(array)->get(1));
Handle<FixedArray>::cast(array)->get(1)));
} }
if (array->IsDictionary()) return Handle<SeededNumberDictionary>::cast(array); if (array->IsDictionary()) return array;
ASSERT(object->HasFastSmiOrObjectElements() || ASSERT(HasFastSmiOrObjectElements() ||
object->HasFastDoubleElements() || HasFastDoubleElements() ||
object->HasFastArgumentsElements()); HasFastArgumentsElements());
// Compute the effective length and allocate a new backing store. // Compute the effective length and allocate a new backing store.
int length = object->IsJSArray() int length = IsJSArray()
? Smi::cast(Handle<JSArray>::cast(object)->length())->value() ? Smi::cast(JSArray::cast(this)->length())->value()
: array->length(); : array->length();
int old_capacity = 0; int old_capacity = 0;
int used_elements = 0; int used_elements = 0;
object->GetElementsCapacityAndUsage(&old_capacity, &used_elements); GetElementsCapacityAndUsage(&old_capacity, &used_elements);
Handle<SeededNumberDictionary> dictionary = SeededNumberDictionary* dictionary;
factory->NewSeededNumberDictionary(used_elements); MaybeObject* maybe_dictionary =
SeededNumberDictionary::Allocate(GetHeap(), used_elements);
if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
dictionary = CopyFastElementsToDictionary(array, length, dictionary); maybe_dictionary = CopyFastElementsToDictionary(
GetIsolate(), array, length, dictionary);
if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
// Switch to using the dictionary as the backing storage for elements. // Switch to using the dictionary as the backing storage for elements.
if (is_arguments) { if (is_arguments) {
FixedArray::cast(object->elements())->set(1, *dictionary); FixedArray::cast(elements())->set(1, dictionary);
} else { } else {
// Set the new map first to satify the elements type assert in // Set the new map first to satify the elements type assert in
// set_elements(). // set_elements().
Handle<Map> new_map = Map* new_map;
JSObject::GetElementsTransitionMap(object, DICTIONARY_ELEMENTS); MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(),
DICTIONARY_ELEMENTS);
JSObject::MigrateToMap(object, new_map); if (!maybe->To(&new_map)) return maybe;
object->set_elements(*dictionary); // TODO(verwaest): Replace by MigrateToMap.
set_map(new_map);
set_elements(dictionary);
} }
isolate->counters()->elements_to_dictionary()->Increment(); old_map->GetHeap()->isolate()->counters()->elements_to_dictionary()->
Increment();
#ifdef DEBUG #ifdef DEBUG
if (FLAG_trace_normalization) { if (FLAG_trace_normalization) {
PrintF("Object elements have been normalized:\n"); PrintF("Object elements have been normalized:\n");
object->Print(); Print();
} }
#endif #endif
ASSERT(object->HasDictionaryElements() || ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements());
object->HasDictionaryArgumentsElements());
return dictionary; return dictionary;
} }
......
...@@ -2608,6 +2608,8 @@ class JSObject: public JSReceiver { ...@@ -2608,6 +2608,8 @@ class JSObject: public JSReceiver {
static Handle<SeededNumberDictionary> NormalizeElements( static Handle<SeededNumberDictionary> NormalizeElements(
Handle<JSObject> object); Handle<JSObject> object);
MUST_USE_RESULT MaybeObject* NormalizeElements();
// Transform slow named properties to fast variants. // Transform slow named properties to fast variants.
static void TransformToFastProperties(Handle<JSObject> object, static void TransformToFastProperties(Handle<JSObject> object,
int unused_property_fields); int unused_property_fields);
......
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