From c8d36c711c6e5ae1ee8c237e151b1108c02d309c Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Fri, 25 Apr 2014 07:56:13 +0000 Subject: [PATCH] Dictionary::New() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/246743003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20957 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/factory.cc | 32 ++---------------------------- src/factory.h | 8 -------- src/heap.cc | 24 +++++++++-------------- src/objects.cc | 51 ++++++++++++------------------------------------ src/objects.h | 6 ------ src/runtime.cc | 5 ++--- src/type-info.cc | 3 +-- 7 files changed, 27 insertions(+), 102 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index eac7ebcc99..2c36ce4873 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -131,35 +131,6 @@ Handle Factory::NewConstantPoolArray( } -Handle Factory::NewNameDictionary(int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - NameDictionary::Allocate(isolate()->heap(), - at_least_space_for), - NameDictionary); -} - - -Handle Factory::NewSeededNumberDictionary( - int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - SeededNumberDictionary::Allocate(isolate()->heap(), - at_least_space_for), - SeededNumberDictionary); -} - - -Handle Factory::NewUnseededNumberDictionary( - int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - UnseededNumberDictionary::Allocate(isolate()->heap(), - at_least_space_for), - UnseededNumberDictionary); -} - - Handle Factory::NewOrderedHashSet() { return OrderedHashSet::Allocate(isolate(), 4); } @@ -1488,7 +1459,8 @@ Handle Factory::NewGlobalObject(Handle constructor) { // Allocate a dictionary object for backing storage. int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size; - Handle dictionary = NewNameDictionary(at_least_space_for); + Handle dictionary = + NameDictionary::New(isolate(), at_least_space_for); // The global object might be created from an object template with accessors. // Fill these accessors into the dictionary. diff --git a/src/factory.h b/src/factory.h index 8549938e61..ae4a6c0991 100644 --- a/src/factory.h +++ b/src/factory.h @@ -50,14 +50,6 @@ class Factory V8_FINAL { int number_of_heap_ptr_entries, int number_of_int32_entries); - Handle NewSeededNumberDictionary( - int at_least_space_for); - - Handle NewUnseededNumberDictionary( - int at_least_space_for); - - Handle NewNameDictionary(int at_least_space_for); - Handle NewObjectHashTable( int at_least_space_for, MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY); diff --git a/src/heap.cc b/src/heap.cc index bb482b80ee..d80e2f93b1 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2916,20 +2916,13 @@ bool Heap::CreateInitialObjects() { } hidden_string_ = String::cast(obj); - // Allocate the code_stubs dictionary. The initial size is set to avoid + // Create the code_stubs dictionary. The initial size is set to avoid // expanding the dictionary during bootstrapping. - { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 128); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_code_stubs(UnseededNumberDictionary::cast(obj)); + set_code_stubs(*UnseededNumberDictionary::New(isolate(), 128)); - - // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size + // Create the non_monomorphic_cache used in stub-cache.cc. The initial size // is set to avoid expanding the dictionary during bootstrapping. - { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 64); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_non_monomorphic_cache(UnseededNumberDictionary::cast(obj)); + set_non_monomorphic_cache(*UnseededNumberDictionary::New(isolate(), 64)); { MaybeObject* maybe_obj = AllocatePolymorphicCodeCache(); if (!maybe_obj->ToObject(&obj)) return false; @@ -3037,11 +3030,12 @@ bool Heap::CreateInitialObjects() { Symbol::cast(obj)->set_is_private(true); set_megamorphic_symbol(Symbol::cast(obj)); - { MaybeObject* maybe_obj = SeededNumberDictionary::Allocate(this, 0, TENURED); - if (!maybe_obj->ToObject(&obj)) return false; + { + Handle dict = + SeededNumberDictionary::New(isolate(), 0, TENURED); + dict->set_requires_slow_elements(); + set_empty_slow_element_dictionary(*dict); } - SeededNumberDictionary::cast(obj)->set_requires_slow_elements(); - set_empty_slow_element_dictionary(SeededNumberDictionary::cast(obj)); { MaybeObject* maybe_obj = AllocateSymbol(); if (!maybe_obj->ToObject(&obj)) return false; diff --git a/src/objects.cc b/src/objects.cc index 1089c15a47..cf2f73ecf0 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -4630,7 +4630,7 @@ void JSObject::NormalizeProperties(Handle object, property_count += 2; // Make space for two more properties. } Handle dictionary = - isolate->factory()->NewNameDictionary(property_count); + NameDictionary::New(isolate, property_count); Handle descs(map->instance_descriptors()); for (int i = 0; i < real_size; i++) { @@ -4853,9 +4853,10 @@ void JSObject::TransformToFastProperties(Handle object, void JSObject::ResetElements(Handle object) { if (object->map()->is_observed()) { // Maintain invariant that observed elements are always in dictionary mode. - Factory* factory = object->GetIsolate()->factory(); + Isolate* isolate = object->GetIsolate(); + Factory* factory = isolate->factory(); Handle dictionary = - factory->NewSeededNumberDictionary(0); + SeededNumberDictionary::New(isolate, 0); if (object->map() == *factory->sloppy_arguments_elements_map()) { FixedArray::cast(object->elements())->set(1, *dictionary); } else { @@ -4910,7 +4911,6 @@ Handle JSObject::NormalizeElements( ASSERT(!object->HasExternalArrayElements() && !object->HasFixedTypedArrayElements()); Isolate* isolate = object->GetIsolate(); - Factory* factory = isolate->factory(); // Find the backing store. Handle array(FixedArrayBase::cast(object->elements())); @@ -4933,7 +4933,7 @@ Handle JSObject::NormalizeElements( int used_elements = 0; object->GetElementsCapacityAndUsage(&old_capacity, &used_elements); Handle dictionary = - factory->NewSeededNumberDictionary(used_elements); + SeededNumberDictionary::New(isolate, used_elements); dictionary = CopyFastElementsToDictionary(array, length, dictionary); @@ -5746,8 +5746,7 @@ MaybeHandle JSObject::Freeze(Handle object) { int capacity = 0; int used = 0; object->GetElementsCapacityAndUsage(&capacity, &used); - new_element_dictionary = - isolate->factory()->NewSeededNumberDictionary(used); + new_element_dictionary = SeededNumberDictionary::New(isolate, used); // Move elements to a dictionary; avoid calling NormalizeElements to avoid // unnecessary transitions. @@ -14897,21 +14896,17 @@ template class Dictionary; -template MaybeObject* +template Handle Dictionary:: - Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); + New(Isolate*, int at_least_space_for, PretenureFlag pretenure); -template MaybeObject* +template Handle Dictionary:: - Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); - -template MaybeObject* -Dictionary >:: - Allocate(Heap* heap, int n, PretenureFlag pretenure); + New(Isolate*, int at_least_space_for, PretenureFlag pretenure); template Handle Dictionary >:: - New(Isolate* isolate, int n, PretenureFlag pretenure); + New(Isolate*, int n, PretenureFlag pretenure); template Handle Dictionary:: @@ -15061,7 +15056,7 @@ Handle JSObject::PrepareSlowElementsForSort( // elements. Handle dict(object->element_dictionary(), isolate); Handle new_dict = - isolate->factory()->NewSeededNumberDictionary(dict->NumberOfElements()); + SeededNumberDictionary::New(isolate, dict->NumberOfElements()); uint32_t pos = 0; uint32_t undefs = 0; @@ -15793,32 +15788,12 @@ Handle MapCache::Put( } -template -MaybeObject* Dictionary::Allocate( - Heap* heap, - int at_least_space_for, - PretenureFlag pretenure) { - Object* obj; - { MaybeObject* maybe_obj = - DerivedHashTable::Allocate( - heap, - at_least_space_for, - USE_DEFAULT_MINIMUM_CAPACITY, - pretenure); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } - // Initialize the next enumeration index. - Dictionary::cast(obj)-> - SetNextEnumerationIndex(PropertyDetails::kInitialIndex); - return obj; -} - - template Handle Dictionary::New( Isolate* isolate, int at_least_space_for, PretenureFlag pretenure) { + ASSERT(0 <= at_least_space_for); Handle dict = DerivedHashTable::New(isolate, at_least_space_for, USE_DEFAULT_MINIMUM_CAPACITY, diff --git a/src/objects.h b/src/objects.h index e313d882c5..502ac80a5a 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4057,12 +4057,6 @@ class Dictionary: public HashTable { return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); } - // Returns a new array for dictionary usage. Might return Failure. - MUST_USE_RESULT static MaybeObject* Allocate( - Heap* heap, - int at_least_space_for, - PretenureFlag pretenure = NOT_TENURED); - // Creates a new dictionary. MUST_USE_RESULT static Handle New( Isolate* isolate, diff --git a/src/runtime.cc b/src/runtime.cc index ca0b99b400..c63a93885d 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -10049,8 +10049,7 @@ class ArrayConcatVisitor { ASSERT(fast_elements_); Handle current_storage(*storage_); Handle slow_storage( - isolate_->factory()->NewSeededNumberDictionary( - current_storage->length())); + SeededNumberDictionary::New(isolate_, current_storage->length())); uint32_t current_length = static_cast(current_storage->length()); for (uint32_t i = 0; i < current_length; i++) { HandleScope loop_scope(isolate_); @@ -10596,7 +10595,7 @@ RUNTIME_FUNCTION(Runtime_ArrayConcat) { uint32_t at_least_space_for = estimate_nof_elements + (estimate_nof_elements >> 2); storage = Handle::cast( - isolate->factory()->NewSeededNumberDictionary(at_least_space_for)); + SeededNumberDictionary::New(isolate, at_least_space_for)); } ArrayConcatVisitor visitor(isolate, storage, fast_case); diff --git a/src/type-info.cc b/src/type-info.cc index ecfe3dae68..25141e7d09 100644 --- a/src/type-info.cc +++ b/src/type-info.cc @@ -445,8 +445,7 @@ void TypeFeedbackOracle::CreateDictionary(Handle code, ZoneList* infos) { AllowHeapAllocation allocation_allowed; Code* old_code = *code; - dictionary_ = - isolate()->factory()->NewUnseededNumberDictionary(infos->length()); + dictionary_ = UnseededNumberDictionary::New(isolate(), infos->length()); RelocateRelocInfos(infos, old_code, *code); }