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

The following examples show how to use jdk.internal.dynalink.linker.GuardedInvocation#getGuard() . 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: WithObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 2
Source File: WithObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 3
Source File: WithObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 4
Source File: WithObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 5
Source File: WithObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 6
Source File: WithObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
    final MethodHandle test = link.getGuard();
    if (test == null) {
        return null;
    }

    final Class<?> receiverType = test.type().parameterType(0);
    final MethodHandle filter = MH.asType(receiverFilter,
            receiverFilter.type().changeParameterType(0, receiverType).
            changeReturnType(receiverType));

    return filterReceiver(test, filter);
}
 
Example 7
Source File: DynamicLinker.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 8
Source File: DynamicLinker.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 * @return return the method handle for the invocation
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(RelinkableCallSite callSite, int relinkCount, Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ? new LinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments)
                    : new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments,
                            runtimeContextArgCount);

    // Find a suitable method handle with a guard
    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 9
Source File: WithObject.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
    final MethodHandle test = link.getGuard();
    return test == null ? null : filter(test, filter);
}
 
Example 10
Source File: DynamicLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 11
Source File: DynamicLinker.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 * @return return the method handle for the invocation
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(RelinkableCallSite callSite, int relinkCount, Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ? new LinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments)
                    : new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments,
                            runtimeContextArgCount);

    // Find a suitable method handle with a guard
    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 12
Source File: WithObject.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
    final MethodHandle test = link.getGuard();
    return test == null ? null : filter(test, filter);
}
 
Example 13
Source File: DynamicLinker.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 * @return return the method handle for the invocation
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(RelinkableCallSite callSite, int relinkCount, Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ? new LinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments)
                    : new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSiteUnstable, arguments,
                            runtimeContextArgCount);

    // Find a suitable method handle with a guard
    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 14
Source File: WithObject.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
    final MethodHandle test = link.getGuard();
    return test == null ? null : filter(test, filter);
}
 
Example 15
Source File: DynamicLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 16
Source File: DynamicLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 17
Source File: DynamicLinker.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
Example 18
Source File: DynamicLinker.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest =
            runtimeContextArgCount == 0 ?
                    new LinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments) :
                    new RuntimeContextLinkRequestImpl(callSiteDescriptor, callSite, relinkCount, callSiteUnstable, arguments, runtimeContextArgCount);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
    // produced invocation into contextual invocation (by dropping the context...)
    if(runtimeContextArgCount > 0) {
        final MethodType origType = callSiteDescriptor.getMethodType();
        final MethodHandle invocation = guardedInvocation.getInvocation();
        if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
            final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
            final MethodHandle guard = guardedInvocation.getGuard();
            guardedInvocation = guardedInvocation.dropArguments(1, prefix);
        }
    }

    // Make sure we filter the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}