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 Project: TencentKona-8   Author: Tencent   File: ApplicableOverloadedMethods.java    License: 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 Project: TencentKona-8   Author: Tencent   File: ApplicableOverloadedMethods.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: ApplicableOverloadedMethods.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: ApplicableOverloadedMethods.java    License: 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 #5
Source Project: openjdk-8-source   Author: keerath   File: ApplicableOverloadedMethods.java    License: 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 #6
Source Project: nashorn   Author: ynsn   File: ApplicableOverloadedMethods.java    License: 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 #7
Source Project: nashorn   Author: ynsn   File: ApplicableOverloadedMethods.java    License: 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 #8
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ApplicableOverloadedMethods.java    License: 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 #9
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ApplicableOverloadedMethods.java    License: 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 #10
Source Project: openjdk-8-source   Author: keerath   File: ApplicableOverloadedMethods.java    License: 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 Project: jdk8u_nashorn   Author: JetBrains   File: ApplicableOverloadedMethods.java    License: 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 #12
Source Project: TencentKona-8   Author: Tencent   File: OptimisticReturnFilters.java    License: 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 #13
Source Project: TencentKona-8   Author: Tencent   File: ApplicableOverloadedMethods.java    License: 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 #14
Source Project: TencentKona-8   Author: Tencent   File: OverloadedMethod.java    License: 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 #15
Source Project: openjdk-8   Author: bpupadhyaya   File: MaximallySpecific.java    License: 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 #16
Source Project: TencentKona-8   Author: Tencent   File: AbstractJavaLinker.java    License: 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 #17
Source Project: openjdk-8-source   Author: keerath   File: ApplicableOverloadedMethods.java    License: 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 #18
Source Project: jdk8u_nashorn   Author: JetBrains   File: OptimisticReturnFilters.java    License: 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 #19
Source Project: jdk8u60   Author: chenghanpeng   File: NativeJava.java    License: 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 #20
Source Project: hottub   Author: dsrg-uoft   File: BeanLinker.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: ApplicableOverloadedMethods.java    License: 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 #22
Source Project: jdk8u60   Author: chenghanpeng   File: OverloadedMethod.java    License: 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 #23
Source Project: jdk8u60   Author: chenghanpeng   File: AbstractJavaLinker.java    License: 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 #24
Source Project: jdk8u60   Author: chenghanpeng   File: BeanLinker.java    License: 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 #25
Source Project: hottub   Author: dsrg-uoft   File: OverloadedMethod.java    License: 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 #26
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: OptimisticReturnFilters.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: OverloadedMethod.java    License: 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 Project: openjdk-8   Author: bpupadhyaya   File: ApplicableOverloadedMethods.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: AbstractJavaLinker.java    License: 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 Project: nashorn   Author: ynsn   File: BeanLinker.java    License: 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;
}