本文整理汇总了Java中java.lang.invoke.VolatileCallSite类的典型用法代码示例。如果您正苦于以下问题:Java VolatileCallSite类的具体用法?Java VolatileCallSite怎么用?Java VolatileCallSite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VolatileCallSite类属于java.lang.invoke包,在下文中一共展示了VolatileCallSite类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerCallSitePlugins
import java.lang.invoke.VolatileCallSite; //导入依赖的package包/类
private static void registerCallSitePlugins(InvocationPlugins plugins) {
InvocationPlugin plugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ValueNode callSite = receiver.get();
ValueNode folded = CallSiteTargetNode.tryFold(GraphUtil.originalValue(callSite), b.getMetaAccess(), b.getAssumptions());
if (folded != null) {
b.addPush(JavaKind.Object, folded);
} else {
b.addPush(JavaKind.Object, new CallSiteTargetNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), callSite));
}
return true;
}
@Override
public boolean inlineOnly() {
return true;
}
};
plugins.register(plugin, ConstantCallSite.class, "getTarget", Receiver.class);
plugins.register(plugin, MutableCallSite.class, "getTarget", Receiver.class);
plugins.register(plugin, VolatileCallSite.class, "getTarget", Receiver.class);
}
示例2: main
import java.lang.invoke.VolatileCallSite; //导入依赖的package包/类
public static void main(String[] args) throws ReflectiveOperationException {
// Objects
test(new Object());
test("TEST");
test(new VMAnonymousClasses());
test(null);
// Class
test(String.class);
// Arrays
test(new boolean[0]);
test(new byte[0]);
test(new char[0]);
test(new short[0]);
test(new int[0]);
test(new long[0]);
test(new float[0]);
test(new double[0]);
test(new Object[0]);
// Multi-dimensional arrays
test(new byte[0][0]);
test(new Object[0][0]);
// MethodHandle-related
MethodType mt = MethodType.methodType(void.class, String[].class);
MethodHandle mh = MethodHandles.lookup().findStatic(VMAnonymousClasses.class, "main", mt);
test(mt);
test(mh);
test(new ConstantCallSite(mh));
test(new MutableCallSite(MethodType.methodType(void.class)));
test(new VolatileCallSite(MethodType.methodType(void.class)));
System.out.println("TEST PASSED");
}