本文整理汇总了Java中java.lang.invoke.MutableCallSite.setTarget方法的典型用法代码示例。如果您正苦于以下问题:Java MutableCallSite.setTarget方法的具体用法?Java MutableCallSite.setTarget怎么用?Java MutableCallSite.setTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MutableCallSite
的用法示例。
在下文中一共展示了MutableCallSite.setTarget方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNonBoundCallSite
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testNonBoundCallSite() throws Throwable {
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
// mcs.context == null
MethodHandle mh = mcs.dynamicInvoker();
execute(1, mh);
// mcs.context == cls1
Class<?> cls1 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("NonBound_1"), null);
MethodHandle mh1 = LOOKUP.findStatic(cls1, METHOD_NAME, TYPE);
execute(1, mh1);
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mh, mh1);
}
示例2: testNonBoundCallSite
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testNonBoundCallSite() throws Throwable {
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
// mcs.context == null
MethodHandle mh = mcs.dynamicInvoker();
execute(1, mh);
// mcs.context == cls1
Class<?> cls1 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("NonBound_1"), null);
MethodHandle mh1 = LOOKUP.findStatic(cls1, METHOD_NAME, TYPE);
execute(1, mh1);
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mh, mh1);
}
示例3: nativeCallSetup
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static MethodHandle nativeCallSetup(MutableCallSite callsite, String name, ExecutionContext cx) {
RuntimeContext context = cx.getRuntimeContext();
MethodHandle target;
try {
MethodHandle mh = context.getNativeCallResolver().apply(name, callsite.type());
if (mh == null) {
throw new IllegalArgumentException();
}
target = adaptNativeMethodHandle(mh);
target = adaptMethodHandle(name, callsite.type(), target);
} catch (IllegalArgumentException e) {
target = invalidCallHandle(name, callsite.type());
}
callsite.setTarget(target);
return target;
}
示例4: setCallSiteTarget
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
private static MethodHandle setCallSiteTarget(MutableCallSite callsite, MethodHandle target, MethodHandle test,
MethodHandle generic) {
MethodHandle callSiteTarget;
if (target != null) {
target = target.asType(callsite.type());
if (test != null) {
MethodHandle fallback = createFallback(callsite, generic);
callSiteTarget = MethodHandles.guardWithTest(test, target, fallback);
} else {
callSiteTarget = target;
}
} else {
callSiteTarget = target = generic;
}
callsite.setTarget(callSiteTarget);
return target;
}
示例5: testSharedCallSite
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testSharedCallSite() throws Throwable {
Class<?> cls1 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("CS_1"), null);
Class<?> cls2 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("CS_2"), null);
MethodHandle[] mhs = new MethodHandle[] {
LOOKUP.findStatic(cls1, METHOD_NAME, TYPE),
LOOKUP.findStatic(cls2, METHOD_NAME, TYPE)
};
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
execute(1, mhs);
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mhs);
}
示例6: testSharedCallSite
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testSharedCallSite() throws Throwable {
Class<?> cls1 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("CS_1"), null);
Class<?> cls2 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("CS_2"), null);
MethodHandle[] mhs = new MethodHandle[] {
LOOKUP.findStatic(cls1, METHOD_NAME, TYPE),
LOOKUP.findStatic(cls2, METHOD_NAME, TYPE)
};
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
execute(1, mhs);
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mhs);
}
示例7: realBootstrap
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
/**
* backing bootstrap method with all parameters
*/
private static CallSite realBootstrap(Lookup caller, String name, int callID, MethodType type, boolean safe, boolean thisCall, boolean spreadCall) {
// since indy does not give us the runtime types
// we produce first a dummy call site, which then changes the target to one,
// that does the method selection including the the direct call to the
// real method.
MutableCallSite mc = new MutableCallSite(type);
MethodHandle mh = makeFallBack(mc,caller.lookupClass(),name,callID,type,safe,thisCall,spreadCall);
mc.setTarget(mh);
return mc;
}
示例8: setValue
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void setValue(String name, LilaObject value) {
// update value
ENV.put(name, value);
// update call sites
List<MutableCallSite> callSites = valueCallSites.get(name);
if (callSites != null) {
// create new method handle for updated value
MethodHandle methodHandle = createValueMethodHandle(name);
// update all call sites using this value
for (MutableCallSite callSite : callSites)
callSite.setTarget(methodHandle);
MutableCallSite.syncAll(callSites.toArray(new MutableCallSite[]{}));
}
}
示例9: testGC
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testGC(boolean clear, boolean precompile) throws Throwable {
String id = "_" + clear + "_" + precompile;
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
Class<?>[] cls = new Class[] {
UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("GC_1" + id), null),
UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("GC_2" + id), null),
};
MethodHandle[] mhs = new MethodHandle[] {
LOOKUP.findStatic(cls[0], METHOD_NAME, TYPE),
LOOKUP.findStatic(cls[1], METHOD_NAME, TYPE),
};
// mcs.context == cls[0]
int r = (int) mhs[0].invokeExact();
execute(1, mhs);
ref = new PhantomReference<>(cls[0], rq);
cls[0] = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("GC_3" + id), null);
mhs[0] = LOOKUP.findStatic(cls[0], METHOD_NAME, TYPE);
do {
System.gc();
try {
Reference ref1 = rq.remove(100);
if (ref1 == ref) {
break;
}
} catch(InterruptedException e) { /* ignore */ }
} while (true);
if (clear) {
ref.clear();
System.gc(); // Ensure that the stale context is unloaded
}
if (precompile) {
execute(1, mhs);
}
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mhs);
}
示例10: testGC
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
public static void testGC(boolean clear, boolean precompile) throws Throwable {
String id = "_" + clear + "_" + precompile;
mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
Class<?>[] cls = new Class[] {
UNSAFE.defineAnonymousClass(Object.class, getClassFile("GC_1" + id), null),
UNSAFE.defineAnonymousClass(Object.class, getClassFile("GC_2" + id), null),
};
MethodHandle[] mhs = new MethodHandle[] {
LOOKUP.findStatic(cls[0], METHOD_NAME, TYPE),
LOOKUP.findStatic(cls[1], METHOD_NAME, TYPE),
};
// mcs.context == cls[0]
int r = (int) mhs[0].invokeExact();
execute(1, mhs);
ref = new PhantomReference<>(cls[0], rq);
cls[0] = UNSAFE.defineAnonymousClass(Object.class, getClassFile("GC_3" + id), null);
mhs[0] = LOOKUP.findStatic(cls[0], METHOD_NAME, TYPE);
do {
System.gc();
try {
Reference ref1 = rq.remove(100);
if (ref1 == ref) {
break;
}
} catch(InterruptedException e) { /* ignore */ }
} while (true);
if (clear) {
ref.clear();
System.gc(); // Ensure that the stale context is unloaded
}
if (precompile) {
execute(1, mhs);
}
mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
execute(2, mhs);
}
示例11: createRuntimeCallSite
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
private static MutableCallSite createRuntimeCallSite(String name, MethodType type) {
MutableCallSite callsite = new MutableCallSite(type);
MethodHandle target = MethodHandles.insertArguments(nativeCallSetupMH, 0, callsite, name);
callsite.setTarget(MethodHandles.foldArguments(MethodHandles.exactInvoker(type), target));
return callsite;
}
示例12: switchToGeneric
import java.lang.invoke.MutableCallSite; //导入方法依赖的package包/类
private static MethodHandle switchToGeneric(MutableCallSite callsite, MethodHandle generic) {
callsite.setTarget(generic);
return generic;
}