当前位置: 首页>>代码示例>>Java>>正文


Java GuardedInvocation.getInvocation方法代码示例

本文整理汇总了Java中jdk.internal.dynalink.linker.GuardedInvocation.getInvocation方法的典型用法代码示例。如果您正苦于以下问题:Java GuardedInvocation.getInvocation方法的具体用法?Java GuardedInvocation.getInvocation怎么用?Java GuardedInvocation.getInvocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.internal.dynalink.linker.GuardedInvocation的用法示例。


在下文中一共展示了GuardedInvocation.getInvocation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fixExpressionCallSite

import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
    // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
    // expression.
    if (!"getMethod".equals(desc.getFirstOperator())) {
        return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
    }

    final MethodHandle linkInvocation      = link.getInvocation();
    final MethodType   linkType            = linkInvocation.type();
    final boolean      linkReturnsFunction = ScriptFunction.class.isAssignableFrom(linkType.returnType());

    return link.replaceMethods(
            // Make sure getMethod will bind the script functions it receives to WithObject.expression
            MH.foldArguments(
                    linkReturnsFunction ?
                            BIND_TO_EXPRESSION_FN :
                            BIND_TO_EXPRESSION_OBJ,
                    filterReceiver(
                            linkInvocation.asType(
                                    linkType.changeReturnType(
                                            linkReturnsFunction ?
                                                    ScriptFunction.class :
                                                    Object.class).
                                                        changeParameterType(
                                                                0,
                                                                Object.class)),
                                    WITHEXPRESSIONFILTER)),
                     filterGuardReceiver(link, WITHEXPRESSIONFILTER));
 // No clever things for the guard -- it is still identically filtered.

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:WithObject.java

示例2: getGuardedInvocation

import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    final Object objSuperAdapter = linkRequest.getReceiver();
    if(!(objSuperAdapter instanceof JavaSuperAdapter)) {
        return null;
    }

    final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
    if(!CallSiteDescriptorFactory.tokenizeOperators(descriptor).contains(GET_METHOD)) {
        // We only handle getMethod
        return null;
    }

    final Object adapter = ((JavaSuperAdapter)objSuperAdapter).getAdapter();

    // Replace argument (javaSuperAdapter, ...) => (adapter, ...) when delegating to BeansLinker
    final Object[] args = linkRequest.getArguments();
    args[0] = adapter;

    // Use R(T0, ...) => R(adapter.class, ...) call site type when delegating to BeansLinker.
    final MethodType type = descriptor.getMethodType();
    final Class<?> adapterClass = adapter.getClass();
    final boolean hasFixedName = descriptor.getNameTokenCount() > 2;
    final String opName = hasFixedName ? (DYN_GET_METHOD_FIXED + descriptor.getNameToken(
            CallSiteDescriptor.NAME_OPERAND)) : DYN_GET_METHOD;

    final CallSiteDescriptor newDescriptor = NashornCallSiteDescriptor.get(descriptor.getLookup(), opName,
            type.changeParameterType(0, adapterClass), 0);

    // Delegate to BeansLinker
    final GuardedInvocation guardedInv = NashornBeansLinker.getGuardedInvocation(
            BeansLinker.getLinkerForClass(adapterClass), linkRequest.replaceArguments(newDescriptor, args),
            linkerServices);

    final MethodHandle guard = IS_ADAPTER_OF_CLASS.bindTo(adapterClass);
    if(guardedInv == null) {
        // Short circuit the lookup here for non-existent methods by linking an empty getter. If we just returned
        // null instead, BeansLinker would find final methods on the JavaSuperAdapter instead: getClass() and
        // wait().
        return new GuardedInvocation(MethodHandles.dropArguments(EMPTY_GETTER, 1,type.parameterList().subList(1,
                type.parameterCount())), guard).asType(descriptor);
    }

    final MethodHandle invocation = guardedInv.getInvocation();
    final MethodType invType = invocation.type();
    // For invocation typed R(T0, ...) create a dynamic method binder of type Object(R, T0)
    final MethodHandle typedBinder = BIND_DYNAMIC_METHOD.asType(MethodType.methodType(Object.class,
            invType.returnType(), invType.parameterType(0)));
    // For invocation typed R(T0, T1, ...) create a dynamic method binder of type Object(R, T0, T1, ...)
    final MethodHandle droppingBinder = MethodHandles.dropArguments(typedBinder, 2,
            invType.parameterList().subList(1, invType.parameterCount()));
    // Finally, fold the invocation into the binder to produce a method handle that will bind every returned
    // DynamicMethod object from dyn:getMethod calls to the actual receiver
    // Object(R(T0, T1, ...), T0, T1, ...)
    final MethodHandle bindingInvocation = MethodHandles.foldArguments(droppingBinder, invocation);

    final MethodHandle typedGetAdapter = asFilterType(GET_ADAPTER, 0, invType, type);
    final MethodHandle adaptedInvocation;
    if(hasFixedName) {
        adaptedInvocation = MethodHandles.filterArguments(bindingInvocation, 0, typedGetAdapter);
    } else {
        // Add a filter that'll prepend "super$" to each name passed to the variable-name "dyn:getMethod".
        final MethodHandle typedAddPrefix = asFilterType(ADD_PREFIX_TO_METHOD_NAME, 1, invType, type);
        adaptedInvocation = MethodHandles.filterArguments(bindingInvocation, 0, typedGetAdapter, typedAddPrefix);
    }

    return guardedInv.replaceMethods(adaptedInvocation, guard).asType(descriptor);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:JavaSuperAdapterLinker.java

示例3: getElementGetter

import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);
    final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor,
            linkerServices, operations);

    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final GuardedInvocationComponent gic;
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementGetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(GET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(GET_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementGetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(GET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(GET_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't retrieve elements for objects that are neither arrays, nor list, nor maps.
        return nextComponent;
    }

    // We can have "dyn:getElem:foo", especially in composites, i.e. "dyn:getElem|getProp|getMethod:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard;
    if(invocation == GET_LIST_ELEMENT) {
        checkGuard = convertArgToInt(RANGE_CHECK_LIST, linkerServices, callSiteDescriptor);
    } else if(invocation == GET_MAP_ELEMENT) {
        // TODO: A more complex solution could be devised for maps, one where we do a get() first, and fold it
        // into a GWT that tests if it returned null, and if it did, do another GWT with containsKey()
        // that returns constant null (on true), or falls back to next component (on false)
        checkGuard = CONTAINS_MAP;
    } else {
        checkGuard = convertArgToInt(RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    }
    final MethodPair matchedInvocations = matchReturnTypes(binder.bind(invocation),
            nextComponent.getGuardedInvocation().getInvocation());
    return nextComponent.compose(matchedInvocations.guardWithTest(binder.bindTest(checkGuard)), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:78,代码来源:BeanLinker.java

示例4: getElementSetter

import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private GuardedInvocationComponent getElementSetter(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);

    final GuardedInvocationComponent gic;
    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementSetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementSetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't set elements for objects that are neither arrays, nor list, nor maps.
        gic = null;
        isMap = false;
    }

    // In contrast to, say, getElementGetter, we only compute the nextComponent if the target object is not a map,
    // as maps will always succeed in setting the element and will never need to fall back to the next component
    // operation.
    final GuardedInvocationComponent nextComponent = isMap ? null : getGuardedInvocationComponent(
            callSiteDescriptor, linkerServices, operations);
    if(gic == null) {
        return nextComponent;
    }

    // We can have "dyn:setElem:foo", especially in composites, i.e. "dyn:setElem|setProp:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard = convertArgToInt(invocation == SET_LIST_ELEMENT ? RANGE_CHECK_LIST :
        RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    final MethodPair matchedInvocations = matchReturnTypes(binder.bind(invocation),
            nextComponent.getGuardedInvocation().getInvocation());
    return nextComponent.compose(matchedInvocations.guardWithTest(binder.bindTest(checkGuard)), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:77,代码来源:BeanLinker.java

示例5: relink

import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
/**
 * 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);
    guardedInvocation.getClass(); // null pointer check

    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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:DynamicLinker.java


注:本文中的jdk.internal.dynalink.linker.GuardedInvocation.getInvocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。