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


Java Guards.getIdentityGuard方法代码示例

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


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

示例1: getGuardedInvocation

import jdk.internal.dynalink.support.Guards; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) {
    final Object receiver = linkRequest.getReceiver();
    if(!(receiver instanceof DynamicMethod)) {
        return null;
    }
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") {
        return null;
    }
    final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR);
    if(operator == "call") {
        final MethodHandle invocation = ((DynamicMethod)receiver).getInvocation(
                CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices);
        if(invocation == null) {
            return null;
        }
        return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0,
                desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver));
    }
    return null;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:23,代码来源:DynamicMethodLinker.java

示例2: getGuardedInvocation

import jdk.internal.dynalink.support.Guards; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) {
    final Object receiver = linkRequest.getReceiver();
    if(!(receiver instanceof DynamicMethod)) {
        return null;
    }
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") {
        return null;
    }
    final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR);
    final DynamicMethod dynMethod = (DynamicMethod)receiver;
    final boolean constructor = dynMethod.isConstructor();
    final MethodHandle invocation;

    if (operator == "call" && !constructor) {
        invocation = dynMethod.getInvocation(
                CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices);
    } else if (operator == "new" && constructor) {
        final MethodHandle ctorInvocation = dynMethod.getInvocation(desc, linkerServices);
        if(ctorInvocation == null) {
            return null;
        }

        // Insert null for StaticClass parameter
        invocation = MethodHandles.insertArguments(ctorInvocation, 0, (Object)null);
    } else {
        return null;
    }

    if (invocation != null) {
        return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0,
            desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver));
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:DynamicMethodLinker.java

示例3: getGuardedInvocation

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

    final BoundDynamicMethod boundDynamicMethod = (BoundDynamicMethod)objBoundDynamicMethod;
    final Object dynamicMethod = boundDynamicMethod.getDynamicMethod();
    final Object boundThis = boundDynamicMethod.getBoundThis();

    // Replace arguments (boundDynamicMethod, this, ...) => (dynamicMethod, boundThis, ...) when delegating to
    // BeansLinker
    final Object[] args = linkRequest.getArguments();
    args[0] = dynamicMethod;
    args[1] = boundThis;

    // Use R(T0, T1, ...) => R(dynamicMethod.class, boundThis.class, ...) call site type when delegating to
    // BeansLinker.
    final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
    final MethodType type = descriptor.getMethodType();
    final Class<?> dynamicMethodClass = dynamicMethod.getClass();
    final CallSiteDescriptor newDescriptor = descriptor.changeMethodType(
            type.changeParameterType(0, dynamicMethodClass).changeParameterType(1, boundThis.getClass()));

    // Delegate to BeansLinker
    final GuardedInvocation inv = NashornBeansLinker.getGuardedInvocation(BeansLinker.getLinkerForClass(dynamicMethodClass),
            linkRequest.replaceArguments(newDescriptor, args), linkerServices);
    if(inv == null) {
        return null;
    }

    // Bind (dynamicMethod, boundThis) to the handle
    final MethodHandle boundHandle = MethodHandles.insertArguments(inv.getInvocation(), 0, dynamicMethod, boundThis);
    final Class<?> p0Type = type.parameterType(0);
    // Ignore incoming (boundDynamicMethod, this)
    final MethodHandle droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type, type.parameterType(1));
    // Identity guard on boundDynamicMethod object
    final MethodHandle newGuard = Guards.getIdentityGuard(boundDynamicMethod);

    return inv.replaceMethods(droppingHandle, newGuard.asType(newGuard.type().changeParameterType(0, p0Type)));
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:43,代码来源:BoundDynamicMethodLinker.java

示例4: getGuardedInvocation

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

    final BoundDynamicMethod boundDynamicMethod = (BoundDynamicMethod)objBoundDynamicMethod;
    final Object dynamicMethod = boundDynamicMethod.getDynamicMethod();
    final Object boundThis = boundDynamicMethod.getBoundThis();

    // Replace arguments (boundDynamicMethod, this, ...) => (dynamicMethod, boundThis, ...) when delegating to
    // BeansLinker
    final Object[] args = linkRequest.getArguments();
    args[0] = dynamicMethod;
    args[1] = boundThis;

    // Use R(T0, T1, ...) => R(dynamicMethod.class, boundThis.class, ...) call site type when delegating to
    // BeansLinker.
    final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
    final MethodType type = descriptor.getMethodType();
    final Class<?> dynamicMethodClass = dynamicMethod.getClass();
    final CallSiteDescriptor newDescriptor = descriptor.changeMethodType(
            type.changeParameterType(0, dynamicMethodClass).changeParameterType(1, boundThis.getClass()));

    // Delegate to BeansLinker
    final GuardedInvocation inv = BeansLinker.getLinkerForClass(dynamicMethodClass).getGuardedInvocation(
            linkRequest.replaceArguments(newDescriptor, args), linkerServices);
    if(inv == null) {
        return null;
    }

    // Bind (dynamicMethod, boundThis) to the handle
    final MethodHandle boundHandle = MethodHandles.insertArguments(inv.getInvocation(), 0, dynamicMethod, boundThis);
    final Class<?> p0Type = type.parameterType(0);
    // Ignore incoming (boundDynamicMethod, this)
    final MethodHandle droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type, type.parameterType(1));
    // Identity guard on boundDynamicMethod object
    final MethodHandle newGuard = Guards.getIdentityGuard(boundDynamicMethod);

    return inv.replaceMethods(droppingHandle, newGuard.asType(newGuard.type().changeParameterType(0, p0Type)));
}
 
开发者ID:wro4j,项目名称:nashorn-backport,代码行数:43,代码来源:BoundDynamicMethodLinker.java


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