Skip to content

Commit ba61de6

Browse files
committed
[GR-46412] PolyglotCachingTest fails with AssertionError: Objects are not collected.
PullRequest: graal/16033
2 parents d74cf9c + 7bb8fed commit ba61de6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

compiler/ci/ci_common/gate.jsonnet

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"--kill-with-sigquit",
4343
"gate",
4444
"--strict-mode",
45-
"--extra-vm-argument=-Djdk.graal.DumpOnError=true -Djdk.graal.PrintGraphFile=true -Djdk.graal.PrintBackendCFG=true" +
45+
"--extra-vm-argument=-Djdk.graal.DumpOnError=true -Djdk.graal.PrintGraphFile=true -Djdk.graal.PrintBackendCFG=true -DGCUtils.saveHeapDumpTo=." +
4646
(if extra_vm_args == "" then "" else " " + extra_vm_args)
4747
] + (if extra_unittest_args != "" then [
4848
"--extra-unittest-argument=" + extra_unittest_args,
@@ -55,6 +55,9 @@
5555
environment+: if jvm_config_suffix != null then {
5656
JVM_CONFIG: jvm_config + jvm_config_suffix
5757
} else {},
58+
logs+: [
59+
"*/gcutils_heapdump_*.hprof",
60+
],
5861
targets: ["gate"],
5962
python_version: "3"
6063
},

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/GCUtils.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import java.nio.file.Files;
4949
import java.nio.file.LinkOption;
5050
import java.nio.file.Path;
51+
import java.nio.file.StandardCopyOption;
52+
import java.nio.file.attribute.FileAttribute;
5153
import java.util.ArrayList;
5254
import java.util.Arrays;
5355
import java.util.Collection;
@@ -85,6 +87,14 @@ public final class GCUtils {
8587

8688
private static final boolean PRESERVE_HEAP_DUMP_ON_FAILURE = Boolean.parseBoolean(System.getProperty(GCUtils.class.getSimpleName() + ".preserveHeapDumpOnFailure", "true"));
8789

90+
/**
91+
* When set, and if the {@link #PRESERVE_HEAP_DUMP_ON_FAILURE} system property is set to
92+
* {@code true}, {@code GCUtils} relocates the heap dump to the designated folder. The target
93+
* heap dump file has the pattern {@code gcutils_heapdump_.+\.hprof} as produced by
94+
* {@link Files#createTempFile(Path, String, String, FileAttribute[])}.
95+
*/
96+
private static final String SAVE_HEAP_DUMP_TO = System.getProperty(GCUtils.class.getSimpleName() + ".saveHeapDumpTo");
97+
8898
private static final ReachabilityAnalyser<?> analyser = selectAnalyser();
8999

90100
private GCUtils() {
@@ -440,9 +450,21 @@ Result analyse(Collection<? extends Reference<?>> references, boolean force, boo
440450
JavaClass trackableReferenceClass = heap.getJavaClassByName(HeapDumpAnalyser.class.getName());
441451
ObjectArrayInstance todoArray = (ObjectArrayInstance) trackableReferenceClass.getValueOfStaticField("todo");
442452
List<Instance> instances = todoArray.getValues();
443-
result = testCollected.apply(new State(collectGCRootPath, preserveHeapDumpIfNonCollectable ? heapDumpFile : null, heap, instances, todoIndexes));
453+
Path targetFile = null;
454+
if (preserveHeapDumpIfNonCollectable) {
455+
if (SAVE_HEAP_DUMP_TO != null) {
456+
Path targetFolder = Path.of(SAVE_HEAP_DUMP_TO);
457+
targetFile = Files.createTempFile(targetFolder, "gcutils_heapdump_", ".hprof");
458+
} else {
459+
targetFile = heapDumpFile;
460+
}
461+
}
462+
result = testCollected.apply(new State(collectGCRootPath, targetFile, heap, instances, todoIndexes));
463+
if (targetFile != null && !targetFile.equals(heapDumpFile)) {
464+
Files.move(heapDumpFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
465+
}
444466
} finally {
445-
if (result == null || result.isCollected() || !preserveHeapDumpIfNonCollectable) {
467+
if (result == null || result.isCollected() || !preserveHeapDumpIfNonCollectable || SAVE_HEAP_DUMP_TO != null) {
446468
delete(tmpDirectory);
447469
}
448470
}

0 commit comments

Comments
 (0)