Search in sources :

Example 21 with ConstantCallSite

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

Example 22 with ConstantCallSite

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

Example 23 with ConstantCallSite

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

Example 24 with ConstantCallSite

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

Example 25 with ConstantCallSite

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);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) ConstantCallSite(java.lang.invoke.ConstantCallSite) NonNull(dyvil.annotation.internal.NonNull)

Aggregations

ConstantCallSite (java.lang.invoke.ConstantCallSite)28 MethodHandle (java.lang.invoke.MethodHandle)25 Test (org.testng.annotations.Test)9 MethodType (java.lang.invoke.MethodType)5 MethodHandles (java.lang.invoke.MethodHandles)4 Lookup (java.lang.invoke.MethodHandles.Lookup)3 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)2 Constructor (java.lang.reflect.Constructor)2 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 BytecodeExpressions.constantString (com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString)1 CompiledObject (com.github.anba.es6draft.compiler.CompiledObject)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 GeneratorObject (com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject)1 HTMLDDAObject (com.github.anba.es6draft.runtime.types.HTMLDDAObject)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 StringObject (com.github.anba.es6draft.runtime.types.builtins.StringObject)1 CrossPackageHelper (differentpackage.CrossPackageHelper)1 NonNull (dyvil.annotation.internal.NonNull)1 MutableCallSite (java.lang.invoke.MutableCallSite)1