diff options
Diffstat (limited to 'deps/v8/src/heap.cc')
-rw-r--r-- | deps/v8/src/heap.cc | 124 |
1 files changed, 58 insertions, 66 deletions
diff --git a/deps/v8/src/heap.cc b/deps/v8/src/heap.cc index c29815e550..949dd80c3b 100644 --- a/deps/v8/src/heap.cc +++ b/deps/v8/src/heap.cc @@ -77,11 +77,11 @@ int Heap::semispace_size_ = 512*KB; int Heap::old_generation_size_ = 128*MB; int Heap::initial_semispace_size_ = 128*KB; #elif defined(V8_TARGET_ARCH_X64) -int Heap::semispace_size_ = 8*MB; +int Heap::semispace_size_ = 16*MB; int Heap::old_generation_size_ = 1*GB; int Heap::initial_semispace_size_ = 1*MB; #else -int Heap::semispace_size_ = 4*MB; +int Heap::semispace_size_ = 8*MB; int Heap::old_generation_size_ = 512*MB; int Heap::initial_semispace_size_ = 512*KB; #endif @@ -1319,7 +1319,7 @@ bool Heap::CreateApiObjects() { void Heap::CreateCEntryStub() { - CEntryStub stub; + CEntryStub stub(1); set_c_entry_code(*stub.GetCode()); } @@ -2795,7 +2795,9 @@ STRUCT_LIST(MAKE_CASE) bool Heap::IdleNotification() { - static const int kIdlesBeforeCollection = 7; + static const int kIdlesBeforeScavenge = 4; + static const int kIdlesBeforeMarkSweep = 7; + static const int kIdlesBeforeMarkCompact = 8; static int number_idle_notifications = 0; static int last_gc_count = gc_count_; @@ -2808,19 +2810,22 @@ bool Heap::IdleNotification() { last_gc_count = gc_count_; } - if (number_idle_notifications >= kIdlesBeforeCollection) { - // The first time through we collect without forcing compaction. - // The second time through we force compaction and quit. - bool force_compaction = - number_idle_notifications > kIdlesBeforeCollection; - CollectAllGarbage(force_compaction); + if (number_idle_notifications == kIdlesBeforeScavenge) { + CollectGarbage(0, NEW_SPACE); + new_space_.Shrink(); last_gc_count = gc_count_; - if (force_compaction) { - // Shrink new space. - new_space_.Shrink(); - number_idle_notifications = 0; - finished = true; - } + + } else if (number_idle_notifications == kIdlesBeforeMarkSweep) { + CollectAllGarbage(false); + new_space_.Shrink(); + last_gc_count = gc_count_; + + } else if (number_idle_notifications == kIdlesBeforeMarkCompact) { + CollectAllGarbage(true); + new_space_.Shrink(); + last_gc_count = gc_count_; + number_idle_notifications = 0; + finished = true; } // Uncommit unused memory in new space. @@ -3185,63 +3190,49 @@ bool Heap::Setup(bool create_heap_objects) { if (!ConfigureHeapDefault()) return false; } - // Setup memory allocator and allocate an initial chunk of memory. The - // initial chunk is double the size of the new space to ensure that we can - // find a pair of semispaces that are contiguous and aligned to their size. + // Setup memory allocator and reserve a chunk of memory for new + // space. The chunk is double the size of the new space to ensure + // that we can find a pair of semispaces that are contiguous and + // aligned to their size. if (!MemoryAllocator::Setup(MaxCapacity())) return false; - void* chunk - = MemoryAllocator::ReserveInitialChunk(2 * young_generation_size_); + void* chunk = + MemoryAllocator::ReserveInitialChunk(2 * young_generation_size_); if (chunk == NULL) return false; - // Put the initial chunk of the old space at the start of the initial - // chunk, then the two new space semispaces, then the initial chunk of - // code space. Align the pair of semispaces to their size, which must be - // a power of 2. + // Align the pair of semispaces to their size, which must be a power + // of 2. ASSERT(IsPowerOf2(young_generation_size_)); - Address code_space_start = reinterpret_cast<Address>(chunk); - Address new_space_start = RoundUp(code_space_start, young_generation_size_); - Address old_space_start = new_space_start + young_generation_size_; - int code_space_size = new_space_start - code_space_start; - int old_space_size = young_generation_size_ - code_space_size; - - // Initialize new space. + Address new_space_start = + RoundUp(reinterpret_cast<byte*>(chunk), young_generation_size_); if (!new_space_.Setup(new_space_start, young_generation_size_)) return false; - // Initialize old space, set the maximum capacity to the old generation - // size. It will not contain code. + // Initialize old pointer space. old_pointer_space_ = new OldSpace(old_generation_size_, OLD_POINTER_SPACE, NOT_EXECUTABLE); if (old_pointer_space_ == NULL) return false; - if (!old_pointer_space_->Setup(old_space_start, old_space_size >> 1)) { - return false; - } + if (!old_pointer_space_->Setup(NULL, 0)) return false; + + // Initialize old data space. old_data_space_ = new OldSpace(old_generation_size_, OLD_DATA_SPACE, NOT_EXECUTABLE); if (old_data_space_ == NULL) return false; - if (!old_data_space_->Setup(old_space_start + (old_space_size >> 1), - old_space_size >> 1)) { - return false; - } + if (!old_data_space_->Setup(NULL, 0)) return false; // Initialize the code space, set its maximum capacity to the old // generation size. It needs executable memory. code_space_ = new OldSpace(old_generation_size_, CODE_SPACE, EXECUTABLE); if (code_space_ == NULL) return false; - if (!code_space_->Setup(code_space_start, code_space_size)) return false; + if (!code_space_->Setup(NULL, 0)) return false; // Initialize map space. map_space_ = new MapSpace(kMaxMapSpaceSize, MAP_SPACE); if (map_space_ == NULL) return false; - // Setting up a paged space without giving it a virtual memory range big - // enough to hold at least a page will cause it to allocate. if (!map_space_->Setup(NULL, 0)) return false; // Initialize global property cell space. cell_space_ = new CellSpace(old_generation_size_, CELL_SPACE); if (cell_space_ == NULL) return false; - // Setting up a paged space without giving it a virtual memory range big - // enough to hold at least a page will cause it to allocate. if (!cell_space_->Setup(NULL, 0)) return false; // The large object code space may contain code or data. We set the memory @@ -3563,7 +3554,7 @@ namespace { class JSConstructorProfile BASE_EMBEDDED { public: JSConstructorProfile() : zscope_(DELETE_ON_EXIT) {} - void CollectStats(JSObject* obj); + void CollectStats(HeapObject* obj); void PrintStats(); // Used by ZoneSplayTree::ForEach. void Call(String* name, const NumberAndSizeInfo& number_and_size); @@ -3608,33 +3599,36 @@ int JSConstructorProfile::CalculateJSObjectNetworkSize(JSObject* obj) { void JSConstructorProfile::Call(String* name, const NumberAndSizeInfo& number_and_size) { - SmartPointer<char> s_name; - if (name != NULL) { - s_name = name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); - } + ASSERT(name != NULL); + SmartPointer<char> s_name( + name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); LOG(HeapSampleJSConstructorEvent(*s_name, number_and_size.number(), number_and_size.bytes())); } -void JSConstructorProfile::CollectStats(JSObject* obj) { - String* constructor_func = NULL; - if (obj->map()->constructor()->IsJSFunction()) { - JSFunction* constructor = JSFunction::cast(obj->map()->constructor()); - SharedFunctionInfo* sfi = constructor->shared(); - String* name = String::cast(sfi->name()); - constructor_func = name->length() > 0 ? name : sfi->inferred_name(); - } else if (obj->IsJSFunction()) { - constructor_func = Heap::function_class_symbol(); +void JSConstructorProfile::CollectStats(HeapObject* obj) { + String* constructor = NULL; + int size; + if (obj->IsString()) { + constructor = Heap::String_symbol(); + size = obj->Size(); + } else if (obj->IsJSObject()) { + JSObject* js_obj = JSObject::cast(obj); + constructor = js_obj->constructor_name(); + size = CalculateJSObjectNetworkSize(js_obj); + } else { + return; } + JSObjectsInfoTree::Locator loc; - if (!js_objects_info_tree_.Find(constructor_func, &loc)) { - js_objects_info_tree_.Insert(constructor_func, &loc); + if (!js_objects_info_tree_.Find(constructor, &loc)) { + js_objects_info_tree_.Insert(constructor, &loc); } NumberAndSizeInfo number_and_size = loc.value(); number_and_size.increment_number(1); - number_and_size.increment_bytes(CalculateJSObjectNetworkSize(obj)); + number_and_size.increment_bytes(size); loc.set_value(number_and_size); } @@ -3676,9 +3670,7 @@ void HeapProfiler::WriteSample() { while (iterator.has_next()) { HeapObject* obj = iterator.next(); CollectStats(obj, info); - if (obj->IsJSObject()) { - js_cons_profile.CollectStats(JSObject::cast(obj)); - } + js_cons_profile.CollectStats(obj); } // Lump all the string types together. |