Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 namespace v8 { | 42 namespace v8 { |
| 43 namespace internal { | 43 namespace internal { |
| 44 | 44 |
| 45 | 45 |
| 46 Heap::Heap() | 46 Heap::Heap() |
| 47 : isolate_(NULL), | 47 : isolate_(NULL), |
| 48 code_range_size_(0), | 48 code_range_size_(0), |
| 49 // semispace_size_ should be a power of 2 and old_generation_size_ should be | 49 // semispace_size_ should be a power of 2 and old_generation_size_ should be |
| 50 // a multiple of Page::kPageSize. | 50 // a multiple of Page::kPageSize. |
| 51 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), | 51 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), |
| 52 max_semispace_size_(8 * (kPointerSize / 4) * MB), | 52 max_semi_space_size_(8 * (kPointerSize / 4) * MB), |
| 53 initial_semispace_size_(Page::kPageSize), | 53 initial_semispace_size_(Page::kPageSize), |
| 54 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), | 54 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), |
| 55 max_executable_size_(256ul * (kPointerSize / 4) * MB), | 55 max_executable_size_(256ul * (kPointerSize / 4) * MB), |
| 56 // Variables set based on semispace_size_ and old_generation_size_ in | 56 // Variables set based on semispace_size_ and old_generation_size_ in |
| 57 // ConfigureHeap (survived_since_last_expansion_, external_allocation_limit_) | 57 // ConfigureHeap (survived_since_last_expansion_, external_allocation_limit_) |
| 58 // Will be 4 * reserved_semispace_size_ to ensure that young | 58 // Will be 4 * reserved_semispace_size_ to ensure that young |
| 59 // generation can be aligned to its size. | 59 // generation can be aligned to its size. |
| 60 maximum_committed_(0), | 60 maximum_committed_(0), |
| 61 old_space_growing_factor_(4), | 61 old_space_growing_factor_(4), |
| 62 survived_since_last_expansion_(0), | 62 survived_since_last_expansion_(0), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 allocation_sites_scratchpad_length_(0), | 130 allocation_sites_scratchpad_length_(0), |
| 131 promotion_queue_(this), | 131 promotion_queue_(this), |
| 132 configured_(false), | 132 configured_(false), |
| 133 external_string_table_(this), | 133 external_string_table_(this), |
| 134 chunks_queued_for_free_(NULL), | 134 chunks_queued_for_free_(NULL), |
| 135 gc_callbacks_depth_(0) { | 135 gc_callbacks_depth_(0) { |
| 136 // Allow build-time customization of the max semispace size. Building | 136 // Allow build-time customization of the max semispace size. Building |
| 137 // V8 with snapshots and a non-default max semispace size is much | 137 // V8 with snapshots and a non-default max semispace size is much |
| 138 // easier if you can define it as part of the build environment. | 138 // easier if you can define it as part of the build environment. |
| 139 #if defined(V8_MAX_SEMISPACE_SIZE) | 139 #if defined(V8_MAX_SEMISPACE_SIZE) |
| 140 max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 140 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
| 141 #endif | 141 #endif |
| 142 | 142 |
| 143 // Ensure old_generation_size_ is a multiple of kPageSize. | 143 // Ensure old_generation_size_ is a multiple of kPageSize. |
| 144 ASSERT(MB >= Page::kPageSize); | 144 ASSERT(MB >= Page::kPageSize); |
| 145 | 145 |
| 146 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); | 146 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); |
| 147 native_contexts_list_ = NULL; | 147 native_contexts_list_ = NULL; |
| 148 array_buffers_list_ = Smi::FromInt(0); | 148 array_buffers_list_ = Smi::FromInt(0); |
| 149 allocation_sites_list_ = Smi::FromInt(0); | 149 allocation_sites_list_ = Smi::FromInt(0); |
| 150 // Put a dummy entry in the remembered pages so we can find the list the | 150 // Put a dummy entry in the remembered pages so we can find the list the |
| (...skipping 2932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3083 for (int i = 0; i < kRegExpResultsCacheSize; i++) { | 3083 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
| 3084 cache->set(i, Smi::FromInt(0)); | 3084 cache->set(i, Smi::FromInt(0)); |
| 3085 } | 3085 } |
| 3086 } | 3086 } |
| 3087 | 3087 |
| 3088 | 3088 |
| 3089 int Heap::FullSizeNumberStringCacheLength() { | 3089 int Heap::FullSizeNumberStringCacheLength() { |
| 3090 // Compute the size of the number string cache based on the max newspace size. | 3090 // Compute the size of the number string cache based on the max newspace size. |
| 3091 // The number string cache has a minimum size based on twice the initial cache | 3091 // The number string cache has a minimum size based on twice the initial cache |
| 3092 // size to ensure that it is bigger after being made 'full size'. | 3092 // size to ensure that it is bigger after being made 'full size'. |
| 3093 int number_string_cache_size = max_semispace_size_ / 512; | 3093 int number_string_cache_size = max_semi_space_size_ / 512; |
| 3094 number_string_cache_size = Max(kInitialNumberStringCacheSize * 2, | 3094 number_string_cache_size = Max(kInitialNumberStringCacheSize * 2, |
| 3095 Min(0x4000, number_string_cache_size)); | 3095 Min(0x4000, number_string_cache_size)); |
| 3096 // There is a string and a number per entry so the length is twice the number | 3096 // There is a string and a number per entry so the length is twice the number |
| 3097 // of entries. | 3097 // of entries. |
| 3098 return number_string_cache_size * 2; | 3098 return number_string_cache_size * 2; |
| 3099 } | 3099 } |
| 3100 | 3100 |
| 3101 | 3101 |
| 3102 void Heap::FlushNumberStringCache() { | 3102 void Heap::FlushNumberStringCache() { |
| 3103 // Flush the number to string cache. | 3103 // Flush the number to string cache. |
| (...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4972 // We don't do a v->Synchronize call here, because in debug mode that will | 4972 // We don't do a v->Synchronize call here, because in debug mode that will |
| 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_semi_space_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_semi_space_size > 0) { | |
| 4990 max_semi_space_size_ = max_semi_space_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_semi_space_size > 0) { |
| 4990 max_semispace_size = (FLAG_max_new_space_size / 2) * kLumpOfMemory; | 5001 max_semi_space_size_ = FLAG_max_semi_space_size * MB; |
| 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_generation_size_ = FLAG_max_old_space_size * MB; |
|
ulan
2016/02/26 10:01:28
This inadvertently broke the public ResourceConstr
| |
| 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_semi_space_size_ = Page::kPageSize; |
| 5002 } | |
| 5003 | |
| 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 } | 5013 } |
| 5014 | 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_semi_space_size_ > reserved_semispace_size_) { |
| 5022 max_semispace_size_ = reserved_semispace_size_; | 5022 max_semi_space_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_semi_space_size_; |
| 5032 } | |
| 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 } | 5032 } |
| 5038 | 5033 |
| 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_semi_space_size_ = RoundUpToPowerOf2(max_semi_space_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_semi_space_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_semi_space_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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5200 | 5191 |
| 5201 CallOnce(&initialize_gc_once, &InitializeGCOnce); | 5192 CallOnce(&initialize_gc_once, &InitializeGCOnce); |
| 5202 | 5193 |
| 5203 MarkMapPointersAsEncoded(false); | 5194 MarkMapPointersAsEncoded(false); |
| 5204 | 5195 |
| 5205 // Set up memory allocator. | 5196 // Set up memory allocator. |
| 5206 if (!isolate_->memory_allocator()->SetUp(MaxReserved(), MaxExecutableSize())) | 5197 if (!isolate_->memory_allocator()->SetUp(MaxReserved(), MaxExecutableSize())) |
| 5207 return false; | 5198 return false; |
| 5208 | 5199 |
| 5209 // Set up new space. | 5200 // Set up new space. |
| 5210 if (!new_space_.SetUp(reserved_semispace_size_, max_semispace_size_)) { | 5201 if (!new_space_.SetUp(reserved_semispace_size_, max_semi_space_size_)) { |
| 5211 return false; | 5202 return false; |
| 5212 } | 5203 } |
| 5213 | 5204 |
| 5214 // Initialize old pointer space. | 5205 // Initialize old pointer space. |
| 5215 old_pointer_space_ = | 5206 old_pointer_space_ = |
| 5216 new OldSpace(this, | 5207 new OldSpace(this, |
| 5217 max_old_generation_size_, | 5208 max_old_generation_size_, |
| 5218 OLD_POINTER_SPACE, | 5209 OLD_POINTER_SPACE, |
| 5219 NOT_EXECUTABLE); | 5210 NOT_EXECUTABLE); |
| 5220 if (old_pointer_space_ == NULL) return false; | 5211 if (old_pointer_space_ == NULL) return false; |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |