8307559: Add better checking in com/sun/jdi tests for debuggee exiting unexpectedly with an exception

Reviewed-by: kevinw, lmesnik
This commit is contained in:
Chris Plummer 2023-05-11 23:16:22 +00:00
parent ce5907727e
commit 54c06d2d91
3 changed files with 31 additions and 19 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, 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
@ -83,19 +83,6 @@ class StackOverflowUncaughtTarg {
}
}
class StackOverflowIndirectTarg {
public static void main(String[] args) {
try {
thrower();
} catch (Throwable exc) {
System.out.println("Got exception: " + exc);
}
}
static void thrower() {
throw new StackOverflowError();
}
}
public class ExceptionEvents extends TestScaffold {
static int failureCount = 0;
static StringBuffer tooManySummary = new StringBuffer();
@ -395,6 +382,17 @@ public class ExceptionEvents extends TestScaffold {
/********** test core **********/
@Override
protected boolean allowedExitValue(int exitValue) {
// If the exception is caught, we expect exitValue == 0. For uncaught we
// we expect exitValue == 1.
if (target.equals("StackOverflowCaughtTarg")) {
return exitValue == 0;
} else {
return exitValue == 1;
}
}
protected void runTests() throws Exception {
/*
* Get to the top of main()

@ -45,12 +45,17 @@ class ResumeOneThreadTarg implements Runnable {
System.out.println(" Debuggee: Howdy!");
Thread t1 = TestScaffold.newThread(new ResumeOneThreadTarg(), name1);
Thread t2 = TestScaffold.newThread(new ResumeOneThreadTarg(), name2);
// Force these threads to be non-daemon threads, even when the debuggee
// is being run as a vthread. See JDK-8283796.
t1.setDaemon(false);
t2.setDaemon(false);
t1.start();
t2.start();
// We must block until these threads exit. Otherwise for virtual threads
// there will be nothing keeping these threads alive because all the threads
// involved are daemon threads. See JDK-8283796.
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
// This just starts two threads. Each runs to a bkpt.

@ -726,7 +726,7 @@ abstract public class TestScaffold extends TargetAdapter {
* Tests that expect an exitValue other than 0 or 1 will need to override this method.
*/
protected boolean allowedExitValue(int exitValue) {
return exitValue == 0 || exitValue == 1;
return exitValue == 0;
}
public synchronized void waitForVMDisconnect() {
@ -1033,6 +1033,15 @@ abstract public class TestScaffold extends TargetAdapter {
vthread.setName("main");
vthread.start();
vthread.join();
if (tg.uncaughtThrowable != null) {
// Note we cant just rethrow tg.uncaughtThrowable because there are tests
// that track ExceptionEvents, and they will complain about the extra
// exception. So instead mimic what happens when the main thread exits
// with an exception.
System.out.println("Uncaught Exception: " + tg.uncaughtThrowable);
tg.uncaughtThrowable.printStackTrace(System.out);
System.exit(1);
}
} else if (wrapper.equals("Kernel")) {
MainThreadGroup tg = new MainThreadGroup();
Thread t = new Thread(tg, () -> {