--- /dev/null 2016-02-25 15:59:29.000000000 +0300 +++ new/test/runtime/valhalla/nestmates/p2/MethodHandleSubTop.java 2016-02-25 15:59:29.000000000 +0300 @@ -0,0 +1,88 @@ +package runtime.valhalla.nestmates.p2; + +import runtime.valhalla.nestmates.p1.Sup; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +public class MethodHandleSubTop extends Sup { + + private final MethodHandles.Lookup METHOD_HANDLE_LOOKUP = MethodHandles.lookup(); + private final MethodType METHOD_TYPE = MethodType.methodType(int.class); + + // verify access check to a "super" method, method can be used in positive and negative test case + public MethodHandle getSuperMethodMH(String methodName) throws NoSuchMethodException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findVirtual(this.getClass(), methodName, METHOD_TYPE); + } + + // verify access check to a "super" field, method can be used in positive and negative test case + public MethodHandle getSuperFieldMH(String fieldName) throws NoSuchFieldException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findGetter(this.getClass(), fieldName, int.class); + } + + public class Inner { + + public Inner() { + getField(); // to force javac to create a bridge + int x = field; // to force javac to create a bridge + } + + // verify presence of an access bridge for a "super" method + public MethodHandle getSuperProtectedMethodMH() throws Throwable { + MethodType mt = MethodType.methodType(int.class, this.getClass().getEnclosingClass()); + MethodHandle mh = METHOD_HANDLE_LOOKUP.findStatic(this.getClass().getEnclosingClass(), "access$000", mt); + return mh; + } + + // verify presence of an access bridge for a "super" field + public MethodHandle getSuperProtectedFieldMH() throws Throwable { + MethodType mt = MethodType.methodType(int.class, this.getClass().getEnclosingClass()); + MethodHandle mh = METHOD_HANDLE_LOOKUP.findStatic(this.getClass().getEnclosingClass(), "access$100", mt); + return mh; + } + + // verify access check to a "super" method without an access bridge + public MethodHandle getSuperMethodMH(String methodName) throws NoSuchMethodException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findVirtual(this.getClass(), methodName, METHOD_TYPE); + } + + // verify access check to a "super" field without an access bridge + public MethodHandle getSuperFieldMH(String fieldName) throws NoSuchFieldException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findGetter(this.getClass(), fieldName, int.class); + } + + public class InnerInner { + + public InnerInner() { + getField(); // to force javac to create a bridge + int x = field; // to force javac to create a bridge + } + + // verify presence of an access bridge for a "super" method + public MethodHandle getSuperProtectedMethodMH() throws Throwable { + MethodType mt = MethodType.methodType(int.class, MethodHandleSubTop.class); + MethodHandle mh = METHOD_HANDLE_LOOKUP.findStatic(MethodHandleSubTop.class, "access$400", mt); + return mh; + } + + // verify presence of an access bridge for a "super" field + public MethodHandle getSuperProtectedFieldMH() throws Throwable { + MethodType mt = MethodType.methodType(int.class, MethodHandleSubTop.class); + MethodHandle mh = METHOD_HANDLE_LOOKUP.findStatic(MethodHandleSubTop.class, "access$500", mt); + return mh; + } + + // verify access check to a "super" method without an access bridge + public MethodHandle getSuperMethodMH(String methodName) throws NoSuchMethodException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findVirtual(this.getClass(), methodName, METHOD_TYPE); + } + + // verify access check to a "super" field without an access bridge + public MethodHandle getSuperFieldMH(String fieldName) throws NoSuchFieldException, IllegalAccessException { + return METHOD_HANDLE_LOOKUP.findGetter(this.getClass(), fieldName, int.class); + } + } + } + +}