Example usage for org.objectweb.asm Opcodes ACC_PRIVATE

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

Introduction

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

Prototype

int ACC_PRIVATE

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

Click Source Link

Usage

From source file:de.zib.sfs.instrument.AbstractSfsAdapter.java

License:BSD License

@Override
public void visitSource(String source, String debug) {
    if (this.callbackTypeDescriptor != null) {
        // private final <CallbackType> callback;
        FieldVisitor callbackFV = this.cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "callback",
                this.callbackTypeDescriptor, null, null);
        callbackFV.visitEnd();//ww w . j a v a 2 s. c o m
    }

    // private final InstrumentationActive instrumentationActive;
    FieldVisitor instrumentationActiveFV = this.cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL,
            "instrumentationActive", Type.getDescriptor(InstrumentationActive.class), null, null);
    instrumentationActiveFV.visitEnd();

    appendFields(this.cv);

    this.cv.visitSource(source, debug);
}

From source file:de.zib.sfs.instrument.FileInputStreamAdapter.java

License:BSD License

@Override
protected void appendWrappedMethods(ClassVisitor visitor) {
    wrapMethod(Opcodes.ACC_PRIVATE, "open", Type.VOID_TYPE, new Type[] { Type.getType(String.class) }, null,
            new String[] { Type.getInternalName(FileNotFoundException.class) }, "openCallback",
            Type.getType(String.class), new ParameterResultPasser(1));

    // for all read methods pass the read result to the callback
    ReturnResultPasser resultPasser = new ReturnResultPasser();

    if (!skipReads()) {
        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, null, null,
                new String[] { Type.getInternalName(IOException.class) }, "readCallback", Type.INT_TYPE,
                resultPasser);/*from www.  j  ava2 s  .c  o  m*/

        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, new Type[] { Type.getType(byte[].class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                resultPasser);

        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE,
                new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                resultPasser);
    }
}

From source file:de.zib.sfs.instrument.FileInputStreamAdapter.java

License:BSD License

private static boolean isOpenMethod(int access, String name, String desc, String signature,
        String[] exceptions) {//  www  . j av a2  s . c  o m
    return access == Opcodes.ACC_PRIVATE && "open".equals(name)
            && Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class)).equals(desc)
            && null == signature && exceptions != null && exceptions.length == 1
            && Type.getInternalName(FileNotFoundException.class).equals(exceptions[0]);
}

From source file:de.zib.sfs.instrument.FileOutputStreamAdapter.java

License:BSD License

@Override
protected void appendWrappedMethods(ClassVisitor visitor) {
    ResultPasser resultDiscarder = new DiscardResultPasser();

    wrapMethod(Opcodes.ACC_PRIVATE, "open", Type.VOID_TYPE,
            new Type[] { Type.getType(String.class), Type.BOOLEAN_TYPE }, null,
            new String[] { Type.getInternalName(FileNotFoundException.class) }, "openCallback",
            Type.getType(String.class), new ParameterResultPasser(1));

    if (!skipWrites()) {
        // 1 byte write, no result needed
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeCallback", null,
                resultDiscarder);/*from  w  w w .ja  v a2 s.c  om*/

        // have the byte array put on top of the stack, then pass its length
        // to the callback
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                new ParameterResultPasser(1) {
                    @Override
                    public void passResult(MethodVisitor mv) {
                        mv.visitInsn(Opcodes.ARRAYLENGTH);
                    }
                });

        // have the len parameter put on top of the stack
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE,
                new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                new ParameterResultPasser(3));
    }
}

From source file:de.zib.sfs.instrument.FileOutputStreamAdapter.java

License:BSD License

private static boolean isOpenMethod(int access, String name, String desc, String signature,
        String[] exceptions) {/*from  w ww  . j  a  v a  2  s  . co  m*/
    return access == Opcodes.ACC_PRIVATE && "open".equals(name)
            && Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class), Type.BOOLEAN_TYPE)
                    .equals(desc)
            && null == signature && exceptions != null && exceptions.length == 1
            && Type.getInternalName(FileNotFoundException.class).equals(exceptions[0]);
}

From source file:de.zib.sfs.instrument.RandomAccessFileAdapter.java

License:BSD License

@Override
protected void appendWrappedMethods(ClassVisitor visitor) {
    ResultPasser resultDiscarder = new DiscardResultPasser();

    wrapMethod(Opcodes.ACC_PRIVATE, "open", Type.VOID_TYPE,
            new Type[] { Type.getType(String.class), Type.INT_TYPE }, null,
            new String[] { Type.getInternalName(FileNotFoundException.class) }, "openCallback",
            Type.getType(String.class), new ParameterResultPasser(1));

    // for all read methods pass the read result to the callback
    ReturnResultPasser resultPasser = new ReturnResultPasser();

    // invokes .length on an array
    ResultPasser arrayLengthPasser = new ParameterResultPasser(1) {
        @Override/*from ww w .java 2 s . c o m*/
        public void passResult(MethodVisitor mv) {
            mv.visitInsn(Opcodes.ARRAYLENGTH);
        }
    };

    // invokes .length(); on the current local variable
    ResultPasser stringLengthPasser = new ReturnResultPasser() {
        @Override
        public void passResult(MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length",
                    Type.getMethodDescriptor(Type.INT_TYPE), false);
        }
    };

    if (!skipReads()) {
        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, null, null,
                new String[] { Type.getInternalName(IOException.class) }, "readCallback", Type.INT_TYPE,
                resultPasser);

        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, new Type[] { Type.getType(byte[].class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                resultPasser);

        wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE,
                new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                resultPasser);

        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readFully", Type.VOID_TYPE,
                new Type[] { Type.getType(byte[].class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                arrayLengthPasser);

        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readFully", Type.VOID_TYPE,
                new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                new ParameterResultPasser(3));

        // record length of read string
        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readLine", Type.getType(String.class), null, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                stringLengthPasser);

        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readUTF", Type.getType(String.class), null, null,
                new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE,
                stringLengthPasser);
    }

    // take length of parameter string instead of return value
    stringLengthPasser = new ParameterResultPasser(1) {
        @Override
        public void passResult(MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length",
                    Type.getMethodDescriptor(Type.INT_TYPE), false);
        }
    };

    if (!skipWrites()) {
        // 1 byte write, no result needed
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeCallback", null,
                resultDiscarder);

        // have the byte array put on top of the stack, then pass its length
        // to
        // the callback
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                arrayLengthPasser);

        // have the len parameter put on top of the stack
        wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE,
                new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                new ParameterResultPasser(3));

        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeBytes", Type.VOID_TYPE,
                new Type[] { Type.getType(String.class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                stringLengthPasser);

        // twice the data if written as characters
        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeChars", Type.VOID_TYPE,
                new Type[] { Type.getType(String.class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                new ParameterResultPasser(1) {
                    @Override
                    public void passResult(MethodVisitor mv) {
                        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length",
                                Type.getMethodDescriptor(Type.INT_TYPE), false);
                        mv.visitInsn(Opcodes.ICONST_2);
                        mv.visitInsn(Opcodes.IMUL);
                    }
                });

        wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeUTF", Type.VOID_TYPE,
                new Type[] { Type.getType(String.class) }, null,
                new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE,
                stringLengthPasser);
    }

}

From source file:de.zib.sfs.instrument.RandomAccessFileAdapter.java

License:BSD License

private static boolean isOpenMethod(int access, String name, String desc, String signature,
        String[] exceptions) {/*from  w  w  w .j  a  v a  2  s . co  m*/
    return access == Opcodes.ACC_PRIVATE && "open".equals(name)
            && Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class), Type.INT_TYPE).equals(desc)
            && null == signature && exceptions != null && exceptions.length == 1
            && Type.getInternalName(FileNotFoundException.class).equals(exceptions[0]);
}

From source file:de.zib.sfs.instrument.ZipFileAdapter.java

License:BSD License

@Override
public void visitSource(String source, String debug) {
    if (!this.skip.contains(OperationCategory.ZIP)) {
        // private long startTime;
        FieldVisitor startTimeFV = this.cv.visitField(Opcodes.ACC_PRIVATE, "startTime",
                Type.getDescriptor(Long.TYPE), null, null);
        startTimeFV.visitEnd();//  w  w  w. j  a  v  a 2 s  . c  o m
    }

    this.cv.visitSource(source, debug);
}

From source file:dodola.anole.lib.IncrementalSupportVisitor.java

License:Apache License

/**
 * Add all unseen methods from the passed ClassNode's methods. {@see ClassNode#methods}
 *
 * @param methods   the methods already encountered in the ClassNode hierarchy
 * @param classNode the class to save all new methods from.
 *///from   w w w .  j  a  v a 2s.  c o m
private static void addAllNewMethods(Map<String, MethodReference> methods, ClassNode classNode) {
    //noinspection unchecked
    for (MethodNode method : (List<MethodNode>) classNode.methods) {
        if (method.name.equals(AsmUtils.CONSTRUCTOR) || method.name.equals("<clinit>")) {
            continue;
        }
        String name = method.name + "." + method.desc;
        if (isAccessCompatibleWithInstantRun(method.access) && !methods.containsKey(name)
                && (method.access & Opcodes.ACC_STATIC) == 0 && (method.access & Opcodes.ACC_PRIVATE) == 0) {
            methods.put(name, new MethodReference(method, classNode));
        }
    }
}

From source file:dodola.anole.lib.IncrementalSupportVisitor.java

License:Apache License

/**
 * Add all constructors from the passed ClassNode's methods. {@see ClassNode#methods}
 *
 * @param methods                 the constructors already encountered in the ClassNode hierarchy
 * @param classNode               the class to save all new methods from.
 * @param keepPrivateConstructors whether to keep the private constructors.
 *//*from ww w  .j  a va  2 s.  c o  m*/
private void addAllNewConstructors(Map<String, MethodNode> methods, ClassNode classNode,
        boolean keepPrivateConstructors) {
    //noinspection unchecked
    for (MethodNode method : (List<MethodNode>) classNode.methods) {
        if (!method.name.equals(AsmUtils.CONSTRUCTOR)) {
            continue;
        }

        if (!isAccessCompatibleWithInstantRun(method.access)) {
            continue;
        }

        if (!keepPrivateConstructors && (method.access & Opcodes.ACC_PRIVATE) != 0) {
            continue;
        }
        if (!classNode.name.equals(visitedClassName) && !classNode.name.equals(visitedSuperName)) {
            continue;
        }
        String key = classNode.name + "." + method.desc;
        if (methods.containsKey(key)) {
            continue;
        }
        methods.put(key, method);
    }
}