Skip to content

Commit

Permalink
8334545: runtime/ClassInitErrors/TestStackOverflowDuringInit.java fai…
Browse files Browse the repository at this point in the history
…ls after JDK-8294960

Reviewed-by: iklam, stuefe
  • Loading branch information
David Holmes committed Jul 3, 2024
1 parent 68ffec9 commit 587535c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ runtime/StackGuardPages/TestStackGuardPagesNative.java 8303612 linux-all
runtime/ErrorHandling/TestDwarf.java#checkDecoder 8305489 linux-all
runtime/ErrorHandling/MachCodeFramesInErrorFile.java 8313315 linux-ppc64le
runtime/cds/appcds/customLoader/HelloCustom_JFR.java 8241075 linux-all,windows-x64
runtime/ClassInitErrors/TestStackOverflowDuringInit.java 8334545 generic-all

applications/jcstress/copy.java 8229852 linux-all

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

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

import java.io.ByteArrayOutputStream;
Expand All @@ -51,26 +50,54 @@ public class TestStackOverflowDuringInit {
// of another class, which is where we will fail to create the EIIE.
// Even then this is non-trivial, only the use of Long.valueOf from
// the original reproducer seems to trigger SOE in just the right places.
// Later changes to the JDK meant that LongCache was initialized before
// the test even started under jtreg so we define local versions.

static class LongCache {
// Must have a static initializer
static {
System.out.println("LongCache is initializing");
}
static java.lang.Long valueOf(long l) {
return Long.valueOf(l);
}
}

static class MyLong {
static java.lang.Long valueOf(long l) {
if (l > -128 && l < 127) {
return LongCache.valueOf(l);
} else {
return Long.valueOf(l);
}
}
}

static void recurse() {
try {
// This will initialize Long but not touch LongCache.
Long.valueOf(1024L);
// This will initialize MyLong but not touch LongCache.
MyLong.valueOf(1024L);
recurse();
} finally {
// This will require initializing LongCache, which will
// initially fail due to StackOverflowError and so LongCache
// will be marked erroneous. As we unwind and again execute this
// we will throw NoClassDefFoundError due to the erroneous
// state of LongCache.
Long.valueOf(0);
MyLong.valueOf(0);
}
}

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

// Pre-load, but not initialize, LongCache, else we will
// hit SOE during class loading.
System.out.println("Pre-loading ...");
Class<?> c = Class.forName("TestStackOverflowDuringInit$LongCache",
false,
TestStackOverflowDuringInit.class.getClassLoader());
try {
recurse();
} catch (Throwable ex) {
Expand Down

0 comments on commit 587535c

Please sign in to comment.