mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8341127: Extra call to MethodHandle::asType from memory segment var handles fails to inline
Reviewed-by: psandoz, redestad, jvernee
This commit is contained in:
parent
1bdd79e7b2
commit
7fa2f229fb
2 changed files with 152 additions and 2 deletions
|
@ -27,6 +27,8 @@ package java.lang.invoke;
|
|||
|
||||
|
||||
import jdk.internal.loader.ClassLoaders;
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
|
||||
import java.lang.constant.ClassDesc;
|
||||
|
@ -856,6 +858,7 @@ public abstract sealed class MethodHandle implements Constable
|
|||
* @throws WrongMethodTypeException if the conversion cannot be made
|
||||
* @see MethodHandles#explicitCastArguments
|
||||
*/
|
||||
@ForceInline
|
||||
public final MethodHandle asType(MethodType newType) {
|
||||
// Fast path alternative to a heavyweight {@code asType} call.
|
||||
// Return 'this' if the conversion will be a no-op.
|
||||
|
@ -867,7 +870,7 @@ public abstract sealed class MethodHandle implements Constable
|
|||
if (at != null) {
|
||||
return at;
|
||||
}
|
||||
return setAsTypeCache(asTypeUncached(newType));
|
||||
return setAsTypeCache(newType);
|
||||
}
|
||||
|
||||
private MethodHandle asTypeCached(MethodType newType) {
|
||||
|
@ -885,7 +888,16 @@ public abstract sealed class MethodHandle implements Constable
|
|||
return null;
|
||||
}
|
||||
|
||||
private MethodHandle setAsTypeCache(MethodHandle at) {
|
||||
/*
|
||||
* We disable inlining here to prevent complex code in the slow path
|
||||
* of MethodHandle::asType from being inlined into that method.
|
||||
* Excessive inlining into MethodHandle::asType can cause that method
|
||||
* to become too big, which will then cause performance issues during
|
||||
* var handle and method handle calls.
|
||||
*/
|
||||
@DontInline
|
||||
private MethodHandle setAsTypeCache(MethodType newType) {
|
||||
MethodHandle at = asTypeUncached(newType);
|
||||
// Don't introduce a strong reference in the cache if newType depends on any class loader other than
|
||||
// current method handle already does to avoid class loader leaks.
|
||||
if (isSafeToCache(at.type)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue