Java Code Examples for sun.reflect.misc.ReflectUtil#isVMAnonymousClass()

The following examples show how to use sun.reflect.misc.ReflectUtil#isVMAnonymousClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReflectionFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 2
Source File: InvokerBytecodeGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 3
Source File: InvokerBytecodeGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 4
Source File: InvokerBytecodeGenerator.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example 5
Source File: InvokerBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 6
Source File: ReflectionFactory.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 7
Source File: ReflectionFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 8
Source File: ReflectionFactory.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 9
Source File: InvokerBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 10
Source File: InvokerBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example 11
Source File: InvokerBytecodeGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 12
Source File: ReflectionFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 13
Source File: InvokerBytecodeGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example 14
Source File: InvokerBytecodeGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example 15
Source File: NativeConstructorAccessorImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Object newInstance(Object[] args)
    throws InstantiationException,
           IllegalArgumentException,
           InvocationTargetException
{
    // We can't inflate a constructor belonging to a vm-anonymous class
    // because that kind of class can't be referred to by name, hence can't
    // be found from the generated bytecode.
    if (++numInvocations > ReflectionFactory.inflationThreshold()
            && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
        ConstructorAccessorImpl acc = (ConstructorAccessorImpl)
            new MethodAccessorGenerator().
                generateConstructor(c.getDeclaringClass(),
                                    c.getParameterTypes(),
                                    c.getExceptionTypes(),
                                    c.getModifiers());
        parent.setDelegate(acc);
    }

    return newInstance0(c, args);
}
 
Example 16
Source File: ReflectionFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
    checkInitted();

    Class<?> declaringClass = c.getDeclaringClass();
    if (Modifier.isAbstract(declaringClass.getModifiers())) {
        return new InstantiationExceptionConstructorAccessorImpl(null);
    }
    if (declaringClass == Class.class) {
        return new InstantiationExceptionConstructorAccessorImpl
            ("Can not instantiate java.lang.Class");
    }
    // Bootstrapping issue: since we use Class.newInstance() in
    // the ConstructorAccessor generation process, we have to
    // break the cycle here.
    if (Reflection.isSubclassOf(declaringClass,
                                ConstructorAccessorImpl.class)) {
        return new BootstrapConstructorAccessorImpl(c);
    }

    if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateConstructor(c.getDeclaringClass(),
                                c.getParameterTypes(),
                                c.getExceptionTypes(),
                                c.getModifiers());
    } else {
        NativeConstructorAccessorImpl acc =
            new NativeConstructorAccessorImpl(c);
        DelegatingConstructorAccessorImpl res =
            new DelegatingConstructorAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 17
Source File: ReflectionFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
    checkInitted();

    Class<?> declaringClass = c.getDeclaringClass();
    if (Modifier.isAbstract(declaringClass.getModifiers())) {
        return new InstantiationExceptionConstructorAccessorImpl(null);
    }
    if (declaringClass == Class.class) {
        return new InstantiationExceptionConstructorAccessorImpl
            ("Can not instantiate java.lang.Class");
    }
    // Bootstrapping issue: since we use Class.newInstance() in
    // the ConstructorAccessor generation process, we have to
    // break the cycle here.
    if (Reflection.isSubclassOf(declaringClass,
                                ConstructorAccessorImpl.class)) {
        return new BootstrapConstructorAccessorImpl(c);
    }

    if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateConstructor(c.getDeclaringClass(),
                                c.getParameterTypes(),
                                c.getExceptionTypes(),
                                c.getModifiers());
    } else {
        NativeConstructorAccessorImpl acc =
            new NativeConstructorAccessorImpl(c);
        DelegatingConstructorAccessorImpl res =
            new DelegatingConstructorAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 18
Source File: ReflectionFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
    checkInitted();

    Class<?> declaringClass = c.getDeclaringClass();
    if (Modifier.isAbstract(declaringClass.getModifiers())) {
        return new InstantiationExceptionConstructorAccessorImpl(null);
    }
    if (declaringClass == Class.class) {
        return new InstantiationExceptionConstructorAccessorImpl
            ("Can not instantiate java.lang.Class");
    }
    // Bootstrapping issue: since we use Class.newInstance() in
    // the ConstructorAccessor generation process, we have to
    // break the cycle here.
    if (Reflection.isSubclassOf(declaringClass,
                                ConstructorAccessorImpl.class)) {
        return new BootstrapConstructorAccessorImpl(c);
    }

    if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateConstructor(c.getDeclaringClass(),
                                c.getParameterTypes(),
                                c.getExceptionTypes(),
                                c.getModifiers());
    } else {
        NativeConstructorAccessorImpl acc =
            new NativeConstructorAccessorImpl(c);
        DelegatingConstructorAccessorImpl res =
            new DelegatingConstructorAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 19
Source File: ReflectionFactory.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
    checkInitted();

    Class<?> declaringClass = c.getDeclaringClass();
    if (Modifier.isAbstract(declaringClass.getModifiers())) {
        return new InstantiationExceptionConstructorAccessorImpl(null);
    }
    if (declaringClass == Class.class) {
        return new InstantiationExceptionConstructorAccessorImpl
            ("Can not instantiate java.lang.Class");
    }
    // Bootstrapping issue: since we use Class.newInstance() in
    // the ConstructorAccessor generation process, we have to
    // break the cycle here.
    if (Reflection.isSubclassOf(declaringClass,
                                ConstructorAccessorImpl.class)) {
        return new BootstrapConstructorAccessorImpl(c);
    }

    if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateConstructor(c.getDeclaringClass(),
                                c.getParameterTypes(),
                                c.getExceptionTypes(),
                                c.getModifiers());
    } else {
        NativeConstructorAccessorImpl acc =
            new NativeConstructorAccessorImpl(c);
        DelegatingConstructorAccessorImpl res =
            new DelegatingConstructorAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}
 
Example 20
Source File: ReflectionFactory.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public MethodAccessor newMethodAccessor(Method method) {
    checkInitted();

    if (Reflection.isCallerSensitive(method)) {
        Method altMethod = findMethodForReflection(method);
        if (altMethod != null) {
            method = altMethod;
        }
    }

    // use the root Method that will not cache caller class
    Method root = langReflectAccess.getRoot(method);
    if (root != null) {
        method = root;
    }

    if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
        return new MethodAccessorGenerator().
            generateMethod(method.getDeclaringClass(),
                           method.getName(),
                           method.getParameterTypes(),
                           method.getReturnType(),
                           method.getExceptionTypes(),
                           method.getModifiers());
    } else {
        NativeMethodAccessorImpl acc =
            new NativeMethodAccessorImpl(method);
        DelegatingMethodAccessorImpl res =
            new DelegatingMethodAccessorImpl(acc);
        acc.setParent(res);
        return res;
    }
}