dart-sdk/tests/standalone/out_of_memory_recovery_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

55 lines
1.3 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 "dart:io";
import "dart:isolate";
import "package:expect/expect.dart";
handleRequest(request) {
if (request % 2 == 0) {
var leak = [];
while (true) {
leak = [leak];
}
}
return "Okay";
}
handleMessage(message) {
print(">> $message");
var responsePort = message[0];
var request = message[1];
try {
responsePort.send(<dynamic>[request, handleRequest(request)]);
} catch (e, st) {
responsePort.send(<dynamic>[request, "Failed: $e\n$st"]);
}
}
main(args) async {
var child = new RawReceivePort(handleMessage);
var parent;
parent = new RawReceivePort((message) {
print("<< $message");
var request = message[0];
var response = message[1];
if (request % 2 == 0) {
Expect.isTrue(response.contains("Out of Memory"));
} else {
Expect.equals("Okay", response);
}
if (request == 5) {
child.close();
parent.close();
} else {
child.sendPort.send(<dynamic>[parent.sendPort, request + 1]);
}
});
child.sendPort.send(<dynamic>[parent.sendPort, 1]);
}