Revision: 20980
Author:   [email protected]
Date:     Fri Apr 25 13:06:21 2014 UTC
Log:      HashTable::New() handlified.

[email protected]

Review URL: https://codereview.chromium.org/257633002
http://code.google.com/p/v8/source/detail?r=20980

Modified:
 /branches/bleeding_edge/src/compilation-cache.cc
 /branches/bleeding_edge/src/factory.cc
 /branches/bleeding_edge/src/factory.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/cctest/test-dictionary.cc
 /branches/bleeding_edge/test/cctest/test-weakmaps.cc
 /branches/bleeding_edge/test/cctest/test-weaksets.cc

=======================================
--- /branches/bleeding_edge/src/compilation-cache.cc Fri Apr 11 07:27:25 2014 UTC +++ /branches/bleeding_edge/src/compilation-cache.cc Fri Apr 25 13:06:21 2014 UTC
@@ -63,20 +63,13 @@


 CompilationCache::~CompilationCache() {}
-
-
-static Handle<CompilationCacheTable> AllocateTable(Isolate* isolate, int size) {
-  CALL_HEAP_FUNCTION(isolate,
- CompilationCacheTable::Allocate(isolate->heap(), size),
-                     CompilationCacheTable);
-}


Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
   ASSERT(generation < generations_);
   Handle<CompilationCacheTable> result;
   if (tables_[generation]->IsUndefined()) {
-    result = AllocateTable(isolate(), kInitialCacheSize);
+    result = CompilationCacheTable::New(isolate(), kInitialCacheSize);
     tables_[generation] = *result;
   } else {
     CompilationCacheTable* table =
=======================================
--- /branches/bleeding_edge/src/factory.cc      Fri Apr 25 11:00:37 2014 UTC
+++ /branches/bleeding_edge/src/factory.cc      Fri Apr 25 13:06:21 2014 UTC
@@ -139,30 +139,6 @@
 Handle<OrderedHashMap> Factory::NewOrderedHashMap() {
   return OrderedHashMap::Allocate(isolate(), 4);
 }
-
-
-Handle<ObjectHashTable> 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<WeakHashTable> 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<DeoptimizationInputData> Factory::NewDeoptimizationInputData(
@@ -2196,14 +2172,6 @@
   ASSERT(result->shared()->IsApiFunction());
   return result;
 }
-
-
-Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
-  CALL_HEAP_FUNCTION(isolate(),
-                     MapCache::Allocate(isolate()->heap(),
-                                        at_least_space_for),
-                     MapCache);
-}


 Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
@@ -2220,7 +2188,7 @@
                                                Handle<FixedArray> keys) {
   if (context->map_cache()->IsUndefined()) {
     // Allocate the new map cache for the native context.
-    Handle<MapCache> new_cache = NewMapCache(24);
+    Handle<MapCache> new_cache = MapCache::New(isolate(), 24);
     context->set_map_cache(*new_cache);
   }
   // Check to see whether there is a matching element in the cache.
=======================================
--- /branches/bleeding_edge/src/factory.h       Fri Apr 25 11:00:37 2014 UTC
+++ /branches/bleeding_edge/src/factory.h       Fri Apr 25 13:06:21 2014 UTC
@@ -50,15 +50,9 @@
       int number_of_heap_ptr_entries,
       int number_of_int32_entries);

-  Handle<ObjectHashTable> NewObjectHashTable(
-      int at_least_space_for,
-      MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
-
   Handle<OrderedHashSet> NewOrderedHashSet();
   Handle<OrderedHashMap> NewOrderedHashMap();

-  Handle<WeakHashTable> NewWeakHashTable(int at_least_space_for);
-
   Handle<DeoptimizationInputData> NewDeoptimizationInputData(
       int deopt_entry_count,
       PretenureFlag pretenure);
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Apr 25 12:21:32 2014 UTC
+++ /branches/bleeding_edge/src/heap.cc Fri Apr 25 13:06:21 2014 UTC
@@ -5678,7 +5678,8 @@

 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));
   }
 }

=======================================
--- /branches/bleeding_edge/src/objects.cc      Fri Apr 25 12:59:07 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Fri Apr 25 13:06:21 2014 UTC
@@ -5176,9 +5176,8 @@
     return Handle<ObjectHashTable>::cast(inline_value);
   }

- Handle<ObjectHashTable> hashtable = isolate->factory()->NewObjectHashTable(
-      kInitialCapacity,
-      USE_CUSTOM_MINIMUM_CAPACITY);
+  Handle<ObjectHashTable> 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 @@


 template<typename Derived, typename Shape, typename Key>
-MaybeObject* HashTable<Derived, Shape, Key>::Allocate(
-    Heap* heap,
+Handle<Derived> HashTable<Derived, Shape, Key>::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 @@
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<FixedArray> array = factory->NewFixedArray(length, pretenure);
+  array->set_map_no_write_barrier(*factory->hash_table_map());
+  Handle<Derived> table = Handle<Derived>::cast(array);

-
-template<typename Derived, typename Shape, typename Key>
-Handle<Derived> HashTable<Derived, Shape, Key>::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;
 }


=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Apr 25 12:59:07 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Fri Apr 25 13:06:21 2014 UTC
@@ -3712,14 +3712,6 @@
     SetNumberOfElements(NumberOfElements() - n);
     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<Derived> New(
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Fri Apr 25 11:00:37 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Fri Apr 25 13:06:21 2014 UTC
@@ -1732,7 +1732,7 @@
     Isolate* isolate,
     Handle<JSWeakCollection> weak_collection) {
   ASSERT(weak_collection->map()->inobject_properties() == 0);
- Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0);
+  Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 0);
   weak_collection->set_table(*table);
   weak_collection->set_next(Smi::FromInt(0));
   return weak_collection;
=======================================
--- /branches/bleeding_edge/test/cctest/test-dictionary.cc Tue Apr 8 20:06:35 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-dictionary.cc Fri Apr 25 13:06:21 2014 UTC
@@ -106,7 +106,7 @@
   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 @@
 TEST(HashTableRehash) {
   LocalContext context;
   Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
   v8::HandleScope scope(context->GetIsolate());
   // Test almost filled table.
   {
-    Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
+    Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100);
ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
     int capacity = t->capacity();
     for (int i = 0; i < capacity - 1; i++) {
@@ -148,7 +147,7 @@
   }
   // Test half-filled table.
   {
-    Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
+    Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100);
ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
     int capacity = t->capacity();
     for (int i = 0; i < capacity / 2; i++) {
@@ -240,7 +239,7 @@
   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
=======================================
--- /branches/bleeding_edge/test/cctest/test-weakmaps.cc Tue Apr 22 08:30:09 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-weakmaps.cc Fri Apr 25 13:06:21 2014 UTC
@@ -43,14 +43,12 @@

 static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) {
   Factory* factory = isolate->factory();
-  Heap* heap = isolate->heap();
   Handle<Map> map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
   Handle<JSObject> weakmap_obj = factory->NewJSObjectFromMap(map);
   Handle<JSWeakMap> 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<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
+  weakmap->set_table(*table);
   weakmap->set_next(Smi::FromInt(0));
   return weakmap;
 }
=======================================
--- /branches/bleeding_edge/test/cctest/test-weaksets.cc Tue Apr 22 08:30:09 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-weaksets.cc Fri Apr 25 13:06:21 2014 UTC
@@ -43,14 +43,12 @@

 static Handle<JSWeakSet> AllocateJSWeakSet(Isolate* isolate) {
   Factory* factory = isolate->factory();
-  Heap* heap = isolate->heap();
   Handle<Map> map = factory->NewMap(JS_WEAK_SET_TYPE, JSWeakSet::kSize);
   Handle<JSObject> weakset_obj = factory->NewJSObjectFromMap(map);
   Handle<JSWeakSet> 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<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
+  weakset->set_table(*table);
   weakset->set_next(Smi::FromInt(0));
   return weakset;
 }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to