From fd02e1220c836e91ede2e6077517738444b06a2b Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Fri, 25 Apr 2014 13:06:21 +0000 Subject: [PATCH] HashTable::New() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/257633002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20980 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compilation-cache.cc | 9 +-------- src/factory.cc | 34 +--------------------------------- src/factory.h | 6 ------ src/heap.cc | 3 ++- src/objects.cc | 40 ++++++++++++++-------------------------- src/objects.h | 8 -------- src/runtime.cc | 2 +- test/cctest/test-dictionary.cc | 9 ++++----- test/cctest/test-weakmaps.cc | 6 ++---- test/cctest/test-weaksets.cc | 6 ++---- 10 files changed, 27 insertions(+), 96 deletions(-) diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc index 8f398e3..fcde232 100644 --- a/src/compilation-cache.cc +++ b/src/compilation-cache.cc @@ -65,18 +65,11 @@ CompilationCache::CompilationCache(Isolate* isolate) CompilationCache::~CompilationCache() {} -static Handle AllocateTable(Isolate* isolate, int size) { - CALL_HEAP_FUNCTION(isolate, - CompilationCacheTable::Allocate(isolate->heap(), size), - CompilationCacheTable); -} - - Handle CompilationSubCache::GetTable(int generation) { ASSERT(generation < generations_); Handle result; if (tables_[generation]->IsUndefined()) { - result = AllocateTable(isolate(), kInitialCacheSize); + result = CompilationCacheTable::New(isolate(), kInitialCacheSize); tables_[generation] = *result; } else { CompilationCacheTable* table = diff --git a/src/factory.cc b/src/factory.cc index 4ca8734..c0c77c5 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -141,30 +141,6 @@ Handle Factory::NewOrderedHashMap() { } -Handle Factory::NewObjectHashTable( - int at_least_space_for, - MinimumCapacity capacity_option) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - ObjectHashTable::Allocate(isolate()->heap(), - at_least_space_for, - capacity_option), - ObjectHashTable); -} - - -Handle Factory::NewWeakHashTable(int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION( - isolate(), - WeakHashTable::Allocate(isolate()->heap(), - at_least_space_for, - USE_DEFAULT_MINIMUM_CAPACITY, - TENURED), - WeakHashTable); -} - - Handle Factory::NewDeoptimizationInputData( int deopt_entry_count, PretenureFlag pretenure) { @@ -2198,14 +2174,6 @@ Handle Factory::CreateApiFunction( } -Handle Factory::NewMapCache(int at_least_space_for) { - CALL_HEAP_FUNCTION(isolate(), - MapCache::Allocate(isolate()->heap(), - at_least_space_for), - MapCache); -} - - Handle Factory::AddToMapCache(Handle context, Handle keys, Handle map) { @@ -2220,7 +2188,7 @@ Handle Factory::ObjectLiteralMapFromCache(Handle context, Handle keys) { if (context->map_cache()->IsUndefined()) { // Allocate the new map cache for the native context. - Handle new_cache = NewMapCache(24); + Handle new_cache = MapCache::New(isolate(), 24); context->set_map_cache(*new_cache); } // Check to see whether there is a matching element in the cache. diff --git a/src/factory.h b/src/factory.h index 8c6ef85..1a230d0 100644 --- a/src/factory.h +++ b/src/factory.h @@ -50,15 +50,9 @@ class Factory V8_FINAL { int number_of_heap_ptr_entries, int number_of_int32_entries); - Handle NewObjectHashTable( - int at_least_space_for, - MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY); - Handle NewOrderedHashSet(); Handle NewOrderedHashMap(); - Handle NewWeakHashTable(int at_least_space_for); - Handle NewDeoptimizationInputData( int deopt_entry_count, PretenureFlag pretenure); diff --git a/src/heap.cc b/src/heap.cc index 561992b..1b0992e 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -5678,7 +5678,8 @@ DependentCode* Heap::LookupWeakObjectToCodeDependency(Object* obj) { void Heap::EnsureWeakObjectToCodeTable() { if (!weak_object_to_code_table()->IsHashTable()) { - set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16)); + set_weak_object_to_code_table(*WeakHashTable::New( + isolate(), 16, USE_DEFAULT_MINIMUM_CAPACITY, TENURED)); } } diff --git a/src/objects.cc b/src/objects.cc index 2fd384d..52b9680 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5176,9 +5176,8 @@ Handle JSObject::GetOrCreateHiddenPropertiesHashtable( return Handle::cast(inline_value); } - Handle hashtable = isolate->factory()->NewObjectHashTable( - kInitialCapacity, - USE_CUSTOM_MINIMUM_CAPACITY); + Handle hashtable = ObjectHashTable::New( + isolate, kInitialCapacity, USE_CUSTOM_MINIMUM_CAPACITY); if (inline_value->IsSmi()) { // We were storing the identity hash inline and now allocated an actual @@ -14585,11 +14584,12 @@ void HashTable::IterateElements(ObjectVisitor* v) { template -MaybeObject* HashTable::Allocate( - Heap* heap, +Handle HashTable::New( + Isolate* isolate, int at_least_space_for, MinimumCapacity capacity_option, PretenureFlag pretenure) { + ASSERT(0 <= at_least_space_for); ASSERT(!capacity_option || IsPowerOf2(at_least_space_for)); int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) ? at_least_space_for @@ -14598,28 +14598,16 @@ MaybeObject* HashTable::Allocate( v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); } - Object* obj; - { MaybeObject* maybe_obj = - heap-> AllocateHashTable(EntryToIndex(capacity), pretenure); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } - HashTable::cast(obj)->SetNumberOfElements(0); - HashTable::cast(obj)->SetNumberOfDeletedElements(0); - HashTable::cast(obj)->SetCapacity(capacity); - return obj; -} - + Factory* factory = isolate->factory(); + int length = EntryToIndex(capacity); + Handle array = factory->NewFixedArray(length, pretenure); + array->set_map_no_write_barrier(*factory->hash_table_map()); + Handle table = Handle::cast(array); -template -Handle HashTable::New( - Isolate* isolate, - int at_least_space_for, - MinimumCapacity capacity_option, - PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( - isolate, - Allocate(isolate->heap(), at_least_space_for, capacity_option, pretenure), - Derived); + table->SetNumberOfElements(0); + table->SetNumberOfDeletedElements(0); + table->SetCapacity(capacity); + return table; } diff --git a/src/objects.h b/src/objects.h index b2b36c1..2970c88 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3713,14 +3713,6 @@ class HashTable: public FixedArray { SetNumberOfDeletedElements(NumberOfDeletedElements() + n); } - // Returns a new HashTable object. Might return Failure. - // TODO(ishell): this will be eventually replaced by New(). - MUST_USE_RESULT static MaybeObject* Allocate( - Heap* heap, - int at_least_space_for, - MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, - PretenureFlag pretenure = NOT_TENURED); - // Returns a new HashTable object. MUST_USE_RESULT static Handle New( Isolate* isolate, diff --git a/src/runtime.cc b/src/runtime.cc index 2e92efb..7bffb21 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1732,7 +1732,7 @@ static Handle WeakCollectionInitialize( Isolate* isolate, Handle weak_collection) { ASSERT(weak_collection->map()->inobject_properties() == 0); - Handle table = isolate->factory()->NewObjectHashTable(0); + Handle table = ObjectHashTable::New(isolate, 0); weak_collection->set_table(*table); weak_collection->set_next(Smi::FromInt(0)); return weak_collection; diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc index fdd35ec..8e218b5 100644 --- a/test/cctest/test-dictionary.cc +++ b/test/cctest/test-dictionary.cc @@ -106,7 +106,7 @@ TEST(HashMap) { LocalContext context; v8::HandleScope scope(context->GetIsolate()); Isolate* isolate = CcTest::i_isolate(); - TestHashMap(isolate->factory()->NewObjectHashTable(23)); + TestHashMap(ObjectHashTable::New(isolate, 23)); TestHashMap(isolate->factory()->NewOrderedHashMap()); } @@ -131,11 +131,10 @@ class ObjectHashTableTest: public ObjectHashTable { TEST(HashTableRehash) { LocalContext context; Isolate* isolate = CcTest::i_isolate(); - Factory* factory = isolate->factory(); v8::HandleScope scope(context->GetIsolate()); // Test almost filled table. { - Handle table = factory->NewObjectHashTable(100); + Handle table = ObjectHashTable::New(isolate, 100); ObjectHashTableTest* t = reinterpret_cast(*table); int capacity = t->capacity(); for (int i = 0; i < capacity - 1; i++) { @@ -148,7 +147,7 @@ TEST(HashTableRehash) { } // Test half-filled table. { - Handle table = factory->NewObjectHashTable(100); + Handle table = ObjectHashTable::New(isolate, 100); ObjectHashTableTest* t = reinterpret_cast(*table); int capacity = t->capacity(); for (int i = 0; i < capacity / 2; i++) { @@ -240,7 +239,7 @@ TEST(ObjectHashTableCausesGC) { LocalContext context; v8::HandleScope scope(context->GetIsolate()); Isolate* isolate = CcTest::i_isolate(); - TestHashMapCausesGC(isolate->factory()->NewObjectHashTable(1)); + TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap()); } #endif diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc index 5eef214..14a5e02 100644 --- a/test/cctest/test-weakmaps.cc +++ b/test/cctest/test-weakmaps.cc @@ -43,14 +43,12 @@ static Isolate* GetIsolateFrom(LocalContext* context) { static Handle AllocateJSWeakMap(Isolate* isolate) { Factory* factory = isolate->factory(); - Heap* heap = isolate->heap(); Handle map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); Handle weakmap_obj = factory->NewJSObjectFromMap(map); Handle weakmap(JSWeakMap::cast(*weakmap_obj)); // Do not use handles for the hash table, it would make entries strong. - Object* table_obj = ObjectHashTable::Allocate(heap, 1)->ToObjectChecked(); - ObjectHashTable* table = ObjectHashTable::cast(table_obj); - weakmap->set_table(table); + Handle table = ObjectHashTable::New(isolate, 1); + weakmap->set_table(*table); weakmap->set_next(Smi::FromInt(0)); return weakmap; } diff --git a/test/cctest/test-weaksets.cc b/test/cctest/test-weaksets.cc index 9fa44c8..a3a9478 100644 --- a/test/cctest/test-weaksets.cc +++ b/test/cctest/test-weaksets.cc @@ -43,14 +43,12 @@ static Isolate* GetIsolateFrom(LocalContext* context) { static Handle AllocateJSWeakSet(Isolate* isolate) { Factory* factory = isolate->factory(); - Heap* heap = isolate->heap(); Handle map = factory->NewMap(JS_WEAK_SET_TYPE, JSWeakSet::kSize); Handle weakset_obj = factory->NewJSObjectFromMap(map); Handle weakset(JSWeakSet::cast(*weakset_obj)); // Do not use handles for the hash table, it would make entries strong. - Object* table_obj = ObjectHashTable::Allocate(heap, 1)->ToObjectChecked(); - ObjectHashTable* table = ObjectHashTable::cast(table_obj); - weakset->set_table(table); + Handle table = ObjectHashTable::New(isolate, 1); + weakset->set_table(*table); weakset->set_next(Smi::FromInt(0)); return weakset; } -- 2.7.4