Skip to content

Commit

Permalink
8297977: vmTestbase/nsk/stress/except/except012.java fails with unexp…
Browse files Browse the repository at this point in the history
…ected Exception

Reviewed-by: mseledtsov, lmesnik
  • Loading branch information
coleenp committed Mar 24, 2023
1 parent 13dd19a commit 4ec720d
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 3,798 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
102 changes: 102 additions & 0 deletions test/hotspot/jtreg/runtime/reflect/ReflectOutOfMemoryError.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
24 changes: 0 additions & 24 deletions test/hotspot/jtreg/vmTestbase/nsk/stress/except/TEST.properties

This file was deleted.

Loading

1 comment on commit 4ec720d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.