use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class BootstrapMethods method bootstrap_filter_arguments_on_drop_arguments.
// Bootstrap method for invokedynamic test where the target MH is a filterArguments() on a dropArguments()
// adapter such that the filters can be discarded once the they have all been inlined.
public static CallSite bootstrap_filter_arguments_on_drop_arguments(Lookup lookup, String name, MethodType type) throws Throwable {
MethodHandle repFirst = MethodHandles.lookup().findVirtual(String.class, "replaceFirst", methodType(String.class, String.class, String.class));
MethodHandle mh0 = MethodHandles.dropArguments(repFirst, 1, Arrays.asList(new Class<?>[] { String.class }));
MethodHandle upcase = MethodHandles.lookup().findVirtual(String.class, "toUpperCase", methodType(String.class));
MethodHandle f0 = MethodHandles.filterArguments(mh0, 0, upcase);
return new ConstantCallSite(f0);
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class BootstrapMethods method bootstrap_filter_return.
// Bootstrap method for filterReturn MH test
public static CallSite bootstrap_filter_return(Lookup lookup, String name, MethodType type) throws Throwable {
MethodHandle handle = MethodHandles.lookup().findStatic(Helper.class, "addStaticPublic", methodType(void.class, int.class, String.class));
MethodHandle filter = MethodHandles.constant(int.class, 0);
MethodHandle filtered = MethodHandles.filterReturnValue(handle, filter);
return new ConstantCallSite(filtered);
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class BootstrapMethods method bootstrapConcatStrings.
public static CallSite bootstrapConcatStrings(Lookup caller, String name, MethodType type) throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
Class<?> thisClass = lookup.lookupClass();
MethodHandle concatStrings = lookup.findStatic(thisClass, "concatStrings", type);
return new ConstantCallSite(concatStrings);
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class InvokeDynamicTestGenerator method bootstrapAddInts.
/* Bootstrap method used by invokedynamic bytecode in the generated class file */
public static CallSite bootstrapAddInts(Lookup caller, String name, MethodType type) throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
Class<?> thisClass = lookup.lookupClass();
MethodHandle addIntegers = lookup.findStatic(thisClass, "addIntegers", type);
return new ConstantCallSite(addIntegers);
}
use of java.lang.invoke.ConstantCallSite in project Dyvil by Dyvil.
the class AnnotationProxyFactory method buildCallSite.
@NonNull
public CallSite buildCallSite() throws Exception {
final Class<?> innerClass = this.spinInnerClass();
if (this.parameterCount == 0) {
final Constructor[] ctrs = innerClass.getDeclaredConstructors();
if (ctrs.length != 1) {
final String message = "Expected one annotation constructor for " + innerClass.getCanonicalName() + ", got " + ctrs.length;
throw new Exception(message);
}
try {
final Constructor ctr = ctrs[0];
ctr.setAccessible(true);
final Object inst = ctr.newInstance();
return new ConstantCallSite(MethodHandles.constant(this.annotationType, inst));
} catch (ReflectiveOperationException e) {
throw new Exception("Exception instantiating annotation proxy", e);
}
}
try {
UNSAFE.ensureClassInitialized(innerClass);
return new ConstantCallSite(LOOKUP.findStatic(innerClass, NAME_FACTORY, this.invokedType));
} catch (ReflectiveOperationException e) {
throw new Exception("Exception finding constructor", e);
}
}
Aggregations