Skip to content

Commit 05fb1da

Browse files
author
duke
committedSep 14, 2023
Automatic merge of jdk:master into master
2 parents e4ae137 + 83dca62 commit 05fb1da

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed
 

‎src/hotspot/share/prims/whitebox.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,12 @@ WB_ENTRY(jint, WB_GetConstantPoolCacheLength(JNIEnv* env, jobject wb, jclass kla
18741874
return cp->cache()->length();
18751875
WB_END
18761876

1877+
WB_ENTRY(jobjectArray, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass klass))
1878+
InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1879+
objArrayOop resolved_refs= ik->constants()->resolved_references();
1880+
return (jobjectArray)JNIHandles::make_local(THREAD, resolved_refs);
1881+
WB_END
1882+
18771883
WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
18781884
InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
18791885
ConstantPool* cp = ik->constants();
@@ -2801,6 +2807,7 @@ static JNINativeMethod methods[] = {
28012807
{CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
28022808
{CC"getConstantPoolCacheIndexTag0", CC"()I", (void*)&WB_GetConstantPoolCacheIndexTag},
28032809
{CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_GetConstantPoolCacheLength},
2810+
{CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
28042811
{CC"remapInstructionOperandFromCPCache0",
28052812
CC"(Ljava/lang/Class;I)I", (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
28062813
{CC"encodeConstantPoolIndyIndex0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2023, 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 ResolvedReferencesNotNullTest
26+
* @bug 8313638
27+
* @summary Testing resolved references array to ensure elements are non-null
28+
* @requires vm.cds.write.archived.java.heap
29+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
30+
* @build jdk.test.whitebox.WhiteBox ResolvedReferencesWb ResolvedReferencesTestApp
31+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
32+
* @run driver ResolvedReferencesNotNullTest
33+
*/
34+
35+
import jdk.test.lib.process.OutputAnalyzer;
36+
import jdk.test.lib.process.ProcessTools;
37+
import jdk.test.whitebox.WhiteBox;
38+
39+
public class ResolvedReferencesNotNullTest {
40+
public static void main(String[] args) throws Exception {
41+
SharedStringsUtils.buildJarAndWhiteBox("ResolvedReferencesWb", "ResolvedReferencesTestApp");
42+
String appJar = TestCommon.getTestJar(SharedStringsUtils.TEST_JAR_NAME_FULL);
43+
String whiteboxParam = SharedStringsUtils.getWbParam();
44+
45+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-cp",
46+
appJar,
47+
whiteboxParam,
48+
"-XX:+UnlockDiagnosticVMOptions",
49+
"-XX:+WhiteBoxAPI",
50+
"ResolvedReferencesWb",
51+
"false" // ResolvedReferencesTestApp is not archived
52+
);
53+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
54+
output.shouldHaveExitValue(0);
55+
56+
TestCommon.dump(appJar,
57+
TestCommon.list("ResolvedReferencesWb", "ResolvedReferencesTestApp"),
58+
TestCommon.concat("-XX:SharedArchiveFile=ResolvedRef.jsa",
59+
"-XX:+UnlockDiagnosticVMOptions",
60+
"-XX:+WhiteBoxAPI",
61+
whiteboxParam));
62+
63+
// Since ResolvedReferencesTestApp is now archived, all of the strings should be in the resolved
64+
// references array
65+
TestCommon.run("-cp",
66+
appJar,
67+
whiteboxParam,
68+
"-XX:SharedArchiveFile=ResolvedRef.jsa",
69+
"-XX:+UnlockDiagnosticVMOptions",
70+
"-XX:+WhiteBoxAPI",
71+
"ResolvedReferencesWb",
72+
"true" // ResolvedReferencesTestApp is archived
73+
).assertNormalExit();
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2023, 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+
public class ResolvedReferencesTestApp {
25+
// These strings must be in the resolved references array
26+
static String foo = "fooString";
27+
static String bar = "barString";
28+
29+
// This method is never called so the string should not be added to the resolved references array
30+
String qux() { return "quxString"; }
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2023, 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+
import jdk.test.whitebox.WhiteBox;
25+
26+
public class ResolvedReferencesWb {
27+
public static void main(String[] args) throws Exception {
28+
WhiteBox wb = WhiteBox.getWhiteBox();
29+
30+
if (args.length < 1) {
31+
throw new RuntimeException("Test requires arg: [true|false]");
32+
}
33+
34+
if (!args[0].equals("true") && !args[0].equals("false")) {
35+
throw new RuntimeException("Invalid argument: Test requires arg: [true|false]");
36+
}
37+
38+
ResolvedReferencesTestApp t = new ResolvedReferencesTestApp();
39+
Object[] resolvedReferences = wb.getResolvedReferences(ResolvedReferencesTestApp.class);
40+
boolean isArchived = (args[0].equals("true"));
41+
42+
if (resolvedReferences.length <= 0) {
43+
throw new RuntimeException("Resolved reference should not be null");
44+
}
45+
46+
boolean foundFoo = false;
47+
boolean foundBar = false;
48+
boolean foundQux = false;
49+
50+
for (Object o : resolvedReferences) {
51+
if (o != null) {
52+
foundFoo |= (o.equals("fooString"));
53+
foundBar |= (o.equals("barString"));
54+
foundQux |= (o.equals("quxString"));
55+
}
56+
}
57+
58+
if (isArchived) {
59+
// CDS eagerly resolves all the string literals in the ConstantPool. At this point, all
60+
// three strings should be in the resolvedReferences array.
61+
if (!foundFoo || !foundBar || !foundQux) {
62+
throwException(resolvedReferences, "Incorrect resolved references array, all strings should be present");
63+
}
64+
} else {
65+
// If the class is not archived, the string literals in the ConstantPool are resolved
66+
// on-demand. At this point, ResolvedReferencesTestApp::<clinit> has been executed
67+
// so the two strings used there should be in the resolvedReferences array.
68+
// ResolvedReferencesTestApp::qux() is not executed so "quxString"
69+
// should not yet be resolved.
70+
if (!foundFoo || !foundBar || foundQux) {
71+
throwException(resolvedReferences, "Incorrect resolved references array, quxString should not be archived");
72+
}
73+
}
74+
}
75+
76+
static void throwException(Object[] resolvedRefs, String errMsg) throws RuntimeException {
77+
System.out.printf("Resolved References Array Length: %d\n", resolvedRefs.length);
78+
for (Object o : resolvedRefs) {
79+
System.out.println(o);
80+
}
81+
throw new RuntimeException(errMsg);
82+
}
83+
}

‎test/lib/jdk/test/whitebox/WhiteBox.java

+6
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ public int getConstantPoolCacheLength(Class<?> aClass) {
140140
return getConstantPoolCacheLength0(aClass);
141141
}
142142

143+
private native Object[] getResolvedReferences0(Class<?> aClass);
144+
public Object[] getResolvedReferences(Class<?> aClass) {
145+
Objects.requireNonNull(aClass);
146+
return getResolvedReferences0(aClass);
147+
}
148+
143149
private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
144150
public int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
145151
Objects.requireNonNull(aClass);

0 commit comments

Comments
 (0)
Please sign in to comment.