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

Side by Side Diff: src/heap.cc

Issue 228923002: Allow the embedder to pass the virtual memory limit to v8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 8 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
« include/v8.h ('K') | « src/heap.h ('k') | src/spaces.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "regexp-macro-assembler.h" 61 #include "regexp-macro-assembler.h"
62 #include "mips/regexp-macro-assembler-mips.h" 62 #include "mips/regexp-macro-assembler-mips.h"
63 #endif 63 #endif
64 64
65 namespace v8 { 65 namespace v8 {
66 namespace internal { 66 namespace internal {
67 67
68 68
69 Heap::Heap() 69 Heap::Heap()
70 : isolate_(NULL), 70 : isolate_(NULL),
71 code_range_size_(kIs64BitArch ? 512 * MB : 0), 71 code_range_size_(0),
72 // semispace_size_ should be a power of 2 and old_generation_size_ should be 72 // semispace_size_ should be a power of 2 and old_generation_size_ should be
73 // a multiple of Page::kPageSize. 73 // a multiple of Page::kPageSize.
74 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), 74 reserved_semispace_size_(8 * (kPointerSize / 4) * MB),
75 max_semispace_size_(8 * (kPointerSize / 4) * MB), 75 max_semispace_size_(8 * (kPointerSize / 4) * MB),
76 initial_semispace_size_(Page::kPageSize), 76 initial_semispace_size_(Page::kPageSize),
77 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), 77 max_old_generation_size_(700ul * (kPointerSize / 4) * MB),
78 max_executable_size_(256ul * (kPointerSize / 4) * MB), 78 max_executable_size_(256ul * (kPointerSize / 4) * MB),
79 // Variables set based on semispace_size_ and old_generation_size_ in 79 // Variables set based on semispace_size_ and old_generation_size_ in
80 // ConfigureHeap (survived_since_last_expansion_, external_allocation_limit_) 80 // ConfigureHeap (survived_since_last_expansion_, external_allocation_limit_)
81 // Will be 4 * reserved_semispace_size_ to ensure that young 81 // Will be 4 * reserved_semispace_size_ to ensure that young
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Allow build-time customization of the max semispace size. Building 158 // Allow build-time customization of the max semispace size. Building
159 // V8 with snapshots and a non-default max semispace size is much 159 // V8 with snapshots and a non-default max semispace size is much
160 // easier if you can define it as part of the build environment. 160 // easier if you can define it as part of the build environment.
161 #if defined(V8_MAX_SEMISPACE_SIZE) 161 #if defined(V8_MAX_SEMISPACE_SIZE)
162 max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; 162 max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE;
163 #endif 163 #endif
164 164
165 // Ensure old_generation_size_ is a multiple of kPageSize. 165 // Ensure old_generation_size_ is a multiple of kPageSize.
166 ASSERT(MB >= Page::kPageSize); 166 ASSERT(MB >= Page::kPageSize);
167 167
168 intptr_t max_virtual = OS::MaxVirtualMemory();
169
170 if (max_virtual > 0) {
171 if (code_range_size_ > 0) {
172 // Reserve no more than 1/8 of the memory for the code range.
173 code_range_size_ = Min(code_range_size_, max_virtual >> 3);
174 }
175 }
176
177 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); 168 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength);
178 native_contexts_list_ = NULL; 169 native_contexts_list_ = NULL;
179 array_buffers_list_ = Smi::FromInt(0); 170 array_buffers_list_ = Smi::FromInt(0);
180 allocation_sites_list_ = Smi::FromInt(0); 171 allocation_sites_list_ = Smi::FromInt(0);
181 // Put a dummy entry in the remembered pages so we can find the list the 172 // Put a dummy entry in the remembered pages so we can find the list the
182 // minidump even if there are no real unmapped pages. 173 // minidump even if there are no real unmapped pages.
183 RememberUnmappedPage(NULL, false); 174 RememberUnmappedPage(NULL, false);
184 175
185 ClearObjectStats(true); 176 ClearObjectStats(true);
186 } 177 }
(...skipping 5943 matching lines...) Expand 10 before | Expand all | Expand 10 after
6130 // deserializer are deliberately a little unsynchronized (see above) so the 6121 // deserializer are deliberately a little unsynchronized (see above) so the
6131 // checking of the sync flag in the snapshot would fail. 6122 // checking of the sync flag in the snapshot would fail.
6132 } 6123 }
6133 6124
6134 6125
6135 // TODO(1236194): Since the heap size is configurable on the command line 6126 // TODO(1236194): Since the heap size is configurable on the command line
6136 // and through the API, we should gracefully handle the case that the heap 6127 // and through the API, we should gracefully handle the case that the heap
6137 // size is not big enough to fit all the initial objects. 6128 // size is not big enough to fit all the initial objects.
6138 bool Heap::ConfigureHeap(int max_semispace_size, 6129 bool Heap::ConfigureHeap(int max_semispace_size,
6139 intptr_t max_old_gen_size, 6130 intptr_t max_old_gen_size,
6140 intptr_t max_executable_size) { 6131 intptr_t max_executable_size,
6132 intptr_t code_range_size) {
6141 if (HasBeenSetUp()) return false; 6133 if (HasBeenSetUp()) return false;
6142 6134
6143 if (FLAG_stress_compaction) { 6135 if (FLAG_stress_compaction) {
6144 // This will cause more frequent GCs when stressing. 6136 // This will cause more frequent GCs when stressing.
6145 max_semispace_size_ = Page::kPageSize; 6137 max_semispace_size_ = Page::kPageSize;
6146 } 6138 }
6147 6139
6148 if (max_semispace_size > 0) { 6140 if (max_semispace_size > 0) {
6149 if (max_semispace_size < Page::kPageSize) { 6141 if (max_semispace_size < Page::kPageSize) {
6150 max_semispace_size = Page::kPageSize; 6142 max_semispace_size = Page::kPageSize;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
6204 Page::kPageSize), 6196 Page::kPageSize),
6205 RoundUp(max_old_generation_size_, 6197 RoundUp(max_old_generation_size_,
6206 Page::kPageSize)); 6198 Page::kPageSize));
6207 6199
6208 // We rely on being able to allocate new arrays in paged spaces. 6200 // We rely on being able to allocate new arrays in paged spaces.
6209 ASSERT(Page::kMaxRegularHeapObjectSize >= 6201 ASSERT(Page::kMaxRegularHeapObjectSize >=
6210 (JSArray::kSize + 6202 (JSArray::kSize +
6211 FixedArray::SizeFor(JSObject::kInitialMaxFastElementArray) + 6203 FixedArray::SizeFor(JSObject::kInitialMaxFastElementArray) +
6212 AllocationMemento::kSize)); 6204 AllocationMemento::kSize));
6213 6205
6206 code_range_size_ = code_range_size;
6207
6214 configured_ = true; 6208 configured_ = true;
6215 return true; 6209 return true;
6216 } 6210 }
6217 6211
6218 6212
6219 bool Heap::ConfigureHeapDefault() { 6213 bool Heap::ConfigureHeapDefault() {
6220 return ConfigureHeap(static_cast<intptr_t>(FLAG_max_new_space_size / 2) * KB, 6214 return ConfigureHeap(static_cast<intptr_t>(FLAG_max_new_space_size / 2) * KB,
6221 static_cast<intptr_t>(FLAG_max_old_space_size) * MB, 6215 static_cast<intptr_t>(FLAG_max_old_space_size) * MB,
6222 static_cast<intptr_t>(FLAG_max_executable_size) * MB); 6216 static_cast<intptr_t>(FLAG_max_executable_size) * MB,
6217 static_cast<intptr_t>(0));
6223 } 6218 }
6224 6219
6225 6220
6226 void Heap::RecordStats(HeapStats* stats, bool take_snapshot) { 6221 void Heap::RecordStats(HeapStats* stats, bool take_snapshot) {
6227 *stats->start_marker = HeapStats::kStartMarker; 6222 *stats->start_marker = HeapStats::kStartMarker;
6228 *stats->end_marker = HeapStats::kEndMarker; 6223 *stats->end_marker = HeapStats::kEndMarker;
6229 *stats->new_space_size = new_space_.SizeAsInt(); 6224 *stats->new_space_size = new_space_.SizeAsInt();
6230 *stats->new_space_capacity = static_cast<int>(new_space_.Capacity()); 6225 *stats->new_space_capacity = static_cast<int>(new_space_.Capacity());
6231 *stats->old_pointer_space_size = old_pointer_space_->SizeOfObjects(); 6226 *stats->old_pointer_space_size = old_pointer_space_->SizeOfObjects();
6232 *stats->old_pointer_space_capacity = old_pointer_space_->Capacity(); 6227 *stats->old_pointer_space_capacity = old_pointer_space_->Capacity();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6365 6360
6366 // Initialize old data space. 6361 // Initialize old data space.
6367 old_data_space_ = 6362 old_data_space_ =
6368 new OldSpace(this, 6363 new OldSpace(this,
6369 max_old_generation_size_, 6364 max_old_generation_size_,
6370 OLD_DATA_SPACE, 6365 OLD_DATA_SPACE,
6371 NOT_EXECUTABLE); 6366 NOT_EXECUTABLE);
6372 if (old_data_space_ == NULL) return false; 6367 if (old_data_space_ == NULL) return false;
6373 if (!old_data_space_->SetUp()) return false; 6368 if (!old_data_space_->SetUp()) return false;
6374 6369
6370 if (!isolate_->code_range()->SetUp(code_range_size_)) return false;
6371
6375 // Initialize the code space, set its maximum capacity to the old 6372 // Initialize the code space, set its maximum capacity to the old
6376 // generation size. It needs executable memory. 6373 // generation size. It needs executable memory.
6377 // On 64-bit platform(s), we put all code objects in a 2 GB range of
6378 // virtual address space, so that they can call each other with near calls.
6379 if (code_range_size_ > 0) {
6380 if (!isolate_->code_range()->SetUp(code_range_size_)) {
6381 return false;
6382 }
6383 }
6384
6385 code_space_ = 6374 code_space_ =
6386 new OldSpace(this, max_old_generation_size_, CODE_SPACE, EXECUTABLE); 6375 new OldSpace(this, max_old_generation_size_, CODE_SPACE, EXECUTABLE);
6387 if (code_space_ == NULL) return false; 6376 if (code_space_ == NULL) return false;
6388 if (!code_space_->SetUp()) return false; 6377 if (!code_space_->SetUp()) return false;
6389 6378
6390 // Initialize map space. 6379 // Initialize map space.
6391 map_space_ = new MapSpace(this, max_old_generation_size_, MAP_SPACE); 6380 map_space_ = new MapSpace(this, max_old_generation_size_, MAP_SPACE);
6392 if (map_space_ == NULL) return false; 6381 if (map_space_ == NULL) return false;
6393 if (!map_space_->SetUp()) return false; 6382 if (!map_space_->SetUp()) return false;
6394 6383
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
7620 static_cast<int>(object_sizes_last_time_[index])); 7609 static_cast<int>(object_sizes_last_time_[index]));
7621 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7610 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7622 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7611 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7623 7612
7624 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7613 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7625 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7614 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7626 ClearObjectStats(); 7615 ClearObjectStats();
7627 } 7616 }
7628 7617
7629 } } // namespace v8::internal 7618 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « src/heap.h ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698