use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class JSR292_MultiThreadedTests method testSyncAll_WithoutJoin.
/**
* Tests visibility of a MutableCallSite update made in the main thread in a separate worker thread after syncAll is performed.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testSyncAll_WithoutJoin() throws Throwable {
MethodHandle K_false = MethodHandles.constant(boolean.class, false);
MethodHandle K_true = MethodHandles.constant(boolean.class, true);
// Run the following code twice so that we provide hints to the JIT to compile the target method.
for (int i = 0; i < 2; i++) {
MutableCallSite mutableCS = new MutableCallSite(K_false);
WorkerThread2_CS workerThread = new WorkerThread2_CS(mutableCS);
workerThread.start();
while (!workerThread.isStarted) {
Thread.sleep(10);
}
mutableCS.setTarget(K_true);
MutableCallSite.syncAll(new MutableCallSite[] { mutableCS });
synchronized (workerThread) {
if (!workerThread.volatileUpdateSeen()) {
workerThread.wait(30000);
}
}
if (!workerThread.volatileUpdateSeen()) {
Assert.fail("ERROR: testSyncAll_WithoutJoin: volatile update made by main thread not visible in worker thread");
}
}
}
use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class MutableCallSiteTest method testIllegalState_getTarget_MutableCallSite.
/**
* Test for validating default MethodHandle behavior of MutableCallSite
* using MutableCallSite.getTarget().invoke()
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testIllegalState_getTarget_MutableCallSite() throws Throwable {
MethodType mt = MethodType.methodType(void.class);
MutableCallSite mcs = new MutableCallSite(mt);
boolean iseHit = false;
try {
mcs.getTarget().invoke();
} catch (IllegalStateException e) {
iseHit = true;
}
AssertJUnit.assertTrue(iseHit);
}
use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class BootstrapMethods method permuteBootstrap.
// (int, int, String) --> (String, int, int) --> (String)
public static CallSite permuteBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle object_toString = lookup.findVirtual(Object.class, "toString", methodType(String.class));
MethodHandle drop = dropArguments(object_toString, 1, int.class, int.class);
MethodHandle permute = permuteArguments(drop, methodType(String.class, int.class, int.class, Object.class), new int[] { 2, 0, 1 });
return new MutableCallSite(permute);
}
use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class BootstrapMethods method fibBootstrap.
public static CallSite fibBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle fib = lookup.findStatic(Class.forName("com.ibm.j9.jsr292.indyn.ComplexIndy"), "fibIndy", methodType(int.class, int.class));
return new MutableCallSite(fib);
}
use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class BootstrapMethods method switchpointBootstrap.
public static CallSite switchpointBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle add = lookup.findStatic(BootstrapMethods.class, "add", methodType(int.class, int.class, int.class));
MethodHandle fallback = lookup.findStatic(BootstrapMethods.class, "throwRuntimeException", methodType(int.class, int.class, int.class));
MethodHandle handle = new SwitchPoint().guardWithTest(add, fallback);
return new MutableCallSite(handle);
}
Aggregations