From 41fad8dbe01639ff77874139d3ec7429dfac58b7 Mon Sep 17 00:00:00 2001 From: yangguo Date: Wed, 5 Aug 2015 04:45:31 -0700 Subject: [PATCH] Revert of Remove serializer-specific hash table size heuristic. (patchset #1 id:1 of https://codereview.chromium.org/1265983006/ ) Reason for revert: This still breaks: https://build.chromium.org/p/client.v8/builders/V8%20Linux64%20GC%20Stress%20-%20custom%20snapshot/builds/1296/steps/Mjsunit/logs/load-proxy Test: mjsunit/strong/load-proxy Flags: --stress-opt --always-opt Command: out/Debug/d8 --test --random-seed=2021532800 --stress-opt --always-opt --nohard-abort --nodead-code-elimination --nofold-constants --enable-slow-asserts --debug-code --verify-heap --harmony-proxies --strong-mode test/mjsunit/strong/load-proxy.js --gc-interval=500 --stress-compaction --concurrent-recompilation-queue-length=64 --concurrent-recompilation-delay=500 --concurrent-recompilation Run #1 Exit code: -11 Result: CRASH Expected outcomes: PASS Duration: 00:00:553 Run #2 Exit code: -11 Result: CRASH Expected outcomes: PASS Duration: 00:00:520 Run #3 Exit code: -11 Result: CRASH Expected outcomes: PASS Duration: 00:00:572 Original issue's description: > Remove serializer-specific hash table size heuristic. > > The heuristic can cause weird behavior when bootstrapping. > The memory savings is not worth this hassle. > > Committed: https://crrev.com/fc80f29a582b758d14aae864232624ca45e47ddc > Cr-Commit-Position: refs/heads/master@{#30019} TBR=ulan@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1268413002 Cr-Commit-Position: refs/heads/master@{#30024} --- src/api.cc | 2 ++ src/bootstrapper.cc | 3 +-- src/isolate.h | 1 + src/objects-inl.h | 7 +++++++ src/objects.cc | 4 +++- src/objects.h | 3 +++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/api.cc b/src/api.cc index 2b874ac488..ceadd4ed8b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -367,12 +367,14 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { base::ElapsedTimer timer; timer.Start(); Isolate::Scope isolate_scope(isolate); + internal_isolate->set_creating_default_snapshot(true); internal_isolate->Init(NULL); Persistent context; i::Snapshot::Metadata metadata; { HandleScope handle_scope(isolate); Local new_context = Context::New(isolate); + internal_isolate->set_creating_default_snapshot(false); context.Reset(isolate, new_context); if (custom_source != NULL) { metadata.set_embeds_script(true); diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 37beeff7dd..c46cc2e525 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2408,8 +2408,7 @@ bool Genesis::InstallNatives(ContextType context_type) { InstallNativeFunctions(); auto function_cache = - ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, - USE_CUSTOM_MINIMUM_CAPACITY); + ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize); native_context()->set_function_cache(*function_cache); // Store the map for the string prototype after the natives has been compiled diff --git a/src/isolate.h b/src/isolate.h index 1451cf58c8..7eac6edd25 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -384,6 +384,7 @@ typedef List DebugObjectCache; V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \ V(PromiseRejectCallback, promise_reject_callback, NULL) \ V(const v8::StartupData*, snapshot_blob, NULL) \ + V(bool, creating_default_snapshot, false) \ ISOLATE_INIT_SIMULATOR_LIST(V) #define THREAD_LOCAL_TOP_ACCESSOR(type, name) \ diff --git a/src/objects-inl.h b/src/objects-inl.h index 3a9fe2991d..ffe4d65afd 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -2996,6 +2996,13 @@ int HashTableBase::ComputeCapacity(int at_least_space_for) { } +int HashTableBase::ComputeCapacityForSerialization(int at_least_space_for) { + const int kMinCapacity = 1; + int capacity = base::bits::RoundUpToPowerOfTwo32(at_least_space_for); + return Max(capacity, kMinCapacity); +} + + template int HashTable::FindEntry(Key key) { return FindEntry(GetIsolate(), key); diff --git a/src/objects.cc b/src/objects.cc index 687426bc76..aea01dc8a9 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -13438,7 +13438,9 @@ Handle HashTable::New( int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) ? at_least_space_for - : ComputeCapacity(at_least_space_for); + : isolate->creating_default_snapshot() + ? ComputeCapacityForSerialization(at_least_space_for) + : ComputeCapacity(at_least_space_for); if (capacity > HashTable::kMaxCapacity) { v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); } diff --git a/src/objects.h b/src/objects.h index 6d052ef3a6..3912d04543 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2950,6 +2950,9 @@ class HashTableBase : public FixedArray { // number of elements. May be more than HashTable::kMaxCapacity. static inline int ComputeCapacity(int at_least_space_for); + // Use a different heuristic to compute capacity when serializing. + static inline int ComputeCapacityForSerialization(int at_least_space_for); + // Tells whether k is a real key. The hole and undefined are not allowed // as keys and can be used to indicate missing or deleted elements. bool IsKey(Object* k) {