List of usage examples for org.objectweb.asm Opcodes V1_1
int V1_1
To view the source code for org.objectweb.asm Opcodes V1_1.
Click Source Link
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 w w. 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 w w w . java2 s.c o m*/ 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.electriccloud.maven.javac2.Javac2MojoSupport.java
License:Open Source License
/** * @param version/*from ww w. ja v a 2 s . co m*/ * * @return the flags for class writer */ private static int getAsmClassWriterFlags(int version) { return version >= Opcodes.V1_6 && version != Opcodes.V1_1 ? ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS; }
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 w w w.j av a 2s . com*/ 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. ja v a 2 s . com throw new IllegalArgumentException(String.format("Unexpected source version: %s", version)); } }
From source file:com.intellij.AbstractNotNullInstrumenterTask.java
License:Apache License
private boolean instrumentClass(@NotNull final File file, @NotNull final InstrumentationClassFinder finder) throws java.io.IOException { final FileInputStream inputStream = new FileInputStream(file); try {//from w w w . ja v a 2s. c om ClassReader reader = new ClassReader(inputStream); int version = getClassFileVersion(reader); if (version != Opcodes.V1_1 && version >= Opcodes.V1_5) { ClassWriter writer = new InstrumenterClassWriter(getAsmClassWriterFlags(version), finder); final NotNullVerifyingInstrumenter instrumenter = new NotNullVerifyingInstrumenter(writer); reader.accept(instrumenter, 0); if (instrumenter.isModification()) { final FileOutputStream fileOutputStream = new FileOutputStream(file); try { fileOutputStream.write(writer.toByteArray()); return true; } finally { fileOutputStream.close(); } } } } finally { inputStream.close(); } return false; }
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 .c o 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:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//w w w . j ava2 s . c o m this.name = name; this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0; this.superName = getHologramSuperclassName(isInterface, name, superName); interfaces = getHologramInterfaces(name, isInterface, interfaces); // Force everything to be public, since HologramClassLoader has to reflectively // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead. // Also remove enum flags. int hologramAccess = forcePublic(access); // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least) // creates objects that claim to be an instance of VirtualMachineError, which is abstract. if (name.equals("hologram/java/lang/VirtualMachineError")) { hologramAccess = ~Opcodes.ACC_ABSTRACT & access; } // We need at least 1.5 to use class literal constants // TODO-RS: Work out a better way to interpret 45.X numbers correctly if (version == Opcodes.V1_1 || version < Opcodes.V1_5) { version = 49; } super.visit(version, hologramAccess, name, signature, this.superName, interfaces); if (this.name.equals(hologramThrowableType.getInternalName())) { // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods, // so we can call them in stubs without hitting hologram code. MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace", Type.getMethodDescriptor(Type.VOID_TYPE), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace", Type.getMethodDescriptor(Type.getType(Throwable.class))); v.visitInsn(Opcodes.RETURN); v.visitMaxs(1, 1); v.visitEnd(); v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class))); v.visitInsn(Opcodes.ARETURN); v.visitMaxs(1, 1); v.visitEnd(); } }
From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java
License:Open Source License
private void generateSkel() throws IOException { skelname = fullclassname + "_Skel"; String skelclassname = classname + "_Skel"; File file = new File(destination == null ? "" : destination + File.separator + skelname.replace('.', File.separatorChar) + ".class"); if (verbose)//from w ww. j a v a 2s .co m System.out.println("[Generating class " + skelname + "]"); final ClassWriter skel = new ClassWriter(true); classInternalName = skelname.replace('.', '/'); skel.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, classInternalName, Type.getInternalName(Object.class), null, new String[] { Type.getType(Skeleton.class).getInternalName() }); skel.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "interfaceHash", Type.LONG_TYPE.getDescriptor(), null, new Long(RMIHashes.getInterfaceHash(clazz))); skel.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "operations", Type.getDescriptor(Operation[].class), null, null); MethodVisitor clinit = skel.visitMethod(Opcodes.ACC_STATIC, "<clinit>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null); fillOperationArray(clinit); clinit.visitInsn(Opcodes.RETURN); clinit.visitMaxs(-1, -1); // no arg public constructor MethodVisitor init = skel.visitMethod(Opcodes.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null); init.visitVarInsn(Opcodes.ALOAD, 0); init.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {})); init.visitInsn(Opcodes.RETURN); init.visitMaxs(-1, -1); /* * public Operation[] getOperations() * returns a clone of the operations array */ MethodVisitor getOp = skel.visitMethod(Opcodes.ACC_PUBLIC, "getOperations", Type.getMethodDescriptor(Type.getType(Operation[].class), new Type[] {}), null, null); getOp.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, "operations", Type.getDescriptor(Operation[].class)); getOp.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Object.class), "clone", Type.getMethodDescriptor(Type.getType(Object.class), new Type[] {})); getOp.visitTypeInsn(Opcodes.CHECKCAST, typeArg(Operation[].class)); getOp.visitInsn(Opcodes.ARETURN); getOp.visitMaxs(-1, -1); // public void dispatch(Remote, RemoteCall, int opnum, long hash) MethodVisitor dispatch = skel.visitMethod(Opcodes.ACC_PUBLIC, "dispatch", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(Remote.class), Type.getType(RemoteCall.class), Type.INT_TYPE, Type.LONG_TYPE }), null, new String[] { Type.getInternalName(Exception.class) }); Variables var = new Variables(); var.declare("this"); var.declare("remoteobj"); var.declare("remotecall"); var.declare("opnum"); var.declareWide("hash"); /* * if opnum >= 0 * XXX it is unclear why there is handling of negative opnums */ dispatch.visitVarInsn(Opcodes.ILOAD, var.get("opnum")); Label nonNegativeOpnum = new Label(); Label opnumSet = new Label(); dispatch.visitJumpInsn(Opcodes.IFGE, nonNegativeOpnum); for (int i = 0; i < remotemethods.length; i++) { // assign opnum if hash matches supplied hash dispatch.visitVarInsn(Opcodes.LLOAD, var.get("hash")); dispatch.visitLdcInsn(new Long(remotemethods[i].hash)); Label notIt = new Label(); dispatch.visitInsn(Opcodes.LCMP); dispatch.visitJumpInsn(Opcodes.IFNE, notIt); // opnum = <opnum> dispatch.visitLdcInsn(new Integer(i)); dispatch.visitVarInsn(Opcodes.ISTORE, var.get("opnum")); dispatch.visitJumpInsn(Opcodes.GOTO, opnumSet); dispatch.visitLabel(notIt); } // throw new SkeletonMismatchException Label mismatch = new Label(); dispatch.visitJumpInsn(Opcodes.GOTO, mismatch); dispatch.visitLabel(nonNegativeOpnum); // if opnum is already set, check that the hash matches the interface dispatch.visitVarInsn(Opcodes.LLOAD, var.get("hash")); dispatch.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, "interfaceHash", Type.LONG_TYPE.getDescriptor()); dispatch.visitInsn(Opcodes.LCMP); dispatch.visitJumpInsn(Opcodes.IFEQ, opnumSet); dispatch.visitLabel(mismatch); dispatch.visitTypeInsn(Opcodes.NEW, typeArg(SkeletonMismatchException.class)); dispatch.visitInsn(Opcodes.DUP); dispatch.visitLdcInsn("interface hash mismatch"); dispatch.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(SkeletonMismatchException.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class) })); dispatch.visitInsn(Opcodes.ATHROW); // opnum has been set dispatch.visitLabel(opnumSet); dispatch.visitVarInsn(Opcodes.ALOAD, var.get("remoteobj")); dispatch.visitTypeInsn(Opcodes.CHECKCAST, typeArg(clazz)); dispatch.visitVarInsn(Opcodes.ASTORE, var.get("remoteobj")); Label deflt = new Label(); Label[] methLabels = new Label[remotemethods.length]; for (int i = 0; i < methLabels.length; i++) methLabels[i] = new Label(); // switch on opnum dispatch.visitVarInsn(Opcodes.ILOAD, var.get("opnum")); dispatch.visitTableSwitchInsn(0, remotemethods.length - 1, deflt, methLabels); // Method dispatch for (int i = 0; i < remotemethods.length; i++) { dispatch.visitLabel(methLabels[i]); Method m = remotemethods[i].meth; generateMethodSkel(dispatch, m, var); } dispatch.visitLabel(deflt); dispatch.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class)); dispatch.visitInsn(Opcodes.DUP); dispatch.visitLdcInsn("invalid method number"); dispatch.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(UnmarshalException.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class) })); dispatch.visitInsn(Opcodes.ATHROW); dispatch.visitMaxs(-1, -1); skel.visitEnd(); byte[] classData = skel.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:jaspex.transactifier.Transactifier.java
License:Open Source License
private byte[] transactify() throws IOException { final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // Copiar mtodos originais inalterados cr.accept(new ClassVisitor(Opcodes.ASM4) { @Override/*from ww w.j a va 2 s . com*/ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { cw.visit(version, access, name, signature, superName, interfaces); } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (name.equals("<clinit>")) return new EmptyMethodVisitor(); return cw.visitMethod(access, name, desc, signature, exceptions); } @Override public void visitEnd() { cw.visitEnd(); } }, 0); // Varivel que contm o ltimo ClassVisitor da "chain" de classvisitors que servem de filtros ao // ficheiro original ClassVisitor cv = cw; // Mtodos alterados so marcados com $transactional no nome // Este marcador temporrio, e ir ser substituido por $speculative mais frente // Nota: Apenas os mtodos so renomeados, os seus INVOKE* ainda no apontam para os // $transactional; essa alterao feita no SpeculativeTransformer cv = new ClassVisitor(Opcodes.ASM4, cv) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (name.equals("<init>")) { desc = desc.replace(")", "Ljaspex/MARKER/Transactional;)"); } else if (!name.equals("<clinit>")) { name += "$transactional"; } return cv.visitMethod(access, name, desc, signature, exceptions); } }; // Remover ACC_SYNCHRONIZED dos mtodos if (Options.REMOVESYNC || _JDKClass) cv = new RemoveSyncClassVisitor(cv); // Remover MONITORENTER/MONITOREXIT dos mtodos if (Options.REMOVEMONITORS) cv = new GenericMethodVisitorAdapter(cv, RemoveMonitorsClassVisitor.class); // Verificar se existem mtodos com ACC_SYNCHRONIZED ou opcodes MONITORENTER/MONITOREXIT if (!_JDKClass) cv = new CheckMonitorUsage(cv); // Corrigir chamadas a alguns mtodos de java.lang.Object cv = new GenericMethodVisitorAdapter(cv, ChangeObjectMethodsMethodVisitor.class, currentClass); // Adicionar overrides a alguns mtodos de java.lang.Object cv = new AddObjectMethodsClassVisitor(cv, currentClass); // Suporte para Arrays cv = new GenericMethodVisitorAdapter(cv, ChangeArrayAccessMethodVisitor.class, currentClass, _JDKClass); // Adicionar inicializao de offsets usados pela unsafetrans ao clinit da classe // Nota: Visitor tem que estar *depois* do FieldTransactifierClassVisitor if (!_JDKClass) cv = new GenericMethodVisitorAdapter(cv, ChangeClinitMethodVisitor.class, currentClass); // Visitor que cria os fields offset e o staticfieldbase if (!_JDKClass) cv = new FieldTransactifierClassVisitor(cv); // Alterar acessos a fields para passarem pela STM cv = new GenericMethodVisitorAdapter(cv, ChangeFieldAccessMethodVisitor.class, currentClass, _JDKClass); // Modificar string com filename da classe que aparece em excepes if (!_JDKClass) cv = new MarkAsTransactifiedClassVisitor(cv); // Verificar e fazer upgrade da verso da classe, se necessrio if (!_JDKClass) cv = new ClassVisitor(Opcodes.ASM4, cv) { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { // Transactificao precisa de version >= 49, porque usa o MethodVisitor.visitLdcInsn(Type) // MethodVisitor.visitLdcInsn(Type), que s funciona a partir dessa verso dos classfiles. // http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitLdcInsn(java.lang.Object) // http://stackoverflow.com/questions/2784791/ // Caso especial: V1_1 196653, por alguma razo... if (version < Opcodes.V1_5 || version == Opcodes.V1_1) { //Log.debug("Class " + name + " has version " + version + ", upgrading it to Java 5"); version = Opcodes.V1_5; } if (version > Opcodes.V1_6 && !name.startsWith("java/")) { Log.warn("Class " + name + " is compiled for Java 7 or newer"); } super.visit(version, access, name, signature, superName, interfaces); } }; cr.accept(cv, ClassReader.EXPAND_FRAMES); return cw.toByteArray(); }