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

Side by Side Diff: src/heap.cc

Issue 271843005: Simplify ConfigureHeap and change --max_new_space_size to --max_semi_space_size. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "accessors.h" 7 #include "accessors.h"
8 #include "api.h" 8 #include "api.h"
9 #include "bootstrapper.h" 9 #include "bootstrapper.h"
10 #include "codegen.h" 10 #include "codegen.h"
(...skipping 4962 matching lines...) Expand 10 before | Expand all | Expand 10 after
4973 // output a flag to the snapshot. However at this point the serializer and 4973 // output a flag to the snapshot. However at this point the serializer and
4974 // deserializer are deliberately a little unsynchronized (see above) so the 4974 // deserializer are deliberately a little unsynchronized (see above) so the
4975 // checking of the sync flag in the snapshot would fail. 4975 // checking of the sync flag in the snapshot would fail.
4976 } 4976 }
4977 4977
4978 4978
4979 // TODO(1236194): Since the heap size is configurable on the command line 4979 // TODO(1236194): Since the heap size is configurable on the command line
4980 // and through the API, we should gracefully handle the case that the heap 4980 // and through the API, we should gracefully handle the case that the heap
4981 // size is not big enough to fit all the initial objects. 4981 // size is not big enough to fit all the initial objects.
4982 bool Heap::ConfigureHeap(int max_semispace_size, 4982 bool Heap::ConfigureHeap(int max_semispace_size,
4983 intptr_t max_old_space_size, 4983 int max_old_space_size,
4984 intptr_t max_executable_size, 4984 int max_executable_size,
4985 intptr_t code_range_size) { 4985 int code_range_size) {
4986 if (HasBeenSetUp()) return false; 4986 if (HasBeenSetUp()) return false;
4987 4987
4988 // Overwrite default configuration.
4989 if (max_semispace_size > 0) {
4990 max_semispace_size_ = max_semispace_size * MB;
4991 }
4992 if (max_old_space_size > 0) {
4993 max_old_generation_size_ = max_old_space_size * MB;
4994 }
4995 if (max_executable_size > 0) {
4996 max_executable_size_ = max_executable_size * MB;
4997 }
4998
4988 // If max space size flags are specified overwrite the configuration. 4999 // If max space size flags are specified overwrite the configuration.
4989 if (FLAG_max_new_space_size > 0) { 5000 if (FLAG_max_semispace_size > 0) {
4990 max_semispace_size = (FLAG_max_new_space_size / 2) * kLumpOfMemory; 5001 max_semispace_size = FLAG_max_semispace_size * MB;
Michael Starzinger 2014/05/08 13:22:02 IMHO, this should target "max_semispace_size_" fie
Hannes Payer (out of office) 2014/05/08 13:53:44 Done.
4991 } 5002 }
4992 if (FLAG_max_old_space_size > 0) { 5003 if (FLAG_max_old_space_size > 0) {
4993 max_old_space_size = FLAG_max_old_space_size * kLumpOfMemory; 5004 max_old_space_size = FLAG_max_old_space_size * MB;
4994 } 5005 }
4995 if (FLAG_max_executable_size > 0) { 5006 if (FLAG_max_executable_size > 0) {
4996 max_executable_size = FLAG_max_executable_size * kLumpOfMemory; 5007 max_executable_size = FLAG_max_executable_size * MB;
4997 } 5008 }
4998 5009
4999 if (FLAG_stress_compaction) { 5010 if (FLAG_stress_compaction) {
5000 // This will cause more frequent GCs when stressing. 5011 // This will cause more frequent GCs when stressing.
5001 max_semispace_size_ = Page::kPageSize; 5012 max_semispace_size_ = Page::kPageSize;
5002 } 5013 }
5003 5014
5004 if (max_semispace_size > 0) {
5005 if (max_semispace_size < Page::kPageSize) {
5006 max_semispace_size = Page::kPageSize;
5007 if (FLAG_trace_gc) {
5008 PrintPID("Max semispace size cannot be less than %dkbytes\n",
5009 Page::kPageSize >> 10);
5010 }
5011 }
5012 max_semispace_size_ = max_semispace_size;
5013 }
5014
5015 if (Snapshot::IsEnabled()) { 5015 if (Snapshot::IsEnabled()) {
5016 // If we are using a snapshot we always reserve the default amount 5016 // If we are using a snapshot we always reserve the default amount
5017 // of memory for each semispace because code in the snapshot has 5017 // of memory for each semispace because code in the snapshot has
5018 // write-barrier code that relies on the size and alignment of new 5018 // write-barrier code that relies on the size and alignment of new
5019 // space. We therefore cannot use a larger max semispace size 5019 // space. We therefore cannot use a larger max semispace size
5020 // than the default reserved semispace size. 5020 // than the default reserved semispace size.
5021 if (max_semispace_size_ > reserved_semispace_size_) { 5021 if (max_semispace_size_ > reserved_semispace_size_) {
5022 max_semispace_size_ = reserved_semispace_size_; 5022 max_semispace_size_ = reserved_semispace_size_;
5023 if (FLAG_trace_gc) { 5023 if (FLAG_trace_gc) {
5024 PrintPID("Max semispace size cannot be more than %dkbytes\n", 5024 PrintPID("Max semispace size cannot be more than %dkbytes\n",
5025 reserved_semispace_size_ >> 10); 5025 reserved_semispace_size_ >> 10);
5026 } 5026 }
5027 } 5027 }
5028 } else { 5028 } else {
5029 // If we are not using snapshots we reserve space for the actual 5029 // If we are not using snapshots we reserve space for the actual
5030 // max semispace size. 5030 // max semispace size.
5031 reserved_semispace_size_ = max_semispace_size_; 5031 reserved_semispace_size_ = max_semispace_size_;
5032 } 5032 }
5033 5033
5034 if (max_old_space_size > 0) max_old_generation_size_ = max_old_space_size;
5035 if (max_executable_size > 0) {
5036 max_executable_size_ = RoundUp(max_executable_size, Page::kPageSize);
5037 }
5038
5039 // The max executable size must be less than or equal to the max old 5034 // The max executable size must be less than or equal to the max old
5040 // generation size. 5035 // generation size.
5041 if (max_executable_size_ > max_old_generation_size_) { 5036 if (max_executable_size_ > max_old_generation_size_) {
5042 max_executable_size_ = max_old_generation_size_; 5037 max_executable_size_ = max_old_generation_size_;
5043 } 5038 }
5044 5039
5045 // The new space size must be a power of two to support single-bit testing 5040 // The new space size must be a power of two to support single-bit testing
5046 // for containment. 5041 // for containment.
5047 max_semispace_size_ = RoundUpToPowerOf2(max_semispace_size_); 5042 max_semispace_size_ = RoundUpToPowerOf2(max_semispace_size_);
5048 reserved_semispace_size_ = RoundUpToPowerOf2(reserved_semispace_size_); 5043 reserved_semispace_size_ = RoundUpToPowerOf2(reserved_semispace_size_);
5049 initial_semispace_size_ = Min(initial_semispace_size_, max_semispace_size_); 5044 initial_semispace_size_ = Min(initial_semispace_size_, max_semispace_size_);
5050 5045
5051 // The external allocation limit should be below 256 MB on all architectures 5046 // The external allocation limit should be below 256 MB on all architectures
5052 // to avoid unnecessary low memory notifications, as that is the threshold 5047 // to avoid unnecessary low memory notifications, as that is the threshold
5053 // for some embedders. 5048 // for some embedders.
5054 external_allocation_limit_ = 12 * max_semispace_size_; 5049 external_allocation_limit_ = 12 * max_semispace_size_;
5055 ASSERT(external_allocation_limit_ <= 256 * MB); 5050 ASSERT(external_allocation_limit_ <= 256 * MB);
5056 5051
5057 // The old generation is paged and needs at least one page for each space. 5052 // The old generation is paged and needs at least one page for each space.
5058 int paged_space_count = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1; 5053 int paged_space_count = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;
5059 max_old_generation_size_ = Max(static_cast<intptr_t>(paged_space_count * 5054 max_old_generation_size_ =
5060 Page::kPageSize), 5055 Max(static_cast<intptr_t>(paged_space_count * Page::kPageSize),
5061 RoundUp(max_old_generation_size_, 5056 max_old_generation_size_);
5062 Page::kPageSize));
5063 5057
5064 // We rely on being able to allocate new arrays in paged spaces. 5058 // We rely on being able to allocate new arrays in paged spaces.
5065 ASSERT(Page::kMaxRegularHeapObjectSize >= 5059 ASSERT(Page::kMaxRegularHeapObjectSize >=
5066 (JSArray::kSize + 5060 (JSArray::kSize +
5067 FixedArray::SizeFor(JSObject::kInitialMaxFastElementArray) + 5061 FixedArray::SizeFor(JSObject::kInitialMaxFastElementArray) +
5068 AllocationMemento::kSize)); 5062 AllocationMemento::kSize));
5069 5063
5070 code_range_size_ = code_range_size; 5064 code_range_size_ = code_range_size * i::MB;
5071 5065
5072 // We set the old generation growing factor to 2 to grow the heap slower on 5066 // We set the old generation growing factor to 2 to grow the heap slower on
5073 // memory-constrained devices. 5067 // memory-constrained devices.
5074 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) { 5068 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) {
5075 old_space_growing_factor_ = 2; 5069 old_space_growing_factor_ = 2;
5076 } 5070 }
5077 5071
5078 configured_ = true; 5072 configured_ = true;
5079 return true; 5073 return true;
5080 } 5074 }
5081 5075
5082 5076
5083 bool Heap::ConfigureHeapDefault() { 5077 bool Heap::ConfigureHeapDefault() {
5084 return ConfigureHeap(static_cast<intptr_t>(FLAG_max_new_space_size / 2) * KB, 5078 return ConfigureHeap(0, 0, 0, 0);
5085 static_cast<intptr_t>(FLAG_max_old_space_size) * MB,
5086 static_cast<intptr_t>(FLAG_max_executable_size) * MB,
5087 static_cast<intptr_t>(0));
5088 } 5079 }
5089 5080
5090 5081
5091 void Heap::RecordStats(HeapStats* stats, bool take_snapshot) { 5082 void Heap::RecordStats(HeapStats* stats, bool take_snapshot) {
5092 *stats->start_marker = HeapStats::kStartMarker; 5083 *stats->start_marker = HeapStats::kStartMarker;
5093 *stats->end_marker = HeapStats::kEndMarker; 5084 *stats->end_marker = HeapStats::kEndMarker;
5094 *stats->new_space_size = new_space_.SizeAsInt(); 5085 *stats->new_space_size = new_space_.SizeAsInt();
5095 *stats->new_space_capacity = static_cast<int>(new_space_.Capacity()); 5086 *stats->new_space_capacity = static_cast<int>(new_space_.Capacity());
5096 *stats->old_pointer_space_size = old_pointer_space_->SizeOfObjects(); 5087 *stats->old_pointer_space_size = old_pointer_space_->SizeOfObjects();
5097 *stats->old_pointer_space_capacity = old_pointer_space_->Capacity(); 5088 *stats->old_pointer_space_capacity = old_pointer_space_->Capacity();
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
6478 static_cast<int>(object_sizes_last_time_[index])); 6469 static_cast<int>(object_sizes_last_time_[index]));
6479 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6470 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6480 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6471 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6481 6472
6482 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6473 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6483 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6474 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6484 ClearObjectStats(); 6475 ClearObjectStats();
6485 } 6476 }
6486 6477
6487 } } // namespace v8::internal 6478 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698