| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 817befd commit 7ad6cfa
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.19', | ||
| 39 | + 'v8_embedder_string': '-node.20', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2761,8 +2761,12 @@ Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy(int size) { | |||
| 2761 | 2761 | map->set_is_access_check_needed(true); | |
| 2762 | 2762 | map->set_may_have_interesting_symbols(true); | |
| 2763 | 2763 | LOG(isolate(), MapDetails(*map)); | |
| 2764 | - return Handle<JSGlobalProxy>::cast( | ||
| 2764 | + Handle<JSGlobalProxy> proxy = Handle<JSGlobalProxy>::cast( | ||
| 2765 | 2765 | NewJSObjectFromMap(map, AllocationType::kYoung)); | |
| 2766 | + // Create identity hash early in case there is any JS collection containing | ||
| 2767 | + // a global proxy key and needs to be rehashed after deserialization. | ||
| 2768 | + proxy->GetOrCreateIdentityHash(isolate()); | ||
| 2769 | + return proxy; | ||
| 2766 | 2770 | } | |
| 2767 | 2771 | ||
| 2768 | 2772 | void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,7 +191,7 @@ class HeapObject : public Object { | |||
| 191 | 191 | bool CanBeRehashed() const; | |
| 192 | 192 | ||
| 193 | 193 | // Rehash the object based on the layout inferred from its map. | |
| 194 | - void RehashBasedOnMap(ReadOnlyRoots root); | ||
| 194 | + void RehashBasedOnMap(Isolate* isolate); | ||
| 195 | 195 | ||
| 196 | 196 | // Layout description. | |
| 197 | 197 | #define HEAP_OBJECT_FIELDS(V) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ class JSSet : public TorqueGeneratedJSSet<JSSet, JSCollection> { | |||
| 30 | 30 | public: | |
| 31 | 31 | static void Initialize(Handle<JSSet> set, Isolate* isolate); | |
| 32 | 32 | static void Clear(Isolate* isolate, Handle<JSSet> set); | |
| 33 | + void Rehash(Isolate* isolate); | ||
| 33 | 34 | ||
| 34 | 35 | // Dispatched behavior. | |
| 35 | 36 | DECL_PRINTER(JSSet) | |
@@ -56,6 +57,7 @@ class JSMap : public TorqueGeneratedJSMap<JSMap, JSCollection> { | |||
| 56 | 57 | public: | |
| 57 | 58 | static void Initialize(Handle<JSMap> map, Isolate* isolate); | |
| 58 | 59 | static void Clear(Isolate* isolate, Handle<JSMap> map); | |
| 60 | + void Rehash(Isolate* isolate); | ||
| 59 | 61 | ||
| 60 | 62 | // Dispatched behavior. | |
| 61 | 63 | DECL_PRINTER(JSMap) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2305,9 +2305,8 @@ bool HeapObject::NeedsRehashing() const { | |||
| 2305 | 2305 | case TRANSITION_ARRAY_TYPE: | |
| 2306 | 2306 | return TransitionArray::cast(*this).number_of_entries() > 1; | |
| 2307 | 2307 | case ORDERED_HASH_MAP_TYPE: | |
| 2308 | - return OrderedHashMap::cast(*this).NumberOfElements() > 0; | ||
| 2309 | 2308 | case ORDERED_HASH_SET_TYPE: | |
| 2310 | - return OrderedHashSet::cast(*this).NumberOfElements() > 0; | ||
| 2309 | + return false; // We'll rehash from the JSMap or JSSet referencing them. | ||
| 2311 | 2310 | case NAME_DICTIONARY_TYPE: | |
| 2312 | 2311 | case GLOBAL_DICTIONARY_TYPE: | |
| 2313 | 2312 | case NUMBER_DICTIONARY_TYPE: | |
@@ -2317,6 +2316,8 @@ bool HeapObject::NeedsRehashing() const { | |||
| 2317 | 2316 | case SMALL_ORDERED_HASH_MAP_TYPE: | |
| 2318 | 2317 | case SMALL_ORDERED_HASH_SET_TYPE: | |
| 2319 | 2318 | case SMALL_ORDERED_NAME_DICTIONARY_TYPE: | |
| 2319 | + case JS_MAP_TYPE: | ||
| 2320 | + case JS_SET_TYPE: | ||
| 2320 | 2321 | return true; | |
| 2321 | 2322 | default: | |
| 2322 | 2323 | return false; | |
@@ -2326,10 +2327,13 @@ bool HeapObject::NeedsRehashing() const { | |||
| 2326 | 2327 | bool HeapObject::CanBeRehashed() const { | |
| 2327 | 2328 | DCHECK(NeedsRehashing()); | |
| 2328 | 2329 | switch (map().instance_type()) { | |
| 2330 | + case JS_MAP_TYPE: | ||
| 2331 | + case JS_SET_TYPE: | ||
| 2332 | + return true; | ||
| 2329 | 2333 | case ORDERED_HASH_MAP_TYPE: | |
| 2330 | 2334 | case ORDERED_HASH_SET_TYPE: | |
| 2335 | + UNREACHABLE(); // We'll rehash from the JSMap or JSSet referencing them. | ||
| 2331 | 2336 | case ORDERED_NAME_DICTIONARY_TYPE: | |
| 2332 | - // TODO(yangguo): actually support rehashing OrderedHash{Map,Set}. | ||
| 2333 | 2337 | return false; | |
| 2334 | 2338 | case NAME_DICTIONARY_TYPE: | |
| 2335 | 2339 | case GLOBAL_DICTIONARY_TYPE: | |
@@ -2353,7 +2357,8 @@ bool HeapObject::CanBeRehashed() const { | |||
| 2353 | 2357 | return false; | |
| 2354 | 2358 | } | |
| 2355 | 2359 | ||
| 2356 | - void HeapObject::RehashBasedOnMap(ReadOnlyRoots roots) { | ||
| 2360 | + void HeapObject::RehashBasedOnMap(Isolate* isolate) { | ||
| 2361 | + ReadOnlyRoots roots = ReadOnlyRoots(isolate); | ||
| 2357 | 2362 | switch (map().instance_type()) { | |
| 2358 | 2363 | case HASH_TABLE_TYPE: | |
| 2359 | 2364 | UNREACHABLE(); | |
@@ -2385,6 +2390,17 @@ void HeapObject::RehashBasedOnMap(ReadOnlyRoots roots) { | |||
| 2385 | 2390 | case SMALL_ORDERED_HASH_SET_TYPE: | |
| 2386 | 2391 | DCHECK_EQ(0, SmallOrderedHashSet::cast(*this).NumberOfElements()); | |
| 2387 | 2392 | break; | |
| 2393 | + case ORDERED_HASH_MAP_TYPE: | ||
| 2394 | + case ORDERED_HASH_SET_TYPE: | ||
| 2395 | + UNREACHABLE(); // We'll rehash from the JSMap or JSSet referencing them. | ||
| 2396 | + case JS_MAP_TYPE: { | ||
| 2397 | + JSMap::cast(*this).Rehash(isolate); | ||
| 2398 | + break; | ||
| 2399 | + } | ||
| 2400 | + case JS_SET_TYPE: { | ||
| 2401 | + JSSet::cast(*this).Rehash(isolate); | ||
| 2402 | + break; | ||
| 2403 | + } | ||
| 2388 | 2404 | case SMALL_ORDERED_NAME_DICTIONARY_TYPE: | |
| 2389 | 2405 | DCHECK_EQ(0, SmallOrderedNameDictionary::cast(*this).NumberOfElements()); | |
| 2390 | 2406 | break; | |
@@ -7864,6 +7880,13 @@ void JSSet::Clear(Isolate* isolate, Handle<JSSet> set) { | |||
| 7864 | 7880 | set->set_table(*table); | |
| 7865 | 7881 | } | |
| 7866 | 7882 | ||
| 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 | + | ||
| 7867 | 7890 | void JSMap::Initialize(Handle<JSMap> map, Isolate* isolate) { | |
| 7868 | 7891 | Handle<OrderedHashMap> table = isolate->factory()->NewOrderedHashMap(); | |
| 7869 | 7892 | map->set_table(*table); | |
@@ -7875,6 +7898,13 @@ void JSMap::Clear(Isolate* isolate, Handle<JSMap> map) { | |||
| 7875 | 7898 | map->set_table(*table); | |
| 7876 | 7899 | } | |
| 7877 | 7900 | ||
| 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 | + | ||
| 7878 | 7908 | void JSWeakCollection::Initialize(Handle<JSWeakCollection> weak_collection, | |
| 7879 | 7909 | Isolate* isolate) { | |
| 7880 | 7910 | Handle<EphemeronHashTable> table = EphemeronHashTable::New(isolate, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,6 +194,13 @@ HeapObject OrderedHashMap::GetEmpty(ReadOnlyRoots ro_roots) { | |||
| 194 | 194 | return ro_roots.empty_ordered_hash_map(); | |
| 195 | 195 | } | |
| 196 | 196 | ||
| 197 | + template <class Derived, int entrysize> | ||
| 198 | + MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::Rehash( | ||
| 199 | + Isolate* isolate, Handle<Derived> table) { | ||
| 200 | + return OrderedHashTable<Derived, entrysize>::Rehash(isolate, table, | ||
| 201 | + table->Capacity()); | ||
| 202 | + } | ||
| 203 | + | ||
| 197 | 204 | template <class Derived, int entrysize> | |
| 198 | 205 | MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::Rehash( | |
| 199 | 206 | Isolate* isolate, Handle<Derived> table, int new_capacity) { | |
@@ -250,6 +257,20 @@ MaybeHandle<OrderedHashSet> OrderedHashSet::Rehash(Isolate* isolate, | |||
| 250 | 257 | new_capacity); | |
| 251 | 258 | } | |
| 252 | 259 | ||
| 260 | + MaybeHandle<OrderedHashSet> OrderedHashSet::Rehash( | ||
| 261 | + Isolate* isolate, Handle<OrderedHashSet> table) { | ||
| 262 | + return OrderedHashTable< | ||
| 263 | + OrderedHashSet, OrderedHashSet::kEntrySizeWithoutChain>::Rehash(isolate, | ||
| 264 | + table); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + MaybeHandle<OrderedHashMap> OrderedHashMap::Rehash( | ||
| 268 | + Isolate* isolate, Handle<OrderedHashMap> table) { | ||
| 269 | + return OrderedHashTable< | ||
| 270 | + OrderedHashMap, OrderedHashMap::kEntrySizeWithoutChain>::Rehash(isolate, | ||
| 271 | + table); | ||
| 272 | + } | ||
| 273 | + | ||
| 253 | 274 | MaybeHandle<OrderedHashMap> OrderedHashMap::Rehash(Isolate* isolate, | |
| 254 | 275 | Handle<OrderedHashMap> table, | |
| 255 | 276 | int new_capacity) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -138,6 +138,7 @@ class OrderedHashTable : public FixedArray { | |||
| 138 | 138 | ||
| 139 | 139 | // The extra +1 is for linking the bucket chains together. | |
| 140 | 140 | static const int kEntrySize = entrysize + 1; | |
| 141 | + static const int kEntrySizeWithoutChain = entrysize; | ||
| 141 | 142 | static const int kChainOffset = entrysize; | |
| 142 | 143 | ||
| 143 | 144 | static const int kNotFound = -1; | |
@@ -200,6 +201,8 @@ class OrderedHashTable : public FixedArray { | |||
| 200 | 201 | static MaybeHandle<Derived> Allocate( | |
| 201 | 202 | Isolate* isolate, int capacity, | |
| 202 | 203 | AllocationType allocation = AllocationType::kYoung); | |
| 204 | + | ||
| 205 | + static MaybeHandle<Derived> Rehash(Isolate* isolate, Handle<Derived> table); | ||
| 203 | 206 | static MaybeHandle<Derived> Rehash(Isolate* isolate, Handle<Derived> table, | |
| 204 | 207 | int new_capacity); | |
| 205 | 208 | ||
@@ -244,6 +247,8 @@ class V8_EXPORT_PRIVATE OrderedHashSet | |||
| 244 | 247 | static MaybeHandle<OrderedHashSet> Rehash(Isolate* isolate, | |
| 245 | 248 | Handle<OrderedHashSet> table, | |
| 246 | 249 | int new_capacity); | |
| 250 | + static MaybeHandle<OrderedHashSet> Rehash(Isolate* isolate, | ||
| 251 | + Handle<OrderedHashSet> table); | ||
| 247 | 252 | static MaybeHandle<OrderedHashSet> Allocate( | |
| 248 | 253 | Isolate* isolate, int capacity, | |
| 249 | 254 | AllocationType allocation = AllocationType::kYoung); | |
@@ -273,6 +278,8 @@ class V8_EXPORT_PRIVATE OrderedHashMap | |||
| 273 | 278 | static MaybeHandle<OrderedHashMap> Rehash(Isolate* isolate, | |
| 274 | 279 | Handle<OrderedHashMap> table, | |
| 275 | 280 | int new_capacity); | |
| 281 | + static MaybeHandle<OrderedHashMap> Rehash(Isolate* isolate, | ||
| 282 | + Handle<OrderedHashMap> table); | ||
| 276 | 283 | Object ValueAt(int entry); | |
| 277 | 284 | ||
| 278 | 285 | // This takes and returns raw Address values containing tagged Object | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ void Deserializer::Initialize(Isolate* isolate) { | |||
| 70 | 70 | void Deserializer::Rehash() { | |
| 71 | 71 | DCHECK(can_rehash() || deserializing_user_code()); | |
| 72 | 72 | for (HeapObject item : to_rehash_) { | |
| 73 | - item.RehashBasedOnMap(ReadOnlyRoots(isolate_)); | ||
| 73 | + item.RehashBasedOnMap(isolate_); | ||
| 74 | 74 | } | |
| 75 | 75 | } | |
| 76 | 76 | ||
@@ -130,6 +130,14 @@ void Deserializer::DeserializeDeferredObjects() { | |||
| 130 | 130 | } | |
| 131 | 131 | } | |
| 132 | 132 | } | |
| 133 | + | ||
| 134 | + // When the deserialization of maps are deferred, they will be created | ||
| 135 | + // as filler maps, and we postpone the post processing until the maps | ||
| 136 | + // are also deserialized. | ||
| 137 | + for (const auto& pair : fillers_to_post_process_) { | ||
| 138 | + DCHECK(!pair.first.IsFiller()); | ||
| 139 | + PostProcessNewObject(pair.first, pair.second); | ||
| 140 | + } | ||
| 133 | 141 | } | |
| 134 | 142 | ||
| 135 | 143 | void Deserializer::LogNewObjectEvents() { | |
@@ -201,7 +209,11 @@ HeapObject Deserializer::PostProcessNewObject(HeapObject obj, | |||
| 201 | 209 | DisallowHeapAllocation no_gc; | |
| 202 | 210 | ||
| 203 | 211 | if ((FLAG_rehash_snapshot && can_rehash_) || deserializing_user_code()) { | |
| 204 | - if (obj.IsString()) { | ||
| 212 | + if (obj.IsFiller()) { | ||
| 213 | + DCHECK_EQ(fillers_to_post_process_.find(obj), | ||
| 214 | + fillers_to_post_process_.end()); | ||
| 215 | + fillers_to_post_process_.insert({obj, space}); | ||
| 216 | + } else if (obj.IsString()) { | ||
| 205 | 217 | // Uninitialize hash field as we need to recompute the hash. | |
| 206 | 218 | String string = String::cast(obj); | |
| 207 | 219 | string.set_hash_field(String::kEmptyHashField); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,6 +194,11 @@ class V8_EXPORT_PRIVATE Deserializer : public SerializerDeserializer { | |||
| 194 | 194 | // TODO(6593): generalize rehashing, and remove this flag. | |
| 195 | 195 | bool can_rehash_; | |
| 196 | 196 | std::vector<HeapObject> to_rehash_; | |
| 197 | + // Store the objects whose maps are deferred and thus initialized as filler | ||
| 198 | + // maps during deserialization, so that they can be processed later when the | ||
| 199 | + // maps become available. | ||
| 200 | + std::unordered_map<HeapObject, SnapshotSpace, Object::Hasher> | ||
| 201 | + fillers_to_post_process_; | ||
| 197 | 202 | ||
| 198 | 203 | #ifdef DEBUG | |
| 199 | 204 | uint32_t num_api_references_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,9 +48,9 @@ MaybeHandle<HeapObject> ObjectDeserializer::Deserialize(Isolate* isolate) { | |||
| 48 | 48 | LinkAllocationSites(); | |
| 49 | 49 | LogNewMapEvents(); | |
| 50 | 50 | result = handle(HeapObject::cast(root), isolate); | |
| 51 | - Rehash(); | ||
| 52 | 51 | allocator()->RegisterDeserializedObjectsForBlackAllocation(); | |
| 53 | 52 | } | |
| 53 | + Rehash(); | ||
| 54 | 54 | CommitPostProcessedObjects(); | |
| 55 | 55 | return scope.CloseAndEscape(result); | |
| 56 | 56 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments