Example usage for org.objectweb.asm Opcodes V1_4

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

Introduction

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

Prototype

int V1_4

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

Click Source Link

Usage

From source file:br.usp.each.saeg.badua.core.internal.ContentTypeDetector.java

License:Open Source License

private static int determineType(final InputStream in) throws IOException {
    final int header = readInt(in);
    switch (header) {
    case ZIPFILE:
        return ZIPFILE;
    case PACK200FILE:
        return PACK200FILE;
    case CLASSFILE:
        // also verify version to distinguish from Mach Object files:
        switch (readInt(in)) {
        case Opcodes.V1_1:
        case Opcodes.V1_2:
        case Opcodes.V1_3:
        case Opcodes.V1_4:
        case Opcodes.V1_5:
        case Opcodes.V1_6:
        case Opcodes.V1_7:
        case Opcodes.V1_8:
            return CLASSFILE;
        }/*from   ww w.  j av a2  s .co m*/
    }
    if ((header & 0xffff0000) == GZFILE) {
        return GZFILE;
    }
    return UNKNOWN;
}

From source file:com.android.build.gradle.shrinker.parser.ProguardFlags.java

License:Apache License

public void target(@NonNull String target) {
    int version;//w  w  w .j av a 2  s. c  om
    switch (target) {
    case "8":
    case "1.8":
        version = Opcodes.V1_8;
        break;
    case "7":
    case "1.7":
        version = Opcodes.V1_7;
        break;
    case "6":
    case "1.6":
        version = Opcodes.V1_6;
        break;
    case "5":
    case "1.5":
        version = Opcodes.V1_5;
        break;
    case "1.4":
        version = Opcodes.V1_4;
        break;
    case "1.3":
        version = Opcodes.V1_3;
        break;
    case "1.2":
        version = Opcodes.V1_2;
        break;
    case "1.1":
        version = Opcodes.V1_1;
        break;
    default:
        throw new AssertionError("Unknown target " + target);
    }

    this.bytecodeVersion = new BytecodeVersion(version);
}

From source file:com.facebook.buck.jvm.java.abi.ClassVisitorDriverFromElement.java

License:Apache License

/** Gets the class file version corresponding to the given source version constant. */
private static int sourceVersionToClassFileVersion(SourceVersion version) {
    switch (version) {
    case RELEASE_0:
        return Opcodes.V1_1; // JVMS8 4.1: 1.0 and 1.1 both support version 45.3 (Opcodes.V1_1)
    case RELEASE_1:
        return Opcodes.V1_1;
    case RELEASE_2:
        return Opcodes.V1_2;
    case RELEASE_3:
        return Opcodes.V1_3;
    case RELEASE_4:
        return Opcodes.V1_4;
    case RELEASE_5:
        return Opcodes.V1_5;
    case RELEASE_6:
        return Opcodes.V1_6;
    case RELEASE_7:
        return Opcodes.V1_7;
    case RELEASE_8:
        return Opcodes.V1_8;
    default:/*from  ww w  .  jav  a  2s.  c  o m*/
        throw new IllegalArgumentException(String.format("Unexpected source version: %s", version));
    }
}

From source file:com.facebook.buck.jvm.java.abi.SourceVersionUtils.java

License:Apache License

/** Gets the class file version corresponding to the given source version constant. */
public static int sourceVersionToClassFileVersion(SourceVersion version) {
    switch (version) {
    case RELEASE_0:
        return Opcodes.V1_1; // JVMS8 4.1: 1.0 and 1.1 both support version 45.3 (Opcodes.V1_1)
    case RELEASE_1:
        return Opcodes.V1_1;
    case RELEASE_2:
        return Opcodes.V1_2;
    case RELEASE_3:
        return Opcodes.V1_3;
    case RELEASE_4:
        return Opcodes.V1_4;
    case RELEASE_5:
        return Opcodes.V1_5;
    case RELEASE_6:
        return Opcodes.V1_6;
    case RELEASE_7:
        return Opcodes.V1_7;
    case RELEASE_8:
        return Opcodes.V1_8;
    default://from  w  w  w . j  a v  a  2s  .  com
        throw new IllegalArgumentException(String.format("Unexpected source version: %s", version));
    }
}

From source file:erjang.EFun.java

License:Apache License

public static EFun get_fun_with_handler(String module, String function, int arity, EFunHandler handler,
        ClassLoader loader) {// w  w  w. jav a 2s .co m
    String signature = module + function + arity;
    Constructor<? extends EFun> h = handlers.get(signature);

    if (h == null) {

        get_fun_class(arity);

        String safe_function = JAVA_ID.matcher(function).matches() ? function : make_valid_java_id(function);
        StringBuffer sb = new StringBuffer();
        String self_type = sb.append(EFUN_TYPE.getInternalName()).append(module).append(safe_function)
                .append("Handler").append(arity).toString();

        ClassWriter cw = new ClassWriter(true);
        String super_class_name = EFUN_TYPE.getInternalName() + arity;
        cw.visit(Opcodes.V1_4, ACC_PUBLIC, self_type, null, super_class_name, null);

        // create handler field
        cw.visitField(ACC_PRIVATE, "handler", EFUNHANDLER_TYPE.getDescriptor(), null, null).visitEnd();
        cw.visitField(ACC_PRIVATE | ACC_FINAL, "module_name", EATOM_DESC, null, null).visitEnd();
        cw.visitField(ACC_PRIVATE | ACC_FINAL, "function_name", EATOM_DESC, null, null).visitEnd();

        // make constructor
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(" + EFUNHANDLER_TYPE.getDescriptor() + ")V",
                null, null);
        mv.visitCode();

        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, super_class_name, "<init>", "()V");

        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitFieldInsn(PUTFIELD, self_type, "handler", EFUNHANDLER_TYPE.getDescriptor());
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(module);
        mv.visitMethodInsn(INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern",
                "(Ljava/lang/String;)Lerjang/EAtom;");
        mv.visitFieldInsn(PUTFIELD, self_type, "module_name", EATOM_DESC);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(function);
        mv.visitMethodInsn(INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern",
                "(Ljava/lang/String;)Lerjang/EAtom;");
        mv.visitFieldInsn(PUTFIELD, self_type, "function_name", EATOM_DESC);

        mv.visitInsn(RETURN);
        mv.visitMaxs(3, 3);
        mv.visitEnd();

        /** forward toString to handler */
        mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0); // load self
        mv.visitFieldInsn(GETFIELD, self_type, "handler", EFUNHANDLER_TYPE.getDescriptor());
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;");
        mv.visitInsn(ARETURN);
        mv.visitMaxs(3, 3);
        mv.visitEnd();

        // make invoke_tail method
        //CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0);
        make_invoke_method(cw, self_type, arity);
        make_go_method(cw, self_type, arity);
        make_encode_method(cw, self_type, arity);

        cw.visitEnd();
        byte[] data = cw.toByteArray();

        data = weave(data);

        Class<? extends EFun> clazz = ERT.defineClass(loader, self_type.replace('/', '.'), data);

        try {
            h = clazz.getConstructor(EFunHandler.class);
        } catch (Exception e) {
            throw new Error(e);
        }

        handlers.put(signature, h);
    }

    try {
        return h.newInstance(handler);
    } catch (Exception e) {
        throw new Error(e);
    }
}

From source file:erjang.ETuple.java

License:Apache License

static byte[] make_tuple_class_data(int num_cells) {
    ClassWriter cww = new ClassWriter(true);

    CheckClassAdapter cw = new CheckClassAdapter(cww);

    String this_class_name = ETUPLE_NAME + num_cells;
    String super_class_name = ETUPLE_NAME;
    cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, this_class_name, null, super_class_name,
            null);// w w  w  . j av  a2  s .  c  o  m

    // create fields

    for (int i = 1; i <= num_cells; i++) {
        cw.visitField(Opcodes.ACC_PUBLIC, "elem" + i, ETERM_TYPE.getDescriptor(), null, null);
    }

    // create count method
    create_count(cw, num_cells);

    // create cast method
    create_cast(cw, num_cells);
    create_cast2(cw, num_cells);

    // create constructor
    create_constructor(cw, super_class_name);

    // create copy
    create_tuple_copy(num_cells, cw, this_class_name, super_class_name);

    // create nth
    create_tuple_nth(num_cells, cw, this_class_name);

    // create set
    create_tuple_set(num_cells, cw, this_class_name);

    cw.visitEnd();
    byte[] data = cww.toByteArray();

    // dump(this_class_name, data);

    return data;
}

From source file:org.apache.tuscany.sdo.codegen.BytecodeInterfaceGenerator.java

License:Apache License

public void visitType(Type type) {
    String name = type.getName();
    int lastDot = name.lastIndexOf('.');
    if (lastDot != -1) {
        name = name.replace('.', '/');
    } else {//from w  ww .j a  v  a 2  s  . c o m
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
    }

    List baseTypes = type.getBaseTypes();
    String[] interfaces = new String[baseTypes.size()];
    for (int i = 0; i < baseTypes.size(); i++) {
        Type baseType = (Type) baseTypes.get(i);
        interfaces[i] = baseType.getInstanceClass().getName().replace('.', '/');
    }

    cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, name, null,
            "java/lang/Object", interfaces);
}

From source file:org.codehaus.groovy.reflection.MethodHandleFactory.java

License:Apache License

private static byte[] genMethodHandle(Method method, ClassWriter cw, String name) {
    cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC, name.replace('.', '/'), null,
            "org/codehaus/groovy/reflection/MethodHandle", null);

    genConstructor(cw, "org/codehaus/groovy/reflection/MethodHandle");

    genInvokeXxxWithArray(cw, method);/*  w ww  . j  av  a  2s .com*/
    genInvokeWithFixedParams(cw, method);
    genInvokeWithFixedPrimitiveParams(cw, method);

    cw.visitEnd();

    return cw.toByteArray();
}

From source file:org.codehaus.groovy.reflection.SunClassLoader.java

License:Apache License

private void loadMagic() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC, "sun/reflect/GroovyMagic", null, "sun/reflect/MagicAccessorImpl",
            null);//from   w  w w.  j av  a2  s. c  om
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "sun/reflect/MagicAccessorImpl", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();

    define(cw.toByteArray(), "sun.reflect.GroovyMagic");
}

From source file:org.codehaus.groovy.runtime.callsite.CallSiteGenerator.java

License:Apache License

private static void classHeader(ClassWriter cw, String internalName, String superName) {
    if (VMPluginFactory.getPlugin().getVersion() >= 8) {
        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, internalName, null, superName, null);
    } else {//from   w w w .j  a  v  a  2  s .  co m
        cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, internalName, null, superName, null);
    }
}