List of usage examples for org.objectweb.asm Opcodes DASTORE
int DASTORE
To view the source code for org.objectweb.asm Opcodes DASTORE.
Click Source Link
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;//from w ww . j a v a 2 s . c o m case Opcodes.ACONST_NULL: { Operand op = new Operand(); op.setNull(true); push(op); } break; case Opcodes.ICONST_M1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(-1)); push(op); } break; case Opcodes.ICONST_0: { Operand op = new Operand(); op.setConstant(Integer.valueOf(0)); push(op); } break; case Opcodes.ICONST_1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(1)); push(op); } break; case Opcodes.ICONST_2: { Operand op = new Operand(); op.setConstant(Integer.valueOf(2)); push(op); } break; case Opcodes.ICONST_3: { Operand op = new Operand(); op.setConstant(Integer.valueOf(3)); push(op); } break; case Opcodes.ICONST_4: { Operand op = new Operand(); op.setConstant(Integer.valueOf(4)); push(op); } break; case Opcodes.ICONST_5: { Operand op = new Operand(); op.setConstant(Integer.valueOf(5)); push(op); } break; case Opcodes.LCONST_0: { Operand op = new Operand(); op.setConstant(Long.valueOf(0)); push(op); } break; case Opcodes.LCONST_1: { Operand op = new Operand(); op.setConstant(Long.valueOf(1)); push(op); } break; case Opcodes.FCONST_0: { Operand op = new Operand(); op.setConstant(Float.valueOf(0)); push(op); } break; case Opcodes.FCONST_1: { Operand op = new Operand(); op.setConstant(Float.valueOf(1)); push(op); } break; case Opcodes.FCONST_2: { Operand op = new Operand(); op.setConstant(Float.valueOf(2)); push(op); } break; case Opcodes.DCONST_0: { Operand op = new Operand(); op.setConstant(Double.valueOf(0)); push(op); } break; case Opcodes.DCONST_1: { Operand op = new Operand(); op.setConstant(Double.valueOf(1)); push(op); } break; case Opcodes.IALOAD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LALOAD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FALOAD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DALOAD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.AALOAD: { pop2(); Operand op = new Operand(); op.setSignature("Ljava/lang/Object;"); push(op); } break; case Opcodes.BALOAD: { pop2(); Operand op = new Operand(); op.setSignature("B"); push(op); } break; case Opcodes.CALOAD: { pop2(); Operand op = new Operand(); op.setSignature("C"); push(op); } break; case Opcodes.SALOAD: { pop2(); Operand op = new Operand(); op.setSignature("S"); push(op); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: if (stack.size() < 2) { stack.clear(); } else { Operand value = stack.remove(stack.size() - 1); Operand reg = stack.remove(stack.size() - 1); registers.put(Integer.valueOf(reg.getRegister()), value); } break; case Opcodes.POP: pop(); break; case Opcodes.POP2: pop2(); break; case Opcodes.DUP: if (!stack.isEmpty()) { Operand op = stack.get(stack.size() - 1); push(op); } break; case Opcodes.DUP_X1: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } break; case Opcodes.DUP_X2: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 2); String sig = op.getSignature(); op = stack.get(stack.size() - 1); if ("J".equals(sig) || "D".equals(sig)) { stack.add(stack.size() - 2, op); } else if (stack.size() >= 3) { stack.add(stack.size() - 3, op); } } break; case Opcodes.DUP2: if (stack.size() >= 2) { stack.add(stack.get(stack.size() - 2)); stack.add(stack.get(stack.size() - 2)); } break; case Opcodes.DUP2_X1: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 3) { stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); } } else { if (stack.size() >= 2) { stack.add(stack.size() - 2, op); } } } break; case Opcodes.DUP2_X2: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 2) { op = stack.get(stack.size() - 2); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } } } } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 3); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } else { if (stack.size() >= 4) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 4, op); } } } } } break; case Opcodes.SWAP: if (stack.size() >= 2) { Operand op = stack.remove(stack.size() - 1); stack.add(stack.size() - 1, op); } break; case Opcodes.IADD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LADD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FADD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DADD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISUB: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSUB: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FSUB: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DSUB: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IMUL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LMUL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FMUL: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DMUL: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IDIV: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LDIV: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FDIV: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DDIV: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IREM: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LREM: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FREM: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DREM: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.INEG: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LNEG: { pop(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FNEG: { pop(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DNEG: { pop(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISHL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.ISHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IUSHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LUSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IAND: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LAND: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IXOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LXOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.I2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Integer) o).longValue())); } } push(lop); } break; case Opcodes.I2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Integer) o).floatValue())); } } push(fop); } break; case Opcodes.I2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Integer) o).doubleValue())); } } push(dop); } break; case Opcodes.L2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Long) o).intValue())); } } push(iop); } break; case Opcodes.L2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Long) o).floatValue())); } } push(fop); } break; case Opcodes.L2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Long) o).doubleValue())); } } push(dop); } break; case Opcodes.F2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Float) o).intValue())); } } push(iop); } break; case Opcodes.F2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Float) o).longValue())); } } push(lop); } break; case Opcodes.F2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Float) o).doubleValue())); } } push(dop); } break; case Opcodes.D2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Double) o).intValue())); } } push(iop); } break; case Opcodes.D2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Double) o).longValue())); } } push(lop); } break; case Opcodes.D2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Double) o).floatValue())); } } push(fop); } break; case Opcodes.I2B: { Operand bop = new Operand(); bop.setSignature("B"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { bop.setConstant(Byte.valueOf(((Integer) o).byteValue())); } } push(bop); } break; case Opcodes.I2C: { Operand cop = new Operand(); cop.setSignature("C"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { cop.setConstant(Character.valueOf((char) ((Integer) o).intValue())); } } push(cop); } break; case Opcodes.I2S: { Operand sop = new Operand(); sop.setSignature("S"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { sop.setConstant(Short.valueOf((short) ((Integer) o).intValue())); } } push(sop); } break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.FCMPG: case Opcodes.DCMPL: case Opcodes.DCMPG: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: pop(); break; case Opcodes.RETURN: //nop break; case Opcodes.ARRAYLENGTH: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.ATHROW: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: pop(); break; } }
From source file:com.offbynull.coroutines.instrumenter.LocalsStateGenerators.java
License:Open Source License
/** * Generates instructions to save the local variables table. * @param markerType debug marker type//from w w w. ja v a 2 s. c om * @param storageVars variables to store locals in to * @param frame execution frame at the instruction where the local variables table is to be saved * @return instructions to save the local variables table in to an array * @throws NullPointerException if any argument is {@code null} */ public static InsnList saveLocals(MarkerType markerType, StorageVariables storageVars, Frame<BasicValue> frame) { Validate.notNull(markerType); Validate.notNull(storageVars); Validate.notNull(frame); Variable intsVar = storageVars.getIntStorageVar(); Variable floatsVar = storageVars.getFloatStorageVar(); Variable longsVar = storageVars.getLongStorageVar(); Variable doublesVar = storageVars.getDoubleStorageVar(); Variable objectsVar = storageVars.getObjectStorageVar(); int intsCounter = 0; int floatsCounter = 0; int longsCounter = 0; int doublesCounter = 0; int objectsCounter = 0; StorageSizes storageSizes = computeSizes(frame); InsnList ret = new InsnList(); // Create storage arrays and save them in respective storage vars ret.add(merge(debugMarker(markerType, "Saving locals"), mergeIf(intsVar != null, () -> new Object[] { debugMarker(markerType, "Generating ints container (" + storageSizes.getIntsSize() + ")"), new LdcInsnNode(storageSizes.getIntsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT), new VarInsnNode(Opcodes.ASTORE, intsVar.getIndex()) }), mergeIf(floatsVar != null, () -> new Object[] { debugMarker(markerType, "Generating floats container (" + storageSizes.getFloatsSize() + ")"), new LdcInsnNode(storageSizes.getFloatsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_FLOAT), new VarInsnNode(Opcodes.ASTORE, floatsVar.getIndex()) }), mergeIf(longsVar != null, () -> new Object[] { debugMarker(markerType, "Generating longs container (" + storageSizes.getLongsSize() + ")"), new LdcInsnNode(storageSizes.getLongsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_LONG), new VarInsnNode(Opcodes.ASTORE, longsVar.getIndex()) }), mergeIf(doublesVar != null, () -> new Object[] { debugMarker(markerType, "Generating doubles container (" + storageSizes.getDoublesSize() + ")"), new LdcInsnNode(storageSizes.getDoublesSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_DOUBLE), new VarInsnNode(Opcodes.ASTORE, doublesVar.getIndex()) }), mergeIf(objectsVar != null, () -> new Object[] { debugMarker(markerType, "Generating objects container (" + storageSizes.getObjectsSize() + ")"), new LdcInsnNode(storageSizes.getObjectsSize()), new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"), new VarInsnNode(Opcodes.ASTORE, objectsVar.getIndex()) }))); // Save the locals for (int i = 0; i < frame.getLocals(); i++) { BasicValue basicValue = frame.getLocal(i); Type type = basicValue.getType(); // If type == null, basicValue is pointing to uninitialized var -- basicValue.toString() will return '.'. This means that this // slot contains nothing to save. So, skip this slot if we encounter it. if (type == null) { ret.add(debugMarker(markerType, "Skipping uninitialized value at " + i)); continue; } // If type is 'Lnull;', this means that the slot has been assigned null and that "there has been no merge yet that would 'raise' // the type toward some class or interface type" (from ASM mailing list). We know this slot will always contain null at this // point in the code so we can avoid saving it. When we load it back up, we can simply push a null in to that slot, thereby // keeping the same 'Lnull;' type. if ("Lnull;".equals(type.getDescriptor())) { ret.add(debugMarker(markerType, "Skipping null value at " + i)); continue; } // Place item in to appropriate storage array switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: ret.add(debugMarker(markerType, "Inserting int at LVT index " + i + " to storage index " + intsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, intsVar.getIndex())); // [int[]] ret.add(new LdcInsnNode(intsCounter)); // [int[], idx] ret.add(new VarInsnNode(Opcodes.ILOAD, i)); // [int[], idx, val] ret.add(new InsnNode(Opcodes.IASTORE)); // [] intsCounter++; break; case Type.FLOAT: ret.add(debugMarker(markerType, "Inserting float at LVT index " + i + " to storage index " + floatsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, floatsVar.getIndex())); // [float[]] ret.add(new LdcInsnNode(floatsCounter)); // [float[], idx] ret.add(new VarInsnNode(Opcodes.FLOAD, i)); // [float[], idx, val] ret.add(new InsnNode(Opcodes.FASTORE)); // [] floatsCounter++; break; case Type.LONG: ret.add(debugMarker(markerType, "Inserting long at LVT index " + i + " to storage index " + longsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, longsVar.getIndex())); // [long[]] ret.add(new LdcInsnNode(longsCounter)); // [long[], idx] ret.add(new VarInsnNode(Opcodes.LLOAD, i)); // [long[], idx, val] ret.add(new InsnNode(Opcodes.LASTORE)); // [] longsCounter++; break; case Type.DOUBLE: ret.add(debugMarker(markerType, "Inserting double at LVT index " + i + " to storage index " + doublesCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, doublesVar.getIndex())); // [double[]] ret.add(new LdcInsnNode(doublesCounter)); // [double[], idx] ret.add(new VarInsnNode(Opcodes.DLOAD, i)); // [double[], idx, val] ret.add(new InsnNode(Opcodes.DASTORE)); // [] doublesCounter++; break; case Type.ARRAY: case Type.OBJECT: ret.add(debugMarker(markerType, "Inserting object at LVT index " + i + " to storage index " + objectsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, objectsVar.getIndex())); // [Object[]] ret.add(new LdcInsnNode(objectsCounter)); // [Object[], idx] ret.add(new VarInsnNode(Opcodes.ALOAD, i)); // [Object[], idx, val] ret.add(new InsnNode(Opcodes.AASTORE)); // [] objectsCounter++; break; case Type.METHOD: case Type.VOID: default: throw new IllegalStateException(); } } return ret; }
From source file:com.offbynull.coroutines.instrumenter.OperandStackStateGenerators.java
License:Open Source License
/** * Generates instructions to save a certain number of items from the top of the operand stack. * <p>// w ww.j a v a 2 s. co m * The instructions generated here expect the operand stack to be fully loaded. The stack items specified by {@code frame} must actually * all be on the operand stack. * <p> * REMEMBER: The items aren't returned to the operand stack after they've been saved (they have been popped off the stack). If you want * them back on the operand stack, reload using * {@code loadOperandStack(markerType, storageVars, frame, frame.getStackSize() - count, frame.getStackSize() - count, count)}. * @param markerType debug marker type * @param storageVars variables to store operand stack in to * @param frame execution frame at the instruction where the operand stack is to be saved * @param count number of items to store from the stack * @return instructions to save the operand stack to the storage variables * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code size} is larger than the number of items in the stack at {@code frame} (or is negative), * or if {@code count} is larger than {@code top} (or is negative) */ public static InsnList saveOperandStack(MarkerType markerType, StorageVariables storageVars, Frame<BasicValue> frame, int count) { Validate.notNull(markerType); Validate.notNull(storageVars); Validate.notNull(frame); Validate.isTrue(count >= 0); Validate.isTrue(count <= frame.getStackSize()); Variable intsVar = storageVars.getIntStorageVar(); Variable floatsVar = storageVars.getFloatStorageVar(); Variable longsVar = storageVars.getLongStorageVar(); Variable doublesVar = storageVars.getDoubleStorageVar(); Variable objectsVar = storageVars.getObjectStorageVar(); StorageSizes storageSizes = computeSizes(frame, frame.getStackSize() - count, count); int intsCounter = storageSizes.getIntsSize() - 1; int floatsCounter = storageSizes.getFloatsSize() - 1; int longsCounter = storageSizes.getLongsSize() - 1; int doublesCounter = storageSizes.getDoublesSize() - 1; int objectsCounter = storageSizes.getObjectsSize() - 1; InsnList ret = new InsnList(); // Create stack storage arrays and save them ret.add(merge(debugMarker(markerType, "Saving operand stack (" + count + " items)"), mergeIf(storageSizes.getIntsSize() > 0, () -> new Object[] { debugMarker(markerType, "Generating ints container (" + storageSizes.getIntsSize() + ")"), new LdcInsnNode(storageSizes.getIntsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT), new VarInsnNode(Opcodes.ASTORE, intsVar.getIndex()) }), mergeIf(storageSizes.getFloatsSize() > 0, () -> new Object[] { debugMarker(markerType, "Generating floats container (" + storageSizes.getFloatsSize() + ")"), new LdcInsnNode(storageSizes.getFloatsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_FLOAT), new VarInsnNode(Opcodes.ASTORE, floatsVar.getIndex()) }), mergeIf(storageSizes.getLongsSize() > 0, () -> new Object[] { debugMarker(markerType, "Generating longs container (" + storageSizes.getLongsSize() + ")"), new LdcInsnNode(storageSizes.getLongsSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_LONG), new VarInsnNode(Opcodes.ASTORE, longsVar.getIndex()) }), mergeIf(storageSizes.getDoublesSize() > 0, () -> new Object[] { debugMarker(markerType, "Generating doubles container (" + storageSizes.getDoublesSize() + ")"), new LdcInsnNode(storageSizes.getDoublesSize()), new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_DOUBLE), new VarInsnNode(Opcodes.ASTORE, doublesVar.getIndex()) }), mergeIf(storageSizes.getObjectsSize() > 0, () -> new Object[] { debugMarker(markerType, "Generating objects container (" + storageSizes.getObjectsSize() + ")"), new LdcInsnNode(storageSizes.getObjectsSize()), new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"), new VarInsnNode(Opcodes.ASTORE, objectsVar.getIndex()) }))); // Save the stack int start = frame.getStackSize() - 1; int end = frame.getStackSize() - count; for (int i = start; i >= end; i--) { BasicValue basicValue = frame.getStack(i); Type type = basicValue.getType(); // If type is 'Lnull;', this means that the slot has been assigned null and that "there has been no merge yet that would 'raise' // the type toward some class or interface type" (from ASM mailing list). We know this slot will always contain null at this // point in the code so we can avoid saving it (but we still need to do a POP to get rid of it). When we load it back up, we can // simply push a null in to that slot, thereby keeping the same 'Lnull;' type. if ("Lnull;".equals(type.getDescriptor())) { ret.add(debugMarker(markerType, "Skipping null value at " + i)); ret.add(new InsnNode(Opcodes.POP)); continue; } // Convert the item to an object (if not already an object) and stores it in local vars table. Item removed from stack. switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: ret.add(debugMarker(markerType, "Popping/storing int at " + i + " to storage index " + intsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, intsVar.getIndex())); // [val, int[]] ret.add(new InsnNode(Opcodes.SWAP)); // [int[], val] ret.add(new LdcInsnNode(intsCounter)); // [int[], val, idx] ret.add(new InsnNode(Opcodes.SWAP)); // [int[], idx, val] ret.add(new InsnNode(Opcodes.IASTORE)); // [] intsCounter--; break; case Type.FLOAT: ret.add(debugMarker(markerType, "Popping/storing float at " + i + " to storage index " + floatsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, floatsVar.getIndex())); // [val, float[]] ret.add(new InsnNode(Opcodes.SWAP)); // [float[], val] ret.add(new LdcInsnNode(floatsCounter)); // [float[], val, idx] ret.add(new InsnNode(Opcodes.SWAP)); // [float[], idx, val] ret.add(new InsnNode(Opcodes.FASTORE)); // [] floatsCounter--; break; case Type.LONG: ret.add(debugMarker(markerType, "Popping/storing long at " + i + " to storage index " + longsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, longsVar.getIndex())); // [val_PART1, val_PART2, long[]] ret.add(new LdcInsnNode(longsCounter)); // [val_PART1, val_PART2, long[], idx] ret.add(new InsnNode(Opcodes.DUP2_X2)); // [long[], idx, val_PART1, val_PART2, long[], idx] ret.add(new InsnNode(Opcodes.POP2)); // [long[], idx, val_PART1, val_PART2] ret.add(new InsnNode(Opcodes.LASTORE)); // [] longsCounter--; break; case Type.DOUBLE: ret.add(debugMarker(markerType, "Popping/storing double at " + i + " to storage index " + doublesCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, doublesVar.getIndex())); // [val_PART1, val_PART2, double[]] ret.add(new LdcInsnNode(doublesCounter)); // [val_PART1, val_PART2, double[], idx] ret.add(new InsnNode(Opcodes.DUP2_X2)); // [double[], idx, val_PART1, val_PART2, double[], idx] ret.add(new InsnNode(Opcodes.POP2)); // [double[], idx, val_PART1, val_PART2] ret.add(new InsnNode(Opcodes.DASTORE)); // [] doublesCounter--; break; case Type.ARRAY: case Type.OBJECT: ret.add(debugMarker(markerType, "Popping/storing object at " + i + " to storage index " + objectsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, objectsVar.getIndex())); // [val, object[]] ret.add(new InsnNode(Opcodes.SWAP)); // [object[], val] ret.add(new LdcInsnNode(objectsCounter)); // [object[], val, idx] ret.add(new InsnNode(Opcodes.SWAP)); // [object[], idx, val] ret.add(new InsnNode(Opcodes.AASTORE)); // [] objectsCounter--; break; case Type.METHOD: case Type.VOID: default: throw new IllegalArgumentException(); } } // At this point, the storage array will contain the saved operand stack AND THE STACK WILL HAVE count ITEMS POPPED OFF OF IT. // // Reload using... // --------------- // ret.add(debugMarker(markerType, "Reloading stack items")); // InsnList reloadInsnList = loadOperandStack(markerType, storageVars, frame, // frame.getStackSize() - count, // frame.getStackSize() - count, // count); // ret.add(reloadInsnList); return ret; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.ArrayInstruction.java
License:Open Source License
@Override public String toString() { switch (getOpcode()) { 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"; default:/*w w w . j a va 2 s . c om*/ assert false; return "--ERROR--"; } }
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 . java 2 s . c o m*/ assert false; return "--ERROR--"; } }
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;//from www . j av a 2s. c om 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 visitInsn(final int opcode) { if (opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) { if (this.cv.cmdLineOptions.traceMethodRetValue) LoggingHelper.emitLogReturn(this.mv, method.getReturnType()); LoggingHelper.emitLogMethodExit(this.mv, this.methodId, LoggingHelper.ExitKind.NORMAL); super.visitInsn(opcode); } else if (opcode == Opcodes.AASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE || opcode == Opcodes.DASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.IASTORE || opcode == Opcodes.LASTORE || opcode == Opcodes.SASTORE) { if (this.cv.cmdLineOptions.traceArrayAccess) visitArrayStoreInsn(opcode); else//w ww . j a va 2s . co m super.visitInsn(opcode); } else if (opcode == Opcodes.AALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD || opcode == Opcodes.DALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.IALOAD || opcode == Opcodes.LALOAD || opcode == Opcodes.SALOAD) { if (this.cv.cmdLineOptions.traceArrayAccess) visitArrayLoadInsn(opcode); else super.visitInsn(opcode); } else super.visitInsn(opcode); }
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
private void visitArrayStoreInsn(final int opcode) { if (opcode == Opcodes.LASTORE || opcode == Opcodes.DASTORE) { super.visitInsn(Opcodes.DUP2_X2); super.visitInsn(Opcodes.POP2); super.visitInsn(Opcodes.DUP2_X2); super.visitInsn(Opcodes.DUP2_X2); super.visitInsn(Opcodes.POP2); super.visitInsn(Opcodes.DUP2_X2); } else {//from w w w. java2 s .c om super.visitInsn(Opcodes.DUP_X2); super.visitInsn(Opcodes.POP); super.visitInsn(Opcodes.DUP2_X1); super.visitInsn(Opcodes.DUP2_X1); super.visitInsn(Opcodes.POP2); super.visitInsn(Opcodes.DUP_X2); } switch (opcode) { case Opcodes.AASTORE: LoggingHelper.emitConvertToString(this.mv, Type.getObjectType("java/lang/Object")); break; case Opcodes.BASTORE: LoggingHelper.emitConvertToString(this.mv, Type.BYTE_TYPE); break; case Opcodes.CASTORE: LoggingHelper.emitConvertToString(this.mv, Type.CHAR_TYPE); break; case Opcodes.FASTORE: LoggingHelper.emitConvertToString(this.mv, Type.FLOAT_TYPE); break; case Opcodes.IASTORE: LoggingHelper.emitConvertToString(this.mv, Type.INT_TYPE); break; case Opcodes.SASTORE: LoggingHelper.emitConvertToString(this.mv, Type.SHORT_TYPE); break; case Opcodes.DASTORE: LoggingHelper.emitConvertToString(this.mv, Type.DOUBLE_TYPE); break; case Opcodes.LASTORE: LoggingHelper.emitConvertToString(this.mv, Type.LONG_TYPE); break; } LoggingHelper.emitLogArray(this.mv, Logger.ArrayAction.PUTA); super.visitInsn(opcode); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(InsnNode insn, FrameState frame, BBInfo block) { ReturnType returnType = block.block.getParent().getType().getReturnType(); switch (insn.getOpcode()) { case Opcodes.NOP: break;/*w w w . j a v a 2 s . co m*/ //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)"> case Opcodes.POP: assert frame.stack.peek().getType().getCategory() == 1; frame.stack.pop(); break; case Opcodes.POP2: final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } }; conditionallyPermute(frame, pop2Permutations); break; case Opcodes.DUP: final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } }; conditionallyPermute(frame, dupPermutations); break; case Opcodes.DUP_X1: final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x1Permutations); break; case Opcodes.DUP_X2: final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x2Permutations); break; case Opcodes.DUP2: final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } }; conditionallyPermute(frame, dup2Permutations); break; case Opcodes.DUP2_X1: final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x1Permutations); break; case Opcodes.DUP2_X2: final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } }, { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x2Permutations); break; case Opcodes.SWAP: final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } }; conditionallyPermute(frame, swapPermutations); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)"> case Opcodes.ACONST_NULL: frame.stack.push(module.constants().getNullConstant()); break; case Opcodes.ICONST_M1: frame.stack.push(module.constants().getSmallestIntConstant(-1)); break; case Opcodes.ICONST_0: frame.stack.push(module.constants().getSmallestIntConstant(0)); break; case Opcodes.ICONST_1: frame.stack.push(module.constants().getSmallestIntConstant(1)); break; case Opcodes.ICONST_2: frame.stack.push(module.constants().getSmallestIntConstant(2)); break; case Opcodes.ICONST_3: frame.stack.push(module.constants().getSmallestIntConstant(3)); break; case Opcodes.ICONST_4: frame.stack.push(module.constants().getSmallestIntConstant(4)); break; case Opcodes.ICONST_5: frame.stack.push(module.constants().getSmallestIntConstant(5)); break; case Opcodes.LCONST_0: frame.stack.push(module.constants().getConstant(0L)); break; case Opcodes.LCONST_1: frame.stack.push(module.constants().getConstant(1L)); break; case Opcodes.FCONST_0: frame.stack.push(module.constants().getConstant(0f)); break; case Opcodes.FCONST_1: frame.stack.push(module.constants().getConstant(1f)); break; case Opcodes.FCONST_2: frame.stack.push(module.constants().getConstant(2f)); break; case Opcodes.DCONST_0: frame.stack.push(module.constants().getConstant(0d)); break; case Opcodes.DCONST_1: frame.stack.push(module.constants().getConstant(1d)); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Return opcodes"> case Opcodes.IRETURN: assert returnType.isSubtypeOf(typeFactory.getType(int.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.LRETURN: assert returnType.isSubtypeOf(typeFactory.getType(long.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.FRETURN: assert returnType.isSubtypeOf(typeFactory.getType(float.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.DRETURN: assert returnType.isSubtypeOf(typeFactory.getType(double.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.ARETURN: assert returnType.isSubtypeOf(typeFactory.getType(Object.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.RETURN: assert returnType instanceof VoidType || method.isConstructor(); block.block.instructions().add(new ReturnInst(typeFactory.getVoidType())); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)"> //Unary minus is rendered as a multiplication by -1. (The obvious //other choice, subtraction from 0, is not equivalent for floats and //doubles due to negative zero.) case Opcodes.INEG: frame.stack.push(module.constants().getSmallestIntConstant(-1)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.LNEG: frame.stack.push(module.constants().getConstant(-1L)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.FNEG: frame.stack.push(module.constants().getConstant(-1f)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.DNEG: frame.stack.push(module.constants().getConstant(-1d)); binary(BinaryInst.Operation.MUL, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Binary math opcodes"> case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: binary(BinaryInst.Operation.ADD, frame, block); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: binary(BinaryInst.Operation.SUB, frame, block); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: binary(BinaryInst.Operation.DIV, frame, block); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: binary(BinaryInst.Operation.REM, frame, block); break; case Opcodes.ISHL: case Opcodes.LSHL: binary(BinaryInst.Operation.SHL, frame, block); break; case Opcodes.ISHR: case Opcodes.LSHR: binary(BinaryInst.Operation.SHR, frame, block); break; case Opcodes.IUSHR: case Opcodes.LUSHR: binary(BinaryInst.Operation.USHR, frame, block); break; case Opcodes.IAND: case Opcodes.LAND: binary(BinaryInst.Operation.AND, frame, block); break; case Opcodes.IOR: case Opcodes.LOR: binary(BinaryInst.Operation.OR, frame, block); break; case Opcodes.IXOR: case Opcodes.LXOR: binary(BinaryInst.Operation.XOR, frame, block); break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.DCMPL: binary(BinaryInst.Operation.CMP, frame, block); break; case Opcodes.FCMPG: case Opcodes.DCMPG: binary(BinaryInst.Operation.CMPG, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Primitive casts"> case Opcodes.I2L: cast(int.class, long.class, frame, block); break; case Opcodes.I2F: cast(int.class, float.class, frame, block); break; case Opcodes.I2D: cast(int.class, double.class, frame, block); break; case Opcodes.L2I: cast(long.class, int.class, frame, block); break; case Opcodes.L2F: cast(long.class, float.class, frame, block); break; case Opcodes.L2D: cast(long.class, double.class, frame, block); break; case Opcodes.F2I: cast(float.class, int.class, frame, block); break; case Opcodes.F2L: cast(float.class, long.class, frame, block); break; case Opcodes.F2D: cast(float.class, double.class, frame, block); break; case Opcodes.D2I: cast(double.class, int.class, frame, block); break; case Opcodes.D2L: cast(double.class, long.class, frame, block); break; case Opcodes.D2F: cast(double.class, float.class, frame, block); break; case Opcodes.I2B: cast(int.class, byte.class, frame, block); break; case Opcodes.I2C: cast(int.class, char.class, frame, block); break; case Opcodes.I2S: cast(int.class, short.class, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array store opcodes"> case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: Value data = frame.stack.pop(); Value index = frame.stack.pop(); Value array = frame.stack.pop(); ArrayStoreInst asi = new ArrayStoreInst(array, index, data); block.block.instructions().add(asi); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array load opcodes"> case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: Value index2 = frame.stack.pop(); Value array2 = frame.stack.pop(); ArrayLoadInst ali = new ArrayLoadInst(array2, index2); block.block.instructions().add(ali); frame.stack.push(ali); break; //</editor-fold> case Opcodes.ARRAYLENGTH: ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop()); block.block.instructions().add(lengthInst); frame.stack.push(lengthInst); break; case Opcodes.ATHROW: block.block.instructions().add(new ThrowInst(frame.stack.pop())); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void emit(ArrayStoreInst i, InsnList insns) { load(i.getArray(), insns);// ww w .ja v a 2s. c o m load(i.getIndex(), insns); load(i.getData(), insns); //TODO: what if the array is a null constant? RegularType componentType = ((ArrayType) i.getArray().getType()).getComponentType(); if (componentType instanceof ReferenceType) insns.add(new InsnNode(Opcodes.AASTORE)); else if (componentType.equals(booleanType) || componentType.equals(byteType)) insns.add(new InsnNode(Opcodes.BASTORE)); else if (componentType.equals(charType)) insns.add(new InsnNode(Opcodes.CASTORE)); else if (componentType.equals(shortType)) insns.add(new InsnNode(Opcodes.SASTORE)); else if (componentType.equals(intType)) insns.add(new InsnNode(Opcodes.IASTORE)); else if (componentType.equals(longType)) insns.add(new InsnNode(Opcodes.LASTORE)); else if (componentType.equals(floatType)) insns.add(new InsnNode(Opcodes.FASTORE)); else if (componentType.equals(doubleType)) insns.add(new InsnNode(Opcodes.DASTORE)); else throw new AssertionError(i); }