List of usage examples for org.objectweb.asm Opcodes BIPUSH
int BIPUSH
To view the source code for org.objectweb.asm Opcodes BIPUSH.
Click Source Link
From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java
License:Open Source License
/** * Checks if node is bipush./* w ww . ja va 2 s. c o m*/ * * @param node * the node * @return true if node is bipush */ public static boolean isBipush(final AbstractInsnNode node) { if (node == null) { return false; } return node.getOpcode() == Opcodes.BIPUSH; }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
private void callLogPrototype(String traceMethod, PDType type) { if (type != PDType.LONG && type != PDType.DOUBLE) { this.visitInsn(Opcodes.DUP); if (type == PDType.FLOAT) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "floatToRawIntBits", "(F)I"); }//from ww w.j a va 2s . c o m } else { this.visitInsn(Opcodes.DUP2); if (type == PDType.DOUBLE) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "doubleToRawLongBits", "(D)J"); } this.visitInsn(Opcodes.DUP2); this.visitIntInsn(Opcodes.BIPUSH, 32); this.visitInsn(Opcodes.LSHR); this.visitInsn(Opcodes.LXOR); this.visitInsn(Opcodes.L2I); } this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitInsn(Opcodes.SWAP); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, traceMethod, "(ILjava/lang/String;Ljava/lang/String;)V"); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.AbstractRicMethodAdapter.java
License:Open Source License
@Override public void visitIntInsn(int opcode, int operand) { if (mutationCode) { super.visitIntInsn(opcode, operand); return;/*from w w w .j av a 2 s . co m*/ } if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) { intConstant(operand); if (forwardCalls) { super.visitIntInsn(opcode, operand); } } else { super.visitIntInsn(opcode, operand); } }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.RicMethodAdapter.java
License:Open Source License
@Override public void visitIntInsn(int opcode, int operand) { if (mutationCode) { super.visitIntInsn(opcode, operand); return;//from w w w.j av a 2 s. com } if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) { intConstant(operand); } else { super.visitIntInsn(opcode, operand); } }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.IntPush.java
License:Open Source License
public IntPush(final ReadMethod readMethod, final int opcode, final int operand, final int lineNumber) { super(readMethod, opcode, lineNumber); assert opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH; this.operand = operand; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.IntPush.java
License:Open Source License
private IntPush(final ReadMethod readMethod, final int lineNumber, final int opcode, final int operand, final int index) { super(readMethod, opcode, lineNumber, index); assert opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH; this.operand = operand; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.IntPush.java
License:Open Source License
@Override public String toString() { return new StringBuilder(18).append(getOpcode() == Opcodes.BIPUSH ? "BIPUSH " : "SIPUSH ") .append(this.operand).toString(); }
From source file:dodola.anole.lib.InstantRunTransform.java
License:Apache License
/** * Use asm to generate a concrete subclass of the AppPathLoaderImpl class. * It only implements one method ://w ww . j a va2 s . com * String[] getPatchedClasses(); * <p> * The method is supposed to return the list of classes that were patched in this iteration. * This will be used by the InstantRun runtime to load all patched classes and register them * as overrides on the original classes.2 class files. * * @param patchFileContents list of patched class names. * @param outputDir output directory where to generate the .class file in. * @return the generated .class files */ public static File writePatchFileContents(List<String> patchFileContents, File outputDir) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, IncrementalVisitor.APP_PATCHES_LOADER_IMPL, null, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, null); { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPatchedClasses", "()[Ljava/lang/String;", null, null); mv.visitCode(); mv.visitIntInsn(Opcodes.BIPUSH, patchFileContents.size()); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String"); for (int index = 0; index < patchFileContents.size(); index++) { mv.visitInsn(Opcodes.DUP); mv.visitIntInsn(Opcodes.BIPUSH, index); mv.visitLdcInsn(patchFileContents.get(index)); mv.visitInsn(Opcodes.AASTORE); } mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(4, 1); mv.visitEnd(); } cw.visitEnd(); byte[] classBytes = cw.toByteArray(); File outputFile = new File(outputDir, IncrementalVisitor.APP_PATCHES_LOADER_IMPL + ".class"); try { Files.createParentDirs(outputFile); Files.write(classBytes, outputFile); // add the files to the list of files to be processed by subsequent tasks. return outputFile; } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:edu.illinois.nondex.instr.PriorityBlockingQueueShufflingAdder.java
License:Open Source License
public void addToString() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode();/*from w ww . j a va 2s . c o m*/ Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, null); Label l3 = new Label(); Label l4 = new Label(); mv.visitTryCatchBlock(l3, l4, l2, null); Label l5 = new Label(); mv.visitTryCatchBlock(l2, l5, l2, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "lock", "Ljava/util/concurrent/locks/ReentrantLock;"); mv.visitVarInsn(Opcodes.ASTORE, 1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lock", "()V", false); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "size", "I"); mv.visitVarInsn(Opcodes.ISTORE, 2); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitJumpInsn(Opcodes.IFNE, l3); mv.visitLdcInsn("[]"); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER }, 0, null); mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 91); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "queue", "[Ljava/lang/Object;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "[Ljava/lang/Object;", "clone", "()Ljava/lang/Object;", false); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 5); Label l6 = new Label(); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] { "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitVarInsn(Opcodes.ILOAD, 2); Label l7 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l7); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitVarInsn(Opcodes.ALOAD, 0); Label l8 = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, l8); mv.visitLdcInsn("(this Collection)"); Label l9 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l9); mv.visitLabel(l8); mv.visitFrame(Opcodes.F_FULL, 7, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" }, 1, new Object[] { "java/lang/StringBuilder" }); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitLabel(l9); mv.visitFrame(Opcodes.F_FULL, 7, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" }, 2, new Object[] { "java/lang/StringBuilder", "java/lang/Object" }); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); Label l10 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l10); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 44); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitIntInsn(Opcodes.BIPUSH, 32); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitInsn(Opcodes.POP); mv.visitLabel(l10); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitIincInsn(5, 1); mv.visitJumpInsn(Opcodes.GOTO, l6); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitIntInsn(Opcodes.BIPUSH, 93); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitVarInsn(Opcodes.ASTORE, 5); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 5); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { "java/util/concurrent/PriorityBlockingQueue", "java/util/concurrent/locks/ReentrantLock" }, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitLabel(l5); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V", false); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitInsn(Opcodes.ATHROW); mv.visitMaxs(3, 8); mv.visitEnd(); }
From source file:edu.mit.streamjit.impl.common.MessageConstraint.java
License:Open Source License
/** * Parse the given getHandle() call instruction and preceding instructions * into a WorkerData. This is a rather brittle pattern-matching job and * will fail on obfuscated bytecodes./*from w w w . j a va 2s . com*/ * @param call * @return */ private static WorkerData dataFromCall(Class<?> klass, MethodInsnNode call) { //Latency is either an integer constant or a getfield on this. Field latencyField = null; int constantLatency = Integer.MIN_VALUE; AbstractInsnNode latencyInsn = call.getPrevious(); if (latencyInsn instanceof FieldInsnNode) { FieldInsnNode fieldInsn = (FieldInsnNode) latencyInsn; if (fieldInsn.getOpcode() != Opcodes.GETFIELD) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": latency field insn opcode " + fieldInsn.getOpcode()); if (!fieldInsn.desc.equals(Type.INT_TYPE.getDescriptor())) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": latency field desc " + fieldInsn.desc); if (!fieldInsn.owner.equals(Type.getType(klass).getInternalName())) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": latency field owner " + fieldInsn.owner); //Move latencyInsn to sync up with the other else-if branches. latencyInsn = latencyInsn.getPrevious(); //We must be loading from this. if (latencyInsn.getOpcode() != Opcodes.ALOAD) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": getfield subject opcode " + latencyInsn.getOpcode()); int varIdx = ((VarInsnNode) latencyInsn).var; if (varIdx != 0) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": getfield not from this but from " + varIdx); //Check the field we're loading from is constant (final). //A static field is okay here since it isn't a reference parameter. try { latencyField = klass.getDeclaredField(fieldInsn.name); if (!Modifier.isFinal(latencyField.getModifiers())) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": latency field not final: " + latencyField.toGenericString()); } catch (NoSuchFieldException ex) { throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": getfield not from this but from " + varIdx); } } else if (latencyInsn instanceof LdcInsnNode) { Object constant = ((LdcInsnNode) latencyInsn).cst; if (!(constant instanceof Integer)) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": ldc " + constant); constantLatency = ((Integer) constant); } else switch (latencyInsn.getOpcode()) { case Opcodes.ICONST_M1: constantLatency = -1; break; case Opcodes.ICONST_0: constantLatency = 0; break; case Opcodes.ICONST_1: constantLatency = 1; break; case Opcodes.ICONST_2: constantLatency = 2; break; case Opcodes.ICONST_3: constantLatency = 3; break; case Opcodes.ICONST_4: constantLatency = 4; break; case Opcodes.ICONST_5: constantLatency = 5; break; case Opcodes.BIPUSH: case Opcodes.SIPUSH: constantLatency = ((IntInsnNode) latencyInsn).operand; break; default: throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": latencyInsn opcode " + latencyInsn.getOpcode()); } //Finally, we've parsed the latency parameter. //Next is an aload_0 for the sender parameter. AbstractInsnNode senderInsn = latencyInsn.getPrevious(); if (senderInsn.getOpcode() != Opcodes.ALOAD || ((VarInsnNode) senderInsn).var != 0) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": bad sender"); //Finally, a getfield of this for a final Portal instance field. AbstractInsnNode portalInsn = senderInsn.getPrevious(); if (!(portalInsn instanceof FieldInsnNode)) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal getfield opcode " + portalInsn.getOpcode()); FieldInsnNode fieldInsn = (FieldInsnNode) portalInsn; if (fieldInsn.getOpcode() != Opcodes.GETFIELD) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal field insn opcode " + fieldInsn.getOpcode()); if (!fieldInsn.desc.equals(Type.getType(Portal.class).getDescriptor())) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": portal field desc " + fieldInsn.desc); if (!fieldInsn.owner.equals(Type.getType(klass).getInternalName())) throw new IllegalStreamGraphException( "Unsupported getHandle() use in " + klass + ": portal field owner " + fieldInsn.owner); portalInsn = portalInsn.getPrevious(); //We must be loading from this. if (portalInsn.getOpcode() != Opcodes.ALOAD) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal getfield subject opcode " + portalInsn.getOpcode()); int varIdx = ((VarInsnNode) portalInsn).var; if (varIdx != 0) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal getfield not from this but from " + varIdx); //Check the field we're loading from is constant (final) and nonstatic. Field portalField; try { portalField = klass.getDeclaredField(fieldInsn.name); if (!Modifier.isFinal(portalField.getModifiers())) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal field not final: " + portalField.toGenericString()); if (Modifier.isStatic(portalField.getModifiers())) throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal field is static: " + portalField.toGenericString()); } catch (NoSuchFieldException ex) { throw new IllegalStreamGraphException("Unsupported getHandle() use in " + klass + ": portal getfield not from this but from " + varIdx); } return latencyField != null ? new WorkerData(portalField, latencyField) : new WorkerData(portalField, constantLatency); }