本文整理汇总了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;
}
示例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;
}
示例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)));
}
示例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)));
}