diff --git a/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java b/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java index 7ca36d40a6f..9e9a6c79c7b 100644 --- a/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java +++ b/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,8 @@ public class JShellHeapDumpTest { static Process jShellProcess; static boolean doSleep = true; // By default do a short sleep when app starts up - public static void launch(String expectedMessage, List toolArgs) + // Returns false if the attempt should be retried. + public static boolean launch(String expectedMessage, List toolArgs, boolean allowRetry) throws IOException { try { @@ -81,6 +82,10 @@ public class JShellHeapDumpTest { System.out.println("###### End of all output which took " + elapsedTime + "ms"); output.shouldHaveExitValue(0); } catch (Exception ex) { + if (allowRetry) { + System.out.println("Exception " + ex + " in 'launch' occured. Allow one retry."); + return false; + } throw new RuntimeException("Test ERROR " + ex, ex); } finally { if (jShellProcess.isAlive()) { @@ -91,12 +96,18 @@ public class JShellHeapDumpTest { System.out.println("Jshell not alive"); } } + return true; } public static void launch(String expectedMessage, String... toolArgs) throws IOException { - launch(expectedMessage, Arrays.asList(toolArgs)); + boolean res = launch(expectedMessage, Arrays.asList(toolArgs), true); + // Allow a retry for !doSleep, because the sleep allows the debuggee to stabilize, + // making it very unlikely that jmap will fail. + if (!res && !doSleep) { + launch(expectedMessage, Arrays.asList(toolArgs), false); + } } /* Returns false if the attempt should be retried. */