Search in sources :

Example 31 with Type

use of org.objectweb.asm.Type in project robolectric by robolectric.

the class SandboxClassLoader method box.

public static void box(final Type type, ListIterator<AbstractInsnNode> instructions) {
    if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
        return;
    }
    if (type == Type.VOID_TYPE) {
        instructions.add(new InsnNode(ACONST_NULL));
    } else {
        Type boxed = getBoxedType(type);
        instructions.add(new TypeInsnNode(NEW, boxed.getInternalName()));
        if (type.getSize() == 2) {
            // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o
            instructions.add(new InsnNode(DUP_X2));
            instructions.add(new InsnNode(DUP_X2));
            instructions.add(new InsnNode(POP));
        } else {
            // p -> po -> opo -> oop -> o
            instructions.add(new InsnNode(DUP_X1));
            instructions.add(new InsnNode(SWAP));
        }
        instructions.add(new MethodInsnNode(INVOKESPECIAL, boxed.getInternalName(), "<init>", "(" + type.getDescriptor() + ")V"));
    }
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InvokeDynamicInsnNode(org.objectweb.asm.tree.InvokeDynamicInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodType.methodType(java.lang.invoke.MethodType.methodType) MethodType(java.lang.invoke.MethodType) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode)

Example 32 with Type

use of org.objectweb.asm.Type in project elasticsearch by elastic.

the class EFunctionRef method write.

@Override
void write(MethodWriter writer, Globals globals) {
    if (ref != null) {
        writer.writeDebugInfo(location);
        // convert MethodTypes to asm Type for the constant pool.
        String invokedType = ref.invokedType.toMethodDescriptorString();
        Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString());
        Type interfaceType = Type.getMethodType(ref.interfaceMethodType.toMethodDescriptorString());
        if (ref.needsBridges()) {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType, ref.implMethodASM, samMethodType, LambdaMetafactory.FLAG_BRIDGES, 1, interfaceType);
        } else {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType, ref.implMethodASM, samMethodType, 0);
        }
    } else {
        // TODO: don't do this: its just to cutover :)
        writer.push((String) null);
    }
}
Also used : Type(org.objectweb.asm.Type)

Example 33 with Type

use of org.objectweb.asm.Type in project elasticsearch by elastic.

the class PSubDefCall method write.

@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeDebugInfo(location);
    List<Type> parameterTypes = new ArrayList<>();
    // first parameter is the receiver, we never know its type: always Object
    parameterTypes.add(Definition.DEF_TYPE.type);
    // append each argument
    for (AExpression argument : arguments) {
        parameterTypes.add(argument.actual.type);
        if (argument instanceof ILambda) {
            ILambda lambda = (ILambda) argument;
            for (Type capture : lambda.getCaptures()) {
                parameterTypes.add(capture);
            }
        }
        argument.write(writer, globals);
    }
    // create method type from return value and arguments
    Type methodType = Type.getMethodType(actual.type, parameterTypes.toArray(new Type[0]));
    List<Object> args = new ArrayList<>();
    args.add(recipe.toString());
    args.addAll(pointers);
    writer.invokeDefCall(name, methodType, DefBootstrap.METHOD_CALL, args.toArray());
}
Also used : Type(org.objectweb.asm.Type) ArrayList(java.util.ArrayList)

Example 34 with Type

use of org.objectweb.asm.Type in project cglib by cglib.

the class EmitUtils method process_arrays.

/**
     * Process two arrays on the stack in parallel. Assumes the top two items on the stack
     * are arrays of the specified class. The arrays must be the same length. For each pair
     * of elements in the arrays, puts the pair on the stack and triggers the callback.
     * @param type the type of the arrays (type.isArray() must be true)
     * @param callback the callback triggered for each pair of elements
     */
public static void process_arrays(CodeEmitter e, Type type, ProcessArrayCallback callback) {
    Type componentType = TypeUtils.getComponentType(type);
    Local array1 = e.make_local();
    Local array2 = e.make_local();
    Local loopvar = e.make_local(Type.INT_TYPE);
    Label loopbody = e.make_label();
    Label checkloop = e.make_label();
    e.store_local(array1);
    e.store_local(array2);
    e.push(0);
    e.store_local(loopvar);
    e.goTo(checkloop);
    e.mark(loopbody);
    e.load_local(array1);
    e.load_local(loopvar);
    e.array_load(componentType);
    e.load_local(array2);
    e.load_local(loopvar);
    e.array_load(componentType);
    callback.processElement(componentType);
    e.iinc(loopvar, 1);
    e.mark(checkloop);
    e.load_local(loopvar);
    e.load_local(array1);
    e.arraylength();
    e.if_icmp(e.LT, loopbody);
}
Also used : Type(org.objectweb.asm.Type) Label(org.objectweb.asm.Label)

Example 35 with Type

use of org.objectweb.asm.Type in project cglib by cglib.

the class ReflectUtils method getClassInfo.

public static ClassInfo getClassInfo(final Class clazz) {
    final Type type = Type.getType(clazz);
    final Type sc = (clazz.getSuperclass() == null) ? null : Type.getType(clazz.getSuperclass());
    return new ClassInfo() {

        public Type getType() {
            return type;
        }

        public Type getSuperType() {
            return sc;
        }

        public Type[] getInterfaces() {
            return TypeUtils.getTypes(clazz.getInterfaces());
        }

        public int getModifiers() {
            return clazz.getModifiers();
        }
    };
}
Also used : Type(org.objectweb.asm.Type)

Aggregations

Type (org.objectweb.asm.Type)185 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)39 MethodVisitor (org.objectweb.asm.MethodVisitor)34 Method (org.objectweb.asm.commons.Method)28 Label (org.objectweb.asm.Label)27 ClassWriter (org.objectweb.asm.ClassWriter)16 Method (java.lang.reflect.Method)13 ArrayList (java.util.ArrayList)12 ClassReader (org.objectweb.asm.ClassReader)10 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)9 ClassVisitor (org.objectweb.asm.ClassVisitor)9 ExprString (lucee.transformer.expression.ExprString)8 ModelType (org.gradle.model.internal.type.ModelType)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 IOException (java.io.IOException)6 MethodType (java.lang.invoke.MethodType)6 HashMap (java.util.HashMap)6 List (java.util.List)6 LitString (lucee.transformer.expression.literal.LitString)6 PropertyAccessorType (org.gradle.internal.reflect.PropertyAccessorType)6