Search in sources :

Example 1 with DynamicCallSiteDesc

use of java.lang.constant.DynamicCallSiteDesc in project openj9 by eclipse.

the class Test_DynamicCallSiteDesc method testDynamicCallSiteDescResolveCallSiteDesc.

/*
	 * Test Java 12 API DynamicCallSiteDesc.resolveCallSiteDesc()
	 */
@Test(groups = { "level.sanity" })
public void testDynamicCallSiteDescResolveCallSiteDesc() throws Throwable {
    /* setup */
    ClassDesc bsmOwnerDesc = Test_DynamicCallSiteDesc.class.describeConstable().orElseThrow();
    ClassDesc bsmRetTypeDesc = ConstantCallSite.class.describeConstable().orElseThrow();
    MethodTypeDesc handleType = MethodType.methodType(void.class).describeConstable().orElseThrow();
    /* describe and resolve callsite */
    DirectMethodHandleDesc bsm = ConstantDescs.ofCallsiteBootstrap(bsmOwnerDesc, "bsm", bsmRetTypeDesc);
    DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(bsm, fieldName, handleType);
    CallSite resolvedSite = desc.resolveCallSiteDesc(MethodHandles.lookup());
    /* verify that the callsite contains the expected MethodHandle */
    logger.debug("testDynamicCallSiteDescResolveCallSiteDesc: resolved CallSite type is: " + resolvedSite.type().toMethodDescriptorString());
    Assert.assertTrue(fieldName.equals((String) resolvedSite.getTarget().invokeExact()));
}
Also used : DirectMethodHandleDesc(java.lang.constant.DirectMethodHandleDesc) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodTypeDesc(java.lang.constant.MethodTypeDesc) CallSite(java.lang.invoke.CallSite) ConstantCallSite(java.lang.invoke.ConstantCallSite) ClassDesc(java.lang.constant.ClassDesc) DynamicCallSiteDesc(java.lang.constant.DynamicCallSiteDesc) Test(org.testng.annotations.Test)

Aggregations

ClassDesc (java.lang.constant.ClassDesc)1 DirectMethodHandleDesc (java.lang.constant.DirectMethodHandleDesc)1 DynamicCallSiteDesc (java.lang.constant.DynamicCallSiteDesc)1 MethodTypeDesc (java.lang.constant.MethodTypeDesc)1 CallSite (java.lang.invoke.CallSite)1 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 Test (org.testng.annotations.Test)1