jdk.internal.dynalink.support.TypeUtilities Java Examples

The following examples show how to use jdk.internal.dynalink.support.TypeUtilities. 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: ApplicableOverloadedMethods.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #2
Source File: ApplicableOverloadedMethods.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #3
Source File: ApplicableOverloadedMethods.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #4
Source File: ApplicableOverloadedMethods.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #5
Source File: ApplicableOverloadedMethods.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #6
Source File: ApplicableOverloadedMethods.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: ApplicableOverloadedMethods.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #8
Source File: ApplicableOverloadedMethods.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #9
Source File: ApplicableOverloadedMethods.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #10
Source File: ApplicableOverloadedMethods.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    if(methodArity != callSiteType.parameterCount()) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < methodArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    return true;
}
 
Example #11
Source File: NativeJava.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example #12
Source File: ApplicableOverloadedMethods.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    if(!method.isVarArgs()) {
        return false;
    }
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    final int fixArity = methodArity - 1;
    final int callSiteArity = callSiteType.parameterCount();
    if(fixArity > callSiteArity) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < fixArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    final Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
    for(int i = fixArity; i < callSiteArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
            return false;
        }
    }
    return true;
}
 
Example #13
Source File: AbstractJavaLinker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
    final MethodType type1 = m1.type();
    final MethodType type2 = m2.type();
    final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
            type2.returnType());
    return new MethodPair(
            m1.asType(type1.changeReturnType(commonRetType)),
            m2.asType(type2.changeReturnType(commonRetType)));
}
 
Example #14
Source File: ApplicableOverloadedMethods.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    if(!method.isVarArgs()) {
        return false;
    }
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    final int fixArity = methodArity - 1;
    final int callSiteArity = callSiteType.parameterCount();
    if(fixArity > callSiteArity) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < fixArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    final Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
    for(int i = fixArity; i < callSiteArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
            return false;
        }
    }
    return true;
}
 
Example #15
Source File: AbstractJavaLinker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
    final MethodType type1 = m1.type();
    final MethodType type2 = m2.type();
    final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
            type2.returnType());
    return new MethodPair(
            m1.asType(type1.changeReturnType(commonRetType)),
            m2.asType(type2.changeReturnType(commonRetType)));
}
 
Example #16
Source File: OverloadedMethod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getCommonReturnType(final List<MethodHandle> methodHandles) {
    final Iterator<MethodHandle> it = methodHandles.iterator();
    Class<?> retType = it.next().type().returnType();
    while(it.hasNext()) {
        retType = TypeUtilities.getCommonLosslessConversionType(retType, it.next().type().returnType());
    }
    return retType;
}
 
Example #17
Source File: ApplicableOverloadedMethods.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
    if(!method.isVarArgs()) {
        return false;
    }
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    final int fixArity = methodArity - 1;
    final int callSiteArity = callSiteType.parameterCount();
    if(fixArity > callSiteArity) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < fixArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    final Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
    for(int i = fixArity; i < callSiteArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
            return false;
        }
    }
    return true;
}
 
Example #18
Source File: AbstractJavaLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
    final MethodType type1 = m1.type();
    final MethodType type2 = m2.type();
    final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
            type2.returnType());
    return new MethodPair(
            m1.asType(type1.changeReturnType(commonRetType)),
            m2.asType(type2.changeReturnType(commonRetType)));
}
 
Example #19
Source File: MaximallySpecific.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(Class<?> c1, Class<?> c2, Class<?>[] argTypes, int i, LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #20
Source File: BeanLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) {
    final Class<?> sourceType = desc.getMethodType().parameterType(1);
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) {
        return mh;
    } else if(ls.canConvert(sourceType, Number.class)) {
        final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class);
        return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType(
                mh.type().parameterType(1))));
    }
    return mh;
}
 
Example #21
Source File: OverloadedMethod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getCommonReturnType(final List<MethodHandle> methodHandles) {
    final Iterator<MethodHandle> it = methodHandles.iterator();
    Class<?> retType = it.next().type().returnType();
    while(it.hasNext()) {
        retType = TypeUtilities.getCommonLosslessConversionType(retType, it.next().type().returnType());
    }
    return retType;
}
 
Example #22
Source File: NativeJava.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example #23
Source File: MaximallySpecific.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #24
Source File: OptimisticReturnFilters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a method handle and an expected return type, perform return value filtering
 * according to the optimistic type coercion rules
 * @param mh method handle
 * @param expectedReturnType expected return type
 * @param programPoint program point
 * @return filtered method
 */
public static MethodHandle filterOptimisticReturnValue(final MethodHandle mh, final Class<?> expectedReturnType, final int programPoint) {
    if(!isValid(programPoint)) {
        return mh;
    }

    final MethodType type = mh.type();
    final Class<?> actualReturnType = type.returnType();
    if(TypeUtilities.isConvertibleWithoutLoss(actualReturnType, expectedReturnType)) {
        return mh;
    }

    final MethodHandle guard = getOptimisticTypeGuard(expectedReturnType, actualReturnType);
    return guard == null ? mh : MH.filterReturnValue(mh, MH.insertArguments(guard, guard.type().parameterCount() - 1, programPoint));
}
 
Example #25
Source File: MaximallySpecific.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #26
Source File: OptimisticReturnFilters.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a method handle and an expected return type, perform return value filtering
 * according to the optimistic type coercion rules
 * @param mh method handle
 * @param expectedReturnType expected return type
 * @param programPoint program point
 * @return filtered method
 */
public static MethodHandle filterOptimisticReturnValue(final MethodHandle mh, final Class<?> expectedReturnType, final int programPoint) {
    if(!isValid(programPoint)) {
        return mh;
    }

    final MethodType type = mh.type();
    final Class<?> actualReturnType = type.returnType();
    if(TypeUtilities.isConvertibleWithoutLoss(actualReturnType, expectedReturnType)) {
        return mh;
    }

    final MethodHandle guard = getOptimisticTypeGuard(expectedReturnType, actualReturnType);
    return guard == null ? mh : MH.filterReturnValue(mh, MH.insertArguments(guard, guard.type().parameterCount() - 1, programPoint));
}
 
Example #27
Source File: OverloadedMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getCommonReturnType(final List<MethodHandle> methodHandles) {
    final Iterator<MethodHandle> it = methodHandles.iterator();
    Class<?> retType = it.next().type().returnType();
    while(it.hasNext()) {
        retType = TypeUtilities.getCommonLosslessConversionType(retType, it.next().type().returnType());
    }
    return retType;
}
 
Example #28
Source File: ApplicableOverloadedMethods.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
    if(!method.isVarArgs()) {
        return false;
    }
    final MethodType methodType = method.getMethodType();
    final int methodArity = methodType.parameterCount();
    final int fixArity = methodArity - 1;
    final int callSiteArity = callSiteType.parameterCount();
    if(fixArity > callSiteArity) {
        return false;
    }
    // 0th arg is receiver; it doesn't matter for overload
    // resolution.
    for(int i = 1; i < fixArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i),
                methodType.parameterType(i))) {
            return false;
        }
    }
    final Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
    for(int i = fixArity; i < callSiteArity; ++i) {
        if(!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
            return false;
        }
    }
    return true;
}
 
Example #29
Source File: AbstractJavaLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
    final MethodType type1 = m1.type();
    final MethodType type2 = m2.type();
    final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
            type2.returnType());
    return new MethodPair(
            m1.asType(type1.changeReturnType(commonRetType)),
            m2.asType(type2.changeReturnType(commonRetType)));
}
 
Example #30
Source File: BeanLinker.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) {
    final Class<?> sourceType = desc.getMethodType().parameterType(1);
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) {
        return mh;
    } else if(ls.canConvert(sourceType, Number.class)) {
        final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class);
        return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType(
                mh.type().parameterType(1))));
    }
    return mh;
}