use of java.lang.invoke.VarHandle.VarHandleDesc in project openj9 by eclipse.
the class Test_VarHandle method describeConstableTestGeneral.
private void describeConstableTestGeneral(String testName, VarHandle handle) throws Throwable {
VarHandleDesc desc = handle.describeConstable().orElseThrow();
/*
* verify that descriptor can be resolved. Otherwise will throw
* ReflectiveOperationException
*/
VarHandle resolvedHandle = (VarHandle) desc.resolveConstantDesc(MethodHandles.lookup());
logger.debug(testName + ": Descriptor of original class varType is: " + handle.varType().descriptorString());
logger.debug(testName + ": Descriptor of VarHandleDesc varType is: " + resolvedHandle.varType().descriptorString());
Assert.assertTrue(handle.varType().equals(resolvedHandle.varType()));
Assert.assertTrue(handle.coordinateTypes().equals(resolvedHandle.coordinateTypes()));
}
use of java.lang.invoke.VarHandle.VarHandleDesc in project openj9 by eclipse.
the class Test_VarHandleDesc method toStringTestGeneral.
/* generic test for toString() */
private void toStringTestGeneral(String testName, int test_type, VarHandle handle) {
Optional<ClassDesc> descOptional = null;
if (test_type == Jep334MHHelperImpl.array_test) {
descOptional = handle.varType().arrayType().describeConstable();
} else {
descOptional = handle.varType().describeConstable();
}
if (!descOptional.isPresent()) {
Assert.fail(testName + ": error with tests ClassDesc could not be generated.");
return;
}
ClassDesc desc = descOptional.get();
VarHandleDesc varDesc = null;
String resultString = null;
switch(test_type) {
case Jep334MHHelperImpl.array_test:
varDesc = VarHandleDesc.ofArray(desc);
resultString = "VarHandleDesc[" + desc.displayName() + "[]]";
break;
case Jep334MHHelperImpl.instance_test:
varDesc = VarHandleDesc.ofField(declaringClassDesc, desc.displayName(), desc);
resultString = "VarHandleDesc[" + declaringClassDesc.displayName() + "." + varDesc.constantName() + ":" + varDesc.varType().displayName() + "]";
break;
case Jep334MHHelperImpl.static_test:
varDesc = VarHandleDesc.ofStaticField(declaringClassDesc, desc.displayName(), desc);
resultString = "VarHandleDesc[static " + declaringClassDesc.displayName() + "." + varDesc.constantName() + ":" + varDesc.varType().displayName() + "]";
break;
default:
Assert.fail(testName + ": unsupported test type.");
}
String outputString = varDesc.toString();
logger.debug(testName + ": toString output is: " + outputString + " and should be: " + resultString);
Assert.assertTrue(outputString.equals(resultString));
}
use of java.lang.invoke.VarHandle.VarHandleDesc in project openj9 by eclipse.
the class Test_VarHandleDesc method resolveConstantDescTestGeneric.
private void resolveConstantDescTestGeneric(String testName, VarHandle handle) throws Throwable {
VarHandleDesc handleDesc = handle.describeConstable().orElseThrow();
VarHandle resolvedHandle = handleDesc.resolveConstantDesc(MethodHandles.lookup());
logger.debug(testName + " is running.");
Assert.assertTrue(handle.varType().equals(resolvedHandle.varType()));
Assert.assertTrue(handle.coordinateTypes().equals(resolvedHandle.coordinateTypes()));
}
use of java.lang.invoke.VarHandle.VarHandleDesc in project openj9 by eclipse.
the class Test_VarHandleDesc method ofTestGeneral.
/* generic test for ofStaticField, ofField and ofArray */
private void ofTestGeneral(String testName, int test_type, VarHandle handle) {
/* setup */
Optional<ClassDesc> descOptional = null;
if (test_type == Jep334MHHelperImpl.array_test) {
descOptional = handle.varType().arrayType().describeConstable();
} else {
descOptional = handle.varType().describeConstable();
}
if (!descOptional.isPresent()) {
Assert.fail(testName + ": error with tests ClassDesc could not be generated.");
return;
}
ClassDesc desc = descOptional.get();
/* call test method ofArray */
VarHandleDesc varDesc = null;
String originalDescriptor = null;
switch(test_type) {
case Jep334MHHelperImpl.array_test:
varDesc = VarHandleDesc.ofArray(desc);
originalDescriptor = desc.componentType().descriptorString();
break;
case Jep334MHHelperImpl.instance_test:
varDesc = VarHandleDesc.ofField(declaringClassDesc, desc.displayName(), desc);
originalDescriptor = desc.descriptorString();
break;
case Jep334MHHelperImpl.static_test:
varDesc = VarHandleDesc.ofStaticField(declaringClassDesc, desc.displayName(), desc);
originalDescriptor = desc.descriptorString();
break;
default:
Assert.fail(testName + ": unsupported test type.");
}
/* verify that the array class is properly described */
String newDescriptor = varDesc.varType().descriptorString();
logger.debug(testName + ": Descriptor of original class is: " + originalDescriptor + " descriptor of VarHandleDesc is: " + newDescriptor);
Assert.assertTrue(originalDescriptor.equals(newDescriptor));
}
Aggregations