From e02315ef778dc349c2aa18ba9ea583e39359fc55 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Tue, 12 Mar 2013 07:06:36 +0000 Subject: [PATCH] Added an Isolate parameter to some HashTable/Dictionary methods. TypeFeedbackOracle tweaks. BUG=v8:2487 Review URL: https://codereview.chromium.org/12764003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13908 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compilation-cache.cc | 2 +- src/factory.cc | 19 +++++--- src/heap.cc | 11 +++-- src/objects-inl.h | 11 ++--- src/objects.cc | 50 +++++++++++++-------- src/objects.h | 27 ++++++++---- src/type-info.cc | 15 +++---- src/type-info.h | 2 +- test/cctest/test-weakmaps.cc | 85 +++++++++++++++++++++--------------- 9 files changed, 133 insertions(+), 89 deletions(-) diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc index 904e84fd6..7ace2f7db 100644 --- a/src/compilation-cache.cc +++ b/src/compilation-cache.cc @@ -67,7 +67,7 @@ CompilationCache::~CompilationCache() {} static Handle AllocateTable(Isolate* isolate, int size) { CALL_HEAP_FUNCTION(isolate, - CompilationCacheTable::Allocate(size), + CompilationCacheTable::Allocate(isolate->heap(), size), CompilationCacheTable); } diff --git a/src/factory.cc b/src/factory.cc index 943902e15..9135d542c 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -73,7 +73,8 @@ Handle Factory::NewFixedDoubleArray(int size, Handle Factory::NewNameDictionary(int at_least_space_for) { ASSERT(0 <= at_least_space_for); CALL_HEAP_FUNCTION(isolate(), - NameDictionary::Allocate(at_least_space_for), + NameDictionary::Allocate(isolate()->heap(), + at_least_space_for), NameDictionary); } @@ -82,7 +83,8 @@ Handle Factory::NewSeededNumberDictionary( int at_least_space_for) { ASSERT(0 <= at_least_space_for); CALL_HEAP_FUNCTION(isolate(), - SeededNumberDictionary::Allocate(at_least_space_for), + SeededNumberDictionary::Allocate(isolate()->heap(), + at_least_space_for), SeededNumberDictionary); } @@ -91,7 +93,8 @@ Handle Factory::NewUnseededNumberDictionary( int at_least_space_for) { ASSERT(0 <= at_least_space_for); CALL_HEAP_FUNCTION(isolate(), - UnseededNumberDictionary::Allocate(at_least_space_for), + UnseededNumberDictionary::Allocate(isolate()->heap(), + at_least_space_for), UnseededNumberDictionary); } @@ -99,7 +102,8 @@ Handle Factory::NewUnseededNumberDictionary( Handle Factory::NewObjectHashSet(int at_least_space_for) { ASSERT(0 <= at_least_space_for); CALL_HEAP_FUNCTION(isolate(), - ObjectHashSet::Allocate(at_least_space_for), + ObjectHashSet::Allocate(isolate()->heap(), + at_least_space_for), ObjectHashSet); } @@ -107,7 +111,8 @@ Handle Factory::NewObjectHashSet(int at_least_space_for) { Handle Factory::NewObjectHashTable(int at_least_space_for) { ASSERT(0 <= at_least_space_for); CALL_HEAP_FUNCTION(isolate(), - ObjectHashTable::Allocate(at_least_space_for), + ObjectHashTable::Allocate(isolate()->heap(), + at_least_space_for), ObjectHashTable); } @@ -1364,7 +1369,9 @@ Handle Factory::CreateApiFunction( Handle Factory::NewMapCache(int at_least_space_for) { CALL_HEAP_FUNCTION(isolate(), - MapCache::Allocate(at_least_space_for), MapCache); + MapCache::Allocate(isolate()->heap(), + at_least_space_for), + MapCache); } diff --git a/src/heap.cc b/src/heap.cc index 4f85705fc..fe1783d02 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2749,7 +2749,8 @@ bool Heap::CreateInitialObjects() { set_the_hole_value(reinterpret_cast(Smi::FromInt(0))); // Allocate initial string table. - { MaybeObject* maybe_obj = StringTable::Allocate(kInitialStringTableSize); + { MaybeObject* maybe_obj = + StringTable::Allocate(this, kInitialStringTableSize); if (!maybe_obj->ToObject(&obj)) return false; } // Don't use set_string_table() due to asserts. @@ -2840,7 +2841,7 @@ bool Heap::CreateInitialObjects() { // Allocate the code_stubs dictionary. The initial size is set to avoid // expanding the dictionary during bootstrapping. - { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(128); + { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 128); if (!maybe_obj->ToObject(&obj)) return false; } set_code_stubs(UnseededNumberDictionary::cast(obj)); @@ -2848,7 +2849,7 @@ bool Heap::CreateInitialObjects() { // Allocate 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(64); + { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 64); if (!maybe_obj->ToObject(&obj)) return false; } set_non_monomorphic_cache(UnseededNumberDictionary::cast(obj)); @@ -2865,7 +2866,8 @@ bool Heap::CreateInitialObjects() { CreateFixedStubs(); // Allocate the dictionary of intrinsic function names. - { MaybeObject* maybe_obj = NameDictionary::Allocate(Runtime::kNumFunctions); + { MaybeObject* maybe_obj = + NameDictionary::Allocate(this, Runtime::kNumFunctions); if (!maybe_obj->ToObject(&obj)) return false; } { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, @@ -4524,6 +4526,7 @@ MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { NameDictionary* dictionary; MaybeObject* maybe_dictionary = NameDictionary::Allocate( + this, map->NumberOfOwnDescriptors() * 2 + initial_size); if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; diff --git a/src/objects-inl.h b/src/objects-inl.h index ec9748439..f2add26cf 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1453,7 +1453,7 @@ MaybeObject* JSObject::ResetElements() { if (map()->is_observed()) { // Maintain invariant that observed elements are always in dictionary mode. SeededNumberDictionary* dictionary; - MaybeObject* maybe = SeededNumberDictionary::Allocate(0); + MaybeObject* maybe = SeededNumberDictionary::Allocate(GetHeap(), 0); if (!maybe->To(&dictionary)) return maybe; if (map() == GetHeap()->non_strict_arguments_elements_map()) { FixedArray::cast(elements())->set(1, dictionary); @@ -5630,8 +5630,8 @@ uint32_t SeededNumberDictionaryShape::SeededHashForObject(uint32_t key, return ComputeIntegerHash(static_cast(other->Number()), seed); } -MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { - return Isolate::Current()->heap()->NumberFromUint32(key); +MaybeObject* NumberDictionaryShape::AsObject(Isolate* isolate, uint32_t key) { + return isolate->heap()->NumberFromUint32(key); } @@ -5653,7 +5653,7 @@ uint32_t NameDictionaryShape::HashForObject(Name* key, Object* other) { } -MaybeObject* NameDictionaryShape::AsObject(Name* key) { +MaybeObject* NameDictionaryShape::AsObject(Isolate* isolate, Name* key) { return key; } @@ -5680,7 +5680,8 @@ uint32_t ObjectHashTableShape::HashForObject(Object* key, template -MaybeObject* ObjectHashTableShape::AsObject(Object* key) { +MaybeObject* ObjectHashTableShape::AsObject(Isolate* isolate, + Object* key) { return key; } diff --git a/src/objects.cc b/src/objects.cc index 72d0dadec..8c0189a2b 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -3725,7 +3725,8 @@ MaybeObject* JSObject::NormalizeProperties(PropertyNormalizationMode mode, property_count += 2; // Make space for two more properties. } NameDictionary* dictionary; - MaybeObject* maybe_dictionary = NameDictionary::Allocate(property_count); + MaybeObject* maybe_dictionary = + NameDictionary::Allocate(GetHeap(), property_count); if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; DescriptorArray* descs = map_of_this->instance_descriptors(); @@ -3863,7 +3864,8 @@ MaybeObject* JSObject::NormalizeElements() { GetElementsCapacityAndUsage(&old_capacity, &used_elements); SeededNumberDictionary* dictionary = NULL; { Object* object; - MaybeObject* maybe = SeededNumberDictionary::Allocate(used_elements); + MaybeObject* maybe = + SeededNumberDictionary::Allocate(GetHeap(), used_elements); if (!maybe->ToObject(&object)) return maybe; dictionary = SeededNumberDictionary::cast(object); } @@ -4149,7 +4151,8 @@ MaybeObject* JSObject::GetHiddenPropertiesHashTable( ObjectHashTable* hashtable; static const int kInitialCapacity = 4; MaybeObject* maybe_obj = - ObjectHashTable::Allocate(kInitialCapacity, + ObjectHashTable::Allocate(GetHeap(), + kInitialCapacity, ObjectHashTable::USE_CUSTOM_MINIMUM_CAPACITY); if (!maybe_obj->To(&hashtable)) return maybe_obj; @@ -6036,7 +6039,8 @@ MaybeObject* CodeCache::Update(Name* name, Code* code) { if (normal_type_cache()->IsUndefined()) { Object* result; { MaybeObject* maybe_result = - CodeCacheHashTable::Allocate(CodeCacheHashTable::kInitialSize); + CodeCacheHashTable::Allocate(GetHeap(), + CodeCacheHashTable::kInitialSize); if (!maybe_result->ToObject(&result)) return maybe_result; } set_normal_type_cache(result); @@ -6317,6 +6321,7 @@ MaybeObject* PolymorphicCodeCache::Update(MapHandleList* maps, Object* result; { MaybeObject* maybe_result = PolymorphicCodeCacheHashTable::Allocate( + GetHeap(), PolymorphicCodeCacheHashTable::kInitialSize); if (!maybe_result->ToObject(&result)) return maybe_result; } @@ -12078,7 +12083,8 @@ void HashTable::IterateElements(ObjectVisitor* v) { template -MaybeObject* HashTable::Allocate(int at_least_space_for, +MaybeObject* HashTable::Allocate(Heap* heap, + int at_least_space_for, MinimumCapacity capacity_option, PretenureFlag pretenure) { ASSERT(!capacity_option || IS_POWER_OF_TWO(at_least_space_for)); @@ -12090,8 +12096,8 @@ MaybeObject* HashTable::Allocate(int at_least_space_for, } Object* obj; - { MaybeObject* maybe_obj = Isolate::Current()->heap()-> - AllocateHashTable(EntryToIndex(capacity), pretenure); + { MaybeObject* maybe_obj = + heap-> AllocateHashTable(EntryToIndex(capacity), pretenure); if (!maybe_obj->ToObject(&obj)) return maybe_obj; } HashTable::cast(obj)->SetNumberOfElements(0); @@ -12193,7 +12199,8 @@ MaybeObject* HashTable::EnsureCapacity(int n, Key key) { (capacity > kMinCapacityForPretenure) && !GetHeap()->InNewSpace(this); Object* obj; { MaybeObject* maybe_obj = - Allocate(nof * 2, + Allocate(GetHeap(), + nof * 2, USE_DEFAULT_MINIMUM_CAPACITY, pretenure ? TENURED : NOT_TENURED); if (!maybe_obj->ToObject(&obj)) return maybe_obj; @@ -12224,7 +12231,8 @@ MaybeObject* HashTable::Shrink(Key key) { !GetHeap()->InNewSpace(this); Object* obj; { MaybeObject* maybe_obj = - Allocate(at_least_room_for, + Allocate(GetHeap(), + at_least_room_for, USE_DEFAULT_MINIMUM_CAPACITY, pretenure ? TENURED : NOT_TENURED); if (!maybe_obj->ToObject(&obj)) return maybe_obj; @@ -12268,12 +12276,13 @@ template class Dictionary; template class Dictionary; template MaybeObject* Dictionary:: - Allocate(int at_least_space_for); + Allocate(Heap* heap, int at_least_space_for); template MaybeObject* Dictionary:: - Allocate(int at_least_space_for); + Allocate(Heap* heap, int at_least_space_for); -template MaybeObject* Dictionary::Allocate(int n); +template MaybeObject* Dictionary:: + Allocate(Heap* heap, int n); template MaybeObject* Dictionary::AtPut( uint32_t, Object*); @@ -12379,7 +12388,7 @@ MaybeObject* JSObject::PrepareSlowElementsForSort(uint32_t limit) { Object* obj; { MaybeObject* maybe_obj = - SeededNumberDictionary::Allocate(dict->NumberOfElements()); + SeededNumberDictionary::Allocate(GetHeap(), dict->NumberOfElements()); if (!maybe_obj->ToObject(&obj)) return maybe_obj; } SeededNumberDictionary* new_dict = SeededNumberDictionary::cast(obj); @@ -13163,10 +13172,11 @@ MaybeObject* MapCache::Put(FixedArray* array, Map* value) { template -MaybeObject* Dictionary::Allocate(int at_least_space_for) { +MaybeObject* Dictionary::Allocate(Heap* heap, + int at_least_space_for) { Object* obj; { MaybeObject* maybe_obj = - HashTable::Allocate(at_least_space_for); + HashTable::Allocate(heap, at_least_space_for); if (!maybe_obj->ToObject(&obj)) return maybe_obj; } // Initialize the next enumeration index. @@ -13294,7 +13304,7 @@ MaybeObject* Dictionary::AtPut(Key key, Object* value) { } Object* k; - { MaybeObject* maybe_k = Shape::AsObject(key); + { MaybeObject* maybe_k = Shape::AsObject(this->GetIsolate(), key); if (!maybe_k->ToObject(&k)) return maybe_k; } PropertyDetails details = PropertyDetails(NONE, NORMAL); @@ -13331,7 +13341,7 @@ MaybeObject* Dictionary::AddEntry(Key key, uint32_t hash) { // Compute the key object. Object* k; - { MaybeObject* maybe_k = Shape::AsObject(key); + { MaybeObject* maybe_k = Shape::AsObject(this->GetIsolate(), key); if (!maybe_k->ToObject(&k)) return maybe_k; } @@ -13431,7 +13441,8 @@ MaybeObject* SeededNumberDictionary::Set(uint32_t key, details = PropertyDetails(details.attributes(), details.type(), DetailsAt(entry).dictionary_index()); - MaybeObject* maybe_object_key = SeededNumberDictionaryShape::AsObject(key); + MaybeObject* maybe_object_key = + SeededNumberDictionaryShape::AsObject(GetIsolate(), key); Object* object_key; if (!maybe_object_key->ToObject(&object_key)) return maybe_object_key; SetEntry(entry, object_key, value, details); @@ -13443,7 +13454,8 @@ MaybeObject* UnseededNumberDictionary::Set(uint32_t key, Object* value) { int entry = FindEntry(key); if (entry == kNotFound) return AddNumberEntry(key, value); - MaybeObject* maybe_object_key = UnseededNumberDictionaryShape::AsObject(key); + MaybeObject* maybe_object_key = + UnseededNumberDictionaryShape::AsObject(GetIsolate(), key); Object* object_key; if (!maybe_object_key->ToObject(&object_key)) return maybe_object_key; SetEntry(entry, object_key, value); diff --git a/src/objects.h b/src/objects.h index a1b07f050..991f68f8e 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2887,7 +2887,7 @@ inline int Search(T* array, Name* name, int valid_entries = 0); // // Returns the hash value for object. // static uint32_t HashForObject(Key key, Object* object); // // Convert key to an object. -// static inline Object* AsObject(Key key); +// static inline Object* AsObject(Isolate* isolate, Key key); // // The prefix size indicates number of elements in the beginning // // of the backing storage. // static const int kPrefixSize = ..; @@ -2973,6 +2973,7 @@ class HashTable: public FixedArray { // Returns a new HashTable object. Might return Failure. MUST_USE_RESULT static MaybeObject* Allocate( + Heap* heap, int at_least_space_for, MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, PretenureFlag pretenure = NOT_TENURED); @@ -3112,7 +3113,8 @@ class StringTableShape : public BaseShape { static inline uint32_t HashForObject(HashTableKey* key, Object* object) { return key->HashForObject(object); } - MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { + MUST_USE_RESULT static inline MaybeObject* AsObject(Isolate* isolate, + HashTableKey* key) { return key->AsObject(); } @@ -3179,7 +3181,8 @@ class MapCacheShape : public BaseShape { return key->HashForObject(object); } - MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { + MUST_USE_RESULT static inline MaybeObject* AsObject(Isolate* isolate, + HashTableKey* key) { return key->AsObject(); } @@ -3268,7 +3271,8 @@ class Dictionary: public HashTable { } // Returns a new array for dictionary usage. Might return Failure. - MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); + MUST_USE_RESULT static MaybeObject* Allocate(Heap* heap, + int at_least_space_for); // Ensure enough space for n additional elements. MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); @@ -3318,7 +3322,8 @@ class NameDictionaryShape : public BaseShape { static inline bool IsMatch(Name* key, Object* other); static inline uint32_t Hash(Name* key); static inline uint32_t HashForObject(Name* key, Object* object); - MUST_USE_RESULT static inline MaybeObject* AsObject(Name* key); + MUST_USE_RESULT static inline MaybeObject* AsObject(Isolate* isolate, + Name* key); static const int kPrefixSize = 2; static const int kEntrySize = 3; static const bool kIsEnumerable = true; @@ -3351,7 +3356,8 @@ class NameDictionary: public Dictionary { class NumberDictionaryShape : public BaseShape { public: static inline bool IsMatch(uint32_t key, Object* other); - MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); + MUST_USE_RESULT static inline MaybeObject* AsObject(Isolate* isolate, + uint32_t key); static const int kEntrySize = 3; static const bool kIsEnumerable = false; }; @@ -3455,7 +3461,8 @@ class ObjectHashTableShape : public BaseShape { static inline bool IsMatch(Object* key, Object* other); static inline uint32_t Hash(Object* key); static inline uint32_t HashForObject(Object* key, Object* object); - MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); + MUST_USE_RESULT static inline MaybeObject* AsObject(Isolate* isolate, + Object* key); static const int kPrefixSize = 0; static const int kEntrySize = entrysize; }; @@ -6906,7 +6913,8 @@ class CompilationCacheShape : public BaseShape { return key->HashForObject(object); } - MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { + MUST_USE_RESULT static MaybeObject* AsObject(Isolate* isolate, + HashTableKey* key) { return key->AsObject(); } @@ -7008,7 +7016,8 @@ class CodeCacheHashTableShape : public BaseShape { return key->HashForObject(object); } - MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { + MUST_USE_RESULT static MaybeObject* AsObject(Isolate* isolate, + HashTableKey* key) { return key->AsObject(); } diff --git a/src/type-info.cc b/src/type-info.cc index 857a55dac..6ac05547a 100644 --- a/src/type-info.cc +++ b/src/type-info.cc @@ -62,10 +62,10 @@ TypeInfo TypeInfo::TypeFromValue(Handle value) { TypeFeedbackOracle::TypeFeedbackOracle(Handle code, Handle native_context, Isolate* isolate, - Zone* zone) { - native_context_ = native_context; - isolate_ = isolate; - zone_ = zone; + Zone* zone) + : native_context_(native_context), + isolate_(isolate), + zone_(zone) { BuildDictionary(code); ASSERT(reinterpret_cast
(*dictionary_.location()) != kHandleZapValue); } @@ -167,7 +167,7 @@ bool TypeFeedbackOracle::CallNewIsMonomorphic(CallNew* expr) { if (info->IsSmi()) { ASSERT(static_cast(Smi::cast(*info)->value()) <= LAST_FAST_ELEMENTS_KIND); - return Isolate::Current()->global_context()->array_function(); + return isolate_->global_context()->array_function(); } return info->IsJSFunction(); } @@ -310,8 +310,7 @@ Handle TypeFeedbackOracle::GetCallNewTarget(CallNew* expr) { if (info->IsSmi()) { ASSERT(static_cast(Smi::cast(*info)->value()) <= LAST_FAST_ELEMENTS_KIND); - return Handle(Isolate::Current()->global_context()-> - array_function()); + return Handle(isolate_->global_context()->array_function()); } else { return Handle::cast(info); } @@ -638,7 +637,7 @@ byte TypeFeedbackOracle::ToBooleanTypes(TypeFeedbackId ast_id) { void TypeFeedbackOracle::BuildDictionary(Handle code) { AssertNoAllocation no_allocation; ZoneList infos(16, zone()); - HandleScope scope(code->GetIsolate()); + HandleScope scope(isolate_); GetRelocInfos(code, &infos); CreateDictionary(code, &infos); ProcessRelocInfos(&infos); diff --git a/src/type-info.h b/src/type-info.h index 1e9064517..583c3fc52 100644 --- a/src/type-info.h +++ b/src/type-info.h @@ -336,8 +336,8 @@ class TypeFeedbackOracle: public ZoneObject { private: Handle native_context_; Isolate* isolate_; - Handle dictionary_; Zone* zone_; + Handle dictionary_; DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); }; diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc index cd333d384..714c8ccec 100644 --- a/test/cctest/test-weakmaps.cc +++ b/test/cctest/test-weakmaps.cc @@ -39,12 +39,14 @@ static Isolate* GetIsolateFrom(LocalContext* context) { } -static Handle AllocateJSWeakMap() { - Handle map = FACTORY->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); - Handle weakmap_obj = FACTORY->NewJSObjectFromMap(map); +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(1)->ToObjectChecked(); + Object* table_obj = ObjectHashTable::Allocate(heap, 1)->ToObjectChecked(); ObjectHashTable* table = ObjectHashTable::cast(table_obj); weakmap->set_table(table); weakmap->set_next(Smi::FromInt(0)); @@ -74,16 +76,19 @@ static void WeakPointerCallback(v8::Isolate* isolate, TEST(Weakness) { FLAG_incremental_marking = false; LocalContext context; + Isolate* isolate = GetIsolateFrom(&context); + Factory* factory = isolate->factory(); + Heap* heap = isolate->heap(); v8::HandleScope scope; - Handle weakmap = AllocateJSWeakMap(); - GlobalHandles* global_handles = GetIsolateFrom(&context)->global_handles(); + Handle weakmap = AllocateJSWeakMap(isolate); + GlobalHandles* global_handles = isolate->global_handles(); // Keep global reference to the key. Handle key; { v8::HandleScope scope; - Handle map = FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - Handle object = FACTORY->NewJSObjectFromMap(map); + Handle map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); + Handle object = factory->NewJSObjectFromMap(map); key = global_handles->Create(*object); } CHECK(!global_handles->IsWeak(key.location())); @@ -93,12 +98,12 @@ TEST(Weakness) { v8::HandleScope scope; PutIntoWeakMap(weakmap, Handle(JSObject::cast(*key)), - Handle(Smi::FromInt(23), GetIsolateFrom(&context))); + Handle(Smi::FromInt(23), isolate)); } CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); // Force a full GC. - HEAP->CollectAllGarbage(false); + heap->CollectAllGarbage(false); CHECK_EQ(0, NumberOfWeakCalls); CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( @@ -117,12 +122,12 @@ TEST(Weakness) { // Force a full GC. // Perform two consecutive GCs because the first one will only clear // weak references whereas the second one will also clear weak maps. - HEAP->CollectAllGarbage(false); + heap->CollectAllGarbage(false); CHECK_EQ(1, NumberOfWeakCalls); CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); - HEAP->CollectAllGarbage(false); + heap->CollectAllGarbage(false); CHECK_EQ(1, NumberOfWeakCalls); CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( @@ -132,8 +137,11 @@ TEST(Weakness) { TEST(Shrinking) { LocalContext context; + Isolate* isolate = GetIsolateFrom(&context); + Factory* factory = isolate->factory(); + Heap* heap = isolate->heap(); v8::HandleScope scope; - Handle weakmap = AllocateJSWeakMap(); + Handle weakmap = AllocateJSWeakMap(isolate); // Check initial capacity. CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); @@ -141,11 +149,10 @@ TEST(Shrinking) { // Fill up weak map to trigger capacity change. { v8::HandleScope scope; - Handle map = FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); + Handle map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); for (int i = 0; i < 32; i++) { - Handle object = FACTORY->NewJSObjectFromMap(map); - PutIntoWeakMap(weakmap, object, - Handle(Smi::FromInt(i), GetIsolateFrom(&context))); + Handle object = factory->NewJSObjectFromMap(map); + PutIntoWeakMap(weakmap, object, Handle(Smi::FromInt(i), isolate)); } } @@ -156,7 +163,7 @@ TEST(Shrinking) { CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); - HEAP->CollectAllGarbage(false); + heap->CollectAllGarbage(false); CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); @@ -171,22 +178,25 @@ TEST(Shrinking) { TEST(Regress2060a) { FLAG_always_compact = true; LocalContext context; + Isolate* isolate = GetIsolateFrom(&context); + Factory* factory = isolate->factory(); + Heap* heap = isolate->heap(); v8::HandleScope scope; Handle function = - FACTORY->NewFunction(FACTORY->function_string(), FACTORY->null_value()); - Handle key = FACTORY->NewJSObject(function); - Handle weakmap = AllocateJSWeakMap(); + factory->NewFunction(factory->function_string(), factory->null_value()); + Handle key = factory->NewJSObject(function); + Handle weakmap = AllocateJSWeakMap(isolate); // Start second old-space page so that values land on evacuation candidate. - Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); - FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); + Page* first_page = heap->old_pointer_space()->anchor()->next_page(); + factory->NewFixedArray(900 * KB / kPointerSize, TENURED); // Fill up weak map with values on an evacuation candidate. { v8::HandleScope scope; for (int i = 0; i < 32; i++) { - Handle object = FACTORY->NewJSObject(function, TENURED); - CHECK(!HEAP->InNewSpace(object->address())); + Handle object = factory->NewJSObject(function, TENURED); + CHECK(!heap->InNewSpace(object->address())); CHECK(!first_page->Contains(object->address())); PutIntoWeakMap(weakmap, key, object); } @@ -194,7 +204,7 @@ TEST(Regress2060a) { // Force compacting garbage collection. CHECK(FLAG_always_compact); - HEAP->CollectAllGarbage(Heap::kNoGCFlags); + heap->CollectAllGarbage(Heap::kNoGCFlags); } @@ -207,32 +217,35 @@ TEST(Regress2060b) { #endif LocalContext context; + Isolate* isolate = GetIsolateFrom(&context); + Factory* factory = isolate->factory(); + Heap* heap = isolate->heap(); v8::HandleScope scope; Handle function = - FACTORY->NewFunction(FACTORY->function_string(), FACTORY->null_value()); + factory->NewFunction(factory->function_string(), factory->null_value()); // Start second old-space page so that keys land on evacuation candidate. - Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); - FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); + Page* first_page = heap->old_pointer_space()->anchor()->next_page(); + factory->NewFixedArray(900 * KB / kPointerSize, TENURED); // Fill up weak map with keys on an evacuation candidate. Handle keys[32]; for (int i = 0; i < 32; i++) { - keys[i] = FACTORY->NewJSObject(function, TENURED); - CHECK(!HEAP->InNewSpace(keys[i]->address())); + keys[i] = factory->NewJSObject(function, TENURED); + CHECK(!heap->InNewSpace(keys[i]->address())); CHECK(!first_page->Contains(keys[i]->address())); } - Handle weakmap = AllocateJSWeakMap(); + Handle weakmap = AllocateJSWeakMap(isolate); for (int i = 0; i < 32; i++) { PutIntoWeakMap(weakmap, keys[i], - Handle(Smi::FromInt(i), GetIsolateFrom(&context))); + Handle(Smi::FromInt(i), isolate)); } // Force compacting garbage collection. The subsequent collections are used // to verify that key references were actually updated. CHECK(FLAG_always_compact); - HEAP->CollectAllGarbage(Heap::kNoGCFlags); - HEAP->CollectAllGarbage(Heap::kNoGCFlags); - HEAP->CollectAllGarbage(Heap::kNoGCFlags); + heap->CollectAllGarbage(Heap::kNoGCFlags); + heap->CollectAllGarbage(Heap::kNoGCFlags); + heap->CollectAllGarbage(Heap::kNoGCFlags); } -- 2.34.1