diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003.java index 840e8def8bc40..658f0d91e1550 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003.java @@ -55,6 +55,7 @@ public class kill003 extends JdbTest { public static void main (String argv[]) { debuggeeClass = DEBUGGEE_CLASS; firstBreak = FIRST_BREAK; + compoundPromptIdent = COMPOUND_PROMPT_IDENT; new kill003().runTest(argv); } @@ -65,6 +66,7 @@ public static void main (String argv[]) { static final String MYTHREAD = "MyThread"; static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD; static final String DEBUGGEE_EXCEPTION = DEBUGGEE_CLASS + ".exception"; + static final String COMPOUND_PROMPT_IDENT = "main"; protected void runCases() { String[] reply; @@ -74,7 +76,10 @@ protected void runCases() { // after creating all the threads. Get the list of debuggee threads. threads = jdb.getThreadIdsByName("main"); - // Stopped at kill.main, so step into synchronized block + // Make sure we stop in jdb when the NPE is thrown or rethrown. + reply = jdb.receiveReplyFor(JdbCommand._catch + "all java.lang.NullPointerException"); + + // Stopped at kill003a.main(), so step into synchronized block reply = jdb.receiveReplyFor(JdbCommand.next); if (threads.length != 1) { @@ -83,24 +88,28 @@ protected void runCases() { success = false; } - // Execution is at a bytecode that is not expected to handle an async exception. Throw one here - // to make sure it gets handled without crashing. The exception will be delivered at the next - // bytecode that can handle the async exception. + // Execution is at a bytecode that is not expected to handle an async exception. + // Throw one here to make sure it gets handled without crashing. The exception + // will be delivered at the next bytecode that can handle the async exception. reply = jdb.receiveReplyForWithMessageWait(JdbCommand.kill + threads[0] + " " + DEBUGGEE_EXCEPTION, "killed"); // Continue the debuggee - the async exception will be delivered to the debuggee. reply = jdb.receiveReplyFor(JdbCommand.cont); - // Ask the debuggee for its local variables at the bytecode where the async exception was delivered, which - // should be reachable. + // jdb got notified of the NPE for the kill command. continue and jdb will get + // notified again when it is rethrown from the synchronized block's implicit + // exception handler, which is where we want to execute the locals command from. + reply = jdb.receiveReplyFor(JdbCommand.cont); + + // Ask the debuggee for its local variables at the bytecode where the async + // exception was rethrown, which should be reachable. reply = jdb.receiveReplyForWithMessageWait(JdbCommand.locals, "Local variables"); if (jdb.terminated()) { throw new Failure("Debuggee exited"); } - // The lack of exception handler in the debuggee should cause it to exit when continued. jdb.contToExit(1); } } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003a.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003a.java index 1e72e02a56006..82b5e166db3e7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003a.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill003/kill003a.java @@ -30,7 +30,10 @@ public class kill003a { static NullPointerException exception = new NullPointerException(); public static void main(String args[]) { - synchronized (args) { + try { + synchronized (args) { + } + } catch (NullPointerException npe) { } System.out.println("done"); System.exit(JdbTest.JCK_STATUS_BASE); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java index 7b3281a7e1794..4b77a1acb8631 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2026, 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 @@ -530,7 +530,7 @@ public int waitForMessage(int startPos, String message) { return found; } - // spleep for awhile + // sleep for awhile synchronized(dummy) { try { dummy.wait(delta); @@ -614,7 +614,7 @@ int findPrompt(StringBuffer lines, boolean compoundPromptOnly, int startPos) { searching: for (int pos = startPos; pos < length; ) { - // skip each simbol not suitable for prompt begin + // skip each symbol not suitable for prompt begin if (!Character.isLetterOrDigit(lines.charAt(pos))) { pos++; continue searching;