dart-sdk/tests/standalone/out_of_memory_recovery_synchronous_test.dart
Ryan Macnak c8dea19836 [vm, gc] Reserve some memory to use during handling of OutOfMemoryErrors.
This reserved space can only be allocated from after an allocation has failed from OutOfMemory, and once some portion of this space is used, refilling it is the first allocation performed after GC.

Also avoid greatly slowing down from ineffective scavenges as the memory limit is reached.

Bug: https://github.com/dart-lang/sdk/issues/43543
Bug: https://github.com/dart-lang/sdk/issues/43642
Bug: b/169880355
Change-Id: Ic7132cb34d7a7d13c67661f057f00dd74306251c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165862
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-10-30 23:07:22 +00:00

50 lines
1 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--old_gen_heap_size=20
import "package:expect/expect.dart";
main() {
var leak;
var exceptionThrown = false;
try {
leak = [];
while (true) {
leak = [leak];
}
} on OutOfMemoryError catch (exception) {
leak = null;
exceptionThrown = true;
print("Okay");
}
Expect.isTrue(exceptionThrown);
exceptionThrown = false;
try {
leak = [];
while (true) {
leak = [leak];
}
} on OutOfMemoryError catch (exception) {
leak = null;
exceptionThrown = true;
print("Okay");
}
Expect.isTrue(exceptionThrown);
exceptionThrown = false;
try {
leak = [];
while (true) {
leak = [leak];
}
} on OutOfMemoryError catch (exception) {
leak = null;
exceptionThrown = true;
print("Okay");
}
Expect.isTrue(exceptionThrown);
}