@@ -2306,9 +2306,8 @@ bool HeapObject::NeedsRehashing() const {
23062306 case TRANSITION_ARRAY_TYPE:
23072307 return TransitionArray::cast (*this ).number_of_entries () > 1 ;
23082308 case ORDERED_HASH_MAP_TYPE:
2309- return OrderedHashMap::cast (*this ).NumberOfElements () > 0 ;
23102309 case ORDERED_HASH_SET_TYPE:
2311- return OrderedHashSet::cast (* this ). NumberOfElements () > 0 ;
2310+ return false ; // We'll rehash from the JSMap or JSSet referencing them.
23122311 case NAME_DICTIONARY_TYPE:
23132312 case GLOBAL_DICTIONARY_TYPE:
23142313 case NUMBER_DICTIONARY_TYPE:
@@ -2318,6 +2317,8 @@ bool HeapObject::NeedsRehashing() const {
23182317 case SMALL_ORDERED_HASH_MAP_TYPE:
23192318 case SMALL_ORDERED_HASH_SET_TYPE:
23202319 case SMALL_ORDERED_NAME_DICTIONARY_TYPE:
2320+ case JS_MAP_TYPE:
2321+ case JS_SET_TYPE:
23212322 return true ;
23222323 default :
23232324 return false ;
@@ -2327,10 +2328,13 @@ bool HeapObject::NeedsRehashing() const {
23272328bool HeapObject::CanBeRehashed () const {
23282329 DCHECK (NeedsRehashing ());
23292330 switch (map ().instance_type ()) {
2331+ case JS_MAP_TYPE:
2332+ case JS_SET_TYPE:
2333+ return true ;
23302334 case ORDERED_HASH_MAP_TYPE:
23312335 case ORDERED_HASH_SET_TYPE:
2336+ UNREACHABLE (); // We'll rehash from the JSMap or JSSet referencing them.
23322337 case ORDERED_NAME_DICTIONARY_TYPE:
2333- // TODO(yangguo): actually support rehashing OrderedHash{Map,Set}.
23342338 return false ;
23352339 case NAME_DICTIONARY_TYPE:
23362340 case GLOBAL_DICTIONARY_TYPE:
@@ -2387,6 +2391,19 @@ void HeapObject::RehashBasedOnMap(LocalIsolateWrapper isolate) {
23872391 case SMALL_ORDERED_HASH_SET_TYPE:
23882392 DCHECK_EQ (0 , SmallOrderedHashSet::cast (*this ).NumberOfElements ());
23892393 break ;
2394+ case ORDERED_HASH_MAP_TYPE:
2395+ case ORDERED_HASH_SET_TYPE:
2396+ UNREACHABLE (); // We'll rehash from the JSMap or JSSet referencing them.
2397+ case JS_MAP_TYPE: {
2398+ DCHECK (isolate.is_main_thread ());
2399+ JSMap::cast (*this ).Rehash (isolate.main_thread ());
2400+ break ;
2401+ }
2402+ case JS_SET_TYPE: {
2403+ DCHECK (isolate.is_main_thread ());
2404+ JSSet::cast (*this ).Rehash (isolate.main_thread ());
2405+ break ;
2406+ }
23902407 case SMALL_ORDERED_NAME_DICTIONARY_TYPE:
23912408 DCHECK_EQ (0 , SmallOrderedNameDictionary::cast (*this ).NumberOfElements ());
23922409 break ;
@@ -7863,6 +7880,13 @@ void JSSet::Clear(Isolate* isolate, Handle<JSSet> set) {
78637880 set->set_table (*table);
78647881}
78657882
7883+ void JSSet::Rehash (Isolate* isolate) {
7884+ Handle<OrderedHashSet> table_handle (OrderedHashSet::cast (table ()), isolate);
7885+ Handle<OrderedHashSet> new_table =
7886+ OrderedHashSet::Rehash (isolate, table_handle).ToHandleChecked ();
7887+ set_table (*new_table);
7888+ }
7889+
78667890void JSMap::Initialize (Handle<JSMap> map, Isolate* isolate) {
78677891 Handle<OrderedHashMap> table = isolate->factory ()->NewOrderedHashMap ();
78687892 map->set_table (*table);
@@ -7874,6 +7898,13 @@ void JSMap::Clear(Isolate* isolate, Handle<JSMap> map) {
78747898 map->set_table (*table);
78757899}
78767900
7901+ void JSMap::Rehash (Isolate* isolate) {
7902+ Handle<OrderedHashMap> table_handle (OrderedHashMap::cast (table ()), isolate);
7903+ Handle<OrderedHashMap> new_table =
7904+ OrderedHashMap::Rehash (isolate, table_handle).ToHandleChecked ();
7905+ set_table (*new_table);
7906+ }
7907+
78777908void JSWeakCollection::Initialize (Handle<JSWeakCollection> weak_collection,
78787909 Isolate* isolate) {
78797910 Handle<EphemeronHashTable> table = EphemeronHashTable::New (isolate, 0 );
0 commit comments