Skip to content

Commit 2785fe9

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM/Runtime] Check for valid values specified for old_gen_heap_size and
new_gen_semi_max_size TEST=new unit test Change-Id: I3dd985baf28c1e876c128252c15b8566d22b170d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212267 Commit-Queue: Siva Annamalai <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent e44b653 commit 2785fe9

6 files changed

+96
-4
lines changed

runtime/vm/dart_api_impl_test.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,52 @@ UNIT_TEST_CASE(DartAPI_DartInitializeCallsCodeObserver) {
8989
EXPECT(Dart_Cleanup() == NULL);
9090
}
9191

92+
UNIT_TEST_CASE(DartAPI_DartInitializeHeapSizes) {
93+
Dart_InitializeParams params;
94+
memset(&params, 0, sizeof(Dart_InitializeParams));
95+
params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
96+
params.vm_snapshot_data = TesterState::vm_snapshot_data;
97+
params.create_group = TesterState::create_callback;
98+
params.shutdown_isolate = TesterState::shutdown_callback;
99+
params.cleanup_group = TesterState::group_cleanup_callback;
100+
params.start_kernel_isolate = true;
101+
102+
// Initialize with a normal heap size specification.
103+
const char* options_1[] = {"--old-gen-heap-size=3192",
104+
"--new-gen-semi-max-size=32"};
105+
EXPECT(Dart_SetVMFlags(2, options_1) == NULL);
106+
EXPECT(Dart_Initialize(&params) == NULL);
107+
EXPECT(FLAG_old_gen_heap_size == 3192);
108+
EXPECT(FLAG_new_gen_semi_max_size == 32);
109+
EXPECT(Dart_Cleanup() == NULL);
110+
111+
const char* options_2[] = {"--old-gen-heap-size=16384",
112+
"--new-gen-semi-max-size=16384"};
113+
EXPECT(Dart_SetVMFlags(2, options_2) == NULL);
114+
EXPECT(Dart_Initialize(&params) == NULL);
115+
if (kMaxAddrSpaceMB == 4096) {
116+
EXPECT(FLAG_old_gen_heap_size == 0);
117+
EXPECT(FLAG_new_gen_semi_max_size == kDefaultNewGenSemiMaxSize);
118+
} else {
119+
EXPECT(FLAG_old_gen_heap_size == 16384);
120+
EXPECT(FLAG_new_gen_semi_max_size == 16384);
121+
}
122+
EXPECT(Dart_Cleanup() == NULL);
123+
124+
const char* options_3[] = {"--old-gen-heap-size=30720",
125+
"--new-gen-semi-max-size=30720"};
126+
EXPECT(Dart_SetVMFlags(2, options_3) == NULL);
127+
EXPECT(Dart_Initialize(&params) == NULL);
128+
if (kMaxAddrSpaceMB == 4096) {
129+
EXPECT(FLAG_old_gen_heap_size == 0);
130+
EXPECT(FLAG_new_gen_semi_max_size == kDefaultNewGenSemiMaxSize);
131+
} else {
132+
EXPECT(FLAG_old_gen_heap_size == 30720);
133+
EXPECT(FLAG_new_gen_semi_max_size == 30720);
134+
}
135+
EXPECT(Dart_Cleanup() == NULL);
136+
}
137+
92138
TEST_CASE(Dart_KillIsolate) {
93139
const char* kScriptChars =
94140
"int testMain() {\n"

runtime/vm/flag_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ constexpr bool FLAG_support_il_printer = false;
152152
"Maximum number of polymorphic check, otherwise it is megamorphic.") \
153153
P(max_equality_polymorphic_checks, int, 32, \
154154
"Maximum number of polymorphic checks in equality operator,") \
155-
P(new_gen_semi_max_size, int, (kWordSize <= 4) ? 8 : 16, \
155+
P(new_gen_semi_max_size, int, kDefaultNewGenSemiMaxSize, \
156156
"Max size of new gen semi space in MB") \
157157
P(new_gen_semi_initial_size, int, (kWordSize <= 4) ? 1 : 2, \
158158
"Initial size of new gen semi space in MB") \

runtime/vm/globals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ static constexpr int kCompressedWordSize = kWordSize;
4242
static constexpr int kCompressedWordSizeLog2 = kWordSizeLog2;
4343
typedef uintptr_t compressed_uword;
4444
#endif
45+
const int kMaxAddrSpaceMB = (kWordSize <= 4) ? 4096 : kMaxInt;
4546

4647
// Number of bytes per BigInt digit.
4748
const intptr_t kBytesPerBigIntDigit = 4;
4849

49-
// The default old gen heap size in MB, where 0 == unlimited.
50+
// The default old gen heap size in MB, where 0 -- unlimited.
5051
// 32-bit: OS limit is 2 or 3 GB
5152
// 64-bit: Linux's limit is
5253
// sysctl vm.max_map_count (default 2^16) * 512 KB OldPages = 32 GB
5354
// Set the VM limit below the OS limit to increase the likelihood of failing
5455
// gracefully with a Dart OutOfMemory exception instead of SIGABORT.
5556
const intptr_t kDefaultMaxOldGenHeapSize = (kWordSize <= 4) ? 1536 : 30720;
57+
const intptr_t kDefaultNewGenSemiMaxSize = (kWordSize <= 4) ? 8 : 16;
5658

5759
#define kPosInfinity bit_cast<double>(DART_UINT64_C(0x7ff0000000000000))
5860
#define kNegInfinity bit_cast<double>(DART_UINT64_C(0xfff0000000000000))

runtime/vm/virtual_memory_fuchsia.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ intptr_t VirtualMemory::CalculatePageSize() {
5252
}
5353

5454
void VirtualMemory::Init() {
55+
if (FLAG_old_gen_heap_size < 0 || FLAG_old_gen_heap_size > kMaxAddrSpaceMB) {
56+
OS::PrintErr(
57+
"warning: value specified for --old_gen_heap_size %d is larger than"
58+
" the physically addressable range, using 0(unlimited) instead.`\n",
59+
FLAG_old_gen_heap_size);
60+
FLAG_old_gen_heap_size = 0;
61+
}
62+
if (FLAG_new_gen_semi_max_size < 0 ||
63+
FLAG_new_gen_semi_max_size > kMaxAddrSpaceMB) {
64+
OS::PrintErr(
65+
"warning: value specified for --new_gen_semi_max_size %d is larger"
66+
" than the physically addressable range, using %" Pd " instead.`\n",
67+
FLAG_new_gen_semi_max_size, kDefaultNewGenSemiMaxSize);
68+
FLAG_new_gen_semi_max_size = kDefaultNewGenSemiMaxSize;
69+
}
70+
5571
#if defined(DART_COMPRESSED_POINTERS)
5672
if (compressed_heap_vmar_ == ZX_HANDLE_INVALID) {
5773
const zx_vm_option_t align_flag =

runtime/vm/virtual_memory_posix.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,22 @@ static MemoryRegion ClipToAlignedRegion(MemoryRegion region, size_t alignment) {
105105
#endif // LARGE_RESERVATIONS_MAY_FAIL
106106

107107
void VirtualMemory::Init() {
108+
if (FLAG_old_gen_heap_size < 0 || FLAG_old_gen_heap_size > kMaxAddrSpaceMB) {
109+
OS::PrintErr(
110+
"warning: value specified for --old_gen_heap_size %d is larger than"
111+
" the physically addressable range, using 0(unlimited) instead.`\n",
112+
FLAG_old_gen_heap_size);
113+
FLAG_old_gen_heap_size = 0;
114+
}
115+
if (FLAG_new_gen_semi_max_size < 0 ||
116+
FLAG_new_gen_semi_max_size > kMaxAddrSpaceMB) {
117+
OS::PrintErr(
118+
"warning: value specified for --new_gen_semi_max_size %d is larger"
119+
" than the physically addressable range, using %" Pd " instead.`\n",
120+
FLAG_new_gen_semi_max_size, kDefaultNewGenSemiMaxSize);
121+
FLAG_new_gen_semi_max_size = kDefaultNewGenSemiMaxSize;
122+
}
108123
page_size_ = CalculatePageSize();
109-
110124
#if defined(DART_COMPRESSED_POINTERS)
111125
ASSERT(compressed_heap_ == nullptr);
112126
#if defined(LARGE_RESERVATIONS_MAY_FAIL)

runtime/vm/virtual_memory_win.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,22 @@ static void* AllocateAlignedImpl(intptr_t size,
5353
}
5454

5555
void VirtualMemory::Init() {
56+
if (FLAG_old_gen_heap_size < 0 || FLAG_old_gen_heap_size > kMaxAddrSpaceMB) {
57+
OS::PrintErr(
58+
"warning: value specified for --old_gen_heap_size %d is larger than"
59+
" the physically addressable range, using 0(unlimited) instead.`\n",
60+
FLAG_old_gen_heap_size);
61+
FLAG_old_gen_heap_size = 0;
62+
}
63+
if (FLAG_new_gen_semi_max_size < 0 ||
64+
FLAG_new_gen_semi_max_size > kMaxAddrSpaceMB) {
65+
OS::PrintErr(
66+
"warning: value specified for --new_gen_semi_max_size %d is larger"
67+
" than the physically addressable range, using %" Pd " instead.`\n",
68+
FLAG_new_gen_semi_max_size, kDefaultNewGenSemiMaxSize);
69+
FLAG_new_gen_semi_max_size = kDefaultNewGenSemiMaxSize;
70+
}
5671
page_size_ = CalculatePageSize();
57-
5872
#if defined(DART_COMPRESSED_POINTERS)
5973
ASSERT(compressed_heap_ == nullptr);
6074
compressed_heap_ = Reserve(kCompressedHeapSize, kCompressedHeapAlignment);

0 commit comments

Comments
 (0)