Skip to content

Commit 587535c

Browse files
author
David Holmes
committedJul 3, 2024
8334545: runtime/ClassInitErrors/TestStackOverflowDuringInit.java fails after JDK-8294960
Reviewed-by: iklam, stuefe
1 parent 68ffec9 commit 587535c

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed
 

‎test/hotspot/jtreg/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ runtime/StackGuardPages/TestStackGuardPagesNative.java 8303612 linux-all
108108
runtime/ErrorHandling/TestDwarf.java#checkDecoder 8305489 linux-all
109109
runtime/ErrorHandling/MachCodeFramesInErrorFile.java 8313315 linux-ppc64le
110110
runtime/cds/appcds/customLoader/HelloCustom_JFR.java 8241075 linux-all,windows-x64
111-
runtime/ClassInitErrors/TestStackOverflowDuringInit.java 8334545 generic-all
112111

113112
applications/jcstress/copy.java 8229852 linux-all
114113

‎test/hotspot/jtreg/runtime/ClassInitErrors/TestStackOverflowDuringInit.java

+38-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,16 +23,15 @@
2323

2424
/**
2525
* @test
26-
* @bug 8309034
26+
* @bug 8309034 8334545
2727
* @summary Test that when saving a class initialization failure caused by
2828
* a StackOverflowError, that we record the SOE as the underlying
2929
* cause, even if we can't create the ExceptionInInitializerError
30-
* @requires os.simpleArch == "x64"
31-
* @comment The reproducer only fails in the desired way on x64.
32-
* @requires vm.flagless
3330
* @comment This test could easily be perturbed so don't allow flag settings.
34-
*
35-
* @run main/othervm -Xss160K -Xint TestStackOverflowDuringInit
31+
* @requires vm.flagless
32+
* @comment Run with the smallest stack possible to limit the execution time.
33+
* This is the smallest stack that is supported by all platforms.
34+
* @run main/othervm -Xss240K -Xint TestStackOverflowDuringInit
3635
*/
3736

3837
import java.io.ByteArrayOutputStream;
@@ -51,26 +50,54 @@ public class TestStackOverflowDuringInit {
5150
// of another class, which is where we will fail to create the EIIE.
5251
// Even then this is non-trivial, only the use of Long.valueOf from
5352
// the original reproducer seems to trigger SOE in just the right places.
53+
// Later changes to the JDK meant that LongCache was initialized before
54+
// the test even started under jtreg so we define local versions.
55+
56+
static class LongCache {
57+
// Must have a static initializer
58+
static {
59+
System.out.println("LongCache is initializing");
60+
}
61+
static java.lang.Long valueOf(long l) {
62+
return Long.valueOf(l);
63+
}
64+
}
65+
66+
static class MyLong {
67+
static java.lang.Long valueOf(long l) {
68+
if (l > -128 && l < 127) {
69+
return LongCache.valueOf(l);
70+
} else {
71+
return Long.valueOf(l);
72+
}
73+
}
74+
}
5475

5576
static void recurse() {
5677
try {
57-
// This will initialize Long but not touch LongCache.
58-
Long.valueOf(1024L);
78+
// This will initialize MyLong but not touch LongCache.
79+
MyLong.valueOf(1024L);
5980
recurse();
6081
} finally {
6182
// This will require initializing LongCache, which will
6283
// initially fail due to StackOverflowError and so LongCache
6384
// will be marked erroneous. As we unwind and again execute this
6485
// we will throw NoClassDefFoundError due to the erroneous
6586
// state of LongCache.
66-
Long.valueOf(0);
87+
MyLong.valueOf(0);
6788
}
6889
}
6990

7091
public static void main(String[] args) throws Exception {
71-
String expected = "java.lang.NoClassDefFoundError: Could not initialize class java.lang.Long$LongCache";
92+
String expected = "java.lang.NoClassDefFoundError: Could not initialize class TestStackOverflowDuringInit$LongCache";
7293
String cause = "Caused by: java.lang.StackOverflowError";
7394

95+
// Pre-load, but not initialize, LongCache, else we will
96+
// hit SOE during class loading.
97+
System.out.println("Pre-loading ...");
98+
Class<?> c = Class.forName("TestStackOverflowDuringInit$LongCache",
99+
false,
100+
TestStackOverflowDuringInit.class.getClassLoader());
74101
try {
75102
recurse();
76103
} catch (Throwable ex) {

0 commit comments

Comments
 (0)
Please sign in to comment.