Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Unified Diff: src/heap.cc

Issue 9235029: Flush number string cache on GC (bug 1605). Also start with a small (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 10495)
+++ src/heap.cc (working copy)
@@ -896,8 +896,7 @@
CompletelyClearInstanceofCache();
- // TODO(1605) select heuristic for flushing NumberString cache with
- // FlushNumberStringCache
+ FlushNumberStringCache();
Michael Starzinger 2012/01/25 13:00:56 If it's intentional that the new heuristic for flu
Erik Corry 2012/01/25 14:37:26 Done.
if (FLAG_cleanup_code_caches_at_gc) {
polymorphic_code_cache()->set_cache(undefined_value());
}
@@ -2506,7 +2505,10 @@
}
set_intrinsic_function_names(StringDictionary::cast(obj));
- if (InitializeNumberStringCache()->IsFailure()) return false;
+ { MaybeObject* maybe_obj = AllocateInitialNumberStringCache();
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_number_string_cache(FixedArray::cast(obj));
// Allocate cache for single character ASCII strings.
{ MaybeObject* maybe_obj =
@@ -2616,17 +2618,35 @@
}
-MaybeObject* Heap::InitializeNumberStringCache() {
+MaybeObject* Heap::AllocateInitialNumberStringCache() {
+ MaybeObject* maybe_obj =
+ AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED);
+ return maybe_obj;
+}
+
+
+int Heap::FullSizeNumberStringCacheLength() {
// Compute the size of the number string cache based on the max heap size.
// max_semispace_size_ == 512 KB => number_string_cache_size = 32.
Michael Starzinger 2012/01/25 13:00:56 This comment no longer is on sync with the computa
Erik Corry 2012/01/25 14:37:26 Done.
// max_semispace_size_ == 8 MB => number_string_cache_size = 16KB.
int number_string_cache_size = max_semispace_size_ / 512;
- number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size));
- Object* obj;
+ number_string_cache_size = Max(kInitialNumberStringCacheSize * 2,
Michael Starzinger 2012/01/25 13:00:56 The constant is multiplied with 2 twice. I think w
Erik Corry 2012/01/25 14:37:26 The first multiplication is there to ensure that t
+ Min(16*KB, number_string_cache_size));
+ return number_string_cache_size * 2;
+}
+
+
+void Heap::AllocateFullSizeNumberStringCache() {
+ // The idea is to have a small number string cache in the snapshot to keep
+ // boot-time memory usage down. If we expand the number string cache already
+ // while creating the snapshot then that didn't work out.
+ ASSERT(!Serializer::enabled());
MaybeObject* maybe_obj =
- AllocateFixedArray(number_string_cache_size * 2, TENURED);
- if (maybe_obj->ToObject(&obj)) set_number_string_cache(FixedArray::cast(obj));
- return maybe_obj;
+ AllocateFixedArray(FullSizeNumberStringCacheLength(), TENURED);
+ Object* new_cache;
+ if (maybe_obj->ToObject(&new_cache)) {
Michael Starzinger 2012/01/25 13:00:56 Can we add a comment that this is a best effort al
Erik Corry 2012/01/25 14:37:26 Done.
+ set_number_string_cache(FixedArray::cast(new_cache));
+ }
}
@@ -2675,11 +2695,17 @@
int mask = (number_string_cache()->length() >> 1) - 1;
if (number->IsSmi()) {
hash = smi_get_hash(Smi::cast(number)) & mask;
- number_string_cache()->set(hash * 2, Smi::cast(number));
} else {
hash = double_get_hash(number->Number()) & mask;
- number_string_cache()->set(hash * 2, number);
}
+ if (number_string_cache()->get(hash * 2) != undefined_value() &&
+ number_string_cache()->length() != FullSizeNumberStringCacheLength()) {
+ // The first time we have a hash collision, we move to the full sized
+ // number string cache.
+ AllocateFullSizeNumberStringCache();
+ return;
+ }
+ number_string_cache()->set(hash * 2, number);
number_string_cache()->set(hash * 2 + 1, string);
}
« src/heap.h ('K') | « src/heap.h ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698