From bc7d9e3d0bc663bbbeb068889082da4a9f0fa8de Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Wed, 29 May 2024 15:01:07 +0000 Subject: [PATCH] 8333013: Update vmTestbase/nsk/share/LocalProcess.java to don't use finalization Reviewed-by: cjplummer, amenkov --- .../vmTestbase/nsk/share/jdb/JdbTest.java | 23 +++++++--------- .../nsk/share/{ => jdb}/LocalProcess.java | 26 +++---------------- 2 files changed, 13 insertions(+), 36 deletions(-) rename test/hotspot/jtreg/vmTestbase/nsk/share/{ => jdb}/LocalProcess.java (89%) diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java index ce2eb8de68f..349216f4329 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java @@ -204,27 +204,24 @@ public abstract class JdbTest { } } - } catch (Exception e) { - failure("Caught unexpected exception: " + e); - e.printStackTrace(out); - + } catch (Throwable t) { + failure("Caught unexpected exception: " + t); + t.printStackTrace(out); + } finally { if (jdb != null) { + log.complain("jdb reference is not null, check for exception in the logs."); try { jdb.close(); } catch (Throwable 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.close() method"); } - if (debuggee != null) { + if (debuggee != null && !debuggee.terminated()) { + log.complain("debuggee is still running, check for exception in the logs."); debuggee.killDebuggee(); - } else { - log.complain("debuggee reference is null, cannot run debuggee.killDebuggee() method"); } - } if (!success) { @@ -232,9 +229,9 @@ public abstract class JdbTest { return FAILED; } - } catch (Exception e) { - out.println("Caught unexpected exception while starting the test: " + e); - e.printStackTrace(out); + } catch (Throwable t) { + out.println("Caught unexpected exception while starting the test: " + t); + t.printStackTrace(out); out.println("TEST FAILED"); return FAILED; } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/LocalProcess.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/LocalProcess.java similarity index 89% rename from test/hotspot/jtreg/vmTestbase/nsk/share/LocalProcess.java rename to test/hotspot/jtreg/vmTestbase/nsk/share/jdb/LocalProcess.java index 6ff5c9a39a5..edb9f78ddc8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/LocalProcess.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/LocalProcess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, 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 @@ -21,9 +21,7 @@ * questions. */ -package nsk.share; - -import nsk.share.*; +package nsk.share.jdb; import java.io.*; @@ -33,14 +31,9 @@ import java.io.*; * This class provides abilities to launch such process, * redirect standard output streams, wait for process terminates * or kill the process, and so on. - *

- * This object is finalized with nsk.share.Finalizer. - * - * @see nsk.share.FinalizableObject - * @see nsk.share.Finalizer */ -public class LocalProcess extends FinalizableObject { +class LocalProcess { public final static int PROCESS_IS_ALIVE = 222; @@ -59,16 +52,11 @@ public class LocalProcess extends FinalizableObject { } process = Runtime.getRuntime().exec(args); - - registerCleanup(); } public void launch (String cmdLine) throws IOException { System.out.println("Launching process by command line: " + cmdLine); - process = Runtime.getRuntime().exec(cmdLine); - - registerCleanup(); } /** Return exit status. */ @@ -163,12 +151,4 @@ public class LocalProcess extends FinalizableObject { process.destroy(); } - /** - * This method is called at finalization and calls kill(). - * - */ - @Override - public void cleanup() { - kill(); - } }