8330595: Invoke ObjectMethods::bootstrap method exactly

Reviewed-by: mchung
This commit is contained in:
Claes Redestad 2024-04-22 08:55:46 +00:00
parent 3d62bbf4f2
commit 35b30c81e0

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -145,6 +145,9 @@ final class BootstrapMethodInvoker {
} else if (isLambdaMetafactoryAltMetafactoryBSM(bsmType)) {
maybeReBoxElements(argv);
result = (CallSite)bootstrapMethod.invokeExact(caller, name, (MethodType)type, argv);
} else if (isObjectMethodsBootstrapBSM(bsmType)) {
MethodHandle[] mhs = Arrays.copyOfRange(argv, 2, argv.length, MethodHandle[].class);
result = bootstrapMethod.invokeExact(caller, name, (TypeDescriptor)type, (Class<?>)argv[0], (String)argv[1], mhs);
} else {
maybeReBoxElements(argv);
if (type instanceof Class<?> c) {
@ -189,7 +192,6 @@ final class BootstrapMethodInvoker {
}
}
/**
* If resultType is a reference type, do Class::cast on the result through
* an identity function of that type, as-type converted to return
@ -247,6 +249,9 @@ final class BootstrapMethodInvoker {
private static final MethodType LMF_ALT_MT = MethodType.methodType(CallSite.class,
Lookup.class, String.class, MethodType.class, Object[].class);
private static final MethodType OBJECT_METHODS_MT = MethodType.methodType(Object.class,
Lookup.class, String.class, TypeDescriptor.class, Class.class, String.class, MethodHandle[].class);
private static final MethodType LMF_CONDY_MT = MethodType.methodType(Object.class,
Lookup.class, String.class, Class.class, MethodType.class, MethodHandle.class, MethodType.class);
@ -289,6 +294,15 @@ final class BootstrapMethodInvoker {
return bsmType == LMF_ALT_MT;
}
/**
* @return true iff the BSM method type exactly matches
* {@link java.lang.runtime.ObjectMethods#bootstrap(
* MethodHandles.Lookup,String,TypeDescriptor,Class,String,MethodHandle[])}
*/
private static boolean isObjectMethodsBootstrapBSM(MethodType bsmType) {
return bsmType == OBJECT_METHODS_MT;
}
/** The JVM produces java.lang.Integer values to box
* CONSTANT_Integer boxes but does not intern them.
* Let's intern them. This is slightly wrong for