Java Code Examples for jdk.internal.dynalink.linker.GuardedInvocation#compose()

The following examples show how to use jdk.internal.dynalink.linker.GuardedInvocation#compose() . 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: TypeConverterFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 2
Source File: TypeConverterFactory.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 3
Source File: TypeConverterFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 4
Source File: TypeConverterFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 5
Source File: TypeConverterFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 6
Source File: TypeConverterFactory.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 7
Source File: TypeConverterFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 8
Source File: TypeConverterFactory.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    boolean cacheable = true;
    for(int i = factories.length; i-- > 0;) {
        final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            cacheable = cacheable && next.isCacheable();
            final GuardedInvocation conversionInvocation = next.getConversionInvocation();
            conversionInvocation.assertType(type);
            last = conversionInvocation.compose(last);
        }
    }
    if(last == identity) {
        return IDENTITY_CONVERSION;
    }
    if(cacheable) {
        return last;
    }
    throw new NotCacheableConverter(last);
}
 
Example 9
Source File: TypeConverterFactory.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
    final MethodType type = MethodType.methodType(targetType, sourceType);
    final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
    MethodHandle last = identity;
    for(int i = factories.length; i-- > 0;) {
        final GuardedInvocation next = factories[i].convertToType(sourceType, targetType);
        if(next != null) {
            next.assertType(type);
            last = next.compose(last);
        }
    }
    return last == identity ? IDENTITY_CONVERSION : last;
}
 
Example 10
Source File: ChainedCallSite.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}
 
Example 11
Source File: ChainedCallSite.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}
 
Example 12
Source File: ChainedCallSite.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}