From 0a41ca6b7503c7d901b450ac8d006e5546a58d6d Mon Sep 17 00:00:00 2001 From: Jorn Vernee Date: Tue, 10 Nov 2020 23:26:02 +0000 Subject: [PATCH] 8254354: Add a withInvokeExactBehavior() VarHandle combinator Reviewed-by: psandoz, chegar --- .../java/lang/invoke/IndirectVarHandle.java | 25 +- .../classes/java/lang/invoke/Invokers.java | 6 + .../invoke/MemoryAccessVarHandleBase.java | 4 +- .../MemoryAccessVarHandleGenerator.java | 72 +- .../classes/java/lang/invoke/VarHandle.java | 115 ++- .../java/lang/invoke/VarHandleGuards.java | 942 ++++++++++++------ .../classes/java/lang/invoke/VarHandles.java | 81 +- .../lang/invoke/X-VarHandle.java.template | 114 ++- .../X-VarHandleByteArrayView.java.template | 52 +- .../invoke/VarHandles/VarHandleTestExact.java | 430 ++++++++ .../java/lang/invoke/VarHandleExact.java | 84 ++ .../jdk/incubator/foreign/VarHandleExact.java | 86 ++ 12 files changed, 1606 insertions(+), 405 deletions(-) create mode 100644 test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java create mode 100644 test/micro/org/openjdk/bench/java/lang/invoke/VarHandleExact.java create mode 100644 test/micro/org/openjdk/bench/jdk/incubator/foreign/VarHandleExact.java 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 85e17a640c8a3..2ef81c145196b 100644 --- a/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java +++ b/src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java @@ -53,7 +53,12 @@ private final Class[] coordinates; IndirectVarHandle(VarHandle target, Class value, Class[] coordinates, BiFunction handleFactory) { - super(new VarForm(value, coordinates)); + this(target, value, coordinates, handleFactory, new VarForm(value, coordinates), false); + } + + private IndirectVarHandle(VarHandle target, Class value, Class[] coordinates, + BiFunction handleFactory, VarForm form, boolean exact) { + super(form, exact); this.handleFactory = handleFactory; this.target = target; this.directTarget = target.asDirect(); @@ -72,8 +77,8 @@ public List> coordinateTypes() { } @Override - MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType(directTarget.getClass(), value, coordinates); + MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType(null, value, coordinates); } @Override @@ -90,6 +95,20 @@ VarHandle target() { return target; } + @Override + public VarHandle withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new IndirectVarHandle(target, value, coordinates, handleFactory, vform, true); + } + + @Override + public VarHandle withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new IndirectVarHandle(target, value, coordinates, handleFactory, vform, false); + } + @Override @ForceInline MethodHandle getMethodHandle(int mode) { diff --git a/src/java.base/share/classes/java/lang/invoke/Invokers.java b/src/java.base/share/classes/java/lang/invoke/Invokers.java index 9e44de433374d..ee1f9baa3da94 100644 --- a/src/java.base/share/classes/java/lang/invoke/Invokers.java +++ b/src/java.base/share/classes/java/lang/invoke/Invokers.java @@ -27,6 +27,7 @@ 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.reflect.Array; @@ -463,7 +464,12 @@ private static LambdaForm varHandleMethodInvokerHandleForm(VarHandle.AccessMode @ForceInline /*non-public*/ + @Hidden static MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.AccessDescriptor ad) { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } // Test for exact match on invoker types // TODO match with erased types and add cast of return value to lambda form MethodHandle mh = handle.getMethodHandle(ad.mode); diff --git a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleBase.java b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleBase.java index dee289fa1573a..0176cbf6d474d 100644 --- a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleBase.java +++ b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleBase.java @@ -42,8 +42,8 @@ abstract class MemoryAccessVarHandleBase extends VarHandle { /** alignment constraint (in bytes, expressed as a bit mask) **/ final long alignmentMask; - MemoryAccessVarHandleBase(VarForm form, boolean be, long length, long offset, long alignmentMask) { - super(form); + MemoryAccessVarHandleBase(VarForm form, boolean be, long length, long offset, long alignmentMask, boolean exact) { + super(form, exact); this.be = be; this.length = length; this.offset = offset; diff --git a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java index 6e66fc1ab4298..addd09f82b722 100644 --- a/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java +++ b/src/java.base/share/classes/java/lang/invoke/MemoryAccessVarHandleGenerator.java @@ -71,6 +71,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.LALOAD; import static jdk.internal.org.objectweb.asm.Opcodes.LASTORE; import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD; +import static jdk.internal.org.objectweb.asm.Opcodes.NEW; import static jdk.internal.org.objectweb.asm.Opcodes.NEWARRAY; import static jdk.internal.org.objectweb.asm.Opcodes.PUTFIELD; import static jdk.internal.org.objectweb.asm.Opcodes.PUTSTATIC; @@ -95,6 +96,12 @@ class MemoryAccessVarHandleGenerator { private final static MethodHandle ADD_OFFSETS_HANDLE; private final static MethodHandle MUL_OFFSETS_HANDLE; + private final static MethodType CONSTR_TYPE = MethodType.methodType(void.class, VarForm.class, + boolean.class, long.class, long.class, long.class, boolean.class, long[].class); + // MemoryAccessVarHandleBase + private final static MethodType SUPER_CONTR_TYPE = MethodType.methodType(void.class, VarForm.class, + boolean.class, long.class, long.class, long.class, boolean.class); + static { helperClassCache = new HashMap<>(); helperClassCache.put(byte.class, MemoryAccessVarHandleByteHelper.class); @@ -140,7 +147,7 @@ class MemoryAccessVarHandleGenerator { Arrays.fill(components, long.class); this.form = new VarForm(BASE_CLASS, MemoryAddressProxy.class, carrier, components); this.helperClass = helperClassCache.get(carrier); - this.implClassName = helperClass.getName().replace('.', '/') + dimensions; + this.implClassName = internalName(helperClass) + dimensions; // live constants Class[] intermediate = new Class[dimensions]; Arrays.fill(intermediate, long.class); @@ -164,8 +171,7 @@ MethodHandle generateHandleFactory() { VarForm form = new VarForm(implCls, MemoryAddressProxy.class, carrier, components); - MethodType constrType = MethodType.methodType(void.class, VarForm.class, boolean.class, long.class, long.class, long.class, long[].class); - MethodHandle constr = lookup.findConstructor(implCls, constrType); + MethodHandle constr = lookup.findConstructor(implCls, CONSTR_TYPE); constr = MethodHandles.insertArguments(constr, 0, form); return constr; } catch (Throwable ex) { @@ -202,6 +208,9 @@ byte[] generateClassBytes() { addCarrierAccessor(cw); + addAsExact(cw); + addAsGeneric(cw); + for (VarHandle.AccessMode mode : VarHandle.AccessMode.values()) { addAccessModeMethodIfNeeded(mode, cw); } @@ -253,23 +262,23 @@ void addStaticInitializer(ClassWriter cw) { } void addConstructor(ClassWriter cw) { - MethodType constrType = MethodType.methodType(void.class, VarForm.class, boolean.class, long.class, long.class, long.class, long[].class); - MethodVisitor mv = cw.visitMethod(0, "", constrType.toMethodDescriptorString(), null, null); + MethodVisitor mv = cw.visitMethod(0, "", CONSTR_TYPE.toMethodDescriptorString(), null, null); mv.visitCode(); //super call mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 1); + mv.visitVarInsn(ALOAD, 1); // vform mv.visitTypeInsn(CHECKCAST, Type.getInternalName(VarForm.class)); - mv.visitVarInsn(ILOAD, 2); - mv.visitVarInsn(LLOAD, 3); - mv.visitVarInsn(LLOAD, 5); - mv.visitVarInsn(LLOAD, 7); + mv.visitVarInsn(ILOAD, 2); // be + mv.visitVarInsn(LLOAD, 3); // length + mv.visitVarInsn(LLOAD, 5); // offset + mv.visitVarInsn(LLOAD, 7); // alignmentMask + mv.visitVarInsn(ILOAD, 9); // exact mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(BASE_CLASS), "", - MethodType.methodType(void.class, VarForm.class, boolean.class, long.class, long.class, long.class).toMethodDescriptorString(), false); + SUPER_CONTR_TYPE.toMethodDescriptorString(), false); //init dimensions for (int i = 0 ; i < dimensions ; i++) { mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 9); + mv.visitVarInsn(ALOAD, 10); mv.visitLdcInsn(i); mv.visitInsn(LALOAD); mv.visitFieldInsn(PUTFIELD, implClassName, "dim" + i, "J"); @@ -280,11 +289,10 @@ void addConstructor(ClassWriter cw) { } void addAccessModeTypeMethod(ClassWriter cw) { - MethodType modeMethType = MethodType.methodType(MethodType.class, VarHandle.AccessMode.class); + MethodType modeMethType = MethodType.methodType(MethodType.class, VarHandle.AccessType.class); MethodVisitor mv = cw.visitMethod(ACC_FINAL, "accessModeTypeUncached", modeMethType.toMethodDescriptorString(), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); - mv.visitFieldInsn(GETFIELD, Type.getInternalName(VarHandle.AccessMode.class), "at", VarHandle.AccessType.class.descriptorString()); mv.visitLdcInsn(Type.getType(MemoryAddressProxy.class)); mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Class.class)); mv.visitFieldInsn(GETSTATIC, implClassName, "carrier", Class.class.descriptorString()); @@ -409,6 +417,38 @@ void addCarrierAccessor(ClassWriter cw) { mv.visitEnd(); } + private void addAsExact(ClassWriter cw) { + addAsExactOrAsGeneric(cw, "asExact", true); + } + + private void addAsGeneric(ClassWriter cw) { + addAsExactOrAsGeneric(cw, "asGeneric", false); + } + + private void addAsExactOrAsGeneric(ClassWriter cw, String name, boolean exact) { + MethodVisitor mv = cw.visitMethod(ACC_FINAL, name, "()Ljava/lang/invoke/VarHandle;", null, null); + mv.visitCode(); + mv.visitTypeInsn(NEW, implClassName); + mv.visitInsn(DUP); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, internalName(VarHandle.class), "vform", VarForm.class.descriptorString()); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, internalName(MemoryAccessVarHandleBase.class), "be", boolean.class.descriptorString()); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, internalName(MemoryAccessVarHandleBase.class), "length", long.class.descriptorString()); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, internalName(MemoryAccessVarHandleBase.class), "offset", long.class.descriptorString()); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, internalName(MemoryAccessVarHandleBase.class), "alignmentMask", long.class.descriptorString()); + mv.visitIntInsn(BIPUSH, exact ? 1 : 0); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, implClassName, "strides", "()[J", false); + mv.visitMethodInsn(INVOKESPECIAL, implClassName, "", CONSTR_TYPE.descriptorString(), false); + mv.visitInsn(ARETURN); + mv.visitMaxs(0, 0); + mv.visitEnd(); + } + // shared code generation helpers private static int getSlotsForType(Class c) { @@ -418,6 +458,10 @@ private static int getSlotsForType(Class c) { return 1; } + private static String internalName(Class cls) { + return cls.getName().replace('.', '/'); + } + /** * Emits an actual return instruction conforming to the given return type. */ 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 4f7d5a54db0e2..698eb8374a132 100644 --- a/src/java.base/share/classes/java/lang/invoke/VarHandle.java +++ b/src/java.base/share/classes/java/lang/invoke/VarHandle.java @@ -282,8 +282,8 @@ * match fails, it means that the access mode method which the caller is * invoking is not present on the individual VarHandle being invoked. * - *

- * Invocation of an access mode method behaves as if an invocation of + *

+ * Invocation of an access mode method behaves, by default, as if an invocation of * {@link MethodHandle#invoke}, where the receiving method handle accepts the * VarHandle instance as the leading argument. More specifically, the * following, where {@code {access-mode}} corresponds to the access mode method @@ -318,7 +318,7 @@ * widen primitive values, as if by {@link MethodHandle#asType asType} (see also * {@link MethodHandles#varHandleInvoker}). * - * More concisely, such behaviour is equivalent to: + * More concisely, such behavior is equivalent to: *

 {@code
  * VarHandle vh = ..
  * VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}");
@@ -328,6 +328,37 @@
  * }
* Where, in this case, the method handle is bound to the VarHandle instance. * + *

+ * A VarHandle's invocation behavior can be adjusted (see {@link #withInvokeExactBehavior}) such that invocation of + * an access mode method behaves as if invocation of {@link MethodHandle#invokeExact}, + * where the receiving method handle accepts the VarHandle instance as the leading argument. + * More specifically, the following, where {@code {access-mode}} corresponds to the access mode method + * name: + *

 {@code
+ * VarHandle vh = ..
+ * R r = (R) vh.{access-mode}(p1, p2, ..., pN);
+ * }
+ * behaves as if: + *
 {@code
+ * VarHandle vh = ..
+ * VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}");
+ * MethodHandle mh = MethodHandles.varHandleExactInvoker(
+ *                       am,
+ *                       vh.accessModeType(am));
+ *
+ * R r = (R) mh.invokeExact(vh, p1, p2, ..., pN)
+ * }
+ * (modulo access mode methods do not declare throwing of {@code Throwable}). + * + * More concisely, such behavior is equivalent to: + *
 {@code
+ * VarHandle vh = ..
+ * VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}");
+ * MethodHandle mh = vh.toMethodHandle(am);
+ *
+ * R r = (R) mh.invokeExact(p1, p2, ..., pN)
+ * }
+ * Where, in this case, the method handle is bound to the VarHandle instance. * *

Invocation checking

* In typical programs, VarHandle access mode type matching will usually @@ -425,7 +456,7 @@ * {@link java.lang.invoke.MethodHandles#varHandleInvoker}. The * {@link java.lang.invoke.MethodHandles.Lookup#findVirtual Lookup.findVirtual} * API is also able to return a method handle to call an access mode method for - * any specified access mode type and is equivalent in behaviour to + * any specified access mode type and is equivalent in behavior to * {@link java.lang.invoke.MethodHandles#varHandleInvoker}. * *

Interoperation between VarHandles and Java generics

@@ -446,9 +477,15 @@ */ public abstract class VarHandle implements Constable { final VarForm vform; + final boolean exact; VarHandle(VarForm vform) { + this(vform, false); + } + + VarHandle(VarForm vform, boolean exact) { this.vform = vform; + this.exact = exact; } RuntimeException unsupported() { @@ -465,6 +502,18 @@ VarHandle asDirect() { VarHandle target() { return null; } + /** + * Returns {@code true} if this VarHandle has invoke-exact behavior. + * + * @see #withInvokeExactBehavior() + * @see #withInvokeBehavior() + * @return {@code true} if this VarHandle has invoke-exact behavior. + * @since 16 + */ + public boolean hasInvokeExactBehavior() { + return exact; + } + // Plain accessors /** @@ -1541,6 +1590,44 @@ VarHandle asDirect() { @IntrinsicCandidate Object getAndBitwiseXorRelease(Object... args); + /** + * Returns a VarHandle, with access to the same variable(s) as this VarHandle, but whose + * invocation behavior of access mode methods is adjusted to + * invoke-exact behavior. + *

+ * If this VarHandle already has invoke-exact behavior this VarHandle is returned. + *

+ * Invoking {@link #hasInvokeExactBehavior()} on the returned var handle + * is guaranteed to return {@code true}. + * + * @apiNote + * Invoke-exact behavior guarantees that upon invocation of an access mode method + * the types and arity of the arguments must match the {@link #accessModeType(AccessMode) access mode type}, + * otherwise a {@link WrongMethodTypeException} is thrown. + * + * @see #withInvokeBehavior() + * @see #hasInvokeExactBehavior() + * @return a VarHandle with invoke-exact behavior + * @since 16 + */ + public abstract VarHandle withInvokeExactBehavior(); + + /** + * Returns a VarHandle, with access to the same variable(s) as this VarHandle, but whose + * invocation behavior of access mode methods is adjusted to + * invoke behavior. + *

+ * If this VarHandle already has invoke behavior this VarHandle is returned. + *

+ * Invoking {@link #hasInvokeExactBehavior()} on the returned var handle + * is guaranteed to return {@code false}. + * + * @see #withInvokeExactBehavior() + * @see #hasInvokeExactBehavior() + * @return a VarHandle with invoke behavior + * @since 16 + */ + public abstract VarHandle withInvokeBehavior(); enum AccessType { GET(Object.class), @@ -1859,6 +1946,7 @@ static MemberName getMemberName(int ordinal, VarForm vform) { } static final class AccessDescriptor { + final MethodType symbolicMethodTypeExact; final MethodType symbolicMethodTypeErased; final MethodType symbolicMethodTypeInvoker; final Class returnType; @@ -1866,6 +1954,7 @@ static final class AccessDescriptor { final int mode; public AccessDescriptor(MethodType symbolicMethodType, int type, int mode) { + this.symbolicMethodTypeExact = symbolicMethodType; this.symbolicMethodTypeErased = symbolicMethodType.erase(); this.symbolicMethodTypeInvoker = symbolicMethodType.insertParameterTypes(0, VarHandle.class); this.returnType = symbolicMethodType.returnType(); @@ -1922,15 +2011,25 @@ public List> coordinateTypes() { * @return the access mode type for the given access mode */ public final MethodType accessModeType(AccessMode accessMode) { + return accessModeType(accessMode.at.ordinal()); + } + + @ForceInline + final MethodType accessModeType(int accessTypeOrdinal) { TypesAndInvokers tis = getTypesAndInvokers(); - MethodType mt = tis.methodType_table[accessMode.at.ordinal()]; + MethodType mt = tis.methodType_table[accessTypeOrdinal]; if (mt == null) { - mt = tis.methodType_table[accessMode.at.ordinal()] = - accessModeTypeUncached(accessMode); + mt = tis.methodType_table[accessTypeOrdinal] = + accessModeTypeUncached(accessTypeOrdinal); } return mt; } - abstract MethodType accessModeTypeUncached(AccessMode accessMode); + + final MethodType accessModeTypeUncached(int accessTypeOrdinal) { + return accessModeTypeUncached(AccessType.values()[accessTypeOrdinal]); + } + + abstract MethodType accessModeTypeUncached(AccessType accessMode); /** * Returns {@code true} if the given access mode is supported, otherwise 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 9df0fe1a54074..36bf67f0559fb 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, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2020, 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 @@ -25,18 +25,23 @@ package java.lang.invoke; import jdk.internal.vm.annotation.ForceInline; +import jdk.internal.vm.annotation.Hidden; // This class is auto-generated by java.lang.invoke.VarHandles$GuardMethodGenerator. Do not edit. final class VarHandleGuards { @ForceInline @LambdaForm.Compiled + @Hidden final static Object guard_L_L(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { Object r = MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); return ad.returnType.cast(r); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -44,14 +49,17 @@ final static Object guard_L_L(VarHandle handle, Object arg0, VarHandle.AccessDes @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LL_V(VarHandle handle, Object arg0, Object arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -59,49 +67,65 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static Object guard_LL_L(VarHandle handle, Object arg0, Object arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - Object r = MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - return ad.returnType.cast(r); + @Hidden + final static boolean guard_LLL_Z(VarHandle handle, Object arg0, Object arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LLL_Z(VarHandle handle, Object arg0, Object arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static Object guard_LLL_L(VarHandle handle, Object arg0, Object arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + return ad.returnType.cast(r); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static Object guard_LLL_L(VarHandle handle, Object arg0, Object arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { + @Hidden + final static Object guard_LL_L(VarHandle handle, Object arg0, Object arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + Object r = MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); return ad.returnType.cast(r); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled + @Hidden final static int guard_L_I(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (int) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -109,14 +133,17 @@ final static int guard_L_I(VarHandle handle, Object arg0, VarHandle.AccessDescri @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LI_V(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -124,47 +151,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static int guard_LI_I(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LII_Z(VarHandle handle, Object arg0, int arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LII_Z(VarHandle handle, Object arg0, int arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_LII_I(VarHandle handle, Object arg0, int arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static int guard_LII_I(VarHandle handle, Object arg0, int arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_LI_I(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled + @Hidden final static long guard_L_J(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (long) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -172,14 +215,17 @@ final static long guard_L_J(VarHandle handle, Object arg0, VarHandle.AccessDescr @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LJ_V(VarHandle handle, Object arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -187,47 +233,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static long guard_LJ_J(VarHandle handle, Object arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LJJ_Z(VarHandle handle, Object arg0, long arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LJJ_Z(VarHandle handle, Object arg0, long arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_LJJ_J(VarHandle handle, Object arg0, long arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static long guard_LJJ_J(VarHandle handle, Object arg0, long arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_LJ_J(VarHandle handle, Object arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled + @Hidden final static float guard_L_F(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (float) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -235,14 +297,17 @@ final static float guard_L_F(VarHandle handle, Object arg0, VarHandle.AccessDesc @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LF_V(VarHandle handle, Object arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -250,47 +315,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static float guard_LF_F(VarHandle handle, Object arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LFF_Z(VarHandle handle, Object arg0, float arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LFF_Z(VarHandle handle, Object arg0, float arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_LFF_F(VarHandle handle, Object arg0, float arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static float guard_LFF_F(VarHandle handle, Object arg0, float arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_LF_F(VarHandle handle, Object arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled + @Hidden final static double guard_L_D(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (double) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -298,14 +379,17 @@ final static double guard_L_D(VarHandle handle, Object arg0, VarHandle.AccessDes @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LD_V(VarHandle handle, Object arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -313,48 +397,64 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static double guard_LD_D(VarHandle handle, Object arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LDD_Z(VarHandle handle, Object arg0, double arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LDD_Z(VarHandle handle, Object arg0, double arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_LDD_D(VarHandle handle, Object arg0, double arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled - final static double guard_LDD_D(VarHandle handle, Object arg0, double arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_LD_D(VarHandle handle, Object arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled + @Hidden final static Object guard__L(VarHandle handle, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { Object r = MethodHandle.linkToStatic(handle, handle.vform.getMemberName(ad.mode)); return ad.returnType.cast(r); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect()); } @@ -362,14 +462,17 @@ final static Object guard__L(VarHandle handle, VarHandle.AccessDescriptor ad) th @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_L_V(VarHandle handle, Object arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -377,11 +480,15 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled + @Hidden final static boolean guard_LL_Z(VarHandle handle, Object arg0, Object arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -389,11 +496,15 @@ final static boolean guard_LL_Z(VarHandle handle, Object arg0, Object arg1, VarH @ForceInline @LambdaForm.Compiled + @Hidden final static int guard__I(VarHandle handle, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (int) MethodHandle.linkToStatic(handle, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect()); } @@ -401,14 +512,17 @@ final static int guard__I(VarHandle handle, VarHandle.AccessDescriptor ad) throw @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_I_V(VarHandle handle, int arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -416,47 +530,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static int guard_I_I(VarHandle handle, int arg0, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_II_Z(VarHandle handle, int arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_II_Z(VarHandle handle, int arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_II_I(VarHandle handle, int arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static int guard_II_I(VarHandle handle, int arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_I_I(VarHandle handle, int arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } } @ForceInline @LambdaForm.Compiled + @Hidden final static long guard__J(VarHandle handle, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (long) MethodHandle.linkToStatic(handle, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect()); } @@ -464,14 +594,17 @@ final static long guard__J(VarHandle handle, VarHandle.AccessDescriptor ad) thro @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_J_V(VarHandle handle, long arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -479,47 +612,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static long guard_J_J(VarHandle handle, long arg0, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_JJ_Z(VarHandle handle, long arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_JJ_Z(VarHandle handle, long arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_JJ_J(VarHandle handle, long arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static long guard_JJ_J(VarHandle handle, long arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_J_J(VarHandle handle, long arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } } @ForceInline @LambdaForm.Compiled + @Hidden final static float guard__F(VarHandle handle, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (float) MethodHandle.linkToStatic(handle, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect()); } @@ -527,14 +676,17 @@ final static float guard__F(VarHandle handle, VarHandle.AccessDescriptor ad) thr @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_F_V(VarHandle handle, float arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -542,47 +694,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static float guard_F_F(VarHandle handle, float arg0, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_FF_Z(VarHandle handle, float arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_FF_Z(VarHandle handle, float arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_FF_F(VarHandle handle, float arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static float guard_FF_F(VarHandle handle, float arg0, float arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_F_F(VarHandle handle, float arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } } @ForceInline @LambdaForm.Compiled + @Hidden final static double guard__D(VarHandle handle, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (double) MethodHandle.linkToStatic(handle, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect()); } @@ -590,14 +758,17 @@ final static double guard__D(VarHandle handle, VarHandle.AccessDescriptor ad) th @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_D_V(VarHandle handle, double arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } @@ -605,48 +776,64 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static double guard_D_D(VarHandle handle, double arg0, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_DD_Z(VarHandle handle, double arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_DD_Z(VarHandle handle, double arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_DD_D(VarHandle handle, double arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } } @ForceInline @LambdaForm.Compiled - final static double guard_DD_D(VarHandle handle, double arg0, double arg1, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_D_D(VarHandle handle, double arg0, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0); } } @ForceInline @LambdaForm.Compiled + @Hidden final static Object guard_LI_L(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { Object r = MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); return ad.returnType.cast(r); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -654,14 +841,17 @@ final static Object guard_LI_L(VarHandle handle, Object arg0, int arg1, VarHandl @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LIL_V(VarHandle handle, Object arg0, int arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -669,52 +859,67 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static Object guard_LIL_L(VarHandle handle, Object arg0, int arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - return ad.returnType.cast(r); + @Hidden + final static boolean guard_LILL_Z(VarHandle handle, Object arg0, int arg1, Object arg2, Object arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LILL_Z(VarHandle handle, Object arg0, int arg1, Object arg2, Object arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static Object guard_LILL_L(VarHandle handle, Object arg0, int arg1, Object arg2, Object arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + return ad.returnType.cast(r); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static Object guard_LILL_L(VarHandle handle, Object arg0, int arg1, Object arg2, Object arg3, VarHandle.AccessDescriptor ad) throws Throwable { + @Hidden + final static Object guard_LIL_L(VarHandle handle, Object arg0, int arg1, Object arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + Object r = MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); return ad.returnType.cast(r); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LII_V(VarHandle handle, Object arg0, int arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -722,11 +927,15 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled + @Hidden final static boolean guard_LIII_Z(VarHandle handle, Object arg0, int arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } @@ -734,11 +943,15 @@ final static boolean guard_LIII_Z(VarHandle handle, Object arg0, int arg1, int a @ForceInline @LambdaForm.Compiled + @Hidden final static int guard_LIII_I(VarHandle handle, Object arg0, int arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } @@ -746,11 +959,15 @@ final static int guard_LIII_I(VarHandle handle, Object arg0, int arg1, int arg2, @ForceInline @LambdaForm.Compiled + @Hidden final static long guard_LI_J(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (long) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -758,14 +975,17 @@ final static long guard_LI_J(VarHandle handle, Object arg0, int arg1, VarHandle. @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LIJ_V(VarHandle handle, Object arg0, int arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -773,47 +993,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static long guard_LIJ_J(VarHandle handle, Object arg0, int arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LIJJ_Z(VarHandle handle, Object arg0, int arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LIJJ_Z(VarHandle handle, Object arg0, int arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_LIJJ_J(VarHandle handle, Object arg0, int arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static long guard_LIJJ_J(VarHandle handle, Object arg0, int arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static long guard_LIJ_J(VarHandle handle, Object arg0, int arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled + @Hidden final static float guard_LI_F(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (float) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -821,14 +1057,17 @@ final static float guard_LI_F(VarHandle handle, Object arg0, int arg1, VarHandle @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LIF_V(VarHandle handle, Object arg0, int arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -836,47 +1075,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static float guard_LIF_F(VarHandle handle, Object arg0, int arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LIFF_Z(VarHandle handle, Object arg0, int arg1, float arg2, float arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LIFF_Z(VarHandle handle, Object arg0, int arg1, float arg2, float arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_LIFF_F(VarHandle handle, Object arg0, int arg1, float arg2, float arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static float guard_LIFF_F(VarHandle handle, Object arg0, int arg1, float arg2, float arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static float guard_LIF_F(VarHandle handle, Object arg0, int arg1, float arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (float) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (float) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled + @Hidden final static double guard_LI_D(VarHandle handle, Object arg0, int arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (double) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -884,14 +1139,17 @@ final static double guard_LI_D(VarHandle handle, Object arg0, int arg1, VarHandl @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LID_V(VarHandle handle, Object arg0, int arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -899,47 +1157,63 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static double guard_LID_D(VarHandle handle, Object arg0, int arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LIDD_Z(VarHandle handle, Object arg0, int arg1, double arg2, double arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LIDD_Z(VarHandle handle, Object arg0, int arg1, double arg2, double arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_LIDD_D(VarHandle handle, Object arg0, int arg1, double arg2, double arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static double guard_LIDD_D(VarHandle handle, Object arg0, int arg1, double arg2, double arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static double guard_LID_D(VarHandle handle, Object arg0, int arg1, double arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (double) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (double) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled + @Hidden final static int guard_LJ_I(VarHandle handle, Object arg0, long arg1, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (int) MethodHandle.linkToStatic(handle, arg0, arg1, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1); } @@ -947,14 +1221,17 @@ final static int guard_LJ_I(VarHandle handle, Object arg0, long arg1, VarHandle. @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LJI_V(VarHandle handle, Object arg0, long arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -962,50 +1239,65 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled - final static int guard_LJI_I(VarHandle handle, Object arg0, long arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + @Hidden + final static boolean guard_LJII_Z(VarHandle handle, Object arg0, long arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); + return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static boolean guard_LJII_Z(VarHandle handle, Object arg0, long arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_LJII_I(VarHandle handle, Object arg0, long arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } } @ForceInline @LambdaForm.Compiled - final static int guard_LJII_I(VarHandle handle, Object arg0, long arg1, int arg2, int arg3, VarHandle.AccessDescriptor ad) throws Throwable { - if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { - return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); + @Hidden + final static int guard_LJI_I(VarHandle handle, Object arg0, long arg1, int arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); } - else { + if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { + return (int) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); - return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); + return (int) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } } @ForceInline @LambdaForm.Compiled + @Hidden final static void guard_LJJ_V(VarHandle handle, Object arg0, long arg1, long arg2, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { + } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { MethodHandle.linkToStatic(handle, arg0, arg1, arg2, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2); } @@ -1013,11 +1305,15 @@ else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbol @ForceInline @LambdaForm.Compiled + @Hidden final static boolean guard_LJJJ_Z(VarHandle handle, Object arg0, long arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (boolean) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (boolean) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } @@ -1025,11 +1321,15 @@ final static boolean guard_LJJJ_Z(VarHandle handle, Object arg0, long arg1, long @ForceInline @LambdaForm.Compiled + @Hidden final static long guard_LJJJ_J(VarHandle handle, Object arg0, long arg1, long arg2, long arg3, VarHandle.AccessDescriptor ad) throws Throwable { + if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { + throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " + + ad.symbolicMethodTypeExact); + } if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { return (long) MethodHandle.linkToStatic(handle, arg0, arg1, arg2, arg3, handle.vform.getMemberName(ad.mode)); - } - else { + } else { MethodHandle mh = handle.getMethodHandle(ad.mode); return (long) mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(handle.asDirect(), arg0, arg1, arg2, arg3); } diff --git a/src/java.base/share/classes/java/lang/invoke/VarHandles.java b/src/java.base/share/classes/java/lang/invoke/VarHandles.java index 60d90104a982a..b06fedac185e4 100644 --- a/src/java.base/share/classes/java/lang/invoke/VarHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/VarHandles.java @@ -31,8 +31,10 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; import java.nio.ByteOrder; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -43,6 +45,8 @@ import static java.lang.invoke.MethodHandleStatics.UNSAFE; import static java.lang.invoke.MethodHandleStatics.VAR_HANDLE_IDENTITY_ADAPT; import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; final class VarHandles { @@ -331,7 +335,8 @@ static VarHandle makeMemoryAddressViewHandle(Class carrier, long alignmentMas .generateHandleFactory()); try { - return maybeAdapt((VarHandle)fac.invoke(be, size, offset, alignmentMask, strides)); + boolean exact = false; + return maybeAdapt((VarHandle)fac.invoke(be, size, offset, alignmentMask, exact, strides)); } catch (Throwable ex) { throw new IllegalStateException(ex); } @@ -341,7 +346,7 @@ private static VarHandle maybeAdapt(VarHandle target) { if (!VAR_HANDLE_IDENTITY_ADAPT) return target; target = filterValue(target, MethodHandles.identity(target.varType()), MethodHandles.identity(target.varType())); - MethodType mtype = target.accessModeType(VarHandle.AccessMode.GET).dropParameterTypes(0, 1); + MethodType mtype = target.accessModeType(VarHandle.AccessMode.GET); for (int i = 0 ; i < mtype.parameterCount() ; i++) { target = filterCoordinates(target, i, MethodHandles.identity(mtype.parameterType(i))); } @@ -671,33 +676,42 @@ private static boolean isCheckedException(Class clazz) { // static final String GUARD_METHOD_SIG_TEMPLATE = " _()"; // // static final String GUARD_METHOD_TEMPLATE = -// "@ForceInline\n" + -// "@LambdaForm.Compiled\n" + -// "final static throws Throwable {\n" + -// " if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodType) {\n" + -// " MethodHandle.linkToStatic();\n" + -// " }\n" + -// " else {\n" + -// " MethodHandle mh = handle.getMethodHandle(ad.mode);\n" + -// " mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic();\n" + -// " }\n" + -// "}"; +// """ +// @ForceInline +// @LambdaForm.Compiled +// @Hidden +// final static throws Throwable { +// if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { +// throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " +// + ad.symbolicMethodTypeExact); +// } +// if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { +// MethodHandle.linkToStatic(); +// } else { +// MethodHandle mh = handle.getMethodHandle(ad.mode); +// mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(); +// } +// }"""; // // static final String GUARD_METHOD_TEMPLATE_V = -// "@ForceInline\n" + -// "@LambdaForm.Compiled\n" + -// "final static throws Throwable {\n" + -// " if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodType) {\n" + -// " MethodHandle.linkToStatic();\n" + -// " }\n" + -// " else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodType) {\n" + -// " MethodHandle.linkToStatic();\n" + -// " }\n" + -// " else {\n" + -// " MethodHandle mh = handle.getMethodHandle(ad.mode);\n" + -// " mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic();\n" + -// " }\n" + -// "}"; +// """ +// @ForceInline +// @LambdaForm.Compiled +// @Hidden +// final static throws Throwable { +// if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) { +// throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found " +// + ad.symbolicMethodTypeExact); +// } +// if (handle.isDirect() && handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { +// MethodHandle.linkToStatic(); +// } else if (handle.isDirect() && handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { +// MethodHandle.linkToStatic(); +// } else { +// MethodHandle mh = handle.getMethodHandle(ad.mode); +// mh.asType(ad.symbolicMethodTypeInvoker).invokeBasic(); +// } +// }"""; // // // A template for deriving the operations // // could be supported by annotating VarHandle directly with the @@ -733,6 +747,7 @@ private static boolean isCheckedException(Class clazz) { // System.out.println("package java.lang.invoke;"); // System.out.println(); // System.out.println("import jdk.internal.vm.annotation.ForceInline;"); +// System.out.println("import jdk.internal.vm.annotation.Hidden;"); // System.out.println(); // System.out.println("// This class is auto-generated by " + // GuardMethodGenerator.class.getName() + @@ -785,11 +800,8 @@ private static boolean isCheckedException(Class clazz) { // hts.flatMap(ht -> Stream.of(VarHandleTemplate.class.getMethods()). // map(m -> generateMethodType(m, ht.receiver, ht.value, ht.intermediates))). // distinct(). -// map(mt -> generateMethod(mt)). -// forEach(s -> { -// System.out.println(s); -// System.out.println(); -// }); +// map(GuardMethodGenerator::generateMethod). +// forEach(System.out::println); // // System.out.println("}"); // } @@ -845,6 +857,7 @@ private static boolean isCheckedException(Class clazz) { // // List LINK_TO_INVOKER_ARGS = params.keySet().stream(). // collect(toList()); +// LINK_TO_INVOKER_ARGS.set(0, LINK_TO_INVOKER_ARGS.get(0) + ".asDirect()"); // // RETURN = returnType == void.class // ? "" @@ -860,7 +873,7 @@ private static boolean isCheckedException(Class clazz) { // // String RETURN_ERASED = returnType != Object.class // ? "" -// : " return ad.returnType.cast(r);"; +// : "\n return ad.returnType.cast(r);"; // // String template = returnType == void.class // ? GUARD_METHOD_TEMPLATE_V @@ -877,7 +890,7 @@ private static boolean isCheckedException(Class clazz) { // collect(joining(", "))). // replace("", LINK_TO_INVOKER_ARGS.stream(). // collect(joining(", "))) -// ; +// .indent(4); // } // // static String className(Class c) { diff --git a/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template b/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template index bad2c675b5c57..e24f5af15ebc8 100644 --- a/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template +++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template @@ -45,12 +45,12 @@ final class VarHandle$Type$s { #end[Object] FieldInstanceReadOnly(Class receiverType, long fieldOffset{#if[Object]?, Class fieldType}) { - this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM); + this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM, false); } protected FieldInstanceReadOnly(Class receiverType, long fieldOffset{#if[Object]?, Class fieldType}, - VarForm form) { - super(form); + VarForm form, boolean exact) { + super(form, exact); this.fieldOffset = fieldOffset; this.receiverType = receiverType; #if[Object] @@ -59,8 +59,22 @@ final class VarHandle$Type$s { } @Override - final MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class}); + public FieldInstanceReadOnly withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType}, vform, true); + } + + @Override + public FieldInstanceReadOnly withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Object]?, fieldType}, vform, false); + } + + @Override + final MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class}); } @Override @@ -110,7 +124,26 @@ final class VarHandle$Type$s { static final class FieldInstanceReadWrite extends FieldInstanceReadOnly { FieldInstanceReadWrite(Class receiverType, long fieldOffset{#if[Object]?, Class fieldType}) { - super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM); + this(receiverType, fieldOffset{#if[Object]?, fieldType}, false); + } + + private FieldInstanceReadWrite(Class receiverType, long fieldOffset{#if[Object]?, Class fieldType}, + boolean exact) { + super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM, exact); + } + + @Override + public FieldInstanceReadWrite withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, true); + } + + @Override + public FieldInstanceReadWrite withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, false); } @ForceInline @@ -356,12 +389,12 @@ final class VarHandle$Type$s { #end[Object] FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class fieldType}) { - this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM); + this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM, false); } protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class fieldType}, - VarForm form) { - super(form); + VarForm form, boolean exact) { + super(form, exact); this.base = base; this.fieldOffset = fieldOffset; #if[Object] @@ -369,6 +402,20 @@ final class VarHandle$Type$s { #end[Object] } + @Override + public FieldStaticReadOnly withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new FieldStaticReadOnly(base, fieldOffset{#if[Object]?, fieldType}, vform, true); + } + + @Override + public FieldStaticReadOnly withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new FieldStaticReadOnly(base, fieldOffset{#if[Object]?, fieldType}, vform, false); + } + @Override public Optional describeConstable() { var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable(); @@ -385,8 +432,8 @@ final class VarHandle$Type$s { } @Override - final MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType(null, {#if[Object]?fieldType:$type$.class}); + final MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType(null, {#if[Object]?fieldType:$type$.class}); } @ForceInline @@ -423,7 +470,26 @@ final class VarHandle$Type$s { static final class FieldStaticReadWrite extends FieldStaticReadOnly { FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class fieldType}) { - super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM); + this(base, fieldOffset{#if[Object]?, fieldType}, false); + } + + private FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class fieldType}, + boolean exact) { + super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM, exact); + } + + @Override + public FieldStaticReadWrite withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, true); + } + + @Override + public FieldStaticReadWrite withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, false); } @ForceInline @@ -670,7 +736,11 @@ final class VarHandle$Type$s { #end[Object] Array(int abase, int ashift{#if[Object]?, Class arrayType}) { - super(Array.FORM); + this(abase, ashift{#if[Object]?, arrayType}, false); + } + + private Array(int abase, int ashift{#if[Object]?, Class arrayType}, boolean exact) { + super(Array.FORM, exact); this.abase = abase; this.ashift = ashift; #if[Object] @@ -679,6 +749,20 @@ final class VarHandle$Type$s { #end[Object] } + @Override + public Array withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new Array(abase, ashift{#if[Object]?, arrayType}, true); + } + + @Override + public Array withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new Array(abase, ashift{#if[Object]?, arrayType}, false); + } + @Override public Optional describeConstable() { var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable(); @@ -689,8 +773,8 @@ final class VarHandle$Type$s { } @Override - final MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class); + final MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class); } #if[Object] diff --git a/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template b/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template index 9ac3d25866eb5..cdbe6df68c4cd 100644 --- a/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template +++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template @@ -68,8 +68,8 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase { private static abstract class ByteArrayViewVarHandle extends VarHandle { final boolean be; - ByteArrayViewVarHandle(VarForm form, boolean be) { - super(form); + ByteArrayViewVarHandle(VarForm form, boolean be, boolean exact) { + super(form, exact); this.be = be; } } @@ -77,12 +77,30 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase { static final class ArrayHandle extends ByteArrayViewVarHandle { ArrayHandle(boolean be) { - super(ArrayHandle.FORM, be); + this(be, false); + } + + private ArrayHandle(boolean be, boolean exact) { + super(ArrayHandle.FORM, be, exact); + } + + @Override + public ArrayHandle withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new ArrayHandle(be, true); + } + + @Override + public ArrayHandle withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new ArrayHandle(be, false); } @Override - final MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType(byte[].class, $type$.class, int.class); + final MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType(byte[].class, $type$.class, int.class); } @ForceInline @@ -555,12 +573,30 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase { static final class ByteBufferHandle extends ByteArrayViewVarHandle { ByteBufferHandle(boolean be) { - super(ByteBufferHandle.FORM, be); + this(be, false); + } + + private ByteBufferHandle(boolean be, boolean exact) { + super(ByteBufferHandle.FORM, be, exact); + } + + @Override + public ByteBufferHandle withInvokeExactBehavior() { + return hasInvokeExactBehavior() + ? this + : new ByteBufferHandle(be, true); + } + + @Override + public ByteBufferHandle withInvokeBehavior() { + return !hasInvokeExactBehavior() + ? this + : new ByteBufferHandle(be, false); } @Override - final MethodType accessModeTypeUncached(AccessMode accessMode) { - return accessMode.at.accessModeType(ByteBuffer.class, $type$.class, int.class); + final MethodType accessModeTypeUncached(AccessType at) { + return at.accessModeType(ByteBuffer.class, $type$.class, int.class); } @ForceInline diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java new file mode 100644 index 0000000000000..f40885f8cbe34 --- /dev/null +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java @@ -0,0 +1,430 @@ +/* + * Copyright (c) 2020, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @modules jdk.incubator.foreign + * + * @run testng/othervm -Xverify:all VarHandleTestExact + * @run testng/othervm -Xverify:all -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestExact + * @run testng/othervm -Xverify:all -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestExact + * @run testng/othervm -Xverify:all -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestExact + */ + +import jdk.incubator.foreign.MemoryAddress; +import jdk.incubator.foreign.MemoryHandles; +import jdk.incubator.foreign.MemorySegment; +import org.testng.SkipException; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; +import java.lang.invoke.WrongMethodTypeException; +import java.lang.reflect.Array; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.Assert.*; + +public class VarHandleTestExact { + + private static class Widget { + static Object objectField_SRW; + static long longField_SRW; + static double doubleField_SRW; + static Long aLongField_SRW; + + Object objectField_RW; + long longField_RW; + double doubleField_RW; + Long aLongField_RW; + + final static Object objectField_SRO = new Object(); + final static long longField_SRO = 1234L; + final static double doubleField_SRO = 1234D; + final static Long aLongField_SRO = 1234L; + + final Object objectField_RO = new Object(); + final long longField_RO = 1234L; + final double doubleField_RO = 1234D; + final Long aLongField_RO = 1234L; + } + + @Test(dataProvider = "dataObjectAccess") + public void testExactSet(String fieldBaseName, Class fieldType, boolean ro, Object testValue, + SetX setter, GetX getter, + SetStaticX staticSetter, GetStaticX staticGetter) + throws NoSuchFieldException, IllegalAccessException { + if (ro) throw new SkipException("Can not test setter with read only field"); + VarHandle vh = MethodHandles.lookup().findVarHandle(Widget.class, fieldBaseName + "_RW", fieldType); + assertFalse(vh.hasInvokeExactBehavior()); + Widget w = new Widget(); + + try { + vh.set(w, testValue); + vh.withInvokeBehavior().set(w, testValue); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + setter.set(vh, w, testValue); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(),".*\\Qexpected (Widget," + fieldType.getSimpleName() + ")void \\E.*"); + } + } + + @Test(dataProvider = "dataObjectAccess") + public void testExactGet(String fieldBaseName, Class fieldType, boolean ro, Object testValue, + SetX setter, GetX getter, + SetStaticX staticSetter, GetStaticX staticGetter) + throws NoSuchFieldException, IllegalAccessException { + VarHandle vh = MethodHandles.lookup().findVarHandle(Widget.class, fieldBaseName + (ro ? "_RO" : "_RW"), fieldType); + assertFalse(vh.hasInvokeExactBehavior()); + Widget w = new Widget(); + + try { + Object o = vh.get(w); + Object o2 = vh.withInvokeBehavior().get(w); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + getter.get(vh, w); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(),".*\\Qexpected (Widget)" + fieldType.getSimpleName() + " \\E.*"); + } + } + + @Test(dataProvider = "dataObjectAccess") + public void testExactSetStatic(String fieldBaseName, Class fieldType, boolean ro, Object testValue, + SetX setter, GetX getter, + SetStaticX staticSetter, GetStaticX staticGetter) + throws NoSuchFieldException, IllegalAccessException { + if (ro) throw new SkipException("Can not test setter with read only field"); + VarHandle vh = MethodHandles.lookup().findStaticVarHandle(Widget.class, fieldBaseName + "_SRW", fieldType); + assertFalse(vh.hasInvokeExactBehavior()); + + try { + vh.set(testValue); + vh.withInvokeBehavior().set(testValue); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + staticSetter.set(vh, testValue); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(),".*\\Qexpected (" + fieldType.getSimpleName() + ")void \\E.*"); + } + } + + @Test(dataProvider = "dataObjectAccess") + public void testExactGetStatic(String fieldBaseName, Class fieldType, boolean ro, Object testValue, + SetX setter, GetX getter, + SetStaticX staticSetter, GetStaticX staticGetter) + throws NoSuchFieldException, IllegalAccessException { + VarHandle vh = MethodHandles.lookup().findStaticVarHandle(Widget.class, fieldBaseName + (ro ? "_SRO" : "_SRW"), fieldType); + assertFalse(vh.hasInvokeExactBehavior()); + + try { + Object o = vh.get(); + Object o2 = vh.withInvokeBehavior().get(); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + staticGetter.get(vh); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(),".*\\Qexpected ()" + fieldType.getSimpleName() + " \\E.*"); + } + } + + @Test(dataProvider = "dataSetArray") + public void testExactArraySet(Class arrayClass, Object testValue, SetArrayX setter) { + VarHandle vh = MethodHandles.arrayElementVarHandle(arrayClass); + Object arr = Array.newInstance(arrayClass.componentType(), 1); + assertFalse(vh.hasInvokeExactBehavior()); + + try { + vh.set(arr, 0, testValue); + vh.withInvokeBehavior().set(arr, 0, testValue); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + setter.set(vh, arr, testValue); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(), + ".*\\Qexpected (" + arrayClass.getSimpleName() + ",int," + arrayClass.componentType().getSimpleName() + ")void \\E.*"); + } + } + + @Test(dataProvider = "dataSetBuffer") + public void testExactBufferSet(Class arrayClass, Object testValue, SetBufferX setter) { + VarHandle vh = MethodHandles.byteBufferViewVarHandle(arrayClass, ByteOrder.nativeOrder()); + assertFalse(vh.hasInvokeExactBehavior()); + ByteBuffer buff = ByteBuffer.allocateDirect(8); + + try { + vh.set(buff, 0, testValue); + vh.withInvokeBehavior().set(buff, 0, testValue); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + setter.set(vh, buff, testValue); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(), + ".*\\Qexpected (ByteBuffer,int," + arrayClass.componentType().getSimpleName() + ")void \\E.*"); + } + } + + @Test(dataProvider = "dataSetMemorySegment") + public void testExactSegmentSet(Class carrier, Object testValue, SetSegmentX setter) { + VarHandle vh = MemoryHandles.varHandle(carrier, ByteOrder.nativeOrder()); + assertFalse(vh.hasInvokeExactBehavior()); + try (MemorySegment seg = MemorySegment.allocateNative(8)) { + MemoryAddress base = seg.baseAddress(); + try { + vh.set(base, testValue); + vh.withInvokeBehavior().set(base, testValue); + } catch (WrongMethodTypeException wmte) { + fail("Unexpected exception", wmte); + } + + vh = vh.withInvokeExactBehavior(); + assertTrue(vh.hasInvokeExactBehavior()); + try { + setter.set(vh, base, testValue); // should throw + fail("Exception expected"); + } catch (WrongMethodTypeException wmte) { + assertMatches(wmte.getMessage(), + ".*\\Qexpected (MemoryAddress," + carrier.getSimpleName() + ")void \\E.*"); + } + } + } + + private static void assertMatches(String str, String pattern) { + if (!str.matches(pattern)) { + throw new AssertionError("'" + str + "' did not match the pattern '" + pattern + "'."); + } + } + + private interface SetX { + void set(VarHandle vh, Widget w, Object testValue); + } + + private interface SetStaticX { + void set(VarHandle vh, Object testValue); + } + + private interface GetX { + void get(VarHandle vh, Widget w); + } + + private interface GetStaticX { + void get(VarHandle vh); + } + + private interface SetArrayX { + void set(VarHandle vh, Object array, Object testValue); + } + + private interface SetBufferX { + void set(VarHandle vh, ByteBuffer buff, Object testValue); + } + + private interface SetSegmentX { + void set(VarHandle vh, MemoryAddress addr, Object testValue); + } + + private static void consume(Object o) {} + + private static void testCaseObjectAccess(List cases, String fieldBaseName, Class fieldType, Object testValue, + SetX setter, GetX getter, + SetStaticX staticSetter, GetStaticX staticGetter) { + cases.add(new Object[] { fieldBaseName, fieldType, false, testValue, setter, getter, staticSetter, staticGetter }); + cases.add(new Object[] { fieldBaseName, fieldType, true, testValue, setter, getter, staticSetter, staticGetter }); + } + + private static void testCaseArraySet(List cases, Class arrayType, Object testValue, SetArrayX setter) { + cases.add(new Object[] { arrayType, testValue, setter }); + } + + private static void testCaseBufferSet(List cases, Class arrayType, Object testValue, SetBufferX setter) { + cases.add(new Object[] { arrayType, testValue, setter }); + } + + private static void testCaseSegmentSet(List cases, Class carrier, Object testValue, SetSegmentX setter) { + cases.add(new Object[] { carrier, testValue, setter }); + } + + @DataProvider + public static Object[][] dataObjectAccess() { + List cases = new ArrayList<>(); + + // create a bunch of different sig-poly call sites + testCaseObjectAccess(cases, "objectField", Object.class, "abcd", + (vh, w, tv) -> vh.set(w, (String) tv), + (vh, w) -> consume((String) vh.get(w)), + (vh, tv) -> vh.set((String) tv), + (vh) -> consume((String) vh.get())); + testCaseObjectAccess(cases, "objectField", Object.class, Integer.valueOf(1234), + (vh, w, tv) -> vh.set(w, (Integer) tv), + (vh, w) -> consume((Integer) vh.get(w)), + (vh, tv) -> vh.set((Integer) tv), + (vh) -> consume((Integer) vh.get())); + testCaseObjectAccess(cases, "longField", long.class, 1234, + (vh, w, tv) -> vh.set(w, (int) tv), + (vh, w) -> consume((int) vh.get(w)), + (vh, tv) -> vh.set((int) tv), + (vh) -> consume((int) vh.get())); + testCaseObjectAccess(cases, "longField", long.class, (short) 1234, + (vh, w, tv) -> vh.set(w, (short) tv), + (vh, w) -> consume((short) vh.get(w)), + (vh, tv) -> vh.set((short) tv), + (vh) -> consume((short) vh.get())); + testCaseObjectAccess(cases, "longField", long.class, (char) 1234, + (vh, w, tv) -> vh.set(w, (char) tv), + (vh, w) -> consume((char) vh.get(w)), + (vh, tv) -> vh.set((char) tv), + (vh) -> consume((char) vh.get())); + testCaseObjectAccess(cases, "longField", long.class, (byte) 1234, + (vh, w, tv) -> vh.set(w, (byte) tv), + (vh, w) -> consume((byte) vh.get(w)), + (vh, tv) -> vh.set((byte) tv), + (vh) -> consume((byte) vh.get())); + testCaseObjectAccess(cases, "longField", long.class, Long.valueOf(1234L), + (vh, w, tv) -> vh.set(w, (Long) tv), + (vh, w) -> consume((Long) vh.get(w)), + (vh, tv) -> vh.set((Long) tv), + (vh) -> consume((Long) vh.get())); + testCaseObjectAccess(cases, "doubleField", double.class, 1234F, + (vh, w, tv) -> vh.set(w, (float) tv), + (vh, w) -> consume((float) vh.get(w)), + (vh, tv) -> vh.set((float) tv), + (vh) -> consume((float) vh.get())); + testCaseObjectAccess(cases, "doubleField", double.class, 1234, + (vh, w, tv) -> vh.set(w, (int) tv), + (vh, w) -> consume((int) vh.get(w)), + (vh, tv) -> vh.set((int) tv), + (vh) -> consume((int) vh.get())); + testCaseObjectAccess(cases, "doubleField", double.class, 1234L, + (vh, w, tv) -> vh.set(w, (long) tv), + (vh, w) -> consume((long) vh.get(w)), + (vh, tv) -> vh.set((long) tv), + (vh) -> consume((long) vh.get())); + testCaseObjectAccess(cases, "doubleField", double.class, Double.valueOf(1234D), + (vh, w, tv) -> vh.set(w, (Double) tv), + (vh, w) -> consume((Double) vh.get(w)), + (vh, tv) -> vh.set((Double) tv), + (vh) -> consume((Double) vh.get())); + testCaseObjectAccess(cases, "aLongField", Long.class, 1234L, + (vh, w, tv) -> vh.set(w, (long) tv), + (vh, w) -> consume((long) vh.get(w)), + (vh, tv) -> vh.set((long) tv), + (vh) -> consume((long) vh.get())); + + return cases.toArray(Object[][]::new); + } + + @DataProvider + public static Object[][] dataSetArray() { + List cases = new ArrayList<>(); + + // create a bunch of different sig-poly call sites + testCaseArraySet(cases, Object[].class, "abcd", (vh, arr, tv) -> vh.set((Object[]) arr, 0, (String) tv)); + testCaseArraySet(cases, Object[].class, Integer.valueOf(1234), (vh, arr, tv) -> vh.set((Object[]) arr, (Integer) tv)); + testCaseArraySet(cases, long[].class, 1234, (vh, arr, tv) -> vh.set((long[]) arr, 0, (int) tv)); + testCaseArraySet(cases, long[].class, (short) 1234, (vh, arr, tv) -> vh.set((long[]) arr, 0, (short) tv)); + testCaseArraySet(cases, long[].class, (char) 1234, (vh, arr, tv) -> vh.set((long[]) arr, 0, (char) tv)); + testCaseArraySet(cases, long[].class, (byte) 1234, (vh, arr, tv) -> vh.set((long[]) arr, 0, (byte) tv)); + testCaseArraySet(cases, long[].class, Long.valueOf(1234L), (vh, arr, tv) -> vh.set((long[]) arr, 0, (Long) tv)); + testCaseArraySet(cases, double[].class, 1234F, (vh, arr, tv) -> vh.set((double[]) arr, 0, (float) tv)); + testCaseArraySet(cases, double[].class, 1234, (vh, arr, tv) -> vh.set((double[]) arr, 0, (int) tv)); + testCaseArraySet(cases, double[].class, 1234L, (vh, arr, tv) -> vh.set((double[]) arr, 0, (long) tv)); + testCaseArraySet(cases, double[].class, Double.valueOf(1234D), (vh, arr, tv) -> vh.set((double[]) arr, 0, (Double) tv)); + testCaseArraySet(cases, Long[].class, 1234L, (vh, arr, tv) -> vh.set((Long[]) arr, 0, (long) tv)); + + return cases.toArray(Object[][]::new); + } + + @DataProvider + public static Object[][] dataSetBuffer() { + List cases = new ArrayList<>(); + + // create a bunch of different sig-poly call sites + testCaseBufferSet(cases, long[].class, 1234, (vh, buff, tv) -> vh.set(buff, 0, (int) tv)); + testCaseBufferSet(cases, long[].class, (short) 1234, (vh, buff, tv) -> vh.set(buff, 0, (short) tv)); + testCaseBufferSet(cases, long[].class, (char) 1234, (vh, buff, tv) -> vh.set(buff, 0, (char) tv)); + testCaseBufferSet(cases, long[].class, (byte) 1234, (vh, buff, tv) -> vh.set(buff, 0, (byte) tv)); + testCaseBufferSet(cases, long[].class, Long.valueOf(1234L), (vh, buff, tv) -> vh.set(buff, 0, (Long) tv)); + testCaseBufferSet(cases, double[].class, 1234F, (vh, buff, tv) -> vh.set(buff, 0, (float) tv)); + testCaseBufferSet(cases, double[].class, 1234, (vh, buff, tv) -> vh.set(buff, 0, (int) tv)); + testCaseBufferSet(cases, double[].class, 1234L, (vh, buff, tv) -> vh.set(buff, 0, (long) tv)); + testCaseBufferSet(cases, double[].class, Double.valueOf(1234D), (vh, buff, tv) -> vh.set(buff, 0, (Double) tv)); + + return cases.toArray(Object[][]::new); + } + + @DataProvider + public static Object[][] dataSetMemorySegment() { + List cases = new ArrayList<>(); + + // create a bunch of different sig-poly call sites + testCaseSegmentSet(cases, long.class, 1234, (vh, addr, tv) -> vh.set(addr, (int) tv)); + testCaseSegmentSet(cases, long.class, (char) 1234, (vh, addr, tv) -> vh.set(addr, (char) tv)); + testCaseSegmentSet(cases, long.class, (short) 1234, (vh, addr, tv) -> vh.set(addr, (short) tv)); + testCaseSegmentSet(cases, long.class, (byte) 1234, (vh, addr, tv) -> vh.set(addr, (byte) tv)); + testCaseSegmentSet(cases, double.class, 1234F, (vh, addr, tv) -> vh.set(addr, (float) tv)); + + return cases.toArray(Object[][]::new); + } + +} diff --git a/test/micro/org/openjdk/bench/java/lang/invoke/VarHandleExact.java b/test/micro/org/openjdk/bench/java/lang/invoke/VarHandleExact.java new file mode 100644 index 0000000000000..1b5e4f776011d --- /dev/null +++ b/test/micro/org/openjdk/bench/java/lang/invoke/VarHandleExact.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.openjdk.bench.java.lang.invoke; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@State(org.openjdk.jmh.annotations.Scope.Thread) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Fork(3) +public class VarHandleExact { + + static final VarHandle exact; + static final VarHandle generic; + + static { + try { + generic = MethodHandles.lookup().findVarHandle(Data.class, "longField", long.class); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + exact = generic.withInvokeExactBehavior(); + } + + Data data; + + static class Data { + long longField; + } + + @Setup + public void setup() { + data = new Data(); + } + + @Benchmark + public void exact_exactInvocation() { + exact.set(data, (long) 42); + } + + @Benchmark + public void generic_genericInvocation() { + generic.set(data, 42); + } + + @Benchmark + public void generic_exactInvocation() { + generic.set(data, (long) 42); + } +} diff --git a/test/micro/org/openjdk/bench/jdk/incubator/foreign/VarHandleExact.java b/test/micro/org/openjdk/bench/jdk/incubator/foreign/VarHandleExact.java new file mode 100644 index 0000000000000..ec920b90ae82c --- /dev/null +++ b/test/micro/org/openjdk/bench/jdk/incubator/foreign/VarHandleExact.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.openjdk.bench.jdk.incubator.foreign; + +import jdk.incubator.foreign.MemoryHandles; +import jdk.incubator.foreign.MemorySegment; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; + +import java.lang.invoke.VarHandle; +import java.nio.ByteOrder; +import java.util.concurrent.TimeUnit; + +import static jdk.incubator.foreign.MemoryLayouts.JAVA_INT; + +@BenchmarkMode(Mode.AverageTime) +@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@State(org.openjdk.jmh.annotations.Scope.Thread) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Fork(value = 3, jvmArgsAppend = { "--add-modules", "jdk.incubator.foreign" }) +public class VarHandleExact { + + static final VarHandle exact; + static final VarHandle generic; + + static { + generic = MemoryHandles.withStride(MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder()), 4); + exact = generic.withInvokeExactBehavior(); + } + + MemorySegment data; + + @Setup + public void setup() { + data = MemorySegment.allocateNative(JAVA_INT); + } + + @TearDown + public void tearDown() { + data.close(); + } + + @Benchmark + public void exact_exactInvocation() { + exact.set(data.baseAddress(), (long) 0, 42); + } + + @Benchmark + public void generic_genericInvocation() { + generic.set(data.baseAddress(), 0, 42); + } + + @Benchmark + public void generic_exactInvocation() { + generic.set(data.baseAddress(), (long) 0, 42); + } +}