本文整理汇总了Java中java.lang.invoke.SwitchPoint.guardWithTest方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPoint.guardWithTest方法的具体用法?Java SwitchPoint.guardWithTest怎么用?Java SwitchPoint.guardWithTest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.SwitchPoint
的用法示例。
在下文中一共展示了SwitchPoint.guardWithTest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: relinkComposableInvoker
import java.lang.invoke.SwitchPoint; //导入方法依赖的package包/类
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) {
final HandleAndAssumptions handleAndAssumptions = inv.getValidOptimisticInvocation(new Supplier<MethodHandle>() {
@Override
public MethodHandle get() {
return inv.getInvokerOrConstructor(constructor);
}
});
final MethodHandle handle = handleAndAssumptions.handle;
final SwitchPoint assumptions = handleAndAssumptions.assumptions;
final MethodHandle target;
if(assumptions == null) {
target = handle;
} else {
final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor);
target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink));
}
cs.setTarget(target.asType(cs.type()));
}
示例2: compose
import java.lang.invoke.SwitchPoint; //导入方法依赖的package包/类
/**
* Composes the invocation, switchpoint, and the guard into a composite method handle that knows how to fall back.
* @param switchpointFallback the fallback method handle in case switchpoint is invalidated.
* @param guardFallback the fallback method handle in case guard returns false.
* @param catchFallback the fallback method in case the exception handler triggers
* @return a composite method handle.
*/
public MethodHandle compose(final MethodHandle guardFallback, final MethodHandle switchpointFallback, final MethodHandle catchFallback) {
final MethodHandle guarded =
guard == null ?
invocation :
MethodHandles.guardWithTest(
guard,
invocation,
guardFallback);
final MethodHandle catchGuarded =
exception == null ?
guarded :
MH.catchException(
guarded,
exception,
MethodHandles.dropArguments(
catchFallback,
0,
exception));
if (switchPoints == null) {
return catchGuarded;
}
MethodHandle spGuarded = catchGuarded;
for (final SwitchPoint sp : switchPoints) {
spGuarded = sp.guardWithTest(spGuarded, switchpointFallback);
}
return spGuarded;
}
示例3: compose
import java.lang.invoke.SwitchPoint; //导入方法依赖的package包/类
/**
* Composes the invocation, guard, switch points, and the exception into a
* composite method handle that knows how to fall back when the guard fails
* or the invocation is invalidated.
* @param switchpointFallback the fallback method handle in case a switch
* point is invalidated.
* @param guardFallback the fallback method handle in case guard returns
* false.
* @param catchFallback the fallback method in case the exception handler
* triggers.
* @return a composite method handle.
*/
public MethodHandle compose(final MethodHandle guardFallback, final MethodHandle switchpointFallback, final MethodHandle catchFallback) {
final MethodHandle guarded =
guard == null ?
invocation :
MethodHandles.guardWithTest(
guard,
invocation,
guardFallback);
final MethodHandle catchGuarded =
exception == null ?
guarded :
MethodHandles.catchException(
guarded,
exception,
MethodHandles.dropArguments(
catchFallback,
0,
exception));
if (switchPoints == null) {
return catchGuarded;
}
MethodHandle spGuarded = catchGuarded;
for (final SwitchPoint sp : switchPoints) {
spGuarded = sp.guardWithTest(spGuarded, switchpointFallback);
}
return spGuarded;
}
示例4: guardWithTest
import java.lang.invoke.SwitchPoint; //导入方法依赖的package包/类
@Override
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {
final MethodHandle mh = sp.guardWithTest(before, after);
return debug(mh, "guardWithTest", sp, before, after);
}