Example usage for org.objectweb.asm Opcodes ACC_PUBLIC

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

Introduction

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

Prototype

int ACC_PUBLIC

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

Click Source Link

Usage

From source file:com.asakusafw.dag.compiler.directio.OutputPatternSerDeGenerator.java

License:Apache License

private static void putDeserialize(DataModelReference reference, List<PropertyReference> properties,
        FieldRef buffer, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserializePair",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(DataInput.class), typeOf(DataInput.class)),
            null, new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef valueInput = new LocalVarRef(Opcodes.ALOAD, 2);
    self.load(v);//w  w  w  . j a  v  a  2 s . c  o m
    getField(v, buffer);
    LocalVarRef object = putLocalVar(v, Type.OBJECT, 3);
    for (PropertyReference property : properties) {
        object.load(v);
        getOption(v, property);
        valueInput.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)),
                false);
    }
    object.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.jdbc.PreparedStatementAdapterGenerator.java

License:Apache License

private static void defineBody(ClassWriter writer, DataModelReference dataType,
        List<PropertyReference> properties, Optional<FieldRef> dateBuf) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "drive", //$NON-NLS-1$
            Type.getMethodDescriptor(typeOf(void.class), typeOf(PreparedStatement.class), typeOf(Object.class)),
            null, new String[] { typeOf(SQLException.class).getInternalName(), });
    LocalVarRef row = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef object = cast(v, 2, dataType.getDeclaration());

    int columnIndex = 0;
    for (PropertyReference property : properties) {
        columnIndex++;// w  w  w . j a va2s . com

        object.load(v);
        getOption(v, property);
        LocalVarRef option = putLocalVar(v, Type.OBJECT, 3);

        Label elseIf = new Label();
        Label endIf = new Label();

        // if (option.isNull()) {
        option.load(v);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(ValueOption.class).getInternalName(), "isNull", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(boolean.class)), false);
        v.visitJumpInsn(Opcodes.IFEQ, elseIf);

        row.load(v);
        getConst(v, columnIndex);
        doSetNull(v, property);

        v.visitJumpInsn(Opcodes.GOTO, endIf);

        // } else { @elseIf
        v.visitLabel(elseIf);

        row.load(v);
        getConst(v, columnIndex);
        option.load(v);
        doSetValue(v, property, dateBuf);

        // } @endIf
        v.visitLabel(endIf);
    }

    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.jdbc.ResultSetAdapterGenerator.java

License:Apache License

private static void defineBody(ClassWriter writer, DataModelReference dataType,
        List<PropertyReference> properties, FieldRef valueBuffer, Optional<FieldRef> calendarBuf) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "extract",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(ResultSet.class)), null,
            new String[] { typeOf(SQLException.class).getInternalName(), });
    LocalVarRef rs = new LocalVarRef(Opcodes.ALOAD, 1);
    valueBuffer.load(v);/*from   w w  w. j  a va 2  s  .c  o m*/
    LocalVarRef buf = putLocalVar(v, Type.OBJECT, 2);

    int columnIndex = 0;
    Set<PropertyName> sawSet = new HashSet<>();
    for (PropertyReference property : properties) {
        columnIndex++;
        Label elseIf = new Label();
        Label endIf = new Label();

        buf.load(v);
        getOption(v, property);

        rs.load(v);
        getConst(v, columnIndex);
        doGetValue(v, property, calendarBuf);

        // if (rs.wasNull()) {
        rs.load(v);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(ResultSet.class).getInternalName(), "wasNull",
                Type.getMethodDescriptor(typeOf(boolean.class)), true);
        v.visitJumpInsn(Opcodes.IFEQ, elseIf);
        if (isWideType(property)) {
            v.visitInsn(Opcodes.POP2);
        } else {
            v.visitInsn(Opcodes.POP);
        }
        doSetNull(v);
        v.visitJumpInsn(Opcodes.GOTO, endIf);

        // } else { @elseIf
        v.visitLabel(elseIf);
        doSetValue(v, property);

        // } @endIf
        v.visitLabel(endIf);

        sawSet.add(property.getName());
    }

    // resets other properties
    for (PropertyReference property : dataType.getProperties()) {
        if (sawSet.contains(property.getName())) {
            continue;
        }
        buf.load(v);
        getOption(v, property);
        doSetNull(v);
    }

    buf.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.bit.learning.java.asm.UDFByteCodeVerifier.java

License:Apache License

public Set<String> verify(byte[] bytes) {
    final Set<String> errors = new TreeSet<String>(); // it's a TreeSet for unit tests
    ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5) {
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            errors.add("field declared: " + name);
            return null;
        }//  w ww. j a  v a  2  s  . co m

        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {

            if (true) {
                return new EvaluateVisitor(errors);
            }

            if ("<init>".equals(name)) {
                if (Opcodes.ACC_PUBLIC != access)
                    errors.add("constructor not public");
                // allowed constructor - JavaUDF(TypeCodec returnCodec, TypeCodec[] argCodecs)
                return new ConstructorVisitor(errors);
            }
            if ("<init>".equals(name) && CTOR_SIG.equals("()V")) {
                if (Opcodes.ACC_PUBLIC != access)
                    errors.add("constructor not public");
                // allowed constructor - JavaUDF(TypeCodec returnCodec, TypeCodec[] argCodecs)
                return new ConstructorVisitor(errors);
            }

            if ("evaluate".equals(name)) {
                if (Opcodes.ACC_PRIVATE == access) {
                    //This should be right, because user can use private evaluate method
                    errors.add("evaluate is private");
                }

                return new EvaluateVisitor(errors);
            }

            if ("executeImpl".equals(name) && "(ILjava/util/List;)Ljava/nio/ByteBuffer;".equals(desc)) {
                if (Opcodes.ACC_PROTECTED != access)
                    errors.add("executeImpl not protected");
                // the executeImpl method - ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params)
                return new ExecuteImplVisitor(errors);
            }
            if ("<clinit>".equals(name)) {
                errors.add("static initializer declared");
            } else {
                //                    errors.add("not allowed method declared: " + name + desc);
                //                    return new ExecuteImplVisitor(errors);
            }
            return null;
        }

        public void visit(int version, int access, String name, String signature, String superName,
                String[] interfaces) {
            //                if (!JAVA_UDF_NAME.equals(superName)) {
            //                    errors.add("class does not extend " + JavaUDF.class.getName());
            //                }
            //                if (access != (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER)) {
            //                    errors.add("class not public final");
            //                }
            super.visit(version, access, name, signature, superName, interfaces);
        }

        public void visitInnerClass(String name, String outerName, String innerName, int access) {
            errors.add("class declared as inner class");
            super.visitInnerClass(name, outerName, innerName, access);
        }
    };

    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);

    return errors;
}

From source file:com.changingbits.Builder.java

License:Apache License

/** Build a {@link LongRangeMultiSet} implementation to
 *  lookup intervals for a given point.//from w w w . jav  a  2 s .c om
 *
 *  @param useAsm If true, the tree will be compiled to
 *  java bytecodes using the {@code asm} library; typically
 *  this results in a faster (~3X) implementation. */
public LongRangeMultiSet getMultiSet(boolean useAsm, boolean useArrayImpl) {

    finish(useArrayImpl);

    if (useAsm) {
        StringBuilder sb = new StringBuilder();
        sb.append('\n');
        int count = 0;
        for (LongRange range : ranges) {
            sb.append("// range ");
            sb.append(count++);
            sb.append(": ");
            sb.append(range);
            sb.append('\n');
        }
        sb.append('\n');
        sb.append("int upto = 0;\n");
        buildJavaSource(root, 0, sb);
        String javaSource = sb.toString();
        //System.out.println("java: " + javaSource);

        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        classWriter.visit(Opcodes.V1_7,
                Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
                COMPILED_TREE_CLASS.replace('.', '/'), null, LONG_RANGE_MULTI_SET_TYPE.getInternalName(), null);
        classWriter.visitSource(javaSource, null);

        Method m = Method.getMethod("void <init> ()");
        GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, m, null,
                null, classWriter);
        constructor.loadThis();
        constructor.loadArgs();
        constructor.invokeConstructor(LONG_RANGE_MULTI_SET_TYPE, m);
        constructor.returnValue();
        constructor.endMethod();

        GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, LOOKUP_METHOD,
                null, null, classWriter);
        //Label labelTop = new Label();
        //Label labelEnd = new Label();
        //gen.visitLabel(labelTop);
        int uptoLocal = gen.newLocal(Type.INT_TYPE);
        //System.out.println("uptoLocal=" + uptoLocal);
        // nocommit is this not needed!?
        //gen.visitLocalVariable("upto", "I", null, labelTop, labelEnd, uptoLocal);
        gen.push(0);
        gen.storeLocal(uptoLocal, Type.INT_TYPE);
        buildAsm(gen, root, uptoLocal);
        // Return upto:
        gen.loadLocal(uptoLocal, Type.INT_TYPE);
        gen.returnValue();
        //gen.visitLabel(labelEnd);
        gen.endMethod();
        classWriter.visitEnd();

        byte[] bytes = classWriter.toByteArray();

        // javap -c /x/tmp/my.class
        /*
        try {
          FileOutputStream fos = new FileOutputStream(new File("/x/tmp/my.class"));
          fos.write(bytes);
          fos.close();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        */

        // nocommit allow changing the class loader
        Class<? extends LongRangeMultiSet> treeClass = new Loader(LongRangeMultiSet.class.getClassLoader())
                .define(COMPILED_TREE_CLASS, classWriter.toByteArray());
        try {
            return treeClass.getConstructor().newInstance();
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                | InvocationTargetException e) {
            throw new RuntimeException(e);
        }

    } else if (useArrayImpl) {
        return new ArrayLongRangeMultiSet(root);
    } else {
        return new SimpleLongRangeMultiSet(root);
    }
}

From source file:com.changingbits.Builder.java

License:Apache License

public LongRangeCounter getCounter(boolean useAsm) {
    finish(false);/*w  w w  .j  a v a 2s .  co m*/
    if (useAsm) {
        StringBuilder sb = new StringBuilder();
        sb.append('\n');
        int count = 0;
        for (LongRange range : ranges) {
            sb.append("// range ");
            sb.append(count++);
            sb.append(": ");
            sb.append(range);
            sb.append('\n');
        }
        sb.append('\n');
        buildJavaCounterSource(root, 0, sb, false);
        String javaSource = sb.toString();
        //System.out.println("javaSource:\n" + javaSource);

        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        classWriter.visit(Opcodes.V1_7,
                Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
                COMPILED_COUNTER_CLASS.replace('.', '/'), null, BASE_LONG_RANGE_COUNTER_TYPE.getInternalName(),
                null);
        classWriter.visitSource(javaSource, null);
        Method m = Method.getMethod("void <init> (com.changingbits.Node, int, int)");
        GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, m, null,
                null, classWriter);
        constructor.loadThis();
        constructor.loadArgs();
        constructor.invokeConstructor(Type.getType(BaseLongRangeCounter.class), m);
        constructor.returnValue();
        constructor.endMethod();

        GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, ADD_METHOD,
                null, null, classWriter);
        buildCounterAsm(gen, root, false);
        gen.returnValue();
        gen.endMethod();
        classWriter.visitEnd();

        byte[] bytes = classWriter.toByteArray();

        // javap -c /x/tmp/my.class
        /*
        try {
          FileOutputStream fos = new FileOutputStream(new File("/x/tmp/counter.class"));
          fos.write(bytes);
          fos.close();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        */

        // nocommit allow changing the class loader
        Class<? extends LongRangeCounter> cl = new CounterLoader(LongRangeCounter.class.getClassLoader())
                .define(COMPILED_COUNTER_CLASS, classWriter.toByteArray());
        try {
            return cl.getConstructor(Node.class, int.class, int.class).newInstance(root,
                    elementaryIntervals.size(), ranges.length);
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    } else {
        return new SimpleLongRangeCounter(root, elementaryIntervals, ranges.length);
    }
}

From source file:com.changingbits.Builder.java

License:Apache License

public LongRangeCounter getCounter2() {
    finish(false);/*  w ww  .  ja va2 s .  co m*/

    // Maps each range to the leaf counts that contribute to it:
    Map<Integer, List<Integer>> rangeToLeaf = new HashMap<>();
    buildRangeToLeaf(root, new ArrayList<Integer>(), rangeToLeaf);

    StringBuilder sb = new StringBuilder();
    sb.append('\n');
    sb.append("public void add(long v) {\n");
    int count = 0;
    for (LongRange range : ranges) {
        sb.append("  // range ");
        sb.append(count++);
        sb.append(": ");
        sb.append(range);
        sb.append('\n');
    }

    buildJavaCounter2Source(root, 1, sb, false);

    sb.append("}\n\n");
    sb.append("public int[] getCounts() {\n");
    sb.append("  int[] counts = new int[");
    sb.append(ranges.length);
    sb.append("];\n");
    for (int range = 0; range < ranges.length; range++) {
        List<Integer> elements = rangeToLeaf.get(range);
        if (elements != null) {
            sb.append("  counts[");
            sb.append(range);
            sb.append("] = count");
            sb.append(elements.get(0));

            for (int i = 1; i < elements.size(); i++) {
                sb.append(" + count");
                sb.append(elements.get(i));
            }
            sb.append(";\n");
        }
    }
    sb.append("  return counts;\n}\n");

    String javaSource = sb.toString();
    //System.out.println("counter2 javaSource:\n" + javaSource);

    ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    classWriter.visit(Opcodes.V1_7,
            Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
            COMPILED_COUNTER_CLASS2.replace('.', '/'), null, LONG_RANGE_COUNTER_TYPE.getInternalName(), null);
    classWriter.visitSource(javaSource, null);

    // Define "int countN" members:
    int numLeaves = elementaryIntervals.size();
    for (int i = 0; i < numLeaves; i++) {
        classWriter.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, "count" + i, "I", null, null);
    }

    // init:
    Method m = Method.getMethod("void <init> ()");
    GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, m, null,
            null, classWriter);
    // Init all counters to 0:
    for (int i = 0; i < numLeaves; i++) {
        constructor.loadThis();
        constructor.push(0);
        constructor.putField(COMPILED_COUNTER_CLASS2_TYPE, "count" + i, Type.INT_TYPE);
    }
    constructor.loadThis();
    constructor.invokeConstructor(LONG_RANGE_COUNTER_TYPE, m);
    constructor.returnValue();
    constructor.endMethod();

    // void add(long v):
    GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, ADD_METHOD, null,
            null, classWriter);
    buildCounterAsm2(gen, root, false);
    gen.returnValue();
    gen.endMethod();

    // int[] getCounts():
    gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, GET_COUNTS_METHOD, null, null,
            classWriter);
    int countsLocal = gen.newLocal(INT_ARRAY_TYPE);
    gen.push(ranges.length);
    gen.newArray(Type.INT_TYPE);
    gen.storeLocal(countsLocal);

    for (int range = 0; range < ranges.length; range++) {
        List<Integer> elements = rangeToLeaf.get(range);
        if (elements != null) {
            gen.loadLocal(countsLocal);
            gen.push(range);

            gen.loadThis();
            gen.getField(COMPILED_COUNTER_CLASS2_TYPE, "count" + elements.get(0), Type.INT_TYPE);

            for (int i = 1; i < elements.size(); i++) {
                gen.loadThis();
                gen.getField(COMPILED_COUNTER_CLASS2_TYPE, "count" + elements.get(i), Type.INT_TYPE);
                gen.visitInsn(Opcodes.IADD);
            }

            gen.arrayStore(Type.INT_TYPE);
        }
    }

    gen.loadLocal(countsLocal);
    gen.returnValue();
    gen.endMethod();

    classWriter.visitEnd();

    byte[] bytes = classWriter.toByteArray();

    // javap -c /x/tmp/my.class
    /*
    try {
      FileOutputStream fos = new FileOutputStream(new File("/x/tmp/counter2.class"));
      fos.write(bytes);
      fos.close();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    */

    // nocommit allow changing the class loader
    Class<? extends LongRangeCounter> cl = new CounterLoader(LongRangeCounter.class.getClassLoader())
            .define(COMPILED_COUNTER_CLASS2, classWriter.toByteArray());
    try {
        return cl.getConstructor().newInstance();
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
            | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.codename1.tools.ikvm.Parser.java

/**
 * Parses an InputStream containing a class.
 * @param input The input stream with a class.
 * @return If a transformation occurred, the bytes for the changed class will be returned.  Otherwise null will be returned.
 * @throws Exception /*from   ww w  . java  2s  . co m*/
 */
public static byte[] parse(InputStream input, ClassLoader classLoader) throws Exception {
    ClassReader r = new ClassReader(input);
    Parser p = new Parser();
    //ClassWriter w = new ClassWriter(r, 0);
    ClassNode classNode = new ClassNode();
    //p.classNode = classNode;

    r.accept(classNode, 0);
    //r.accept(p, ClassReader.EXPAND_FRAMES)

    List<MethodNode> methodsToAdd = new ArrayList<MethodNode>();
    int methodNum = 0;
    for (Object o : classNode.methods) {
        methodNum++;
        MethodNode methodNode = (MethodNode) o;
        boolean synchronizedMethod = (methodNode.access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED;
        if (synchronizedMethod) {
            // Check for a try statement
            final boolean[] tryCatchFound = new boolean[1];
            //System.out.println("Found sync method "+methodNode.name+". Checking for try blocks");
            methodNode.accept(new MethodVisitor(Opcodes.ASM5) {

                @Override
                public void visitTryCatchBlock(Label label, Label label1, Label label2, String string) {
                    tryCatchFound[0] = true;
                }

            });
            if (!tryCatchFound[0]) {
                continue;
            }

            //System.out.println("Instructions: "+Arrays.toString(methodNode.instructions.toArray()));

            System.out.println("Transforming method " + methodNode.name + " of class " + classNode.name);
            MethodDescriptor md = new MethodDescriptor(methodNode.access, methodNode.name, methodNode.desc);
            //methodNode.access = methodNode.access & ~Opcodes.ACC_SYNCHRONIZED;
            String privateMethodName = (md.constructor ? "___cn1init__" : methodNode.name) + "___cn1sync"
                    + (methodNum);
            MethodNode syncMethod = new MethodNode(methodNode.access, methodNode.name, methodNode.desc,
                    methodNode.signature,
                    (String[]) methodNode.exceptions.toArray(new String[methodNode.exceptions.size()]));

            methodNode.name = privateMethodName;
            methodNode.access = (methodNode.access | Opcodes.ACC_PRIVATE) & ~Opcodes.ACC_PUBLIC
                    & ~Opcodes.ACC_PROTECTED & ~Opcodes.ACC_SYNCHRONIZED;
            LabelNode startLabel = new LabelNode();
            syncMethod.instructions.add(startLabel);
            LabelNode endLabel = new LabelNode();

            int argIndex = 0;
            if (!md.staticMethod) {
                //System.out.println(methodNode.name + " is not static");
                syncMethod.localVariables.add(new LocalVariableNode("arg" + (argIndex),
                        "L" + classNode.name + ";", null, startLabel, endLabel, argIndex));
                syncMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, argIndex++));

            }

            for (ByteCodeMethodArg arg : md.arguments) {
                char typeChar = arg.type;
                if (arg.dim > 0) {
                    typeChar = 'L';
                }
                if (arg.desc == null || arg.desc.isEmpty()) {
                    throw new RuntimeException(
                            "Invalid arg description for arg " + argIndex + " of method " + methodNode.name);
                }
                syncMethod.localVariables.add(new LocalVariableNode("arg" + (argIndex), arg.desc, arg.desc,
                        startLabel, endLabel, argIndex));

                switch (typeChar) {
                case 'L':
                    syncMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, argIndex++));
                    //syncMethod.localVariables.add(new LocalVariableNode("arg"+(argIndex-1), arg.desc, null, startLabel, endLabel, argIndex-1));
                    break;
                case 'S':
                case 'I':
                case 'B':
                case 'Z':
                case 'C':
                    syncMethod.instructions.add(new VarInsnNode(Opcodes.ILOAD, argIndex++));
                    break;
                case 'J':
                    syncMethod.instructions.add(new VarInsnNode(Opcodes.LLOAD, argIndex++));
                    argIndex++; // arg index increments 2 for double size args
                    break;
                case 'F':
                    syncMethod.instructions.add(new VarInsnNode(Opcodes.FLOAD, argIndex++));
                    break;
                case 'D':
                    syncMethod.instructions.add(new VarInsnNode(Opcodes.DLOAD, argIndex++));
                    argIndex++;// arg index increments 2 for double size args
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported argument type " + arg.type);
                }
            }

            if (md.staticMethod) {
                syncMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name,
                        privateMethodName, methodNode.desc));
            } else {
                syncMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.name,
                        privateMethodName, methodNode.desc));
            }

            if (md.returnType != null) {
                char typeChar = md.returnType.type;
                if (md.returnType.dim > 0) {
                    typeChar = 'L';
                }
                switch (typeChar) {
                case 'L':
                    syncMethod.instructions.add(new InsnNode(Opcodes.ARETURN));
                    break;
                case 'S':
                case 'I':
                case 'B':
                case 'Z':
                case 'C':
                    syncMethod.instructions.add(new InsnNode(Opcodes.IRETURN));
                    break;
                case 'J':
                    syncMethod.instructions.add(new InsnNode(Opcodes.LRETURN));
                    break;
                case 'F':
                    syncMethod.instructions.add(new InsnNode(Opcodes.FRETURN));
                    break;
                case 'D':
                    syncMethod.instructions.add(new InsnNode(Opcodes.DRETURN));
                    break;
                case 'V':
                    syncMethod.instructions.add(new InsnNode(Opcodes.RETURN));
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported argument type " + md.returnType.type);
                }
            } else {
                syncMethod.instructions.add(new InsnNode(Opcodes.DRETURN));
            }

            syncMethod.instructions.add(endLabel);

            methodsToAdd.add(syncMethod);

        }
    }
    if (!methodsToAdd.isEmpty()) {
        changed = true;
        System.out
                .println("Transforming " + methodsToAdd.size() + " synchronized methods in " + classNode.name);
        classNode.methods.addAll(methodsToAdd);
        ClassWriter w = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        classNode.accept(w);
        byte[] out = w.toByteArray();
        if (verify) {
            verify(out, classLoader);
        }
        return out;
    } else {
        ClassWriter w = new ClassWriter(0);
        classNode.accept(w);
        byte[] out = w.toByteArray();
        return out;
    }

}

From source file:com.datatorrent.stram.webapp.asm.ASMUtil.java

License:Apache License

public static boolean isPublic(int opCode) {
    return (opCode & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC;
}

From source file:com.devexperts.usages.ClassUsagesAnalyzer.java

License:Open Source License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    Member usedFrom = cache.resolveMember(className, name);
    markTypeUse(Type.getType(desc), usedFrom, UseKind.FIELD);
    markSignatureUse(signature, usedFrom);
    if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 && ((access & Opcodes.ACC_STATIC) == 0))
        usages.getUsagesForClass(className).addInheritableMember(name);
    return null;//from   ww w.ja v  a 2 s .c  o  m
}