From f66a58661459bf64212ec332540c12d5d691270f Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Fri, 24 May 2024 17:31:30 +0000 Subject: [PATCH] 8332641: Update nsk.share.jpda.Jdb to don't use finalization Reviewed-by: cjplummer, kevinw --- .../jtreg/vmTestbase/nsk/share/jdb/Jdb.java | 15 +++++--------- .../vmTestbase/nsk/share/jdb/JdbTest.java | 20 ++++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Jdb.java index 107f8f2e0d8d2..7b3281a7e1794 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, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -24,7 +24,6 @@ package nsk.share.jdb; import nsk.share.*; -import nsk.share.jpda.*; import java.util.*; import java.io.*; @@ -36,7 +35,7 @@ * This class provides abilities to launch it, to send command, * to read reply on the command, to set breakpoint on entry in debugggee's method. */ -public class Jdb extends LocalProcess implements Finalizable { +public class Jdb extends LocalProcess { /** File to log stdout stream */ static final String JDB_STDOUT_FILE = "jdb.stdout"; /** File to log stderr stream */ @@ -95,11 +94,8 @@ public static Launcher getLauncher() { return launcher; } - public void finalizeAtExit() throws Throwable { - finalize(); - } - public void finalize() throws Throwable { + public void close() { if (fout != null) { // fout.flush(); fout.close(); @@ -116,7 +112,6 @@ public void finalize() throws Throwable { if (jdbStderrReader != null) { jdbStderrReader.close(); } - super.finalize(); } /** Create Jdb object. */ @@ -961,10 +956,10 @@ public static Jdb startAttachingJdb (Launcher launcher, String[] jdbCmdArgs, Str System.out.println("Unsuccessful launch of attaching jdb. Next try..."); try { - jdb.finalize(); + jdb.close(); } catch (Throwable t) { t.printStackTrace(getLauncher().getLog().getOutStream()); - throw new Failure("Caught unexpected error while finalizing jdb: " + t); + throw new Failure("Caught unexpected error while closing jdb streams: " + t); } break; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java index c0edc58993bc1..ce2eb8de68fba 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -24,10 +24,8 @@ package nsk.share.jdb; import nsk.share.*; -import nsk.share.jpda.*; import java.io.*; -import java.util.*; public abstract class JdbTest { public static final int PASSED = 0; // Exit code for passed test @@ -174,6 +172,14 @@ protected int runTest(String argv[], PrintStream out) { } else { failure("jdb abnormally exited with code: " + code); } + + try { + jdb.close(); + } catch (Throwable ex) { + failure("Caught exception/error while closing jdb streams:\n\t" + ex); + ex.printStackTrace(log.getOutStream()); + } + jdb = null; if (debuggee != null @@ -204,19 +210,19 @@ protected int runTest(String argv[], PrintStream out) { if (jdb != null) { try { - jdb.finalize(); + jdb.close(); } catch (Throwable ex) { - failure("Caught exception/error while finalization of jdb:\n\t" + ex); + failure("Caught exception/error while closing jdb streams:\n\t" + ex); ex.printStackTrace(log.getOutStream()); } } else { - log.complain("jdb reference is null, cannot run jdb.finalize() method"); + log.complain("jdb reference is null, cannot run jdb.close() method"); } if (debuggee != null) { debuggee.killDebuggee(); } else { - log.complain("debuggee reference is null, cannot run debuggee.finalize() method"); + log.complain("debuggee reference is null, cannot run debuggee.killDebuggee() method"); } }