Example usage for org.objectweb.asm Opcodes V1_2

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

Introduction

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

Prototype

int V1_2

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

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;
        }//  w ww  . j  a  v  a 2s.c  o 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;//from  ww  w .  j  a v a  2s.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:/*  w  w w .  j av  a  2 s . co 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:/*  w  ww .j a v a 2 s .  co  m*/
        throw new IllegalArgumentException(String.format("Unexpected source version: %s", version));
    }
}

From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java

License:Open Source License

private void generateStub() throws IOException {
    stubname = fullclassname + "_Stub";
    String stubclassname = classname + "_Stub";
    File file = new File((destination == null ? "." : destination) + File.separator
            + stubname.replace('.', File.separatorChar) + ".class");

    if (verbose)/*  www . j  a v a2 s  . c o  m*/
        System.out.println("[Generating class " + stubname + "]");

    final ClassWriter stub = new ClassWriter(true);
    classInternalName = stubname.replace('.', '/');
    final String superInternalName = Type.getType(RemoteStub.class).getInternalName();

    String[] remoteInternalNames = internalNameArray((Class[]) mRemoteInterfaces.toArray(new Class[] {}));
    stub.visit(Opcodes.V1_2, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, classInternalName, null, superInternalName,
            remoteInternalNames);

    if (need12Stubs) {
        stub.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "serialVersionUID",
                Type.LONG_TYPE.getDescriptor(), null, new Long(2L));
    }

    if (need11Stubs) {
        stub.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "interfaceHash",
                Type.LONG_TYPE.getDescriptor(), null, new Long(RMIHashes.getInterfaceHash(clazz)));

        if (need12Stubs) {
            stub.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "useNewInvoke",
                    Type.BOOLEAN_TYPE.getDescriptor(), null, null);
        }

        stub.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "operations",
                Type.getDescriptor(Operation[].class), null, null);
    }

    // Set of method references.
    if (need12Stubs) {
        for (int i = 0; i < remotemethods.length; i++) {
            Method m = remotemethods[i].meth;
            String slotName = "$method_" + m.getName() + "_" + i;
            stub.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, slotName,
                    Type.getDescriptor(Method.class), null, null);
        }
    }

    MethodVisitor clinit = stub.visitMethod(Opcodes.ACC_STATIC, "<clinit>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);

    if (need11Stubs) {
        fillOperationArray(clinit);
        if (!need12Stubs)
            clinit.visitInsn(Opcodes.RETURN);
    }

    if (need12Stubs) {
        // begin of try
        Label begin = new Label();

        // beginning of catch
        Label handler = new Label();
        clinit.visitLabel(begin);

        // Initialize the methods references.
        if (need11Stubs) {
            /*
             * RemoteRef.class.getMethod("invoke", new Class[] {
             *   Remote.class, Method.class, Object[].class, long.class })
             */
            generateClassConstant(clinit, RemoteRef.class);
            clinit.visitLdcInsn("invoke");
            generateClassArray(clinit, new Class[] { Remote.class, Method.class, Object[].class, long.class });
            clinit.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Class.class), "getMethod",
                    Type.getMethodDescriptor(Type.getType(Method.class),
                            new Type[] { Type.getType(String.class), Type.getType(Class[].class) }));

            // useNewInvoke = true
            clinit.visitInsn(Opcodes.ICONST_1);
            clinit.visitFieldInsn(Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
                    Type.BOOLEAN_TYPE.getDescriptor());
        }

        generateStaticMethodObjs(clinit);

        // jump past handler
        clinit.visitInsn(Opcodes.RETURN);
        clinit.visitLabel(handler);
        if (need11Stubs) {
            // useNewInvoke = false
            clinit.visitInsn(Opcodes.ICONST_0);
            clinit.visitFieldInsn(Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
                    Type.BOOLEAN_TYPE.getDescriptor());
            clinit.visitInsn(Opcodes.RETURN);
        } else {
            // throw NoSuchMethodError
            clinit.visitTypeInsn(Opcodes.NEW, typeArg(NoSuchMethodError.class));
            clinit.visitInsn(Opcodes.DUP);
            clinit.visitLdcInsn("stub class initialization failed");
            clinit.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(NoSuchMethodError.class),
                    "<init>",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
            clinit.visitInsn(Opcodes.ATHROW);
        }

        clinit.visitTryCatchBlock(begin, handler, handler, Type.getInternalName(NoSuchMethodException.class));

    }

    clinit.visitMaxs(-1, -1);

    generateClassForNamer(stub);

    // Constructors
    if (need11Stubs) {
        // no arg public constructor
        MethodVisitor code = stub.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
        code.visitVarInsn(Opcodes.ALOAD, 0);
        code.visitMethodInsn(Opcodes.INVOKESPECIAL, superInternalName, "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
        code.visitInsn(Opcodes.RETURN);

        code.visitMaxs(-1, -1);
    }

    // public RemoteRef constructor
    MethodVisitor constructor = stub.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(RemoteRef.class) }), null, null);
    constructor.visitVarInsn(Opcodes.ALOAD, 0);
    constructor.visitVarInsn(Opcodes.ALOAD, 1);
    constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, superInternalName, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(RemoteRef.class) }));
    constructor.visitInsn(Opcodes.RETURN);
    constructor.visitMaxs(-1, -1);

    // Method implementations
    for (int i = 0; i < remotemethods.length; i++) {
        Method m = remotemethods[i].meth;
        Class[] sig = m.getParameterTypes();
        Class returntype = m.getReturnType();
        Class[] except = sortExceptions((Class[]) remotemethods[i].exceptions.toArray(new Class[0]));

        MethodVisitor code = stub.visitMethod(Opcodes.ACC_PUBLIC, m.getName(),
                Type.getMethodDescriptor(Type.getType(returntype), typeArray(sig)), null,
                internalNameArray(typeArray(except)));

        final Variables var = new Variables();

        // this and parameters are the declared vars
        var.declare("this");
        for (int j = 0; j < sig.length; j++)
            var.declare(param(m, j), size(sig[j]));

        Label methodTryBegin = new Label();
        code.visitLabel(methodTryBegin);

        if (need12Stubs) {
            Label oldInvoke = new Label();
            if (need11Stubs) {
                // if not useNewInvoke jump to old invoke
                code.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, "useNewInvoke",
                        Type.getDescriptor(boolean.class));
                code.visitJumpInsn(Opcodes.IFEQ, oldInvoke);
            }

            // this.ref
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
            code.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class), "ref",
                    Type.getDescriptor(RemoteRef.class));

            // "this" is first arg to invoke
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));

            // method object is second arg to invoke
            String methName = "$method_" + m.getName() + "_" + i;
            code.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, methName,
                    Type.getDescriptor(Method.class));

            // args to remote method are third arg to invoke
            if (sig.length == 0)
                code.visitInsn(Opcodes.ACONST_NULL);
            else {
                // create arg Object[] (with boxed primitives) and push it
                code.visitLdcInsn(new Integer(sig.length));
                code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Object.class));

                var.allocate("argArray");
                code.visitVarInsn(Opcodes.ASTORE, var.get("argArray"));

                for (int j = 0; j < sig.length; j++) {
                    int size = size(sig[j]);
                    int insn = loadOpcode(sig[j]);
                    Class box = sig[j].isPrimitive() ? box(sig[j]) : null;

                    code.visitVarInsn(Opcodes.ALOAD, var.get("argArray"));
                    code.visitLdcInsn(new Integer(j));

                    // put argument on stack
                    if (box != null) {
                        code.visitTypeInsn(Opcodes.NEW, typeArg(box));
                        code.visitInsn(Opcodes.DUP);
                        code.visitVarInsn(insn, var.get(param(m, j)));
                        code.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(box), "<init>",
                                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(sig[j]) }));
                    } else
                        code.visitVarInsn(insn, var.get(param(m, j)));

                    code.visitInsn(Opcodes.AASTORE);
                }

                code.visitVarInsn(Opcodes.ALOAD, var.deallocate("argArray"));
            }

            // push remote operation opcode
            code.visitLdcInsn(new Long(remotemethods[i].hash));
            code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteRef.class), "invoke",
                    Type.getMethodDescriptor(Type.getType(Object.class),
                            new Type[] { Type.getType(Remote.class), Type.getType(Method.class),
                                    Type.getType(Object[].class), Type.LONG_TYPE }));

            if (!returntype.equals(Void.TYPE)) {
                int retcode = returnOpcode(returntype);
                Class boxCls = returntype.isPrimitive() ? box(returntype) : null;
                code.visitTypeInsn(Opcodes.CHECKCAST, typeArg(boxCls == null ? returntype : boxCls));
                if (returntype.isPrimitive()) {
                    // unbox
                    code.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(boxCls).getInternalName(),
                            unboxMethod(returntype),
                            Type.getMethodDescriptor(Type.getType(returntype), new Type[] {}));
                }

                code.visitInsn(retcode);
            } else
                code.visitInsn(Opcodes.RETURN);

            if (need11Stubs)
                code.visitLabel(oldInvoke);
        }

        if (need11Stubs) {

            // this.ref.newCall(this, operations, index, interfaceHash)
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
            code.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class), "ref",
                    Type.getDescriptor(RemoteRef.class));

            // "this" is first arg to newCall
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));

            // operations is second arg to newCall
            code.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, "operations",
                    Type.getDescriptor(Operation[].class));

            // method index is third arg
            code.visitLdcInsn(new Integer(i));

            // interface hash is fourth arg
            code.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, "interfaceHash",
                    Type.LONG_TYPE.getDescriptor());

            code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteRef.class), "newCall",
                    Type.getMethodDescriptor(Type.getType(RemoteCall.class),
                            new Type[] { Type.getType(RemoteObject.class), Type.getType(Operation[].class),
                                    Type.INT_TYPE, Type.LONG_TYPE }));

            // store call object on stack and leave copy on stack
            var.allocate("call");
            code.visitInsn(Opcodes.DUP);
            code.visitVarInsn(Opcodes.ASTORE, var.get("call"));

            Label beginArgumentTryBlock = new Label();
            code.visitLabel(beginArgumentTryBlock);

            // ObjectOutput out = call.getOutputStream();
            code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteCall.class),
                    "getOutputStream",
                    Type.getMethodDescriptor(Type.getType(ObjectOutput.class), new Type[] {}));

            for (int j = 0; j < sig.length; j++) {
                // dup the ObjectOutput
                code.visitInsn(Opcodes.DUP);

                // get j'th arg to remote method
                code.visitVarInsn(loadOpcode(sig[j]), var.get(param(m, j)));

                Class argCls = sig[j].isPrimitive() ? sig[j] : Object.class;

                // out.writeFoo
                code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(ObjectOutput.class),
                        writeMethod(sig[j]),
                        Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(argCls) }));
            }

            // pop ObjectOutput
            code.visitInsn(Opcodes.POP);

            Label iohandler = new Label();
            Label endArgumentTryBlock = new Label();
            code.visitJumpInsn(Opcodes.GOTO, endArgumentTryBlock);
            code.visitLabel(iohandler);

            // throw new MarshalException(msg, ioexception);
            code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
            code.visitTypeInsn(Opcodes.NEW, typeArg(MarshalException.class));
            code.visitInsn(Opcodes.DUP);
            code.visitLdcInsn("error marshalling arguments");
            code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
            code.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(MarshalException.class), "<init>",
                    Type.getMethodDescriptor(Type.VOID_TYPE,
                            new Type[] { Type.getType(String.class), Type.getType(Exception.class) }));
            code.visitInsn(Opcodes.ATHROW);

            code.visitLabel(endArgumentTryBlock);
            code.visitTryCatchBlock(beginArgumentTryBlock, iohandler, iohandler,
                    Type.getInternalName(IOException.class));

            // this.ref.invoke(call)
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
            code.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class), "ref",
                    Type.getDescriptor(RemoteRef.class));
            code.visitVarInsn(Opcodes.ALOAD, var.get("call"));
            code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteRef.class), "invoke",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(RemoteCall.class) }));

            // handle return value
            boolean needcastcheck = false;

            Label beginReturnTryCatch = new Label();
            code.visitLabel(beginReturnTryCatch);

            int returncode = returnOpcode(returntype);

            if (!returntype.equals(Void.TYPE)) {
                // call.getInputStream()
                code.visitVarInsn(Opcodes.ALOAD, var.get("call"));
                code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteCall.class),
                        "getInputStream",
                        Type.getMethodDescriptor(Type.getType(ObjectInput.class), new Type[] {}));

                Class readCls = returntype.isPrimitive() ? returntype : Object.class;
                code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(ObjectInput.class),
                        readMethod(returntype), Type.getMethodDescriptor(Type.getType(readCls), new Type[] {}));

                boolean castresult = false;

                if (!returntype.isPrimitive()) {
                    if (!returntype.equals(Object.class))
                        castresult = true;
                    else
                        needcastcheck = true;
                }

                if (castresult)
                    code.visitTypeInsn(Opcodes.CHECKCAST, typeArg(returntype));

                // leave result on stack for return
            }

            // this.ref.done(call)
            code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
            code.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class), "ref",
                    Type.getDescriptor(RemoteRef.class));
            code.visitVarInsn(Opcodes.ALOAD, var.deallocate("call"));
            code.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteRef.class), "done",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(RemoteCall.class) }));

            // return; or return result;
            code.visitInsn(returncode);

            // exception handler
            Label handler = new Label();
            code.visitLabel(handler);
            code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));

            // throw new UnmarshalException(msg, e)
            code.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class));
            code.visitInsn(Opcodes.DUP);
            code.visitLdcInsn("error unmarshalling return");
            code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
            code.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(UnmarshalException.class),
                    "<init>", Type.getMethodDescriptor(Type.VOID_TYPE,
                            new Type[] { Type.getType(String.class), Type.getType(Exception.class) }));
            code.visitInsn(Opcodes.ATHROW);

            Label endReturnTryCatch = new Label();

            // catch IOException
            code.visitTryCatchBlock(beginReturnTryCatch, handler, handler,
                    Type.getInternalName(IOException.class));

            if (needcastcheck) {
                // catch ClassNotFoundException
                code.visitTryCatchBlock(beginReturnTryCatch, handler, handler,
                        Type.getInternalName(ClassNotFoundException.class));
            }
        }

        Label rethrowHandler = new Label();
        code.visitLabel(rethrowHandler);
        // rethrow declared exceptions
        code.visitInsn(Opcodes.ATHROW);

        boolean needgeneral = true;
        for (int j = 0; j < except.length; j++) {
            if (except[j] == Exception.class)
                needgeneral = false;
        }

        for (int j = 0; j < except.length; j++) {
            code.visitTryCatchBlock(methodTryBegin, rethrowHandler, rethrowHandler,
                    Type.getInternalName(except[j]));
        }

        if (needgeneral) {
            // rethrow unchecked exceptions
            code.visitTryCatchBlock(methodTryBegin, rethrowHandler, rethrowHandler,
                    Type.getInternalName(RuntimeException.class));

            Label generalHandler = new Label();
            code.visitLabel(generalHandler);
            String msg = "undeclared checked exception";

            // throw new java.rmi.UnexpectedException(msg, e)
            code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
            code.visitTypeInsn(Opcodes.NEW, typeArg(UnexpectedException.class));
            code.visitInsn(Opcodes.DUP);
            code.visitLdcInsn(msg);
            code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
            code.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(UnexpectedException.class),
                    "<init>", Type.getMethodDescriptor(Type.VOID_TYPE,
                            new Type[] { Type.getType(String.class), Type.getType(Exception.class) }));
            code.visitInsn(Opcodes.ATHROW);

            code.visitTryCatchBlock(methodTryBegin, rethrowHandler, generalHandler,
                    Type.getInternalName(Exception.class));
        }

        code.visitMaxs(-1, -1);
    }

    stub.visitEnd();
    byte[] classData = stub.toByteArray();
    if (!noWrite) {
        if (file.exists())
            file.delete();
        if (file.getParentFile() != null)
            file.getParentFile().mkdirs();
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(classData);
        fos.flush();
        fos.close();
    }
}

From source file:org.jacoco.core.internal.analysis.ContentTypeDetector.java

License:Open Source License

private static int determineType(final InputStream in) throws IOException {
    switch (readInt(in)) {
    case ZIPFILE:
        return ZIPFILE;
    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:
            return CLASSFILE;
        }/* w w  w .jav a  2s.  c  o m*/
    }
    return UNKNOWN;
}

From source file:org.jacoco.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:
            return CLASSFILE;
        }/* w  w w .  j  av  a 2 s. co m*/
    }
    if ((header & 0xffff0000) == GZFILE) {
        return GZFILE;
    }
    return UNKNOWN;
}

From source file:org.jacoco.core.internal.instr.ProbeArrayStrategyFactoryTest.java

License:Open Source License

@Test
public void testClass2() {
    final IProbeArrayStrategy strategy = test(Opcodes.V1_2, 0, false, true, true);
    assertEquals(ClassFieldProbeArrayStrategy.class, strategy.getClass());
    assertDataField(InstrSupport.DATAFIELD_ACC);
    assertInitMethod(false);//from  w w w .ja v  a2s  . co m
}

From source file:scouter.agent.AgentTransformer.java

License:Apache License

private ClassWriter getClassWriter(final ClassDesc classDesc) {
    ClassWriter cw;/*  www  .  j  a  va2  s.  c  om*/
    switch (classDesc.version) {
    case Opcodes.V1_1:
    case Opcodes.V1_2:
    case Opcodes.V1_3:
    case Opcodes.V1_4:
    case Opcodes.V1_5:
    case Opcodes.V1_6:
        cw = new ScouterClassWriter(ClassWriter.COMPUTE_MAXS);
        break;
    default:
        cw = new ScouterClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    }
    return cw;
}