diff --git a/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java b/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java index 96d94bab409..69f8596e320 100644 --- a/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java +++ b/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java @@ -103,6 +103,6 @@ import java.util.function.BiFunction; @Override MethodHandle getMethodHandleUncached(int mode) { MethodHandle targetHandle = target.getMethodHandle(mode); // might throw UOE of access mode is not supported, which is ok - return handleFactory.apply(AccessMode.values()[mode], targetHandle); + return handleFactory.apply(AccessMode.valueFromOrdinal(mode), targetHandle); } } diff --git a/src/java.base/share/classes/java/lang/invoke/VarForm.java b/src/java.base/share/classes/java/lang/invoke/VarForm.java index 1308c48cebb..0856bf126f9 100644 --- a/src/java.base/share/classes/java/lang/invoke/VarForm.java +++ b/src/java.base/share/classes/java/lang/invoke/VarForm.java @@ -26,6 +26,7 @@ package java.lang.invoke; import jdk.internal.vm.annotation.DontInline; import jdk.internal.vm.annotation.ForceInline; +import jdk.internal.vm.annotation.Hidden; import jdk.internal.vm.annotation.Stable; import java.lang.invoke.VarHandle.AccessMode; @@ -108,6 +109,7 @@ final class VarForm { } @ForceInline + @Hidden final MemberName getMemberName(int mode) { // Can be simplified by calling getMemberNameOrNull, but written in this // form to improve interpreter/coldpath performance. @@ -115,7 +117,7 @@ final class VarForm { if (mn == null) { mn = resolveMemberName(mode); if (mn == null) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(AccessMode.valueFromOrdinal(mode).methodName()); } } return mn; @@ -132,7 +134,7 @@ final class VarForm { @DontInline MemberName resolveMemberName(int mode) { - AccessMode value = AccessMode.values()[mode]; + AccessMode value = AccessMode.valueFromOrdinal(mode); String methodName = value.methodName(); MethodType type = methodType_table[value.at.ordinal()].insertParameterTypes(0, VarHandle.class); return memberName_table[mode] = MethodHandles.Lookup.IMPL_LOOKUP diff --git a/src/java.base/share/classes/java/lang/invoke/VarHandle.java b/src/java.base/share/classes/java/lang/invoke/VarHandle.java index 79607068801..f5fae207b93 100644 --- a/src/java.base/share/classes/java/lang/invoke/VarHandle.java +++ b/src/java.base/share/classes/java/lang/invoke/VarHandle.java @@ -2003,6 +2003,11 @@ public abstract sealed class VarHandle implements Constable default -> throw new IllegalArgumentException("No AccessMode value for method name " + methodName); }; } + + private static final @Stable AccessMode[] VALUES = values(); + static AccessMode valueFromOrdinal(int mode) { + return VALUES[mode]; + } } static final class AccessDescriptor { @@ -2215,7 +2220,7 @@ public abstract sealed class VarHandle implements Constable * @throws UnsupportedOperationException if the access mode is not supported */ MethodHandle getMethodHandleUncached(int mode) { - MethodType mt = accessModeType(AccessMode.values()[mode]). + MethodType mt = accessModeType(AccessMode.valueFromOrdinal(mode)). insertParameterTypes(0, VarHandle.class); MemberName mn = vform.getMemberName(mode); DirectMethodHandle dmh = DirectMethodHandle.make(mn); diff --git a/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java b/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java index be1dfac8a86..8b73587eca5 100644 --- a/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java +++ b/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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