Example usage for org.objectweb.asm Opcodes ASM4

List of usage examples for org.objectweb.asm Opcodes ASM4

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ASM4.

Prototype

int ASM4

To view the source code for org.objectweb.asm Opcodes ASM4.

Click Source Link

Usage

From source file:instrumentj.impl.InstrumentMethodVisitor.java

License:Apache License

/**
 *
 * @param className/* w  w w.j  av  a 2 s.  co  m*/
 * @param mv
 * @param access
 * @param methodName
 * @param methodDescription
 */
public InstrumentMethodVisitor(final String className, final MethodVisitor mv, final int access,
        final String methodName, final String methodDescription) {
    super(Opcodes.ASM4, mv, access, methodName, methodDescription);

    if (className == null) {
        throw new NullPointerException("className");
    }

    if (methodName == null) {
        throw new NullPointerException("methodName");
    }

    this.className = className;
    this.methodName = methodName;
    this.methodDescription = methodDescription;
}

From source file:interactivespaces.workbench.project.test.JunitTestClassVisitor.java

License:Apache License

/**
 * Construct a new class visitor.
 */
public JunitTestClassVisitor() {
    super(Opcodes.ASM4);
}

From source file:io.tesla.zipcomparator.internal.ClassfileComparator.java

License:Open Source License

private String disassemble(byte[] bytes) {
    ClassReader reader = new ClassReader(bytes);
    ClassNode clazz = new ClassNode();
    reader.accept(clazz, Opcodes.ASM4 | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);

    // inner class list gets reordered during pack200 normalization
    if (clazz.innerClasses != null) {
        List<InnerClassNode> sorted = new ArrayList<InnerClassNode>(clazz.innerClasses);
        Collections.sort(sorted, new Comparator<InnerClassNode>() {
            public int compare(InnerClassNode o1, InnerClassNode o2) {
                return o1.name.compareTo(o2.name);
            }//w w w.  ja v a 2 s . c  om
        });
        clazz.innerClasses = sorted;
    }

    // rendering human-readable bytecode is an eyecandy, we can compare ClassNodes directly

    StringWriter buffer = new StringWriter();
    PrintWriter writer = new PrintWriter(buffer);
    clazz.accept(new TraceClassVisitor(writer));
    writer.flush();
    writer.close();
    return buffer.toString();
}

From source file:jaspex.speculation.Cache.java

License:Open Source License

public static void saveClass(final Type className, byte[] classBytes) {
    new File(CACHE_DIR).mkdir();
    try {/*from w w  w . j av  a 2  s .c om*/
        ClassReader cr = new ClassReader(classBytes);
        ClassWriter cw = new ClassWriter(cr, 0);

        cr.accept(new ClassVisitor(Opcodes.ASM4, cw) {
            @Override
            public void visitEnd() {
                visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_HASH_FIELD,
                        asmlib.Type.STRING.bytecodeName(), null, hashClass(className));
                cv.visitEnd();
            }
        }, 0);

        FileOutputStream fos = new FileOutputStream(CACHE_DIR + className.commonName() + ".class");
        fos.write(cw.toByteArray());
        fos.close();
    } catch (IOException e) {
        throw new Error(e);
    }
}

From source file:jaspex.speculation.Cache.java

License:Open Source License

public static byte[] lookupClass(Type className) {
    try {/*from ww w. jav  a2  s .  c o  m*/
        byte[] classBytes = IOUtils.readFile(new File(CACHE_DIR + className.commonName() + ".class"));

        ClassReader cr = new ClassReader(classBytes);

        final String[] hash = new String[1];

        cr.accept(new ClassVisitor(Opcodes.ASM4) {
            @Override
            public FieldVisitor visitField(int access, String name, String desc, String signature,
                    Object value) {
                if (name.equals(CLASS_HASH_FIELD))
                    hash[0] = (String) value;
                return null;
            }
        }, 0);

        if (hash[0] == null)
            throw new Error("Unexpected class file found in cache");

        if (!hash[0].equals(hashClass(className))) {
            clearCache();
            // Ver nota no inicio do ficheiro sobre porque  que isto tem de dar erro
            throw new Error("Invalid class in cache, clear cache and re-run");
        }

        return classBytes;
    } catch (FileNotFoundException e) {
        return null;
    } catch (IOException e) {
        throw new Error(e);
    }
}

From source file:jaspex.speculation.CreateNonSpeculativeMethodsClassVisitor.java

License:Open Source License

public CreateNonSpeculativeMethodsClassVisitor(ClassVisitor cv) {
    super(Opcodes.ASM4);
    this.cv = cv;
}

From source file:jaspex.speculation.CreateSpeculativeMethodVisitor.java

License:Open Source License

public CreateSpeculativeMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv, InfoClass currentClass, Boolean JDKClass) {
    super(Opcodes.ASM4, createNextMethodVisitor(access, name, desc, signature, exceptions, cv));

    _active = name.endsWith("$transactional") || (name.equals("<clinit>") && !JDKClass) // No modificar <clinit> quando usado com o JDKTransactifier
            || (name.equals("<init>") && desc.contains(CommonTypes.SPECULATIVECTORMARKER.bytecodeName()));
    _currentClass = currentClass;// w ww.j ava  2  s  .c  om
    name = name.replace("$transactional", "");
    _methodName = name;

    InfoMethod im = new InfoMethod(access, name, desc, signature, exceptions, null);

    if (_active && im.isSynchronized()) {
        insertBlacklistedActionAttemptedCall("INSIDE SYNCHRONIZED METHOD, USE -REMOVESYNC");
    }

    // Tratamento especial para mtodos nativos
    // Ver tambm no wiki em "Transformaes Especulao"
    if (_active && im.isNative()) {
        if (im.isPrivate()) {
            // Se este  o overload de um mtodo nativo privado, temos que corrigir aqui o
            // nome para obter o mtodo original
            name = FixPrivateMethodAccessMethodVisitor.stripPrivate(name);
        }

        mv.visitCode();
        // Contador de posies de argumentos
        int pos = 0;
        if (!im.isStatic())
            mv.visitVarInsn(ALOAD, pos++);
        for (Type argType : im.argumentTypes()) {
            mv.visitVarInsn(argType.getLoadInsn(), pos);
            pos += argType.getNumberSlots();
        }
        insertSpeculationControlCall("INVOKE NATIVE METHOD (" + name + desc + ")", "");
        mv.visitMethodInsn(im.isStatic() ? INVOKESTATIC : INVOKESPECIAL, _currentClass.type().asmName(), name,
                desc);
        mv.visitInsn(im.returnType().getReturnInsn());
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
}

From source file:jaspex.speculation.FixPrivateMethodAccessMethodVisitor.java

License:Open Source License

public FixPrivateMethodAccessMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv, InfoClass currentClass, Boolean JDKClass) {
    super(Opcodes.ASM4, cv.visitMethod(convertAccess(access, name), convertName(access, name, currentClass),
            desc, signature, exceptions));
    _currentClass = currentClass;//www  . j av  a 2 s .c  o  m
    _active = name.endsWith("$transactional") || (name.equals("<clinit>") && !JDKClass) // No modificar <clinit> quando usado com o JDKTransactifier
            || (name.equals("<init>") && desc.contains("jaspex/MARKER/Transactional"));
}

From source file:jaspex.speculation.InjectDetectLocalClassVisitor.java

License:Open Source License

public InjectDetectLocalClassVisitor(ClassVisitor cv) {
    super(Opcodes.ASM4, cv);
}

From source file:jaspex.speculation.InjectDetectLocalClassVisitor.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (_active && name.equals("<init>") && desc.contains("/SpeculativeCtorMarker")) {
        return new MethodVisitor(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions)) {
            @Override//  ww w  .  ja  va 2s  .  co  m
            public void visitCode() {
                mv.visitCode();
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKESTATIC, CommonTypes.TRANSACTION.asmName(), "getOwnerTag",
                        "()" + Type.OBJECT.bytecodeName());
                mv.visitFieldInsn(PUTFIELD, _name, "$owner", Type.OBJECT.bytecodeName());
            }
        };
    } else {
        return cv.visitMethod(access, name, desc, signature, exceptions);
    }
}