diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt
index b6ec1d83b83..927a85fd6bc 100644
--- a/test/hotspot/jtreg/ProblemList.txt
+++ b/test/hotspot/jtreg/ProblemList.txt
@@ -169,5 +169,4 @@ vmTestbase/vm/mlvm/indy/func/jvmti/mergeCP_indy2manySame_b/TestDescription.java
vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java 7199837 generic-all
-vmTestbase/nsk/stress/except/except012.java 8297977 generic-all
vmTestbase/nsk/monitoring/ThreadMXBean/ThreadInfo/Multi/Multi005/TestDescription.java 8076494 windows-x64
diff --git a/test/hotspot/jtreg/runtime/reflect/ReflectOutOfMemoryError.java b/test/hotspot/jtreg/runtime/reflect/ReflectOutOfMemoryError.java
new file mode 100644
index 00000000000..40fc13acaa2
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/reflect/ReflectOutOfMemoryError.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/*
+ * @test
+ * @bug 8297977
+ * @summary Test that throwing OOM from reflected method gets InvocationTargetException
+ * @run main/othervm ReflectOutOfMemoryError
+ */
+import java.lang.reflect.*;
+
+// This test salvaged out of vmTestbase except tests.
+public class ReflectOutOfMemoryError {
+
+ private static volatile Object pool[] = null;
+
+ public static void raiseOutOfMemory() throws OutOfMemoryError {
+ try {
+ // Repository for objects, which should be allocated:
+ int index = 0;
+ for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
+ try {
+ pool = new Object[size];
+ } catch (OutOfMemoryError oome) {
+ }
+ if (pool == null)
+ throw new Error("HS bug: cannot allocate new Object[1]");
+
+ // Sum up time spent, when it was hard to JVM to allocate next object
+ // (i.e.: when JVM has spent more than 1 second to allocate new object):
+ double totalDelay = 0;
+ long timeMark = System.currentTimeMillis();
+
+ for (; index < pool.length; index++) {
+ //-------------------------
+ pool[index] = new Object();
+ long nextTimeMark = System.currentTimeMillis();
+ long elapsed = nextTimeMark - timeMark;
+ timeMark = nextTimeMark;
+ //----------------------
+ if (elapsed > 1000) {
+ double seconds = elapsed / 1000.0;
+ System.out.println(
+ "pool[" + index +
+ "]=new Object(); // elapsed " + seconds + "s");
+ totalDelay += seconds;
+ if (totalDelay > 300) {
+ System.out.println(
+ "Memory allocation became slow: so heap seems exhausted.");
+ throw new OutOfMemoryError();
+ }
+ }
+ }
+
+ // This method should never return:
+ throw new Error("TEST_BUG: failed to provoke OutOfMemoryError");
+ } finally {
+ // Make sure there will be enough memory for next object allocation
+ pool = null;
+ }
+ }
+
+ public static void main(java.lang.String[] unused) throws Exception {
+ System.out.println("Starting test");
+ Class testClass = ReflectOutOfMemoryError.class;
+ try {
+ Method testMethod = testClass.getMethod("raiseOutOfMemory", new Class [0]);
+ Object junk = testMethod.invoke(null, new Object [0]);
+ throw new RuntimeException("InvocationTargetException should be thrown");
+ } catch (InvocationTargetException ite) {
+ Throwable targetException = ite.getTargetException();
+ if (targetException instanceof OutOfMemoryError) {
+ System.out.println("OutOfMemoryError thrown as expected.");
+ System.out.println("Test passed.");
+ } else {
+ throw new RuntimeException("Unexpected InvocationTargetException: " + targetException);
+ }
+ } catch (Exception exception) {
+ throw new RuntimeException("Unexpected exception: " + exception);
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/TEST.properties b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/TEST.properties
deleted file mode 100644
index 8b51b2a9115..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/TEST.properties
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# Copyright (c) 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.
-#
-
-exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except001.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except001.java
deleted file mode 100644
index 0d87fe4e103..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except001.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except001.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if OutOfMemoryError exception is correctly enwrapped into
- * InvocationTargetException when thrown inside a method invoked via
- * reflection.
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new Object() instances. Instances of the "empty"
- * type Object are the smallest objects, so they apparently should occupy
- * most fine-grained fragments in the heap. Thus, there apparently should
- * not remain any free space to incarnate new Throwable instance, and VM
- * possibly could crash while trying to throw new OutOfMemoryError and
- * enwrap it into new InvocationTargetException instance.
- * By the way, the test checks time elapsed to allocate memory. Both
- * classic VM and HotSpot seem to fall into poor performance of memory
- * allocation when heap is almost over. E.g.: HotSpot 1.3-betaH may spend
- * more than 1 minute to allocate next Object in this case (tested on
- * Pentium-II, 350MHz, 128Mb RAM). To avoid this problem, the test enforce
- * OutOfMemoryError if more then 5 minutes is spent to allocate "last bytes"
- * of memory.
- * COMMENTS
- * HotSpot releases 1.0-fcsE (both Win32 and Sparc), and 1.3-betaH (Win32)
- * fail on this test due to poor performance of memory allocation.
- * #4248801 (P3/S5) slow memory allocation when heap is almost exhausted
- * Despite this bug is treated fixed in HotSpot 1.0.1, it still does suffer
- * slow memory allocation when running on PC having 64Mb or less of RAM.
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace may fail under JDK 1.2 for Win32 even so.
- * HotSpot 2.0-devA (Win32) crashes due to the known HotSpot bug:
- * #4239828 (P1/S4) 1.3c1: VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except001
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * This checks if OutOfMemoryError exception is correctly
- * enwrapped into InvocationTargetException when thrown inside
- * a method invoked via reflection.
- *
- *
The test tries to occupy all of memory available in the heap by
- * allocating lots of new Object() instances. Instances of the
- * ``empty'' type Object are the smallest objects, so they
- * apparently should occupy most fine-grained fragments in the heap.
- * Thus, there apparently should not remain any free space to incarnate new
- * Throwable instance, and VM possibly could crash while trying
- * to throw new OutOfMemoryError and enwrap it into new
- * InvocationTargetException instance.
- *
- *
By the way, the test checks time elapsed to allocate memory.
- * Both classic VM and HotSpot seem to fall into poor performance of memory
- * allocation when heap is almost over. E.g.: HotSpot 1.3-betaH may spend
- * more than 1 minute to allocate next Object in this case
- * (tested on Pentium-II, 350MHz, 128Mb RAM). To workaround this problem,
- * the test enforces OutOfMemoryError if more then 5 minutes
- * is spent to allocate ``last bytes'' of the memory.
- */
-public class except001 {
- /**
- * This field allows or supresses printing with display()
- * method.
- *
- * @see #display(Object)
- * @see #complain(Object)
- * @see #out
- */
- private static boolean MODE_VERBOSE = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
-
- /**
- * Print execution trace if MODE_VERBOSE is true
- * (optional).
- *
- * @see #MODE_VERBOSE
- * @see #complain(Object)
- * @see #out
- */
- private static void display(Object message) {
- if (MODE_VERBOSE)
- out.println(message.toString());
- out.flush();
- }
-
- /**
- * Print error message.
- *
- * @see #display(Object)
- * @see #out
- */
- private static void complain(Object message) {
- out.println("# " + message);
- out.flush();
- }
-
- /**
- * The log-stream assigned at runtime by the method
- * run(args,out).
- *
- * @see #display(Object)
- * @see #complain(Object)
- * @see #run(String[], PrintStream)
- */
- private static PrintStream out;
-
- /**
- * Try to allocate lots of instances of the type Object.
- * Such instances are most fine-grained, and thus they should occupy
- * smallest fragments of free memory in the heap.
- *
- *
By the way, break the test, if JVM has spent more than
- * 5 minutes to allocate latest portions of memory.
- */
- public static void raiseOutOfMemory() throws OutOfMemoryError {
- try {
- // Repository for objects, which should be allocated:
- int index = 0;
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
-
- for (; index < pool.length; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- display(
- "pool[" + index +
- "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 300) {
- complain(
- "Memory allocation became slow: so heap seems exhausted.");
- throw new OutOfMemoryError();
- }
- }
- }
-
- // This method should never return:
- throw new Error("TEST_BUG: failed to provoke OutOfMemoryError");
- } finally {
- // Make sure there will be enough memory for next object allocation
- pool = null;
- }
- }
-
- /**
- * Invoke the method raiseOutOfMemory() with reflection,
- * and check if the exception it throws is just
- * OutOfMemoryError enwrapped into
- * InvocationTargetException instance.
- *
- *
Before the test begins, this.out filed is assigned
- * to the parameter out. Parameter args[]
- * is ignored.
- *
- * @see #raiseOutOfMemory()
- */
- public static int run(String args[], PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so.");
-
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- MODE_VERBOSE = true;
- }
-
- except001.out = out;
- Class testClass = except001.class;
- try {
- Method testMethod = testClass.getMethod("raiseOutOfMemory", new Class [0]);
- Object junk = testMethod.invoke(null, new Object [0]);
-
- } catch (InvocationTargetException ite) {
- Throwable targetException = ite.getTargetException();
- if (targetException instanceof OutOfMemoryError) {
- display("OutOfMemoryError thrown as expected.");
- display("Test passed.");
- return 0;
- }
- complain("Unexpected InvocationTargetException: " + targetException);
- complain("Test failed.");
- return 2;
-
- } catch (Exception exception) {
- complain("Unexpected exception: " + exception);
- complain("Test failed.");
- return 2;
- }
- //
- complain("The test has finished unexpectedly.");
- complain("Test failed.");
- return 2;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(95);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except002.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except002.java
deleted file mode 100644
index 7fa25f6aea0..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except002.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except002.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except002
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- *
- *
The test tries to occupy all of memory available in the heap by
- * allocating lots of new Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- *
Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- *
There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- *
- *
Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except002 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- public static volatile Object pool[] = null;
- /**
- * Temporary log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will return the");
- out.println("# exit status 96 instead of 97 to indicate the problem.");
-
- // Prepare some items, which will be used by the test:
- Object trash = null;
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
- int index = 0;
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
-
- // Do not release any byte once allocated:
- pool[index++] = oome;
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check ClassNotFoundException (positive):
- try {
- trash = Class.forName("nsk.stress.except.except002$Abra$Cadabra"); // correct - should pass
-// trash = Class.forName("nsk.stress.except.except002.Abra.Cadabra"); // incorrect - should fail
- if (TRACE_ON)
- log[messages++] = "Success: ClassNotFoundException (positive)";
- } catch (ClassNotFoundException cnfe) {
- log[messages++] = "Failure: ClassNotFoundException (positive)";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ClassNotFoundException (positive)";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
- /**
- * This class should be used to check ClassNotFoundException
- * and IllegalAccessException.
- */
- private static class Abra {
- /**
- * Will try to incorrectly find this class as Cadabra
- * instead of Abra$Cadabra.
- */
- public static class Cadabra {
- }
-
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except003.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except003.java
deleted file mode 100644
index cb97fd8d3f9..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except003.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except003.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except003
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- *
- *
The test tries to occupy all of memory available in the heap by
- * allocating lots of new Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- *
Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- *
There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- *
- *
Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except003 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will return the");
- out.println("# exit status 96 instead of 97 to indicate the problem.");
-
- // Prepare some items, which will be used by the test:
- Object trash = null;
-
- // Allocate repository for a lots of tiny objects:
- pool = null;
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
- int index = 0;
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
-
- // Do not release any byte once allocated:
- pool[index++] = oome;
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check ClassNotFoundException (negative):
- try {
-// trash = Class.forName("nsk.stress.except.except003$Abra$Cadabra"); // correct - should pass
- trash = Class.forName("nsk.stress.except.except003.Abra.Cadabra"); // incorrect - should fail
- log[messages++] = "Failure: ClassNotFoundException (negative)";
- exitCode = 2;
- } catch (ClassNotFoundException cnfe) {
- if (TRACE_ON)
- log[messages++] = "Success: ClassNotFoundException (negative)";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ClassNotFoundException (negative)";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(95);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
- /**
- * This class should be used to check ClassNotFoundException
- * and IllegalAccessException.
- */
- private static class Abra {
- /**
- * Will try to incorrectly find this class as Cadabra
- * instead of Abra$Cadabra.
- */
- public static class Cadabra {
- }
-
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except004.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except004.java
deleted file mode 100644
index 865e506353c..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except004.java
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * Copyright (c) 1999, 2021, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except004.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M -XX:-UseGCOverheadLimit nsk.stress.except.except004
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-import java.lang.reflect.Field;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- *
- *
The test tries to occupy all of memory available in the heap by
- * allocating lots of new Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- *
Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- *
There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- *
- *
Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except004 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except005 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
-
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except006 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except007 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except008 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except009 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except010 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
- /**
- * Temporary
- * The test tries to occupy all of memory available in the heap by
- * allocating lots of new
- * Note, that memory occupation is terminated if memory allocation slows
- * down crucially. This is a workaround intended to avoid the HotSpot bug:
- *
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- *
- * Also note, that the test needs a lot of memory to start up, so it should
- * not run under older JDK 1.1.x release due to its poor heap utilization.
- */
-public class except012 {
- /**
- * Either allow or supress printing of execution trace.
- */
- private static boolean TRACE_ON = false;
- /**
- * Either allow or supress printing of warning messages.
- */
- private static final boolean WARN_ON = true;
-
- /**
- * Temporary log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode;
- try {
- exitCode = run(out);
- } finally { // ensure we have free memory for exception processing
- pool = null;
- System.gc();
- }
- if (TRACE_ON)
- out.println("Test completed.");
-
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could cause OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will return the");
- out.println("# exit status 96 instead of 97 to indicate the problem.");
-
- // run all tests normally to ensure all needed classes are loaded and
- // initialized before the heap is exhausted - else we may trigger OOME
- // in unexpected places.
- try {
- if (TRACE_ON)
- out.println("Running without heap exhaustion");
- runTests(out, false);
- } catch (Throwable unexpected) {
- out.println("Test pre-initialisation failed: " + unexpected);
- return 2;
- }
-
- if (TRACE_ON)
- out.println("Running with heap exhaustion");
-
- return runTests(out, true);
- }
-
- private static int runTests(PrintStream out, boolean exhaustHeap) {
- // reset message index
- messages = 0;
-
- // Prepare some items, which will be used by the test:
- Object stringArray[] = new String[1];
- Object integerValue = Integer.valueOf(0);
- Object doubleValue = Double.valueOf(0);
- Object trash = null;
- Field abraIntegerField;
- Field abraBooleanField;
- Field extPrivateField;
- try {
- abraIntegerField = Abra.class.getDeclaredField("MAIN_CYR_NUMBER");
- abraBooleanField = Abra.class.getDeclaredField("NOT_AN_INTEGER");
- extPrivateField = Ext.class.getDeclaredField("DONT_TOUCH_ME");
- } catch (NoSuchFieldException nsfe) {
- out.println("Test initialisation failed: field not found: " + nsfe.getMessage());
- return 2;
- }
-
- Abra abra = new Abra("via public constructor");
- Abra.Cadabra cadabra = new Abra.Cadabra();
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
-
- int poolSize = 0;
- int index = 0;
-
- if (exhaustHeap) {
- pool = null;
- // Allocate repository for lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1) {
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- poolSize = pool.length;
- index = 0;
-
- // Sum up time spent, when it was hard for JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- // Do not release any byte once allocated:
- pool[index++] = oome;
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
- } else {
- // pool gets used for array index tests
- pool = new Object[3];
- poolSize = pool.length;
- }
-
- // Check ArithmeticException:
- try {
- int x, y, z;
- x = y = 0;
- z = x / y;
- log[messages++] = "Failure: ArithmeticException";
- exitCode = 2; // FAILED
- } catch (ArithmeticException ae) {
- if (TRACE_ON)
- log[messages++] = "Success: ArithmeticException";
- if (exhaustHeap)
- pool[index++] = ae;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ArithmeticException";
- skipped++;
- }
-
- // Check ArrayIndexOutOfBoundsException:
- try {
- pool[poolSize] = pool[0];
- log[messages++] = "Failure: ArrayIndexOutOfBoundsException";
- exitCode = 2; // FAILED
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- if (TRACE_ON)
- log[messages++] = "Success: ArrayIndexOutOfBoundsException";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ArrayIndexOutOfBoundsException";
- skipped++;
- }
-
- // Check ArrayStoreException:
- try {
- stringArray[0] = integerValue;
- log[messages++] = "Failure: ArrayStoreException";
- exitCode = 2; // FAILED
- } catch (ArrayStoreException ase) {
- if (TRACE_ON)
- log[messages++] = "Success: ArrayStoreException";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ArrayStoreException";
- skipped++;
- }
-
- // Check ClassCastException:
- try {
- trash = (Double) integerValue;
- log[messages++] = "Failure: ClassCastException";
- exitCode = 2; // FAILED
- } catch (ClassCastException cce) {
- if (TRACE_ON)
- log[messages++] = "Success: ClassCastException";
- if (exhaustHeap)
- pool[index++] = cce;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: ClassCastException";
- skipped++;
- }
-
- // Check CloneNotSupportedException:
- try {
- trash = abra.clone(); // illegal - should fail
-// trash = cadabra.clone(); // legal - should pass
- log[messages++] = "Failure: CloneNotSupportedException";
- exitCode = 2; // FAILED
- } catch (CloneNotSupportedException cnse) {
- if (TRACE_ON)
- log[messages++] = "Success: CloneNotSupportedException";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: CloneNotSupportedException";
- skipped++;
- }
-
- // Check IllegalAccessException (positive):
- try {
- int junkIt = abraIntegerField.getInt(null); // legal - should pass
- if (TRACE_ON)
- log[messages++] = "Success: IllegalAccessException (positive)";
- } catch (IllegalAccessException iae) {
- log[messages++] = "Failure: IllegalAccessException (positive)";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalAccessException (positive)";
- skipped++;
- }
-
- // Check IllegalAccessException (negative):
- try {
- int junkIt = extPrivateField.getInt(null); // illegal - should fail
- log[messages++] = "Failure: IllegalAccessException (negative)";
- exitCode = 2; // FAILED
- } catch (IllegalAccessException iae) {
- if (TRACE_ON)
- log[messages++] = "Success: IllegalAccessException (negative)";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalAccessException (negative)";
- skipped++;
- }
-
- // Check IllegalArgumentException (positive):
- try {
- int junkIt = abraIntegerField.getInt(null); // legal - should pass
-// int junkIt = abraBooleanField.getInt(null); // illegal - should fail
- if (TRACE_ON)
- log[messages++] = "Success: IllegalArgumentException (positive)";
- } catch (IllegalAccessException iae) {
- log[messages++] =
- "Failure: IllegalArgumentException (positive) incorrectly thrown IllegalAccessException";
- exitCode = 2;
- } catch (IllegalArgumentException iae) {
- log[messages++] = "Failure: IllegalArgumentException (positive)";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalArgumentException (positive)";
- skipped++;
- }
-
- // Check IllegalArgumentException (negative):
- try {
-// int junkIt = abraIntegerField.getInt(null); // legal - should pass
- int junkIt = abraBooleanField.getInt(null); // illegal - should fail
- log[messages++] = "Failure: IllegalArgumentException (negative)";
- exitCode = 2; // FAILED
- } catch (IllegalAccessException iae) {
- log[messages++] =
- "Failure: IllegalArgumentException (negative) incorrectly thrown IllegalAccessException";
- exitCode = 2;
- } catch (IllegalArgumentException iae) {
- if (TRACE_ON)
- log[messages++] = "Success: IllegalArgumentException (negative)";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalArgumentException (negative)";
- skipped++;
- }
-
- // Check IllegalMonitorStateException (positive):
- try {
- synchronized (cadabra) {
- cadabra.notifyAll(); // legal - should pass
- }
-// cadabra.notifyAll(); // illegal - should fail
- if (TRACE_ON)
- log[messages++] = "Success: IllegalMonitorStateException (positive)";
- } catch (IllegalMonitorStateException imse) {
- log[messages++] = "Failure: IllegalMonitorStateException (positive)";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalMonitorStateException (positive)";
- skipped++;
- }
-
- // Check IllegalMonitorStateException (negative):
- try {
-// synchronized (cadabra) {
-// cadabra.notifyAll(); // legal - should pass
-// }
- cadabra.notifyAll(); // illegal - should fail
- log[messages++] = "Failure: IllegalMonitorStateException (negative)";
- exitCode = 2;
- } catch (IllegalMonitorStateException imse) {
- if (TRACE_ON)
- log[messages++] = "Success: IllegalMonitorStateException (negative)";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: IllegalMonitorStateException (negative)";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- if (e instanceof RuntimeException)
- throw (RuntimeException) e;
- else if (e instanceof Error)
- throw (Error) e;
- else
- throw new Error("Unexpected checked exception", e);
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
- /**
- * This class should be used to check CloneNotSupportedException,
- * and IllegalArgumentException.
- * The class extends except004 in order that its (protected)
- * method clone() be available from except004.
- */
- private static class Abra extends except004 {
- /**
- * Will try to incorrectly find this class as Cadabra
- * instead of Abra$Cadabra.
- */
- public static class Cadabra implements Cloneable {
- }
-
- /**
- * Will try to incorrectly access to this field from outside this class.
- */
- public static final int MAIN_CYR_NUMBER = 47;
- /**
- * Will try to get this field like int zero.
- */
- public static final boolean NOT_AN_INTEGER = false;
-
- /**
- * Will try to correctly instantiate Abra.Cadabra,
- * not Abra.
- */
- private Abra() {
- }
-
- /**
- * Yet another constructor, which is public.
- */
- public Abra(String nothingSpecial) {
- }
- }
-}
-
-/* Package accessible class that has non-accessible private member */
-class Ext {
- /**
- * Will try to incorrectly access to this field from outside this class.
- */
- private static final int DONT_TOUCH_ME = 666;
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except005.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except005.java
deleted file mode 100644
index cc74efb4f2f..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except005.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except005.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except005
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * pool to store tiny objects to fill up the Heap
- */
- private static volatile Object pool[] = null;
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# Test have been updated!");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
- int index = 0;
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON) {
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- }
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check InstantiationException (positive):
- try {
-// Object junkIt = Abra_Cadabra.class.newInstance(); // illegal - should fail
- Object junkIt = Abra.Cadabra.class.newInstance(); // legal - should pass
- if (TRACE_ON)
- log[messages++] = "Success: InstantiationException (positive)";
- } catch (IllegalAccessException iae) {
- log[messages++] =
- "Failure: InstantiationException (positive) incorrectly thrown IllegalAccessException";
- pool[index++] = iae;
- exitCode = 2;
- } catch (InstantiationException ie) {
- log[messages++] = "Failure: InstantiationException (positive)";
- pool[index++] = ie;
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: InstantiationException (positive)";
- pool[index++] = oome;
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some OOME, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
- /**
- * This class should be used to check CloneNotSupportedException,
- * IllegalAccessException, and IllegalArgumentException.
- * The class extends except005 in order that its (protected)
- * method clone() be available from except005.
- */
- private static class Abra {
- /**
- * Will correctly instantiate Abra.Cadabra object.
- */
- public static class Cadabra {
- }
-
- /**
- * Will try to correctly instantiate Abra.Cadabra,
- * not Abra.
- */
- private Abra() {
- }
-
- }
-
- /**
- * Will try to incorrectly instantiate and object of this class.
- */
- private interface Abra_Cadabra {
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except006.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except006.java
deleted file mode 100644
index 88676b632a7..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except006.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except006.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except006
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
- int index = 0;
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- Object junkIt;
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
-
- // Check InstantiationException (negative):
- try {
- junkIt = Abra_Cadabra.class.newInstance(); // illegal - should fail
-// Object junkIt = Abra.Cadabra.class.newInstance(); // legal - should pass
- log[messages++] = "Failure: InstantiationException (negative)";
- exitCode = 2;
- } catch (IllegalAccessException iae) {
- log[messages++] =
- "Failure: InstantiationException (negative) incorrectly thrown IllegalAccessException";
- exitCode = 2;
- } catch (InstantiationException ie) {
- if (TRACE_ON)
- log[messages++] = "Success: InstantiationException (negative)";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: InstantiationException (negative)";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
- /**
- * This class should be used to check CloneNotSupportedException,
- * IllegalAccessException, and IllegalArgumentException.
- * The class extends except006 in order that its (protected)
- * method clone() be available from except006.
- */
- private static class Abra {
- /**
- * Will correctly instantiate Abra.Cadabra object.
- */
- public static class Cadabra {
- }
-
- /**
- * Will try to correctly instantiate Abra.Cadabra,
- * not Abra.
- */
- private Abra() {
- }
-
- }
-
- /**
- * Will try to incorrectly instantiate and object of this class.
- */
- private interface Abra_Cadabra {
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except007.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except007.java
deleted file mode 100644
index ffa17454459..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except007.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except007.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except007
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Prepare some items, which will be used by the test:
- Thread rabbit = new Rabbit();
-
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
-
- int index = 0;
- pool[index++] = new Object();
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
-
- // Check InterruptedException:
- try {
- synchronized (rabbit) {
- rabbit.start();
- rabbit.wait();
- }
- rabbit.interrupt();
- while (rabbit.isAlive())
- rabbit.join();
- Throwable exception = ((Rabbit) rabbit).exception;
- if (exception == null) {
- log[messages++] = "Failure: InterruptedException not thrown";
- exitCode = 2;
- } else {
- if (exception instanceof InterruptedException) {
- if (TRACE_ON)
- log[messages++] =
- "Success: InterruptedException thrown as expected";
- } else if (exception instanceof OutOfMemoryError) {
- if (WARN_ON)
- log[messages++] = "Skipped: InterruptedException";
- skipped++;
- } else {
- log[messages++] =
- "Failure: InterruptedException: unexpected exception thrown";
- exitCode = 2;
- }
- pool[index++] = exception;
- }
- } catch (InterruptedException ie) {
- log[messages++] = "Failure: InterruptedException thrown unexpectedly";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: InterruptedException";
- skipped++;
- }
-
- // Check NegativeArraySizeException:
- try {
- int negative = -1;
- byte array[] = new byte[negative];
- log[messages++] = "Failure: NegativeArraySizeException not thrown as expected";
- exitCode = 2;
- } catch (NegativeArraySizeException ie) {
- if (TRACE_ON)
- log[messages++] = "Success: NegativeArraySizeException thrown as expected";
- pool[index++] = ie;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: NegativeArraySizeException";
- skipped++;
- }
-
- // Check NullPointerException:
- try {
- Double none = null;
- double oops = none.doubleValue();
- log[messages++] = "Failure: NullPointerException not thrown as expected";
- exitCode = 2;
- } catch (NullPointerException npe) {
- if (TRACE_ON)
- log[messages++] = "Success: NullPointerException thrown as expected";
- pool[index++] = npe;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: NullPointerException";
- skipped++;
- }
-
- // Check NumberFormatException:
- try {
- double oops = Double.parseDouble("3.14159D00"); // FORTRAN-like
- log[messages++] = "Failure: NumberFormatException not thrown as expected";
- exitCode = 2;
- } catch (NumberFormatException nfe) {
- if (TRACE_ON)
- log[messages++] = "Success: NumberFormatException thrown as expected";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] = "Skipped: NumberFormatException";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Will shoot a rabbit when it waits -- in order to provoke
- * InterruptedException.
- */
- private static class Rabbit extends Thread {
- Throwable exception = null;
-
- public void run() {
- try {
- synchronized (this) {
- this.notify();
- this.wait();
- }
- } catch (InterruptedException ie) {
- exception = ie;
- } catch (OutOfMemoryError oome) {
- exception = oome;
- }
- }
-
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except008.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except008.java
deleted file mode 100644
index 75e0543ba2a..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except008.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except008.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M -XX:-UseGCOverheadLimit nsk.stress.except.except008
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Prepare some items, which will be used by the test:
- Zoo zoo = new Zoo(); // load the class Zoo
- Class noArgs[] = new Class[0];
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
-
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
-
- int index = 0;
- pool[index++] = new Object();
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check NoSuchFieldException (positive):
- try {
- Field valid = Zoo.class.getField("PUBLIC_FIELD"); // should pass
-// Field wrong = Zoo.class.getField("PRIVATE_FIELD"); // should fail
- if (TRACE_ON)
- log[messages++] = "Success: NoSuchFieldException not thrown as expected";
- } catch (NoSuchFieldException nsfe) {
- pool[index++] = nsfe;
- log[messages++] = "Failure: NoSuchFieldException thrown unexpectedly";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: NoSuchFieldException positive check - OutOfMemoryError thrown";
- skipped++;
- }
-
- // Check NoSuchFieldException (negative):
- try {
-// Field valid = Zoo.class.getField("PUBLIC_FIELD"); // should pass
- Field wrong = Zoo.class.getField("PRIVATE_FIELD"); // should fail
- log[messages++] = "Failure: NoSuchFieldException incorrectly not thrown";
- exitCode = 2;
- } catch (NoSuchFieldException nsfe) {
- if (TRACE_ON)
- log[messages++] = "Success: NoSuchFieldException thrown as expected";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "NoSuchFieldException negative check - OutOfMemoryError thrown";
- skipped++;
- }
-
- // Check NoSuchMethodException (positive):
- try {
- Method valid = Zoo.class.getMethod("PUBLIC_METHOD", noArgs); // should pass
-// Method wrong = Zoo.class.getMethod("PRIVATE_METHOD",noArgs); // should fail
- if (TRACE_ON)
- log[messages++] = "Success: NoSuchFieldException not thrown as expected";
- } catch (NoSuchMethodException nsme) {
- pool[index++] = nsme;
- log[messages++] = "Failure: NoSuchMethodException thrown unexpectedly";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: NoSuchMethodException positive check - OutOfMemoryError thrown";
- pool[index++] = oome;
- skipped++;
- }
-
- // Check NoSuchMethodException (negative):
- try {
-// Method valid = Zoo.class.getMethod("PUBLIC_METHOD",noArgs); // should pass
- Method wrong = Zoo.class.getMethod("PRIVATE_METHOD", noArgs); // should fail
- log[messages++] = "Failure: NoSuchMethodException incorrectly not thrown";
- exitCode = 2;
- } catch (NoSuchMethodException nsme) {
- pool[index++] = nsme;
- if (TRACE_ON)
- log[messages++] = "Success: NoSuchFieldException thrown as expected";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: NoSuchMethodException negative check - OutOfMemoryError thrown";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Several items used to check reflections.
- */
- private static class Zoo {
- public String PUBLIC_FIELD = "Accessible via reflection";
- private String PRIVATE_FIELD = "Inaccessible via reflection";
-
- public String PUBLIC_METHOD() {
- return "Accessible via reflection";
- }
-
- private String PRIVATE_METHOD() {
- return "Inaccessible via reflection";
- }
-
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exception outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except009.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except009.java
deleted file mode 100644
index 1f0fb5d0ce0..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except009.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (c) 1999, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except009.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except009
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- String s = "qwerty";
- char c;
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
-
- int index = 0;
- pool[index++] = new Object();
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check StringIndexOutOfBoundsException:
- try {
- c = s.charAt(6); // should fail
- log[messages++] = "Failure: StringIndexOutOfBoundsException incorrectly not thrown";
- exitCode = 2;
- } catch (StringIndexOutOfBoundsException sioobe) {
- pool[index++] = sioobe;
- if (TRACE_ON)
- log[messages++] = "Success: StringIndexOutOfBoundsException thrown as expected";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: StringIndexOutOfBoundsException: thrown OutOfMemoryError";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exceprions outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except010.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except010.java
deleted file mode 100644
index c5c4d41b81f..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except010.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright (c) 1999, 2022, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except010.
- * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @requires vm.opt.DeoptimizeALot != true
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except010
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
-
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
-
- int index = 0;
- pool[index++] = new Object();
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check StackOverflowError:
- try {
- goIntoInfiniteRecursion();
- log[messages++] = "Failure: StackOverflowError failed to throw";
- exitCode = 2;
- } catch (StackOverflowError soe) {
- pool[index++] = soe;
- if (TRACE_ON)
- log[messages++] = "Success: StackOverflowError thrown as expected";
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: StackOverflowError: thrown OutOfMemoryError";
- skipped++;
- }
-
- return exitCode;
- }
-
- private static void goIntoInfiniteRecursion() {
- goIntoInfiniteRecursion();
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some exceptions outside the code, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- log = null;
- System.gc();
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // No code in the handler can provoke correct exceptions.
- } else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}
diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except012.java b/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except012.java
deleted file mode 100644
index 8b096343cd9..00000000000
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/except/except012.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Copyright (c) 1999, 2020, 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.
- */
-
-
-/*
- * @test
- * @key stress
- *
- * @summary converted from VM testbase nsk/stress/except/except012.
- * VM testbase keywords: [stress, slow, nonconcurrent, quick]
- * VM testbase readme:
- * DESCRIPTION
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * The test tries to occupy all of memory available in the heap by allocating
- * lots of new Object() instances. Instances of the type Object are the smallest
- * objects, so they apparently should occupy most fine-grained fragments in the
- * heap and leave no free space for new Throwable instance. After that, the test
- * provokes various exceptions (e.g.: by executing integer division by 0 and so
- * on), and checks if appropriate exceptions are thrown.
- * COMMENTS
- * The test needs a lot of memory to start up, so it should not run under older
- * JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
- * skipped when testing classic VM, because OutOfMemoryError is correctly thrown
- * instead of target exception.
- * When the test is being self-initiating (i.e.: eating heap), memory occupation
- * is terminated if memory allocation slows down crucially. This is a workaround
- * intended to avoid the HotSpot bug:
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- * There is also a workaround involved to avoid the following bugs known
- * for HotSpot and for classic VM:
- * #4239841 (P1/S5) 1.1: poor garbage collector performance (HotSpot bug)
- * #4245060 (P4/S5) poor garbage collector performance (Classic VM bug)
- * However, printing of the test's error messages, warnings, and of execution
- * trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
- * problem, exit status 96 is returned instead of 97.
- * JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
- * #4245057 (P2/S3) VM crashes when heap is exhausted
- *
- * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except012
- */
-
-package nsk.stress.except;
-
-import java.io.PrintStream;
-import java.util.Random;
-
-/**
- * This checks if various exceptions are thrown (and caught) correctly
- * when there apparently are no free space in the heap to allocate new
- * Throwable instance.
- * Object() instances. Instances of the
- * type Object are the smallest objects, so they apparently should
- * occupy most fine-grained fragments in the heap and leave no free space for
- * new Throwable instance. After that, the test provokes various
- * exceptions (e.g.: by executing integer division by 0 and so on), and checks
- * if appropriate exceptions are thrown.
- *
- * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
- *
- * #4239841 (P1/S5) 1.1: poor garbage collector performance
- *
- * #4245060 (P4/S5) poor garbage collector performance
- *
However, printing of the test's error messages, warnings, and of
- * execution trace may fail even so. If the test fails due to poor GC
- * performance, exit status 96 is returned instead of 97.
- * log for error messages, warnings and/or execution trace.
- *
- * @see #messages
- */
- private static String log[] = new String[1000]; // up to 1000 messages
- /**
- * How many messages were submitted to the log.
- *
- * @see #log
- */
- private static int messages = 0;
- /*
- * Storage for a lot of tiny objects
- * "static volatile" keywords are for preventing heap optimization
- */
- private static volatile Object pool[] = null;
-
- /**
- * Re-call to the method run(out) (ignore args[]),
- * and print the test summary - either test passed of failed.
- */
- public static int run(String args[], PrintStream out) {
- if (args.length > 0) {
- if (args[0].toLowerCase().startsWith("-v"))
- TRACE_ON = true;
- }
-
- int exitCode = run(out);
- pool = null;
- System.gc();
- // Print the log[] and the test summary:
- try {
- for (int i = 0; i < messages; i++)
- out.println(log[i]);
- if (exitCode == 0) {
- if (TRACE_ON)
- out.println("Test passed.");
- } else
- out.println("Test failed.");
- } catch (OutOfMemoryError oome) {
- // Poor performance of garbage collector:
- exitCode = 1;
- }
-
- return exitCode;
- }
-
- /**
- * Allocate as much Object instances as possible to bring JVM
- * into stress, and then check if exceptions are correctly thrown accordingly
- * to various situations like integer division by 0, etc.
- */
- private static int run(PrintStream out) {
- out.println("# While printing this message, JVM seems to initiate the output");
- out.println("# stream, so that it will not need more memory to print later,");
- out.println("# when the heap would fail to provide more memory.");
- out.println("# ");
- out.println("# Note, that the test maintains especial static log[] field in");
- out.println("# order to avoid printing when the heap seems exhausted.");
- out.println("# Nevertheless, printing could arise OutOfMemoryError even");
- out.println("# after all the memory allocated by the test is released.");
- out.println("# ");
- out.println("# That problem is caused by the known JDK/HotSpot bugs:");
- out.println("# 4239841 (P1/S5) 1.1: poor garbage collector performance");
- out.println("# 4245060 (P4/S5) poor garbage collector performance");
- out.println("# ");
- out.println("# This message is just intended to work-around that problem.");
- out.println("# If printing should fail even so, the test will try to return");
- out.println("# the exit status 96 instead of 97 to indicate the problem.");
- out.println("# However, the test may fail or even crash on some platforms");
- out.println("# suffering the bug 4239841 or 4245060.");
-
- // Allocate items necessary for the test:
- CrazyClassLoader crazyClassLoader = new CrazyClassLoader();
- MustDie threadToDie = new MustDie();
-
- // Sum up exit code:
- int exitCode = 0; // apparently PASSED
- int skipped = 0; // some checks may correctly suffer OutOfMemoryError
- // Allocate repository for a lots of tiny objects:
- for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
- try {
- pool = new Object[size];
- } catch (OutOfMemoryError oome) {
- }
- if (pool == null)
- throw new Error("HS bug: cannot allocate new Object[1]");
- int poolSize = pool.length;
-
- int index = 0;
- pool[index++] = new Object();
-
- // Sum up time spent, when it was hard to JVM to allocate next object
- // (i.e.: when JVM has spent more than 1 second to allocate new object):
- double totalDelay = 0;
- long timeMark = System.currentTimeMillis();
- try {
- for (; index < poolSize; index++) {
- //-------------------------
- pool[index] = new Object();
- long nextTimeMark = System.currentTimeMillis();
- long elapsed = nextTimeMark - timeMark;
- timeMark = nextTimeMark;
- //----------------------
- if (elapsed > 1000) {
- double seconds = elapsed / 1000.0;
- if (TRACE_ON)
- out.println(
- "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
- totalDelay += seconds;
- if (totalDelay > 60) {
- if (TRACE_ON)
- out.println(
- "Memory allocation became slow; so, heap seems exhausted.");
- break;
- }
- }
- }
- } catch (OutOfMemoryError oome) {
- if (TRACE_ON)
- log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
- }
-
- if (index > poolSize - 1000) {
- if (WARN_ON)
- log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
- }
-
- // Check ClassFormatError:
- try {
- Class oops = crazyClassLoader.loadClass("name doesn't matter");
- log[messages++] = "Failure: ClassFormatError failed to throw";
- exitCode = 2;
- } catch (ClassFormatError cfe) {
- if (TRACE_ON)
- log[messages++] = "Success: ClassFormatError thrown as expected";
- } catch (ClassNotFoundException cnfe) {
- log[messages++] =
- "Failure: ClassFormatError: unexpectedly thrown ClassNotFoundException";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: ClassFormatError: thrown OutOfMemoryError";
- skipped++;
- }
-
- // Check ThreadDeath:
- try {
- threadToDie.start();
- while (threadToDie.isAlive())
- threadToDie.join();
- Throwable exception = threadToDie.exception;
- if (exception == null) {
- log[messages++] = "Failure: ThreadDeath failed to throw";
- exitCode = 2;
- } else if (exception instanceof OutOfMemoryError) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: ThreadDeath: thrown OutOfMemoryError instead";
- } else if (!(exception instanceof ThreadDeath)) {
- log[messages++] =
- "Failure: ThreadDeath: unexpected exception thrown";
- exitCode = 2;
- } else if (TRACE_ON)
- log[messages++] = "Success: ThreadDeath thrown as expected";
- } catch (InterruptedException ie) {
- pool[index++] = ie;
- log[messages++] =
- "Failure: ThreadDeath: thrown InterruptedException instead";
- exitCode = 2;
- } catch (OutOfMemoryError oome) {
- if (WARN_ON)
- log[messages++] =
- "Skipped: ThreadDeath: thrown OutOfMemoryError";
- skipped++;
- }
-
- return exitCode;
- }
-
- /**
- * This class loader provokes ClassFormatError.
- */
- private static class CrazyClassLoader extends ClassLoader {
- public Class loadClass(String name) throws ClassNotFoundException {
- Class crazyClass = defineClass(null, crazyBytecode, 0, crazyBytecode.length);
- return crazyClass; // return is unreacable, due to ClassFormatError
- }
-
- private static byte crazyBytecode[];
-
- static {
- crazyBytecode = new byte[1000];
- Random random = new Random(42);
- for (int i = 0; i < crazyBytecode.length; i++)
- crazyBytecode[i] = (byte) random.nextInt(256);
- }
-
- }
-
- /**
- * This thread should die in order to check ThreadDeath error.
- */
- private static class MustDie extends Thread {
- Throwable exception = null;
-
- public void run() {
- try {
- stop();
- } catch (Throwable throwable) {
- exception = throwable;
- if (throwable instanceof ThreadDeath)
- throw (ThreadDeath) throwable;
- }
- }
-
- }
-
- /**
- * Re-call to run(args,out), and return JCK-like exit status.
- * (The stream out is assigned to System.out here.)
- *
- * @see #run(String[], PrintStream)
- */
- public static void main(String args[]) {
- Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- // Last try. If there is some OOME, test should end correctly
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- try {
- pool = null;
- System.gc(); // Empty memory to be able to write to the output
- if (e instanceof OutOfMemoryError) {
- try {
- System.out.println("OOME : Test Skipped");
- System.exit(0);
- } catch (Throwable ignore) {
- } // any of the test exceptions are handled in test.#
- // No code in the handler can provoke correct exceptions.
- } else if (e instanceof ThreadDeath) {
- } //ignore since it thrown as expected
- else {
- e.printStackTrace();
- throw (RuntimeException) e;
- }
- } catch (OutOfMemoryError oome) {
- }
- }
- });
- int exitCode = run(args, System.out);
- System.exit(exitCode + 95);
- // JCK-like exit status.
- }
-
-}