Skip to content

Commit 747f84e

Browse files
committed
Merge master jdk-17.0.7+5 into openj9-staging
Signed-off-by: J9 Build <[email protected]>
2 parents 1a49d73 + 280f86e commit 747f84e

File tree

8 files changed

+537
-11
lines changed

8 files changed

+537
-11
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8048190
27+
* @summary Test that the NCDFE saves the stack trace for the original exception
28+
* during class initialization with ExceptionInInitializationError,
29+
* and doesn't prevent the classes in the stacktrace to be unloaded.
30+
* @requires vm.opt.final.ClassUnloading
31+
* @modules java.base/jdk.internal.misc
32+
* @library /test/lib
33+
* @build sun.hotspot.WhiteBox
34+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35+
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI InitExceptionUnloadTest
36+
*/
37+
38+
import java.io.ByteArrayOutputStream;
39+
import java.io.PrintStream;
40+
41+
import sun.hotspot.WhiteBox;
42+
import jdk.test.lib.classloader.ClassUnloadCommon;
43+
44+
public class InitExceptionUnloadTest {
45+
static public class ThrowsRuntimeException { static int x = 1/0; }
46+
static public class ThrowsError { static { if (true) throw new Error(); } }
47+
static public class SpecialException extends RuntimeException {
48+
SpecialException(int count, String message) {
49+
super(message + count);
50+
}
51+
}
52+
static public class ThrowsSpecialException {
53+
static {
54+
if (true) throw new SpecialException(3, "Very Special ");
55+
}
56+
}
57+
58+
static public class ThrowsOOM {
59+
static {
60+
if (true) {
61+
// Actually getting an OOM might be fragile but it was tested.
62+
throw new OutOfMemoryError("Java heap space");
63+
}
64+
}
65+
}
66+
67+
private static void verify_stack(Throwable e, String expected, String cause) throws Exception {
68+
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
69+
PrintStream printStream = new PrintStream(byteOS);
70+
e.printStackTrace(printStream);
71+
printStream.close();
72+
String stackTrace = byteOS.toString("ASCII");
73+
if (!stackTrace.contains(expected) || (cause != null && !stackTrace.contains(cause))) {
74+
throw new RuntimeException(expected + " and " + cause + " missing from stacktrace");
75+
}
76+
}
77+
78+
static String[] expected = new String[] {
79+
"java.lang.ExceptionInInitializerError",
80+
"Caused by: java.lang.ArithmeticException: / by zero",
81+
"java.lang.NoClassDefFoundError: Could not initialize class InitExceptionUnloadTest$ThrowsRuntimeException",
82+
"Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.ArithmeticException: / by zero [in thread",
83+
"java.lang.Error",
84+
null,
85+
"java.lang.NoClassDefFoundError: Could not initialize class InitExceptionUnloadTest$ThrowsError",
86+
"Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.Error [in thread",
87+
"java.lang.ExceptionInInitializerError",
88+
"Caused by: InitExceptionUnloadTest$SpecialException: Very Special 3",
89+
"java.lang.NoClassDefFoundError: Could not initialize class InitExceptionUnloadTest$ThrowsSpecialException",
90+
"Caused by: java.lang.ExceptionInInitializerError: Exception InitExceptionUnloadTest$SpecialException: Very Special 3",
91+
"java.lang.OutOfMemoryError",
92+
"Java heap space",
93+
"java.lang.NoClassDefFoundError: Could not initialize class InitExceptionUnloadTest$ThrowsOOM",
94+
"Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.OutOfMemoryError: Java heap space [in thread"
95+
};
96+
97+
static String[] classNames = new String[] {
98+
"InitExceptionUnloadTest$ThrowsRuntimeException",
99+
"InitExceptionUnloadTest$ThrowsError",
100+
"InitExceptionUnloadTest$ThrowsSpecialException",
101+
"InitExceptionUnloadTest$ThrowsOOM" };
102+
103+
public static WhiteBox wb = WhiteBox.getWhiteBox();
104+
105+
static void test() throws Throwable {
106+
ClassLoader cl = ClassUnloadCommon.newClassLoader();
107+
int i = 0;
108+
for (String className : classNames) {
109+
for (int tries = 2; tries-- > 0; ) {
110+
System.err.println("--- try to load " + className);
111+
try {
112+
Class<?> c = cl.loadClass(className);
113+
Object inst = c.newInstance();
114+
} catch (Throwable t) {
115+
t.printStackTrace();
116+
System.err.println();
117+
System.err.println("Check results");
118+
verify_stack(t, expected[i], expected[i+1]);
119+
i += 2;
120+
System.err.println();
121+
}
122+
}
123+
}
124+
cl = null;
125+
ClassUnloadCommon.triggerUnloading(); // should unload these classes
126+
for (String className : classNames) {
127+
ClassUnloadCommon.failIf(wb.isClassAlive(className), "should be unloaded");
128+
}
129+
}
130+
public static void main(java.lang.String[] unused) throws Throwable {
131+
test();
132+
test();
133+
}
134+
}
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package xpath;
24+
25+
import org.testng.Assert;
26+
import org.testng.annotations.DataProvider;
27+
import org.testng.annotations.Test;
28+
import org.w3c.dom.Document;
29+
import org.w3c.dom.Node;
30+
import org.w3c.dom.NodeList;
31+
32+
import javax.xml.parsers.DocumentBuilderFactory;
33+
import javax.xml.xpath.XPath;
34+
import javax.xml.xpath.XPathConstants;
35+
import javax.xml.xpath.XPathExpressionException;
36+
import javax.xml.xpath.XPathFactory;
37+
import java.io.ByteArrayInputStream;
38+
import java.io.InputStream;
39+
40+
/*
41+
* @test
42+
* @bug 8289511
43+
* @run testng/othervm xpath.XPathExpChildTest
44+
* @summary Tests for XPath child axis specifier.
45+
*/
46+
public class XPathExpChildTest {
47+
48+
private static final String XML = """
49+
<store>
50+
<book id="1" lang="en">
51+
<title/>
52+
<author id="1"/>
53+
<isbn>1234</isbn>
54+
</book>
55+
<book id="2" lang="en">
56+
<title/>
57+
<author id="2"/>
58+
<isbn>5678</isbn>
59+
</book>
60+
</store>
61+
""";
62+
private static final String AUTHOR_1 = "author_1";
63+
private static final String AUTHOR_2 = "author_2";
64+
private static final Document doc;
65+
66+
static {
67+
try {
68+
var builder =
69+
DocumentBuilderFactory.newInstance().newDocumentBuilder();
70+
InputStream s = new ByteArrayInputStream(XML.getBytes());
71+
doc = builder.parse(s);
72+
} catch (Exception e) {
73+
System.out.println("Exception while initializing XML document");
74+
throw new RuntimeException(e.getMessage());
75+
}
76+
}
77+
78+
/*
79+
* DataProvider: provides XPath expression and expected result
80+
*/
81+
@DataProvider(name = "parameters")
82+
public Object[][] getXPathExpression() {
83+
return new Object[][]{
84+
// abbreviated text
85+
{"/store/book/author", AUTHOR_1},
86+
{"/child::store/child::book/child::author", AUTHOR_1},
87+
{"/store/child::book/author", AUTHOR_1},
88+
89+
// any nodes
90+
{"/store/book/child::*[2]", AUTHOR_1},
91+
{"/store/child::*[child::author]/author", AUTHOR_1},
92+
{"/store/child::*[child::author][2]/author", AUTHOR_2},
93+
{"/store/child::node()/child::author", AUTHOR_1},
94+
{"/store/child::node()[child::author]/author", AUTHOR_1},
95+
{"/store/child::node()[child::author][2]/author", AUTHOR_2},
96+
97+
// position
98+
{"/store/child::book[position()=1]/author", AUTHOR_1},
99+
{"/store/child::book[last()]/author", AUTHOR_2},
100+
101+
// descendant
102+
{"//book/child::*[2]", AUTHOR_1},
103+
{"//child::*[child::author]/author", AUTHOR_1},
104+
{"//child::*[child::author][2]/author", AUTHOR_2},
105+
{"//child::node()/child::author", AUTHOR_1},
106+
{"//child::node()[child::author]/author", AUTHOR_1},
107+
{"//child::node()[child::author][2]/author", AUTHOR_2},
108+
109+
// parent node
110+
{"//child::book/../child::book/child::author", AUTHOR_1},
111+
112+
// dot reference
113+
{"//child::book/./child::author", AUTHOR_1},
114+
{"//child::node()/./child::author", AUTHOR_1},
115+
{"//././/./child::author", AUTHOR_1},
116+
117+
// attributes
118+
{"/store/child::book[@id=1]/author", AUTHOR_1},
119+
{"/store/child::book[attribute::id=1]/author", AUTHOR_1},
120+
{"/store/child::book[@id]/author", AUTHOR_1},
121+
{"/store/child::book[@id=1][@lang='en']/author", AUTHOR_1},
122+
{"/store/child::book[@lang='en'][1]/author", AUTHOR_1},
123+
{"/store/child::book[child::isbn='1234']/author", AUTHOR_1},
124+
{"/store/child::book[@lang='en' and " +
125+
"child::isbn='1234']/author", AUTHOR_1},
126+
{"/store/child::*[@lang='en'][2]/author", AUTHOR_2},
127+
{"/store/child::node()[@id='1']/author", AUTHOR_1},
128+
{"/store/child::node()[@lang='en'][2]/author", AUTHOR_2},
129+
{"/store/child::*[child::author][child::title][@id='2']/author",
130+
AUTHOR_2},
131+
{"/store/child::*[child::author or child::ssn][@id='2']/author",
132+
AUTHOR_2},
133+
{"/store/child::*[child::*]/author", AUTHOR_1},
134+
{"/store/child::*[attribute::*]/author", AUTHOR_1},
135+
{"/store/*[*][*][*][*][*][*][*][*]/author", AUTHOR_1},
136+
{"/store/*[@*][@*][@*][@*][@*][@*][@*][@*]/author", AUTHOR_1},
137+
{"//author[@*]", AUTHOR_1},
138+
139+
// text node
140+
{"/store/book[1]/isbn/child::text()/../../author", AUTHOR_1},
141+
{"/store/book/isbn[child::text()='5678']/../author", AUTHOR_2},
142+
{"/store/book/isbn[.='5678']/../author", AUTHOR_2},
143+
144+
// count child nodes
145+
{"/store/book[count(./child::author)]/author", AUTHOR_1},
146+
{"/store/book[count(child::author)]/author", AUTHOR_1},
147+
{"/store/book[count(../child::book)]/author", AUTHOR_2},
148+
};
149+
}
150+
151+
/*
152+
* DataProvider: provides XPath expressions that return zero children
153+
*/
154+
@DataProvider(name = "zeroChildrenExp")
155+
public Object[][] getZeroChildrenExp() {
156+
return new Object[][]{
157+
{"/store/book[3]/author"},
158+
{"/store/book/author/ssn"},
159+
{"/store/child[book]/author"},
160+
{"/store/child[@id='1']/book/author"},
161+
{"/store/child::*[@category]/author"},
162+
{"//author[*]/../author"},
163+
{"//title[@*]/../author"},
164+
{"/store/book[-1]/author"},
165+
{"/store/child:book/author"},
166+
{"//book[.='1']/author"},
167+
};
168+
}
169+
170+
/*
171+
* DataProvider: provides invalid XPath expression and expected exception
172+
* to be thrown
173+
*/
174+
@DataProvider(name = "invalidExp")
175+
public Object[][] getInvalidExp() {
176+
return new Object[][]{
177+
// XPathExpressionException
178+
{"/store/*[child::author] and [child::title]/author",
179+
XPathExpressionException.class},
180+
{"//book[@id='en'] and book[@lang='en']/author",
181+
XPathExpressionException.class},
182+
{"/store/book[child::count()]/author",
183+
XPathExpressionException.class},
184+
{"//book[child::position()=1]", XPathExpressionException.class},
185+
};
186+
}
187+
188+
/**
189+
* Verifies XPath child axis specifier.
190+
*
191+
* @param exp XPath expression
192+
* @param expected expected result
193+
* @throws Exception
194+
*/
195+
@Test(dataProvider = "parameters")
196+
void testXPathEvaluate(String exp, String expected) throws Exception {
197+
XPath xPath = XPathFactory.newInstance().newXPath();
198+
NodeList nl = (NodeList) xPath.evaluate(exp, doc,
199+
XPathConstants.NODESET);
200+
Node node = xPath.evaluateExpression(exp, doc, Node.class);
201+
Assert.assertEquals(nl.item(0).getNodeName(), node.getNodeName());
202+
Assert.assertEquals(nl.item(0).getNodeValue(), node.getNodeValue());
203+
Assert.assertEquals(nl.item(0).getAttributes(), node.getAttributes());
204+
205+
Assert.assertEquals(node.getNodeName() + "_" +
206+
node.getAttributes().item(0).getNodeValue(),
207+
expected);
208+
}
209+
210+
/**
211+
* Verifies no child nodes returned from the XPath expression.
212+
*
213+
* @param exp XPath expression
214+
* @throws Exception
215+
*/
216+
@Test(dataProvider = "zeroChildrenExp")
217+
void testZeroChildrenExp(String exp) throws Exception {
218+
XPath xPath = XPathFactory.newInstance().newXPath();
219+
Node node = xPath.evaluateExpression(exp, doc, Node.class);
220+
Assert.assertNull(node);
221+
}
222+
223+
/**
224+
* Verifies exception thrown for invalid expression.
225+
*
226+
* @param exp XPath expression
227+
* @param throwableClass expected exception
228+
* @throws Exception
229+
*/
230+
@Test(dataProvider = "invalidExp")
231+
void testInvalidExp(String exp, Class throwableClass) throws Exception {
232+
XPath xPath = XPathFactory.newInstance().newXPath();
233+
Assert.assertThrows(throwableClass,
234+
() -> ((NodeList) xPath.evaluate(exp, doc,
235+
XPathConstants.NODESET)).item(0).getNodeName());
236+
}
237+
}

test/jdk/com/sun/jdi/RedefineTTYLineNumber.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, 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
@@ -59,7 +59,7 @@ public static void main(String[] args) {
5959

6060
public class RedefineTTYLineNumber extends JdbTest {
6161

62-
public static void main(String argv[]) {
62+
public static void main(String[] argv) {
6363
new RedefineTTYLineNumber().run();
6464
}
6565

@@ -104,7 +104,7 @@ protected void runCases() {
104104
// so bp2Line should be equals bp1Line-1
105105
Asserts.assertEquals(bp2Line, bp1Line - 1, "BP line numbers");
106106
verifyBPSource(1, bp1Reply);
107-
// uncomment the following line to reproduce JDK-8210927
108-
//verifyBPSource(2, bp2Reply);
107+
// verify source code is printed correctly
108+
verifyBPSource(2, bp2Reply);
109109
}
110110
}

0 commit comments

Comments
 (0)