List of usage examples for org.objectweb.asm Opcodes T_FLOAT
int T_FLOAT
To view the source code for org.objectweb.asm Opcodes T_FLOAT.
Click Source Link
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>//from w ww . j a va 2 s. c o 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:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public void emitNewArray(TypeWidget elementType, BytecodeExpression e) { MethodVisitor mv = getMethodVisitor(); exec(e);//from w ww. ja v a 2s . c om cast(BaseTypeAdapter.INT32, e.getType()); switch (elementType.getJVMType().getSort()) { case Type.BYTE: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_BYTE); break; case Type.BOOLEAN: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_BOOLEAN); break; case Type.SHORT: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_SHORT); break; case Type.INT: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); break; case Type.CHAR: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_CHAR); break; case Type.FLOAT: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_FLOAT); break; case Type.LONG: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_LONG); break; case Type.DOUBLE: mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_DOUBLE); break; case Type.OBJECT: mv.visitTypeInsn(Opcodes.ANEWARRAY, elementType.getJVMType().getInternalName()); break; default: throw new UnsupportedOperationException("unknown sort for newArray" + elementType.getJVMType()); } }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
private int getSort(final Type type) { final int sort = type.getSort(); switch (sort) { case Type.INT: return Opcodes.T_INT; case Type.FLOAT: return Opcodes.T_FLOAT; case Type.LONG: return Opcodes.T_LONG; case Type.DOUBLE: return Opcodes.T_DOUBLE; case Type.SHORT: return Opcodes.T_SHORT; case Type.CHAR: return Opcodes.T_CHAR; case Type.BOOLEAN: return Opcodes.T_BOOLEAN; case Type.BYTE: return Opcodes.T_BYTE; default:/*from w w w . j av a2 s . co m*/ return -1; } }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
private Type getObjectType(final int operand) { if (Opcodes.T_INT == operand) { return Type.getType(int[].class); }// w ww .j a v a 2s .co m if (Opcodes.T_FLOAT == operand) { return Type.getType(float[].class); } if (Opcodes.T_LONG == operand) { return Type.getType(long[].class); } if (Opcodes.T_DOUBLE == operand) { return Type.getType(double[].class); } return Type.getType(Object.class); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.NewArrayInstruction.java
License:Open Source License
public NewArrayInstruction(final ReadMethod readMethod, final int lineNumber, final int arrayElemType, int newObjIdSeqIndex) { super(readMethod, Opcodes.NEWARRAY, lineNumber); assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG; this.arrayElemType = arrayElemType; this.newObjectIdentifierSequenceIndex = newObjIdSeqIndex; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.NewArrayInstruction.java
License:Open Source License
private NewArrayInstruction(final ReadMethod readMethod, final int lineNumber, final int arrayElemType, final int index, int newObjIdSeqIndex) { super(readMethod, Opcodes.NEWARRAY, lineNumber, index); assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG; this.arrayElemType = arrayElemType; this.newObjectIdentifierSequenceIndex = newObjIdSeqIndex; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.NewArrayInstruction.java
License:Open Source License
@Override public String toString() { String elemType;/*from www.j a v a 2 s. c o m*/ switch (this.arrayElemType) { case Opcodes.T_BOOLEAN: elemType = "T_BOOLEAN"; break; case Opcodes.T_CHAR: elemType = "T_CHAR"; break; case Opcodes.T_FLOAT: elemType = "T_FLOAT"; break; case Opcodes.T_DOUBLE: elemType = "T_DOUBLE"; break; case Opcodes.T_BYTE: elemType = "T_BYTE"; break; case Opcodes.T_SHORT: elemType = "T_SHORT"; break; case Opcodes.T_INT: elemType = "T_INT"; break; case Opcodes.T_LONG: elemType = "T_LONG"; break; default: elemType = "--ERROR--"; } return new StringBuilder(elemType.length() + 9).append("NEWARRAY ").append(elemType).toString(); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.NewArrayInstruction2.java
License:Open Source License
public NewArrayInstruction2(final ReadMethod readMethod, final int lineNumber, final int arrayElemType, long newObjIdSeqIndex) { super(readMethod, Opcodes.NEWARRAY, lineNumber); assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG; this.arrayElemType = arrayElemType; this.newObjectIdentifier = newObjIdSeqIndex; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.NewArrayInstruction2.java
License:Open Source License
public NewArrayInstruction2(final ReadMethod readMethod, final int lineNumber, final int arrayElemType, final int index, long newObjIdSeqIndex) { super(readMethod, Opcodes.NEWARRAY, lineNumber, index); assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG; this.arrayElemType = arrayElemType; this.newObjectIdentifier = newObjIdSeqIndex; }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(IntInsnNode insn, FrameState frame, BBInfo block) { int operand = insn.operand; switch (insn.getOpcode()) { case Opcodes.BIPUSH: case Opcodes.SIPUSH: frame.stack.push(module.constants().getSmallestIntConstant(insn.operand)); break;//ww w .ja va2 s . c o m case Opcodes.NEWARRAY: ArrayType t; switch (operand) { case Opcodes.T_BOOLEAN: t = module.types().getArrayType(boolean[].class); break; case Opcodes.T_BYTE: t = module.types().getArrayType(byte[].class); break; case Opcodes.T_CHAR: t = module.types().getArrayType(char[].class); break; case Opcodes.T_SHORT: t = module.types().getArrayType(short[].class); break; case Opcodes.T_INT: t = module.types().getArrayType(int[].class); break; case Opcodes.T_LONG: t = module.types().getArrayType(long[].class); break; case Opcodes.T_FLOAT: t = module.types().getArrayType(float[].class); break; case Opcodes.T_DOUBLE: t = module.types().getArrayType(double[].class); break; default: throw new AssertionError(operand); } NewArrayInst i = new NewArrayInst(t, frame.stack.pop()); block.block.instructions().add(i); frame.stack.push(i); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }