Example usage for org.objectweb.asm Type LONG_TYPE

List of usage examples for org.objectweb.asm Type LONG_TYPE

Introduction

In this page you can find the example usage for org.objectweb.asm Type LONG_TYPE.

Prototype

Type LONG_TYPE

To view the source code for org.objectweb.asm Type LONG_TYPE.

Click Source Link

Document

The long type.

Usage

From source file:boilerplate.processor.adapters.ToStringMethodInsertion.java

License:Open Source License

private static List<BytecodeGenerator> createMethodList() {
    final Type objectType = Type.getType(Object.class);
    class ObjectMethodInsn extends ToStringMethodInsertion {
        ObjectMethodInsn() {//from  ww  w.j ava2s.  c  om
            super(objectType, "appendObject",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)V");
        }

        @Override
        public boolean matches(Type type) {
            return true;
        }
    }

    BytecodeGenerator[] arr = {
            new ToStringMethodInsertion(Type.BOOLEAN_TYPE, "appendBoolean",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;Z)V"),
            new ToStringMethodInsertion(Type.BYTE_TYPE, "appendByte",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;B)V"),
            new ToStringMethodInsertion(Type.CHAR_TYPE, "appendChar",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;C)V"),
            new ToStringMethodInsertion(Type.DOUBLE_TYPE, "appendDouble",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;D)V"),
            new ToStringMethodInsertion(Type.FLOAT_TYPE, "appendFloat",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;F)V"),
            new ToStringMethodInsertion(Type.INT_TYPE, "appendInt",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;I)V"),
            new ToStringMethodInsertion(Type.LONG_TYPE, "appendLong",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;J)V"),
            new ToStringMethodInsertion(Type.SHORT_TYPE, "appendShort",
                    "(Ljava/lang/StringBuilder;Ljava/lang/String;S)V"),
            // default
            new ObjectMethodInsn(), };
    List<BytecodeGenerator> list = Arrays.asList(arr);
    return Collections.unmodifiableList(list);
}

From source file:cc.adf.metrics.agent.visitor.MetricsMethodVisitor.java

@Override
public void visitCode() {
    System.out.println("Visit Code " + methodName);
    mv.visitCode();/*from   www .j  a va  2 s  . co  m*/
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime", "()J", false);
    time = localVariablesSorter.newLocal(Type.LONG_TYPE);
    mv.visitVarInsn(LSTORE, time);
    if (methodName.equals("passivateState")) {
        addPassivationMessageInjection();
    }
    System.out.println("End Visit Code " + methodName);
    //maxStack = 1;
}

From source file:cc.adf.metrics.agent.visitor.MetricsMethodVisitor_OLD.java

@Override
public void visitCode() {
    System.out.print("hihihihi");
    mv.visitCode();//from  w ww.  jav a 2  s.c  o  m
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime", "()J", true);
    time = newLocal(Type.LONG_TYPE);
    mv.visitVarInsn(LSTORE, time);

}

From source file:cl.inria.stiq.instrumenter.BCIUtils.java

License:Open Source License

public static Type getTypeForSig(char aSig) {
    switch (aSig) {
    case 'I':
        return Type.INT_TYPE;
    case 'J':
        return Type.LONG_TYPE;
    case 'F':
        return Type.FLOAT_TYPE;
    case 'D':
        return Type.DOUBLE_TYPE;
    case 'L':
        return TYPE_OBJECTID;
    default:// w  ww .  j  av a  2 s.co  m
        throw new RuntimeException("Not handled: " + aSig);
    }
}

From source file:com.android.build.gradle.internal.incremental.ByteCodeUtils.java

License:Apache License

/**
 * Given a *STORE opcode, it returns the type associated to the variable, or null if
 * not a valid opcode.//  w w w. j  a va2 s.c o  m
 */
static Type getTypeForStoreOpcode(int opcode) {
    switch (opcode) {
    case Opcodes.ISTORE:
        return Type.INT_TYPE;
    case Opcodes.LSTORE:
        return Type.LONG_TYPE;
    case Opcodes.FSTORE:
        return Type.FLOAT_TYPE;
    case Opcodes.DSTORE:
        return Type.DOUBLE_TYPE;
    case Opcodes.ASTORE:
        return Type.getType(Object.class);
    }
    return null;
}

From source file:com.android.build.gradle.internal2.incremental.IncrementalSupportVisitor.java

License:Apache License

/**
 * Adds serialVersionUID for the classes that does not define one. Reason for this is that if a
 * class does not define a serialVersionUID value, and is used for serialization, instrumented
 * and non-instrumented class will have different serialVersionUID values, and that will break
 * serialization.//from w  w  w .jav  a  2 s.  com
 */
private void addSerialUidIfMissing() {
    // noinspection unchecked
    for (FieldNode f : (List<FieldNode>) classNode.fields) {
        if (f.name.equals("serialVersionUID")) {
            // We should not generate serial uuid, field already exists. Although it might
            // not be static, final, and long, adding would break the instrumented class.
            return;
        }
    }
    try {
        String className = Type.getObjectType(classNode.name).getClassName();
        Class<?> clazz = Class.forName(className, false, Thread.currentThread().getContextClassLoader());

        ObjectStreamClass objectStreamClass = ObjectStreamClass.lookupAny(clazz);
        long serialUuid = objectStreamClass.getSerialVersionUID();

        // adds the field
        super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "serialVersionUID",
                Type.LONG_TYPE.getDescriptor(), null, serialUuid);

    } catch (ClassNotFoundException ex) {
        LOG.verbose("Unable to add auto-generated serialVersionUID for %1$s : %2$s", classNode.name,
                ex.getMessage());
    } catch (LinkageError | AssertionError e) {
        // http://b.android.com/220635 - static initializer might be invoked
        LOG.warning("Unable to generate serialVersionUID for %s. In case you make this class"
                + " serializable and use it to persist data in InstantRun mode, please"
                + " add a serialVersionUID field.", classNode.name);
    }
}

From source file:com.android.builder.testing.MockableJarGenerator.java

License:Apache License

/**
 * Rewrites the method bytecode to remove the "Stub!" exception.
 *///ww w .  j a  v  a 2s  . c o m
private void fixMethodBody(MethodNode methodNode, ClassNode classNode) {
    if ((methodNode.access & Opcodes.ACC_NATIVE) != 0 || (methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
        // Abstract and native method don't have bodies to rewrite.
        return;
    }

    if ((classNode.access & Opcodes.ACC_ENUM) != 0 && ENUM_METHODS.contains(methodNode.name)) {
        // Don't break enum classes.
        return;
    }

    Type returnType = Type.getReturnType(methodNode.desc);
    InsnList instructions = methodNode.instructions;

    if (methodNode.name.equals(CONSTRUCTOR)) {
        // Keep the call to parent constructor, delete the exception after that.

        boolean deadCode = false;
        for (AbstractInsnNode instruction : instructions.toArray()) {
            if (!deadCode) {
                if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
                    instructions.insert(instruction, new InsnNode(Opcodes.RETURN));
                    // Start removing all following instructions.
                    deadCode = true;
                }
            } else {
                instructions.remove(instruction);
            }
        }
    } else {
        instructions.clear();

        if (returnDefaultValues || methodNode.name.equals(CLASS_CONSTRUCTOR)) {
            if (INTEGER_LIKE_TYPES.contains(returnType)) {
                instructions.add(new InsnNode(Opcodes.ICONST_0));
            } else if (returnType.equals(Type.LONG_TYPE)) {
                instructions.add(new InsnNode(Opcodes.LCONST_0));
            } else if (returnType.equals(Type.FLOAT_TYPE)) {
                instructions.add(new InsnNode(Opcodes.FCONST_0));
            } else if (returnType.equals(Type.DOUBLE_TYPE)) {
                instructions.add(new InsnNode(Opcodes.DCONST_0));
            } else {
                instructions.add(new InsnNode(Opcodes.ACONST_NULL));
            }

            instructions.add(new InsnNode(returnType.getOpcode(Opcodes.IRETURN)));
        } else {
            instructions.insert(throwExceptionsList(methodNode, classNode));
        }
    }
}

From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java

License:Apache License

private static void countMapper(MethodVisitor method, PropertyReference src, PropertyReference dst,
        LocalVarRef srcVar, LocalVarRef dstVar) {
    Invariants.require(dst.getType().equals(LONG_DESC));
    dstVar.load(method);//from ww  w.j av a 2  s  .c  om
    getOption(method, dst);
    getConst(method, 1L);
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(LONG_DESC).getInternalName(), "modify",
            Type.getMethodDescriptor(typeOf(LONG_DESC), Type.LONG_TYPE), false);
}

From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java

License:Apache License

/**
 * Returns the ASM {@link Type} object.//from  w w w. j a  va  2 s  .com
 * @param type the target type description
 * @return the corresponded {@link Type} object
 */
public static Type typeOf(TypeDescription type) {
    Arguments.requireNonNull(type);
    TypeDescription e = type.getErasure();
    switch (e.getTypeKind()) {
    case BASIC:
        switch (((BasicTypeDescription) e).getBasicTypeKind()) {
        case BOOLEAN:
            return Type.BOOLEAN_TYPE;
        case BYTE:
            return Type.BYTE_TYPE;
        case CHAR:
            return Type.CHAR_TYPE;
        case DOUBLE:
            return Type.DOUBLE_TYPE;
        case FLOAT:
            return Type.FLOAT_TYPE;
        case INT:
            return Type.INT_TYPE;
        case LONG:
            return Type.LONG_TYPE;
        case SHORT:
            return Type.SHORT_TYPE;
        case VOID:
            return Type.VOID_TYPE;
        default:
            throw new AssertionError(type);
        }
    case ARRAY:
        return Type.getType('[' + typeOf(((ArrayTypeDescription) e).getComponentType()).getDescriptor());
    case CLASS:
        return Type.getObjectType(((ClassDescription) e).getInternalName());
    default:
        throw new AssertionError(type);
    }
}

From source file:com.changingbits.Builder.java

License:Apache License

private void buildAsm(GeneratorAdapter gen, Node node, int uptoLocal) {

    if (node.outputs != null) {
        //System.out.println("gen outputs=" + node.outputs);
        // Increment any range outputs at the current node:
        for (int range : node.outputs) {
            // Load arg 1 (the int[] answers):
            gen.loadArg(1);//w ww .  ja  va2s  .  c o m
            // Load the index we will store to
            gen.loadLocal(uptoLocal, Type.INT_TYPE);
            // The range value we will store:
            gen.push(range);
            // Store it
            gen.arrayStore(Type.INT_TYPE);
            // Increment our upto:
            gen.iinc(uptoLocal, 1);
        }
    }

    if (node.left != null && (node.left.hasOutputs || node.right.hasOutputs)) {
        assert node.left.end + 1 == node.right.start;
        if (node.left.hasOutputs && node.right.hasOutputs) {
            // Recurse on either left or right
            Label labelLeft = new Label();
            Label labelEnd = new Label();
            gen.loadArg(0);
            gen.push(node.left.end);

            gen.ifCmp(Type.LONG_TYPE, GeneratorAdapter.LE, labelLeft);
            buildAsm(gen, node.right, uptoLocal);
            gen.goTo(labelEnd);
            gen.visitLabel(labelLeft);
            buildAsm(gen, node.left, uptoLocal);
            gen.visitLabel(labelEnd);
        } else if (node.left.hasOutputs) {
            // Recurse only on left
            Label labelEnd = new Label();
            gen.loadArg(0);
            gen.push(node.left.end);

            gen.ifCmp(Type.LONG_TYPE, GeneratorAdapter.GT, labelEnd);
            buildAsm(gen, node.left, uptoLocal);
            gen.visitLabel(labelEnd);
        } else {
            // Recurse only on right
            Label labelEnd = new Label();
            gen.loadArg(0);
            gen.push(node.left.end);

            gen.ifCmp(Type.LONG_TYPE, GeneratorAdapter.LE, labelEnd);
            buildAsm(gen, node.right, uptoLocal);
            gen.visitLabel(labelEnd);
        }
    }
}