diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java index 6b41e8f790e..5f402a5540c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -33,22 +33,23 @@ import nsk.share.jdi.AbstractJDIDebuggee; */ public class VMOutOfMemoryException001t extends AbstractJDIDebuggee { + public static int[] reserverdMemory = new int[1024 * 1024]; public static void main(String args[]) { new VMOutOfMemoryException001t().doTest(args); } // Just call normal doTest() function, but hide any OutOfMemoryErrors. + @Override public void doTest() { boolean isOutOfMemory = false; try { super.doTest(); } catch (OutOfMemoryError e) { - // Don't log anything. We are out of memory. - // A println is likely to genereate a new OutOfMemoryError isOutOfMemory = true; + reserverdMemory = null; + log.display("Got expected OOME."); } - // Normally the super class handles the return value. // If we got here after an OutOfMemoryError, we consider the test passed. if (isOutOfMemory && callExit) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java deleted file mode 100644 index b515721e925..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; -import java.lang.ref.Cleaner; - -/** - * Finalizable interface allows Finalizer to perform finalization of an object. - * Each object that requires finalization at VM shutdown time should implement this - * interface and call the registerCleanup to activate a Finalizer hook. - * - * @see Finalizer - */ -public interface Finalizable { - - /** - * This method will be implemented by FinalizableObject and is called in finalizeAtExit. - * - * @see Finalizer - */ - public void cleanup(); - - /** - * This method will be invoked by Finalizer when virtual machine - * shuts down. - * - * @throws Throwable if any throwable exception thrown during finalization - */ - default public void finalizeAtExit() throws Throwable { - cleanup(); - } - - /** - * This method will register a cleanup method and create an instance of Finalizer - * to register the object for finalization at VM exit. - * - * @see Finalizer - */ - default public void registerCleanup() { - Finalizer finalizer = new Finalizer(this); - finalizer.activate(); - - Cleaner.create().register(this, () -> cleanup()); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java b/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java deleted file mode 100644 index 7ffee4a43fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; - - -/** - * This class is a simple example of finalizable object, that - * implements interface Finalizable. - * - * @see Finalizable - * @see Finalizer - */ -public class FinalizableObject implements Finalizable { - /** - * Subclasses should override this method to provide the specific - * cleanup actions that they need. - */ - public void cleanup() {} -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java deleted file mode 100644 index 1d274c54b2a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2001, 2018, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; - -import java.util.Stack; - -/** - * Finalizer performs object finalization when virtual mashine shuts down. - * Finalizer is a thread that acts as a VM shutdown hook. - * This thread will be activated as VM shuts down because of - * invocation of exit() or termination. After activation - * Finalizer just calls finalizeAtExit() method of the specified object. - * The finalizable object should implement interface Finalizable. - * - * @see Finalizable - */ -public class Finalizer { - - /** Finalizer thread to register as a VM shutdown hook. */ - private static FinalizerThread finalizerThread = null; - - /** An object to finalize. */ - private Finalizable object; - - /** - * Create finalizer for the specified object. - */ - public Finalizer(Finalizable object) { - this.object = object; - } - - /** - * Register finalizer for finalization at VM shutdown. - */ - public void activate() { - if (finalizerThread == null) { - finalizerThread = new FinalizerThread("FinalizerThread for Finalizable objects"); - finalizerThread.activate(); - } - finalizerThread.add(object); - } - - /** - * Unregister finalizer for finalization at VM shutdown. - */ - public void deactivate() { - if (finalizerThread == null) - return; - finalizerThread.remove(object); - } - - /** - * Static inner thread that is registered as a VM shutdown hook - * and performs finalization of all registered finalizable objects. - */ - private static class FinalizerThread extends Thread { - - /** Stack of objects registered for finalization. */ - private Stack objects = new Stack(); - - /** Make new instance of FinalizerThread with given thread name. */ - public FinalizerThread(String threadName) { - super(threadName); - } - - /** - * Push an object to the stack of registered objects. - */ - public void add(Finalizable object) { - objects.push(object); - } - - /** - * Remove an object from the stack of registered objects. - */ - public void remove(Finalizable object) { - objects.remove(object); - } - - /** - * Register finalizer thread as a VM shutdown hook. - */ - public void activate() { - Runtime.getRuntime().addShutdownHook( this ); - } - - /** - * Unregister finalizer thread as a VM shutdown hook. - */ - public void deactivate() { - Runtime.getRuntime().removeShutdownHook( this ); - } - - /** - * Pop all registered objects from the stack and finalize them. - */ - public void run() { - while (!objects.empty()) { - Finalizable object = (Finalizable)objects.pop(); - try { - object.finalizeAtExit(); - } catch (ThreadDeath e) { - throw e; - } catch (Throwable ex) { - ex.printStackTrace(); - } - } - } - - } // end of FinalizerThread - -} // end of Finalizer diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java index b84c975ffaa..784cbd7c9c9 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -41,11 +41,6 @@ public final class MainWrapper { String[] classArgs = new String[args.length - 2]; System.arraycopy(args, 2, classArgs, 0, args.length - 2); - // It is needed to register finalizer thread in default thread group - // So FinalizerThread thread can't be in virtual threads group - FinalizableObject finalizableObject = new FinalizableObject(); - finalizableObject.registerCleanup(); - // Some tests use this property to understand if virtual threads are used System.setProperty("test.thread.factory", wrapperName); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java index 64688e4a655..bb726453e9b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java @@ -54,17 +54,23 @@ public class DummyTargetApplication { } public void runTargetApplication() { - pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0); - log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'"); - pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH); + try { + pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0); + log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'"); + pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH); - targetApplicationActions(); + targetApplicationActions(); - String signal = pipe.readln(); - log.display("Signal received: '" + signal + "'"); + String signal = pipe.readln(); + log.display("Signal received: '" + signal + "'"); - if ((signal == null) || !signal.equals(AODTestRunner.SIGNAL_FINISH)) - throw new TestBug("Unexpected signal: '" + signal + "'"); + if ((signal == null) || !signal.equals(AODTestRunner.SIGNAL_FINISH)) + throw new TestBug("Unexpected signal: '" + signal + "'"); + } finally { + if (pipe != null) { + pipe.close(); + } + } } public static void main(String[] args) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java index 962f4252684..58732bd0aa4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java @@ -66,7 +66,7 @@ import java.util.*; * @see nsk.share.jdi.Binder * @see nsk.share.jdwp.Binder */ -public class DebugeeBinder extends Log.Logger implements Finalizable { +public class DebugeeBinder extends Log.Logger { private static final boolean IS_WINDOWS = System.getProperty("os.name") .toLowerCase() @@ -118,8 +118,6 @@ public class DebugeeBinder extends Log.Logger implements Finalizable { public DebugeeBinder (DebugeeArgumentHandler argumentHandler, Log log) { super(log, LOG_PREFIX); this.argumentHandler = argumentHandler; - - registerCleanup(); } /** @@ -546,14 +544,6 @@ public class DebugeeBinder extends Log.Logger implements Finalizable { closePipeServerSocket(); } - /** - * Finalize binder by invoking close(). - * - */ - public void cleanup() { - close(); - } - /** * Separate thread for listening connection from BindServer. */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java index 94bca6fd734..6eb1f327660 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java @@ -196,16 +196,26 @@ abstract public class DebugeeProcess { */ public int waitFor () { long timeout = binder.getArgumentHandler().getWaitTime() * 60 * 1000; - int exitCode = 0; + int exitCode; try { exitCode = waitForDebugee(); } catch (InterruptedException ie) { ie.printStackTrace(log.getOutStream()); throw new Failure("Caught exception while waiting for debuggee process: \n\t" + ie); - } - waitForRedirectors(timeout); - if (process != null) { - process.destroy(); + } finally { + try { + waitForRedirectors(timeout); + } finally { + if (process != null) { + process.destroy(); + } + if (pipe != null) { + pipe.close(); + } + if (binder != null) { + binder.close(); + } + } } return exitCode; } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java index 1a1d6cab645..74e3a7c3a6d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -72,12 +72,16 @@ public class IOPipe extends SocketIOPipe { (long)debugee.getArgumentHandler().getWaitTime() * 60 * 1000, true); setServerSocket(debugee.getPipeServerSocket()); + if (debugee.pipe != null) { + throw new RuntimeException("debugee pipe is already set"); + } + debugee.pipe = this; } /** * Make general IOPipe object with specified parameters. */ - protected IOPipe(Log log, String host, int port, long timeout, boolean listening) { + private IOPipe(Log log, String host, int port, long timeout, boolean listening) { super("IOPipe", log, PIPE_LOG_PREFIX, host, port, timeout, listening); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java index baee16534e5..15e4d517970 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java @@ -62,7 +62,7 @@ import nsk.share.*; * pipe.println(command); * */ -public class SocketIOPipe extends Log.Logger implements Finalizable { +public class SocketIOPipe extends Log.Logger { public static final int DEFAULT_TIMEOUT_VALUE = 1 * 60 * 1000; @@ -93,8 +93,6 @@ public class SocketIOPipe extends Log.Logger implements Finalizable { this.timeout = timeout; this.listening = listening; this.name = name; - - registerCleanup(); } /** @@ -106,8 +104,6 @@ public class SocketIOPipe extends Log.Logger implements Finalizable { this.port = port; this.timeout = timeout; this.listening = listening; - - registerCleanup(); } /** @@ -311,17 +307,6 @@ public class SocketIOPipe extends Log.Logger implements Finalizable { return connection.getPingTimeout(); } - /** - * Perform finalization of the object by invoking close(). - * - * This is replacement of finalize() method and is called - * when this instance becomes unreachable. - * - */ - public void cleanup() { - close(); - } - /** * Field 'pipeCounter' and method 'getNextPipeNumber' are used to construct unique names for SocketIOPipes