本文整理汇总了Java中jdk.internal.dynalink.linker.GuardedInvocation.getGuard方法的典型用法代码示例。如果您正苦于以下问题:Java GuardedInvocation.getGuard方法的具体用法?Java GuardedInvocation.getGuard怎么用?Java GuardedInvocation.getGuard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.dynalink.linker.GuardedInvocation
的用法示例。
在下文中一共展示了GuardedInvocation.getGuard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterGuardReceiver
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
final MethodHandle test = link.getGuard();
if (test == null) {
return null;
}
final Class<?> receiverType = test.type().parameterType(0);
final MethodHandle filter = MH.asType(receiverFilter,
receiverFilter.type().changeParameterType(0, receiverType).
changeReturnType(receiverType));
return filterReceiver(test, filter);
}
示例2: 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();
}