List of usage examples for org.objectweb.asm Opcodes ACONST_NULL
int ACONST_NULL
To view the source code for org.objectweb.asm Opcodes ACONST_NULL.
Click Source Link
From source file:de.fhkoeln.gm.cui.javahardener.CheckNullMethodVisitor.java
License:Open Source License
/** * Push the default value to the stack for the given type. * /*from w ww . j a va 2s .c o m*/ * @param type */ private void pushDefault(Type type) { switch (type.getSort()) { case Type.VOID: break; case Type.BOOLEAN: super.visitIntInsn(Opcodes.BIPUSH, 0); // Push false to the stack break; case Type.BYTE: super.visitIntInsn(Opcodes.BIPUSH, 0); // Push byte 0 to the stack break; case Type.CHAR: super.visitIntInsn(Opcodes.BIPUSH, 0); // Push char 0 to the stack break; case Type.SHORT: super.visitIntInsn(Opcodes.SIPUSH, 0); // Push short 0 to the stack break; case Type.INT: super.visitInsn(Opcodes.ICONST_0); // Push int 0 to the stack break; case Type.FLOAT: super.visitInsn(Opcodes.FCONST_0); // Push float 0 to the stack break; case Type.LONG: super.visitInsn(Opcodes.LCONST_0); // Push long 0 to the stack break; case Type.DOUBLE: super.visitInsn(Opcodes.DCONST_0); // Push double 0 to the stack break; default: super.visitInsn(Opcodes.ACONST_NULL); // Push NULL to the stack break; } }
From source file:de.tuberlin.uebb.jbop.optimizer.array.FieldArrayValueInliner.java
License:Open Source License
private void handleValue(final InsnList newList, final AbstractInsnNode aload, final ArrayHelper arrayHelper, final ListIterator<AbstractInsnNode> iterator) throws JBOPClassException { final Object value = arrayHelper.getValue(instance); final AbstractInsnNode replacementNode; if (value == null) { replacementNode = new InsnNode(Opcodes.ACONST_NULL); } else if ((value instanceof Number)) { replacementNode = NodeHelper.getInsnNodeFor((Number) value); } else if (value instanceof String) { replacementNode = new LdcInsnNode(value); } else {//from w ww .ja va2 s.c om moveIterator(iterator, arrayHelper); final GetFieldChainInliner fieldChainInliner = new GetFieldChainInliner(); fieldChainInliner.setIterator(iterator); fieldChainInliner.setInputObject(value); fieldChainInliner.optimize(newList, null); if (fieldChainInliner.isOptimized()) { // the new valuenode is already put in the list, the chain-nodes are consumed. // but aload, getfield... have to be removed yet. replacementNode = null; } else { // this is not a value we can handle, but its definitly not null. final NonNullArrayValue arrayValue = new NonNullArrayValue(aload, arrayHelper.getFieldNode(), arrayHelper.getIndexes(), arrayHelper.getArrayloads()); nonNullArrayValues.add(arrayValue); return; } } replaceNodes(newList, aload, arrayHelper, replacementNode, iterator); }
From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInliner.java
License:Open Source License
private boolean handleNullInstruction(final AbstractInsnNode currentNode, final AbstractInsnNode node1, final InsnList list, final Iterator<AbstractInsnNode> iterator) throws JBOPClassException { if ((currentNode.getOpcode() == Opcodes.IFNULL) || (currentNode.getOpcode() == Opcodes.IFNONNULL)) { final boolean eval; if (node1.getOpcode() == Opcodes.ACONST_NULL) { if (!checkNullInstruction(node1, currentNode, list, iterator)) { return false; }/* www .j a v a2s . co m*/ eval = evalSingleOpValue(null, currentNode.getOpcode()); } else { final AbstractInsnNode node2 = NodeHelper.getPrevious(node1); if (!checkNumberInstruction(node1, node2, currentNode, list, iterator)) { return false; } // doesn't work for multiarrays yet final AbstractInsnNode node3 = NodeHelper.getPrevious(node2); final AbstractInsnNode node4 = NodeHelper.getPrevious(node3); boolean isNonNullArrayValue = false; if (arrayValue != null) { for (final NonNullArrayValue nonNullarrayValue : arrayValue.getNonNullArrayValues()) { if (nonNullarrayValue.is(node4, node3, Arrays.asList(node2), Arrays.asList(node1))) { isNonNullArrayValue = true; break; } } } if (!isNonNullArrayValue) { return false; } if (node2 != null) { list.remove(node2); } if (node3 != null) { list.remove(node3); } if (node4 != null) { list.remove(node4); } eval = evalSingleOpValue(NONNULL, currentNode.getOpcode()); } removeNodes(currentNode, node1, null, null, list, iterator, eval); return true; } return false; }
From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java
License:Open Source License
/** * Tests that constantIfInliner is working correctly. * //w w w. j ava 2 s . co m * Input is * * <pre> * if(a==null) * ... * </pre> * * where a is null * * @throws JBOPClassException * the jBOP class exception */ @Test public void testConstantIfInlinerIFNONNULL() throws JBOPClassException { // INIT final LabelNode label = new LabelNode(); builder.addInsn(new InsnNode(Opcodes.ACONST_NULL)).// addInsn(new JumpInsnNode(Opcodes.IFNONNULL, label)).// addInsn(new InsnNode(Opcodes.NOP)).// addInsn(label).// addInsn(new InsnNode(Opcodes.RETURN)); // RUN assertEquals(5, method.instructions.size()); final InsnList optimized = constantIfInliner.optimize(method.instructions, method); // ASSERT assertEquals(3, optimized.size()); assertEquals(Opcodes.NOP, optimized.get(0).getOpcode()); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.SimpleInstruction.java
License:Open Source License
@Override public String toString() { switch (getOpcode()) { // the not interesting ones: case Opcodes.NOP: return "NOP"; // constants: case Opcodes.ACONST_NULL: return "ACONST_NULL"; case Opcodes.ICONST_M1: return "ICONST_M1"; case Opcodes.ICONST_0: return "ICONST_0"; case Opcodes.ICONST_1: return "ICONST_1"; case Opcodes.ICONST_2: return "ICONST_2"; case Opcodes.ICONST_3: return "ICONST_3"; case Opcodes.ICONST_4: return "ICONST_4"; case Opcodes.ICONST_5: return "ICONST_5"; case Opcodes.LCONST_0: return "LCONST_0"; case Opcodes.LCONST_1: return "LCONST_1"; case Opcodes.FCONST_0: return "FCONST_0"; case Opcodes.FCONST_1: return "FCONST_1"; case Opcodes.FCONST_2: return "FCONST_2"; case Opcodes.DCONST_0: return "DCONST_0"; case Opcodes.DCONST_1: return "DCONST_1"; // array load: case Opcodes.IALOAD: return "IALOAD"; case Opcodes.LALOAD: return "LALOAD"; case Opcodes.FALOAD: return "FALOAD"; case Opcodes.DALOAD: return "DALOAD"; case Opcodes.AALOAD: return "AALOAD"; case Opcodes.BALOAD: return "BALOAD"; case Opcodes.CALOAD: return "CALOAD"; case Opcodes.SALOAD: return "SALOAD"; // array store: case Opcodes.IASTORE: return "IASTORE"; case Opcodes.LASTORE: return "LASTORE"; case Opcodes.FASTORE: return "FASTORE"; case Opcodes.DASTORE: return "DASTORE"; case Opcodes.AASTORE: return "AASTORE"; case Opcodes.BASTORE: return "BASTORE"; case Opcodes.CASTORE: return "CASTORE"; case Opcodes.SASTORE: return "SASTORE"; // stack manipulation: case Opcodes.POP: return "POP"; case Opcodes.POP2: return "POP2"; case Opcodes.DUP: return "DUP"; case Opcodes.DUP_X1: return "DUP_X1"; case Opcodes.DUP_X2: return "DUP_X2"; case Opcodes.DUP2: return "DUP2"; case Opcodes.DUP2_X1: return "DUP2_X1"; case Opcodes.DUP2_X2: return "DUP2_X2"; case Opcodes.SWAP: return "SWAP"; // arithmetic: case Opcodes.IADD: return "IADD"; case Opcodes.LADD: return "LADD"; case Opcodes.FADD: return "FADD"; case Opcodes.DADD: return "DADD"; case Opcodes.ISUB: return "ISUB"; case Opcodes.LSUB: return "LSUB"; case Opcodes.FSUB: return "FSUB"; case Opcodes.DSUB: return "DSUB"; case Opcodes.IMUL: return "IMUL"; case Opcodes.LMUL: return "LMUL"; case Opcodes.FMUL: return "FMUL"; case Opcodes.DMUL: return "DMUL"; case Opcodes.IDIV: return "IDIV"; case Opcodes.LDIV: return "LDIV"; case Opcodes.FDIV: return "FDIV"; case Opcodes.DDIV: return "DDIV"; case Opcodes.IREM: return "IREM"; case Opcodes.LREM: return "LREM"; case Opcodes.FREM: return "FREM"; case Opcodes.DREM: return "DREM"; case Opcodes.INEG: return "INEG"; case Opcodes.LNEG: return "LNEG"; case Opcodes.FNEG: return "FNEG"; case Opcodes.DNEG: return "DNEG"; case Opcodes.ISHL: return "ISHL"; case Opcodes.LSHL: return "LSHL"; case Opcodes.ISHR: return "ISHR"; case Opcodes.LSHR: return "LSHR"; case Opcodes.IUSHR: return "IUSHR"; case Opcodes.LUSHR: return "LUSHR"; case Opcodes.IAND: return "IAND"; case Opcodes.LAND: return "LAND"; case Opcodes.IOR: return "IOR"; case Opcodes.LOR: return "LOR"; case Opcodes.IXOR: return "IXOR"; case Opcodes.LXOR: return "LXOR"; // type conversions: case Opcodes.I2L: return "I2L"; case Opcodes.I2F: return "I2F"; case Opcodes.I2D: return "I2D"; case Opcodes.L2I: return "L2I"; case Opcodes.L2F: return "L2F"; case Opcodes.L2D: return "L2D"; case Opcodes.F2I: return "F2I"; case Opcodes.F2L: return "F2L"; case Opcodes.F2D: return "F2D"; case Opcodes.D2I: return "D2I"; case Opcodes.D2L: return "D2L"; case Opcodes.D2F: return "D2F"; case Opcodes.I2B: return "I2B"; case Opcodes.I2C: return "I2C"; case Opcodes.I2S: return "I2S"; // comparison: case Opcodes.LCMP: return "LCMP"; case Opcodes.FCMPL: return "FCMPL"; case Opcodes.FCMPG: return "FCMPG"; case Opcodes.DCMPL: return "DCMPL"; case Opcodes.DCMPG: return "DCMPG"; // control-flow statements: case Opcodes.IRETURN: return "IRETURN"; case Opcodes.LRETURN: return "LRETURN"; case Opcodes.FRETURN: return "FRETURN"; case Opcodes.DRETURN: return "DRETURN"; case Opcodes.ARETURN: return "ARETURN"; case Opcodes.RETURN: return "RETURN"; // special things case Opcodes.ARRAYLENGTH: return "ARRAYLENGTH"; case Opcodes.ATHROW: return "ATHROW"; case Opcodes.MONITORENTER: return "MONITORENTER"; case Opcodes.MONITOREXIT: return "MONITOREXIT"; default:/*from w w w .j a v a2s.c o m*/ assert false; return "--ERROR--"; } }
From source file:dodola.anole.lib.IncrementalChangeVisitor.java
License:Apache License
/** * To each class, add the dispatch method called by the original code that acts as a trampoline to * invoke the changed methods.//from www.j ava 2 s.c om * <p/> * Pseudo code: * <code> * Object access$dispatch(String name, object[] args) { * if (name.equals( * "firstMethod.(L$type;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;")) { * return firstMethod(($type)arg[0], (String)arg[1], arg[2]); * } * if (name.equals("secondMethod.(L$type;Ljava/lang/String;I;)V")) { * secondMethod(($type)arg[0], (String)arg[1], (int)arg[2]); * return; * } * ... * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " + visitedClassName + * "$dispatch implementation, restart the application"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void addDispatchMethod() { int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_VARARGS; Method m = new Method("access$dispatch", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); if (TRACING_ENABLED) { mv.push("Redirecting "); mv.loadArg(0); trace(mv, 2); } List<MethodNode> allMethods = new ArrayList<MethodNode>(); // if we are disabled, do not generate any dispatch, the method will throw an exception // if invoked which should never happen. if (!instantRunDisabled) { //noinspection unchecked allMethods.addAll(classNode.methods); allMethods.addAll(addedMethods); } final Map<String, MethodNode> methods = new HashMap<String, MethodNode>(); for (MethodNode methodNode : allMethods) { if (methodNode.name.equals("<clinit>") || methodNode.name.equals("<init>")) { continue; } if (!isAccessCompatibleWithInstantRun(methodNode.access)) { continue; } methods.put(methodNode.name + "." + methodNode.desc, methodNode); } new StringSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitCase(String methodName) { MethodNode methodNode = methods.get(methodName); String name = methodNode.name; boolean isStatic = (methodNode.access & Opcodes.ACC_STATIC) != 0; String newDesc = computeOverrideMethodDesc(methodNode.desc, isStatic); if (TRACING_ENABLED) { trace(mv, "M: " + name + " P:" + newDesc); } Type[] args = Type.getArgumentTypes(newDesc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } mv.visitMethodInsn(Opcodes.INVOKESTATIC, visitedClassName + "$override", isStatic ? computeOverrideMethodName(name, methodNode.desc) : name, newDesc, false); Type ret = Type.getReturnType(methodNode.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, methods.keySet()); mv.visitMaxs(0, 0); mv.visitEnd(); super.visitEnd(); }
From source file:dodola.anole.lib.IncrementalSupportVisitor.java
License:Apache License
/*** * Inserts a trampoline to this class so that the updated methods can make calls to super * class methods./*from w ww. j ava 2s . co m*/ * <p/> * Pseudo code for this trampoline: * <code> * Object access$super($classType instance, String name, object[] args) { * switch(name) { * case "firstMethod.(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;": * return super~instance.firstMethod((String)arg[0], arg[1]); * case "secondMethod.(Ljava/lang/String;I)V": * return super~instance.firstMethod((String)arg[0], arg[1]); * <p> * default: * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " $classType $super implementation"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void createAccessSuper() { int access = Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_VARARGS; Method m = new Method("access$super", "(L" + visitedClassName + ";Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); // Gather all methods from itself and its superclasses to generate a giant access$super // implementation. // This will work fine as long as we don't support adding methods to a class. final Map<String, MethodReference> uniqueMethods = new HashMap<String, MethodReference>(); if (parentNodes.isEmpty()) { // if we cannot determine the parents for this class, let's blindly add all the // method of the current class as a gateway to a possible parent version. addAllNewMethods(uniqueMethods, classNode); } else { // otherwise, use the parent list. for (ClassNode parentNode : parentNodes) { addAllNewMethods(uniqueMethods, parentNode); } } new StringSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitCase(String methodName) { MethodReference methodRef = uniqueMethods.get(methodName); mv.visitVarInsn(Opcodes.ALOAD, 0); Type[] args = Type.getArgumentTypes(methodRef.method.desc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } if (TRACING_ENABLED) { trace(mv, "super selected ", methodRef.owner.name, methodRef.method.name, methodRef.method.desc); } // Call super on the other object, yup this works cos we are on the right place to // call from. mv.visitMethodInsn(Opcodes.INVOKESPECIAL, methodRef.owner.name, methodRef.method.name, methodRef.method.desc, false); Type ret = Type.getReturnType(methodRef.method.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, uniqueMethods.keySet()); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java
License:BSD License
@Override public void visitInsn(final int opcode) { super.visitInsn(opcode); switch (opcode) { case Opcodes.IRETURN: // 1 before n/a after case Opcodes.FRETURN: // 1 before n/a after case Opcodes.ARETURN: // 1 before n/a after case Opcodes.ATHROW: // 1 before n/a after this.stackFrame.pop(); break;// w ww . j a v a 2 s. c o m case Opcodes.LRETURN: // 2 before n/a after case Opcodes.DRETURN: // 2 before n/a after this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.NOP: case Opcodes.LALOAD: // remove 2 add 2 case Opcodes.DALOAD: // remove 2 add 2 case Opcodes.LNEG: case Opcodes.DNEG: case Opcodes.FNEG: case Opcodes.INEG: case Opcodes.L2D: case Opcodes.D2L: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.I2F: case Opcodes.ARRAYLENGTH: break; case Opcodes.ACONST_NULL: case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: case Opcodes.F2L: // 1 before 2 after case Opcodes.F2D: case Opcodes.I2L: case Opcodes.I2D: this.stackFrame.push(OTHER); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: case Opcodes.DCONST_0: case Opcodes.DCONST_1: this.stackFrame.push(OTHER); this.stackFrame.push(OTHER); break; case Opcodes.IALOAD: // remove 2 add 1 case Opcodes.FALOAD: // remove 2 add 1 case Opcodes.AALOAD: // remove 2 add 1 case Opcodes.BALOAD: // remove 2 add 1 case Opcodes.CALOAD: // remove 2 add 1 case Opcodes.SALOAD: // remove 2 add 1 case Opcodes.POP: case Opcodes.IADD: case Opcodes.FADD: case Opcodes.ISUB: case Opcodes.LSHL: // 3 before 2 after case Opcodes.LSHR: // 3 before 2 after case Opcodes.LUSHR: // 3 before 2 after case Opcodes.L2I: // 2 before 1 after case Opcodes.L2F: // 2 before 1 after case Opcodes.D2I: // 2 before 1 after case Opcodes.D2F: // 2 before 1 after case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: case Opcodes.FCMPL: // 2 before 1 after case Opcodes.FCMPG: // 2 before 1 after case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.IUSHR: case Opcodes.IAND: case Opcodes.IOR: case Opcodes.IXOR: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: this.stackFrame.pop(); break; case Opcodes.POP2: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LOR: case Opcodes.LXOR: case Opcodes.DADD: case Opcodes.DMUL: case Opcodes.DSUB: case Opcodes.DDIV: case Opcodes.DREM: this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.IASTORE: case Opcodes.FASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.LCMP: // 4 before 1 after case Opcodes.DCMPL: case Opcodes.DCMPG: this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.LASTORE: case Opcodes.DASTORE: this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.DUP: this.stackFrame.push(this.stackFrame.peek()); break; case Opcodes.DUP_X1: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); break; } case Opcodes.DUP_X2: { final int _s = stackFrame.size(); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2_X1: { final int _s = stackFrame.size(); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2_X2: { final int _s = stackFrame.size(); stackFrame.add(_s - 4, stackFrame.get(_s - 1)); stackFrame.add(_s - 4, stackFrame.get(_s - 1)); break; } case Opcodes.SWAP: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); stackFrame.remove(_s); break; } } }
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
@Override public final void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if (this.cv.cmdLineOptions.traceFieldAccess) { final Type _fieldType = Type.getType(desc); final String _fieldId = this.cv.getFieldId(name, owner, desc); final boolean _isFieldStatic = opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC; if (opcode == Opcodes.GETSTATIC || opcode == Opcodes.GETFIELD) { if (_isFieldStatic) super.visitInsn(Opcodes.ACONST_NULL); else if (this.thisInitialized) super.visitInsn(Opcodes.DUP); else { super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS); super.visitInsn(Opcodes.SWAP); }//from ww w. j ava 2 s . c o m super.visitFieldInsn(opcode, owner, name, desc); LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.GETF); } else if (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.PUTFIELD) { if (_isFieldStatic) { super.visitInsn(Opcodes.ACONST_NULL); } else if (this.thisInitialized) { LoggingHelper.emitSwapTwoWordsAndOneWord(this.mv, _fieldType); final int _fieldSort = _fieldType.getSort(); if (_fieldSort == Type.LONG || _fieldSort == Type.DOUBLE) super.visitInsn(Opcodes.DUP_X2); else super.visitInsn(Opcodes.DUP_X1); } else { super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS); } LoggingHelper.emitSwapOneWordAndTwoWords(this.mv, _fieldType); LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.PUTF); super.visitFieldInsn(opcode, owner, name, desc); } } else super.visitFieldInsn(opcode, owner, name, desc); }
From source file:edu.illinois.nondex.instr.PriorityQueueShufflingAdder.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if ("hasNext".equals(name)) { return super.visitMethod(access, "originalHasNext", desc, signature, exceptions); }//from w w w. ja va 2 s. c om if ("next".equals(name)) { return super.visitMethod(access, "originalNext", desc, signature, exceptions); } if ("<init>".equals(name)) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { @Override public void visitInsn(int opcode) { if (opcode == Opcodes.RETURN) { super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, 1); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "this$0", "Ljava/util/PriorityQueue;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ICONST_0); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "cursor", "I"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ICONST_M1); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ACONST_NULL); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "forgetMeNot", "Ljava/util/ArrayDeque;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ACONST_NULL); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "this$0", "Ljava/util/PriorityQueue;"); super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue", "modCount", "I"); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "expectedModCount", "I"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList"); super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "elements", "Ljava/util/List;"); Label l0 = new Label(); super.visitLabel(l0); super.visitFrame(Opcodes.F_FULL, 2, new Object[] { "java/util/PriorityQueue$Itr", "java/util/PriorityQueue" }, 0, new Object[] {}); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/PriorityQueue$Itr", "originalHasNext", "()Z", false); Label l1 = new Label(); super.visitJumpInsn(Opcodes.IFEQ, l1); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements", "Ljava/util/List;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/PriorityQueue$Itr", "originalNext", "()Ljava/lang/Object;", false); super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); super.visitInsn(Opcodes.POP); super.visitJumpInsn(Opcodes.GOTO, l0); super.visitLabel(l1); super.visitFrame(Opcodes.F_SAME, 0, null, 0, null); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements", "Ljava/util/List;"); super.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle", "(Ljava/util/List;)Ljava/util/List;", false); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "elements", "Ljava/util/List;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements", "Ljava/util/List;"); super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "iterator", "()Ljava/util/Iterator;", true); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "iter", "Ljava/util/Iterator;"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ICONST_M1); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I"); super.visitVarInsn(Opcodes.ALOAD, 0); super.visitInsn(Opcodes.ACONST_NULL); super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;"); } super.visitInsn(opcode); } }; } return super.visitMethod(access, name, desc, signature, exceptions); }