Example usage for org.objectweb.asm Opcodes ACC_STATIC

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

Introduction

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

Prototype

int ACC_STATIC

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

Click Source Link

Usage

From source file:com.xruby.compiler.codegen.RubyIDClassGenerator.java

License:BSD License

private static byte[] visitEnd() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC, RubyIDClassName, null, "java/lang/Object", null);
    Method staticBlock = Method.getMethod("void <clinit> ()V");
    GeneratorAdapter staticBlockMg = new GeneratorAdapter(Opcodes.ACC_STATIC, staticBlock, null, null, cw);

    for (Map.Entry<String, String> e : idMap.entrySet()) {
        cw.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, e.getValue(), Types.RUBY_ID_TYPE.getDescriptor(),
                null, null);/*from  ww  w .ja  v a  2  s.  co m*/

        staticBlockMg.push(e.getKey());
        staticBlockMg.invokeStatic(Type.getType(RubyID.class),
                Method.getMethod("com.xruby.runtime.lang.RubyID intern(String)"));
        staticBlockMg.putStatic(Type.getType("L" + RubyIDClassName + ";"), e.getValue(), Types.RUBY_ID_TYPE);
    }

    staticBlockMg.returnValue();
    staticBlockMg.endMethod();
    cw.visitEnd();

    clear();

    return cw.toByteArray();
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.DynamicBootstrapUnit.java

public void init() {
    ProgramValueTypeAdapter types = environment.getValueTypeAdapter();
    BytecodeExpression classSource = types.constant(getEnvironment());
    TypeWidget dynamicLinker = types.adaptInternal(DynamicLinker.class);
    FieldDefinition field = createField(dynamicLinker, "bootstrap");
    field.addModifier(Opcodes.ACC_STATIC | Opcodes.ACC_FINAL);
    MethodGenerator sl = createMethod("<clinit>");
    sl.setModifier(Opcodes.ACC_STATIC);//from ww w  . ja v a2  s .c o  m
    sl.add(classSource);
    sl.add(new BytecodeSequence() {
        @Override
        public void generate(CodeEmitter code) {
            final MethodVisitor mv = code.getMethodVisitor();
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Dynamic.class), "createDynamicLinker",
                    MethodType.methodType(DynamicLinker.class, ASMClassSource.class).toMethodDescriptorString(),
                    false);
            mv.visitFieldInsn(Opcodes.PUTSTATIC, Dynamic.DYNAMIC_INTERNAL_NAME, "bootstrap",
                    Type.getDescriptor(DynamicLinker.class));
            mv.visitInsn(Opcodes.RETURN);

        }
    });

    MethodGenerator mgen = createStaticMethod(Dynamic.DYNAMIC_BOOTSTRAP_METHOD);
    TypeWidget callSite = types.adaptInternal(CallSite.class);
    TypeWidget lookup = types.adaptInternal(MethodHandles.Lookup.class);
    TypeWidget methodType = types.adaptInternal(MethodType.class);
    mgen.setReturnType(callSite);
    AssignableValue lu = mgen.addArgument("lookup", lookup);
    AssignableValue name = mgen.addArgument("name", BaseTypeAdapter.STRING);
    AssignableValue sig = mgen.addArgument("sig", methodType);
    final String desc = MethodType.methodType(CallSite.class, // ...that will return a CallSite object, ...
            MethodHandles.Lookup.class, // ... when given a lookup object, ...
            String.class, // ... the operation name, ...
            MethodType.class, // ... and the signature at the call site.
            DynamicLinker.class).toMethodDescriptorString();

    mgen.add(lu.read());
    mgen.add(name.read());
    mgen.add(sig.read());

    mgen.add(new BytecodeSequence() {
        @Override
        public void generate(CodeEmitter code) {
            final MethodVisitor mv = code.getMethodVisitor();
            mv.visitFieldInsn(Opcodes.GETSTATIC, Dynamic.DYNAMIC_INTERNAL_NAME, "bootstrap",
                    Type.getDescriptor(DynamicLinker.class));
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Dynamic.class), "link", desc, false);
            mv.visitInsn(Opcodes.ARETURN);
        }
    });

}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.UnitGenerator.java

public void generate(ClassSink cws) {
    if (constructors.size() == 0) {
        createConstructor();//from www.j  ava 2s. com
    }

    ClassVisitor cw = cws.create(internalName);
    String[] interfaceList = null;
    if (interfaces.size() > 0) {
        interfaceList = new String[interfaces.size()];
        for (int i = 0; i < interfaces.size(); ++i) {
            interfaceList[i] = interfaces.get(i).getInternalName();
        }
    }
    cw.visit(V1_7, ACC_PUBLIC | ACC_FINAL | ACC_SUPER, internalName, null, superInternalName, interfaceList);

    annotations.generateAnnotations(cw);
    {
        FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$TYPE$",
                Type.getDescriptor(TypeWidget.class), null, null);
        fv.visitEnd();
    }

    for (Map.Entry<String, FieldDefinition> e : fields.entrySet()) {
        e.getValue().generate(cw);
    }

    for (ConstructorGenerator constructor : constructors) {
        constructor.generate(cw);
    }

    for (Map.Entry<String, MethodGenerator> e : methods.entries()) {
        e.getValue().generate(cw);
    }

    cw.visitEnd();
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.FunctionGenerator.java

protected FunctionGenerator(UnitGenerator unit, boolean isStatic) {
    super(unit.getEnvironment());
    this.unit = unit;
    this.intrinsic = new LocalFrame();
    if (isStatic) {
        addModifier(Opcodes.ACC_STATIC);
    } else {//from   w  ww  .  ja  va2s.  c  o m
        intrinsic.allocate("this", unit.getType());
    }
    this.arguments = new LocalFrame(intrinsic);
    this.code = new LocalBatchCode(arguments);
}

From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java

License:Open Source License

/**
 * Creates text representation of asm method access flag.
 * //from   ww w  .j  a v a  2  s .  co m
 * @param flag asm method access flag
 * @return formatted string representing the access flag
 */
public static String formatMethodAccessFlags(int flag) {
    List<String> accesses = new ArrayList<>();
    if ((flag & Opcodes.ACC_PUBLIC) != 0) {
        accesses.add("public");
    }
    if ((flag & Opcodes.ACC_PROTECTED) != 0) {
        accesses.add("protected");
    }
    if ((flag & Opcodes.ACC_PRIVATE) != 0) {
        accesses.add("private");
    }
    if ((flag & Opcodes.ACC_STATIC) != 0) {
        accesses.add("static");
    }
    if ((flag & Opcodes.ACC_ABSTRACT) != 0) {
        accesses.add("abstract");
    }
    if ((flag & Opcodes.ACC_FINAL) != 0) {
        accesses.add("final");
    }
    return join(accesses.toArray(new String[accesses.size()]), " ");
}

From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java

License:Open Source License

/**
 * Creates text representation of asm class access flag.
 * /*from w w w . j  a  va2 s.  c  o m*/
 * @param flag asm class access flag
 * @return formatted string representing the access flag
 */
public static String formatClassAccessFlags(int flag) {
    List<String> accesses = new ArrayList<>();
    if ((flag & Opcodes.ACC_PUBLIC) != 0) {
        accesses.add("public");
    }
    if ((flag & Opcodes.ACC_PROTECTED) != 0) {
        accesses.add("protected");
    }
    if ((flag & Opcodes.ACC_PRIVATE) != 0) {
        accesses.add("private");
    }
    if ((flag & Opcodes.ACC_STATIC) != 0) {
        accesses.add("static");
    }
    if ((flag & Opcodes.ACC_ABSTRACT) != 0) {
        accesses.add("abstract");
    }
    if ((flag & Opcodes.ACC_FINAL) != 0) {
        accesses.add("final");
    }
    if ((flag & Opcodes.ACC_ENUM) != 0) {
        accesses.add("enum");
    } else if ((flag & Opcodes.ACC_INTERFACE) != 0) {
        accesses.add("interface");
    } else {
        accesses.add("class");
    }
    return join(accesses.toArray(new String[accesses.size()]), " ");
}

From source file:de.scoopgmbh.copper.instrument.BuildStackInfoAdapter.java

License:Apache License

private static void testClass(File file, final String className) throws IOException, FileNotFoundException {
    ClassReader cr = new ClassReader(new FileInputStream(file));
    ClassWriter cw = new ClassWriter(0);
    final String cDesc = Type.getObjectType(className).getDescriptor();
    ClassVisitor cv = new ClassVisitor(ASM4, cw) {

        @Override/*from  ww  w.  j  a  v  a2  s  . com*/
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            if (logger.isDebugEnabled())
                logger.debug("=======>" + access + " " + name + " " + desc + " " + signature);
            return new BuildStackInfoAdapter(cDesc, (access & Opcodes.ACC_STATIC) > 0, name, desc, signature);
        }

        @Override
        public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) {
            if (logger.isDebugEnabled())
                logger.debug("== VISIT INNER =======>" + arg0 + " " + arg1 + " " + arg2 + " " + arg3);
            super.visitInnerClass(arg0, arg1, arg2, arg3);
        }

    };
    cr.accept(cv, 0);
}

From source file:de.scoopgmbh.copper.instrument.MethodInfo.java

License:Apache License

public String getDeclaration() {
    StringBuilder sb = new StringBuilder();
    if ((access & Opcodes.ACC_PRIVATE) != 0)
        sb.append("private ");
    if ((access & Opcodes.ACC_PROTECTED) != 0)
        sb.append("protected ");
    if ((access & Opcodes.ACC_PUBLIC) != 0)
        sb.append("public ");
    if ((access & Opcodes.ACC_STATIC) != 0)
        sb.append("static ");
    if ((access & Opcodes.ACC_FINAL) != 0)
        sb.append("final ");
    sb.append(Type.getReturnType(descriptor).getClassName()).append(' ').append(methodName).append('(');

    boolean first = true;
    for (Type t : Type.getArgumentTypes(descriptor)) {
        if (!first)
            sb.append(", ");
        first = false;/*from   w  w  w . j a  v a 2 s.c o m*/
        sb.append(t.getClassName());
    }
    sb.append(')');
    return sb.toString();
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.MutationsCollectorClassAdapter.java

License:Open Source License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    if ((access & Opcodes.ACC_STATIC) != 0) {
        staticVariables.add(new VariableInfo(name, desc));
    }//  w ww.  j a va2  s .  c  o  m
    return super.visitField(access, name, desc, signature, value);

}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceVariables.VariableScannerAdapter.java

License:Open Source License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    if ((access & Opcodes.ACC_STATIC) != 0) {
        staticVariables.add(new VariableInfo(name, desc));
    } else {/*from  w w w. j  a  v  a  2 s .co m*/
        classVariables.add(new VariableInfo(name, desc));
    }
    return super.visitField(access, name, desc, signature, value);
}