Search in sources :

Example 1 with MutableCallSite

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");
        }
    }
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) SwitchPoint(java.lang.invoke.SwitchPoint) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 2 with MutableCallSite

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);
}
Also used : MethodType(java.lang.invoke.MethodType) MutableCallSite(java.lang.invoke.MutableCallSite) Test(org.testng.annotations.Test)

Example 3 with MutableCallSite

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);
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Example 4 with MutableCallSite

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);
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with MutableCallSite

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);
}
Also used : SwitchPoint(java.lang.invoke.SwitchPoint) MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MutableCallSite (java.lang.invoke.MutableCallSite)17 MethodHandle (java.lang.invoke.MethodHandle)15 Lookup (java.lang.invoke.MethodHandles.Lookup)7 Test (org.testng.annotations.Test)7 MethodType (java.lang.invoke.MethodType)4 SwitchPoint (java.lang.invoke.SwitchPoint)3 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)1