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


Java LinkerServices类代码示例

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


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

示例1: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = requestWithoutContext.getReceiver();
    final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
    checkJSObjectClass();

    if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) {
        // We only support standard "dyn:*[:*]" operations
        return null;
    }

    final GuardedInvocation inv;
    if (jsObjectClass.isInstance(self)) {
        inv = lookup(desc, request, linkerServices);
    } else {
        throw new AssertionError(); // Should never reach here.
    }

    return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:BrowserJSObjectLinker.java

示例2: lookup

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
    final int c = desc.getNameTokenCount();

    switch (operator) {
        case "getProp":
        case "getElem":
        case "getMethod":
            if (c > 2) {
                return findGetMethod(desc);
            }
        // For indexed get, we want GuardedInvocation from beans linker and pass it.
        // BrowserJSObjectLinker.get uses this fallback getter for explicit signature method access.
        return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices));
        case "setProp":
        case "setElem":
            return c > 2 ? findSetMethod(desc) : findSetIndexMethod();
        case "call":
            return findCallMethod(desc);
        default:
            return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:BrowserJSObjectLinker.java

示例3: lookup

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
    final int c = desc.getNameTokenCount();

    switch (operator) {
        case "getProp":
        case "getElem":
        case "getMethod":
            if (c > 2) {
                return findGetMethod(desc);
            }
        // For indexed get, we want get GuardedInvocation beans linker and pass it.
        // JSObjectLinker.get uses this fallback getter for explicit signature method access.
        return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices));
        case "setProp":
        case "setElem":
            return c > 2 ? findSetMethod(desc) : findSetIndexMethod();
        case "call":
            return findCallMethod(desc);
        case "new":
            return findNewMethod(desc);
        default:
            return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:JSObjectLinker.java

示例4: getMaximallySpecificMethods

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
/**
 * Given a list of methods, returns a list of maximally specific methods, applying language-runtime specific
 * conversion preferences.
 *
 * @param methods the list of methods
 * @param varArgs whether to assume the methods are varargs
 * @param argTypes concrete argument types for the invocation
 * @return the list of maximally specific methods.
 */
private static <T> List<T> getMaximallySpecificMethods(final List<T> methods, final boolean varArgs,
        final Class<?>[] argTypes, final LinkerServices ls, final MethodTypeGetter<T> methodTypeGetter) {
    if(methods.size() < 2) {
        return methods;
    }
    final LinkedList<T> maximals = new LinkedList<>();
    for(final T m: methods) {
        final MethodType methodType = methodTypeGetter.getMethodType(m);
        boolean lessSpecific = false;
        for(final Iterator<T> maximal = maximals.iterator(); maximal.hasNext();) {
            final T max = maximal.next();
            switch(isMoreSpecific(methodType, methodTypeGetter.getMethodType(max), varArgs, argTypes, ls)) {
                case TYPE_1_BETTER: {
                    maximal.remove();
                    break;
                }
                case TYPE_2_BETTER: {
                    lessSpecific = true;
                    break;
                }
                case INDETERMINATE: {
                    // do nothing
                    break;
                }
                default: {
                    throw new AssertionError();
                }
            }
        }
        if(!lessSpecific) {
            maximals.addLast(m);
        }
    }
    return maximals;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:MaximallySpecific.java

示例5: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
        throws Exception {
    final LinkRequest ncrequest = request.withoutRuntimeContext();
    // BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
    final CallSiteDescriptor callSiteDescriptor = ncrequest.getCallSiteDescriptor();
    final String op = callSiteDescriptor.getNameToken(CallSiteDescriptor.OPERATOR);
    // Either dyn:callMethod:name(this[,args]) or dyn:callMethod(this,name[,args]).
    if("callMethod" == op) {
        return getCallPropWithThis(callSiteDescriptor, linkerServices);
    }
    List<String> operations = CallSiteDescriptorFactory.tokenizeOperators(callSiteDescriptor);
    while(!operations.isEmpty()) {
        final GuardedInvocationComponent gic = getGuardedInvocationComponent(callSiteDescriptor, linkerServices,
                operations);
        if(gic != null) {
            return gic.getGuardedInvocation();
        }
        operations = pop(operations);
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:AbstractJavaLinker.java

示例6: getGuardedInvocationComponent

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // Either dyn:getProp:name(this) or dyn:getProp(this, name)
    if("getProp".equals(op)) {
        return getPropertyGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:setProp:name(this, value) or dyn:setProp(this, name, value)
    if("setProp".equals(op)) {
        return getPropertySetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:getMethod:name(this), or dyn:getMethod(this, name)
    if("getMethod".equals(op)) {
        return getMethodGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:AbstractJavaLinker.java

示例7: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
        throws Exception {
    final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
    final int l = callSiteDescriptor.getNameTokenCount();
    // All names conforming to the dynalang MOP should have at least two tokens, the first one being "dyn"
    if(l < 2 || "dyn" != callSiteDescriptor.getNameToken(CallSiteDescriptor.SCHEME)) {
        return null;
    }

    final Object receiver = request.getReceiver();
    if(receiver == null) {
        // Can't operate on null
        return null;
    }
    return getLinkerForClass(receiver.getClass()).getGuardedInvocation(request, linkerServices);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:BeansLinker.java

示例8: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
        throws Exception {
    final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices);
    if(gi != null) {
        return gi;
    }
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    final String op = desc.getNameToken(CallSiteDescriptor.OPERATOR);
    if("new" == op && constructor != null) {
        final MethodHandle ctorInvocation = constructor.getInvocation(desc, linkerServices);
        if(ctorInvocation != null) {
            return new GuardedInvocation(ctorInvocation, getClassGuard(desc.getMethodType()));
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:StaticClassLinker.java

示例9: lookup

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
    final int c = desc.getNameTokenCount();
    GuardedInvocation inv;
    try {
        inv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
    } catch (Throwable th) {
        inv = null;
    }

    switch (operator) {
        case "getProp":
        case "getElem":
        case "getMethod":
            return c > 2? findGetMethod(desc, inv) : findGetIndexMethod(inv);
        case "setProp":
        case "setElem":
            return c > 2? findSetMethod(desc, inv) : findSetIndexMethod();
        case "call":
            return findCallMethod(desc);
        default:
            return null;
    }
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:25,代码来源:BrowserJSObjectLinker.java

示例10: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = requestWithoutContext.getReceiver();
    final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();

    if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) {
        // We only support standard "dyn:*[:*]" operations
        return null;
    }

    GuardedInvocation inv;
    if (self instanceof JSObject) {
        inv = lookup(desc, request, linkerServices);
        inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard());
    } else if (self instanceof Map || self instanceof Bindings) {
        // guard to make sure the Map or Bindings does not turn into JSObject later!
        final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
        inv = new GuardedInvocation(beanInv.getInvocation(),
            NashornGuards.combineGuards(beanInv.getGuard(), NashornGuards.getNotJSObjectGuard()));
    } else {
        throw new AssertionError(); // Should never reach here.
    }

    return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:27,代码来源:JSObjectLinker.java

示例11: convert

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
/**
 * Convert the given object to the given type.
 *
 * @param obj object to be converted
 * @param type destination type to convert to
 * @return converted object
 */
public static Object convert(final Object obj, final Object type) {
    if (obj == null) {
        return null;
    }

    final Class<?> clazz;
    if (type instanceof Class) {
        clazz = (Class<?>)type;
    } else if (type instanceof StaticClass) {
        clazz = ((StaticClass)type).getRepresentedClass();
    } else {
        throw new IllegalArgumentException("type expected");
    }

    final LinkerServices linker = Bootstrap.getLinkerServices();
    final Object objToConvert = unwrap(obj);
    final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(),  clazz);
    if (converter == null) {
        // no supported conversion!
        throw new UnsupportedOperationException("conversion not supported");
    }

    try {
        return converter.invoke(objToConvert);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ScriptUtils.java

示例12: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = requestWithoutContext.getReceiver();
    final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();

    if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) {
        // We only support standard "dyn:*[:*]" operations
        return null;
    }

    return Bootstrap.asTypeSafeReturn(getGuardedInvocation(self,  request, desc), linkerServices, desc);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:NashornLinker.java

示例13: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final Method m = getFunctionalInterfaceMethod(self.getClass());
        if (m != null) {
            final MethodType callType = desc.getMethodType();
            // 'callee' and 'thiz' passed from script + actual arguments
            if (callType.parameterCount() != m.getParameterCount() + 2) {
                throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
            }
            return new GuardedInvocation(
                    // drop 'thiz' passed from the script.
                    MH.dropArguments(desc.getLookup().unreflect(m), 1, callType.parameterType(1)),
                    Guards.getInstanceOfGuard(m.getDeclaringClass())).asTypeSafeReturn(
                            new NashornBeansLinkerServices(linkerServices), callType);
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:NashornBeansLinker.java

示例14: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest origRequest, final LinkerServices linkerServices)
        throws Exception {
    final LinkRequest request = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context

    final Object self = request.getReceiver();
    final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor) request.getCallSiteDescriptor();

    return Bootstrap.asTypeSafeReturn(Global.primitiveLookup(request, self), linkerServices, desc);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:NashornPrimitiveLinker.java

示例15: getGuardedInvocation

import jdk.internal.dynalink.linker.LinkerServices; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest origRequest, final LinkerServices linkerServices)
        throws Exception {
    checkLinkRequest(origRequest);
    // let the next linker deal with actual linking
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:ReflectionCheckLinker.java


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