jdk.internal.dynalink.support.LinkRequestImpl Java Examples

The following examples show how to use jdk.internal.dynalink.support.LinkRequestImpl. 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: 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 #2
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 #3
Source File: NativeObject.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #4
Source File: NativeObject.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(String operation, MethodType methodType, Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), false, source);
}
 
Example #5
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 #6
Source File: NativeObject.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(String operation, MethodType methodType, Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), false, source);
}
 
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: NativeObject.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #9
Source File: NativeObject.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #10
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 #11
Source File: NativeObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #12
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 #13
Source File: NativeObject.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(String operation, MethodType methodType, Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), false, source);
}
 
Example #14
Source File: NativeObject.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #15
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 #16
Source File: NativeObject.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
    return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
            methodType), null, 0, false, source);
}
 
Example #17
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();
}
 
Example #18
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 #19
Source File: JavaAdapterFactory.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #20
Source File: JavaAdapterFactory.java    From jdk8u_nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #21
Source File: JavaAdapterFactory.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single argument of the source type (which,
 * really, should be one of {@link ScriptObject}, {@link ScriptFunction}, or {@link Object}, and returns an instance
 * of the adapter for the target type. Used to implement the function autoconverters as well as the Nashorn's
 * JSR-223 script engine's {@code getInterface()} method.
 * @param sourceType the source type; should be either {@link ScriptObject}, {@link ScriptFunction}, or
 * {@link Object}. In case of {@code Object}, it will return a method handle that dispatches to either the script
 * object or function constructor at invocation based on the actual argument.
 * @param targetType the target type, for which adapter instances will be created
 * @return the constructor method handle.
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(MethodHandles.publicLookup(),  "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #22
Source File: JavaAdapterFactory.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single argument of the source type (which,
 * really, should be one of {@link ScriptObject}, {@link ScriptFunction}, or {@link Object}, and returns an instance
 * of the adapter for the target type. Used to implement the function autoconverters as well as the Nashorn's
 * JSR-223 script engine's {@code getInterface()} method.
 * @param sourceType the source type; should be either {@link ScriptObject}, {@link ScriptFunction}, or
 * {@link Object}. In case of {@code Object}, it will return a method handle that dispatches to either the script
 * object or function constructor at invocation based on the actual argument.
 * @param targetType the target type, for which adapter instances will be created
 * @return the constructor method handle.
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #23
Source File: JavaAdapterFactory.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single argument of the source type (which,
 * really, should be one of {@link ScriptObject}, {@link ScriptFunction}, or {@link Object}, and returns an instance
 * of the adapter for the target type. Used to implement the function autoconverters as well as the Nashorn's
 * JSR-223 script engine's {@code getInterface()} method.
 * @param sourceType the source type; should be either {@link ScriptObject}, {@link ScriptFunction}, or
 * {@link Object}. In case of {@code Object}, it will return a method handle that dispatches to either the script
 * object or function constructor at invocation based on the actual argument.
 * @param targetType the target type, for which adapter instances will be created
 * @return the constructor method handle.
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #24
Source File: JavaAdapterFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #25
Source File: JavaAdapterFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #26
Source File: JavaAdapterFactory.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}
 
Example #27
Source File: JavaAdapterFactory.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a method handle representing a constructor that takes a single
 * argument of the source type (which, really, should be one of {@link ScriptObject},
 * {@link ScriptFunction}, or {@link Object}, and returns an instance of the
 * adapter for the target type. Used to implement the function autoconverters
 * as well as the Nashorn JSR-223 script engine's {@code getInterface()}
 * method.
 *
 * @param sourceType the source type; should be either {@link ScriptObject},
 *        {@link ScriptFunction}, or {@link Object}. In case of {@code Object},
 *        it will return a method handle that dispatches to either the script
 *        object or function constructor at invocation based on the actual
 *        argument.
 * @param targetType the target type, for which adapter instances will be created
 * @param lookup method handle lookup to use
 *
 * @return the constructor method handle.
 *
 * @throws Exception if anything goes wrong
 */
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception {
    final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null, lookup);
    return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(
            NashornCallSiteDescriptor.get(lookup, "dyn:new",
                    MethodType.methodType(targetType, StaticClass.class, sourceType), 0), null, 0, false,
                    adapterClass, null)).getInvocation(), adapterClass);
}