Skip to content

Commit 1587836

Browse files
David LeopoldsederDoug Simon
authored andcommitted
8310425: [JVMCI] compiler/runtime/TestConstantDynamic: lookupConstant returned an object of incorrect type: null
Reviewed-by: dnsimon, never
1 parent 73d7aa1 commit 1587836

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ C2V_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, job
701701
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
702702
oop obj = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
703703
constantTag tag = cp->tag_at(index);
704-
if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
705-
if (obj == Universe::the_null_sentinel()) {
704+
if (tag.is_dynamic_constant()) {
705+
if (obj == nullptr) {
706706
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
707707
}
708708
BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(index));

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test/TestDynamicConstant.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public void test() throws Throwable {
249249
long.class,
250250
double.class,
251251
String.class,
252+
Object.class,
252253
List.class
253254
};
254255

@@ -275,14 +276,20 @@ public void test() throws Throwable {
275276
// with condy resolved via ConstantPool
276277
Object expect = m.invoke(null);
277278
Object actual;
278-
if (lastConstant instanceof PrimitiveConstant) {
279+
if (lastConstant == PrimitiveConstant.NULL_POINTER) {
280+
actual = null;
281+
} else if (lastConstant instanceof PrimitiveConstant) {
279282
actual = ((PrimitiveConstant) lastConstant).asBoxedPrimitive();
280283
} else {
281284
actual = ((HotSpotObjectConstant) lastConstant).asObject(type);
282285
}
283286
Assert.assertEquals(actual, expect, m + ":");
284287

285-
testLookupBootstrapMethodInvocation(condyType, metaAccess, testClass, getTagAt);
288+
if (type != Object.class) {
289+
testLookupBootstrapMethodInvocation(condyType, metaAccess, testClass, getTagAt);
290+
} else {
291+
// StringConcatFactoryStringConcatFactory cannot accept null constants
292+
}
286293
}
287294
}
288295
}
@@ -347,6 +354,7 @@ private static void testLoadReferencedType(ResolvedJavaMethod method) {
347354
@SuppressWarnings("unused") public static long getLongBSM (MethodHandles.Lookup l, String name, Class<?> type) { return Long.MAX_VALUE; }
348355
@SuppressWarnings("unused") public static double getDoubleBSM (MethodHandles.Lookup l, String name, Class<?> type) { return Double.MAX_VALUE; }
349356
@SuppressWarnings("unused") public static String getStringBSM (MethodHandles.Lookup l, String name, Class<?> type) { return "a string"; }
357+
@SuppressWarnings("unused") public static Object getObjectBSM (MethodHandles.Lookup l, String name, Class<?> type) { return null; }
350358
@SuppressWarnings("unused") public static List<?> getListBSM (MethodHandles.Lookup l, String name, Class<?> type) { return List.of("element"); }
351359

352360

@@ -359,6 +367,7 @@ private static void testLoadReferencedType(ResolvedJavaMethod method) {
359367
public static long getLong () { return Long.MAX_VALUE; }
360368
public static double getDouble () { return Double.MAX_VALUE; }
361369
public static String getString () { return "a string"; }
370+
public static Object getObject () { return null; }
362371
public static List<?> getList () { return List.of("element"); }
363372

364373
public static boolean getBoolean(boolean v1, boolean v2) { return v1 || v2; }
@@ -370,6 +379,7 @@ private static void testLoadReferencedType(ResolvedJavaMethod method) {
370379
public static long getLong (long v1, long v2) { return v1 ^ v2; }
371380
public static double getDouble (double v1, double v2) { return v1 * v2; }
372381
public static String getString (String v1, String v2) { return v1 + v2; }
382+
public static Object getObject (Object v1, Object v2) { return null; }
373383
public static List<?> getList (List<?> v1, List<?> v2) { return List.of(v1, v2); }
374384
// @formatter:on
375385
}

0 commit comments

Comments
 (0)