List of usage examples for org.objectweb.asm Opcodes FSTORE
int FSTORE
To view the source code for org.objectweb.asm Opcodes FSTORE.
Click Source Link
From source file:com.geeksaga.light.profiler.util.ASMUtil.java
License:Apache License
public static VarInsnNode createFSTORE(LocalVariableNode localVariableNode) { return new VarInsnNode(Opcodes.FSTORE, localVariableNode.index); }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
private void store(int var, Type type) { assert var >= 0; variables.activate(var); switch (type.getOpcode(Opcodes.ISTORE)) { case Opcodes.ISTORE: istore(var); return;/*from www . j a v a2 s . c o m*/ case Opcodes.LSTORE: lstore(var); return; case Opcodes.FSTORE: fstore(var); return; case Opcodes.DSTORE: dstore(var); return; case Opcodes.ASTORE: astore(var); return; default: throw new IllegalArgumentException(); } }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
private void fstore(int var) { methodVisitor.visitVarInsn(Opcodes.FSTORE, var); stack.fstore(var); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: push(InferredType.INT);// w ww.j a va2s . co m break; case Opcodes.LLOAD: push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.FLOAD: push(InferredType.FLOAT); break; case Opcodes.DLOAD: push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.ALOAD: push(getLocalVariableType(var)); break; case Opcodes.ISTORE: case Opcodes.FSTORE: case Opcodes.ASTORE: { InferredType type = pop(); setLocalVariableTypes(var, type); break; } case Opcodes.LSTORE: case Opcodes.DSTORE: { InferredType type = pop(2); setLocalVariableTypes(var, type); setLocalVariableTypes(var + 1, InferredType.TOP); break; } case Opcodes.RET: throw new RuntimeException("The instruction RET is not supported"); default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitVarInsn(opcode, var); }
From source file:com.google.devtools.build.wireless.testing.java.injector.TypeDescriptorTest.java
License:Apache License
/** * Test method for {@link TypeDescriptor#getStoreOpcode()}. *///from w ww.j av a 2 s .com public void testGetStoreOpcode() { try { TypeDescriptor.VOID.getStoreOpcode(); fail("Void should have thrown an exception!"); } catch (IllegalStateException e) { // OK! } assertEquals("Wrong STORE instruction", Opcodes.ISTORE, TypeDescriptor.BOOLEAN.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ISTORE, TypeDescriptor.BYTE.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ISTORE, TypeDescriptor.CHAR.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ISTORE, TypeDescriptor.SHORT.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ISTORE, TypeDescriptor.INTEGER.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.LSTORE, TypeDescriptor.LONG.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.FSTORE, TypeDescriptor.FLOAT.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.DSTORE, TypeDescriptor.DOUBLE.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ASTORE, TypeDescriptor.CLASS.getStoreOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ASTORE, TypeDescriptor.ARRAY.getStoreOpcode()); }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitVarInsn(final int opcode, final int var) { switch (opcode) { case Opcodes.ILOAD: load(var, JavaType.INT); break;//from ww w .ja v a 2 s . c o m case Opcodes.LLOAD: load(var, JavaType.LONG); break; case Opcodes.FLOAD: load(var, JavaType.FLOAT); break; case Opcodes.DLOAD: load(var, JavaType.DOUBLE); break; case Opcodes.ALOAD: load(var, JavaType.OBJECT); break; case Opcodes.ISTORE: store(var, JavaType.INT); break; case Opcodes.LSTORE: store(var, JavaType.LONG); break; case Opcodes.FSTORE: store(var, JavaType.FLOAT); break; case Opcodes.DSTORE: store(var, JavaType.DOUBLE); break; case Opcodes.ASTORE: store(var, JavaType.OBJECT); break; case Opcodes.RET: recorder.add(new Runnable() { public void run() { block.addOp(new RetSub(lineNumber)); } }); break; default: throw new UnsupportedOperationException("opcode: " + opcode); } }
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: case Opcodes.LLOAD: case Opcodes.FLOAD: case Opcodes.DLOAD: case Opcodes.ALOAD: stack.add(registers.get(Integer.valueOf(var))); break;//from w w w . j a va 2s . c o m case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: registers.put(Integer.valueOf(var), stack.remove(stack.size() - 1)); break; case Opcodes.RET: //nop - a fudge break; } }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Pops the stack in to the the local variable table. You may run in to problems if the item on top of the stack isn't of the same type * as the variable it's being put in to. * @param variable variable within the local variable table to save to * @return instructions to pop an item off the top of the stack and save it to {@code variable} * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code variable} has been released *///from w w w . jav a 2 s . co m public static InsnList saveVar(Variable variable) { Validate.notNull(variable); InsnList ret = new InsnList(); switch (variable.getType().getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: ret.add(new VarInsnNode(Opcodes.ISTORE, variable.getIndex())); break; case Type.LONG: ret.add(new VarInsnNode(Opcodes.LSTORE, variable.getIndex())); break; case Type.FLOAT: ret.add(new VarInsnNode(Opcodes.FSTORE, variable.getIndex())); break; case Type.DOUBLE: ret.add(new VarInsnNode(Opcodes.DSTORE, variable.getIndex())); break; case Type.OBJECT: case Type.ARRAY: ret.add(new VarInsnNode(Opcodes.ASTORE, variable.getIndex())); break; default: throw new IllegalStateException(); // should never happen, there is code in Variable/VariableTable to make sure invalid // types aren't set } return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Generates instructions to load the local variables table from an object array. * * @param arrayLocalsVar variable that the object array containing local variables table is stored * @param tempObjectVar variable to use for temporary objects * @param frame execution frame at the instruction for which the local variables table is to be restored * @return instructions to load the local variables table from an array * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if variables have the same index, or if variables have been released, or if variables are of wrong * type/*from w w w . j a v a 2 s. co m*/ */ public static InsnList loadLocalVariableTable(Variable arrayLocalsVar, Variable tempObjectVar, Frame<BasicValue> frame) { Validate.notNull(arrayLocalsVar); Validate.notNull(tempObjectVar); Validate.notNull(frame); Validate.isTrue(arrayLocalsVar.getType().equals(Type.getType(Object[].class))); Validate.isTrue(tempObjectVar.getType().equals(Type.getType(Object.class))); validateLocalIndicies(arrayLocalsVar.getIndex(), tempObjectVar.getIndex()); InsnList ret = new InsnList(); // Load 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 load. So, skip this slot if we encounter it (such that it will remain uninitialized). if (type == null) { 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 there's no specific value to load up from the array. Instead we push a null in to that slot, thereby // keeping the same 'Lnull;' type originally assigned to that slot (it doesn't make sense to do a CHECKCAST because 'null' is // not a real class and can never be a real class -- null is a reserved word in Java). if (type.getSort() == Type.OBJECT && "Lnull;".equals(type.getDescriptor())) { ret.add(new InsnNode(Opcodes.ACONST_NULL)); ret.add(new VarInsnNode(Opcodes.ASTORE, i)); continue; } // Load item from locals storage array ret.add(new VarInsnNode(Opcodes.ALOAD, arrayLocalsVar.getIndex())); ret.add(new LdcInsnNode(i)); ret.add(new InsnNode(Opcodes.AALOAD)); // Convert the item from an object stores it in local vars table. switch (type.getSort()) { case Type.BOOLEAN: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Boolean")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false)); ret.add(new VarInsnNode(Opcodes.ISTORE, i)); break; case Type.BYTE: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Byte")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false)); ret.add(new VarInsnNode(Opcodes.ISTORE, i)); break; case Type.SHORT: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Short")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false)); ret.add(new VarInsnNode(Opcodes.ISTORE, i)); break; case Type.CHAR: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Character")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C", false)); ret.add(new VarInsnNode(Opcodes.ISTORE, i)); break; case Type.INT: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Integer")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false)); ret.add(new VarInsnNode(Opcodes.ISTORE, i)); break; case Type.FLOAT: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Float")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false)); ret.add(new VarInsnNode(Opcodes.FSTORE, i)); break; case Type.LONG: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Long")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false)); ret.add(new VarInsnNode(Opcodes.LSTORE, i)); break; case Type.DOUBLE: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Double")); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false)); ret.add(new VarInsnNode(Opcodes.DSTORE, i)); break; case Type.ARRAY: case Type.OBJECT: ret.add(new TypeInsnNode(Opcodes.CHECKCAST, basicValue.getType().getInternalName())); ret.add(new VarInsnNode(Opcodes.ASTORE, i)); break; case Type.METHOD: case Type.VOID: default: throw new IllegalStateException(); } } return ret; }
From source file:com.offbynull.coroutines.instrumenter.LocalsStateGenerators.java
License:Open Source License
/** * Generates instructions to load the local variables table. * @param markerType debug marker type//from w w w .j a v a 2 s. co m * @param storageVars variables to load locals from * @param frame execution frame at the instruction for which the local variables table is to be restored * @return instructions to load the local variables table from an array * @throws NullPointerException if any argument is {@code null} */ public static InsnList loadLocals(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; InsnList ret = new InsnList(); // Load the locals ret.add(debugMarker(markerType, "Loading 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 load. So, skip this slot if we encounter it (such that it will remain uninitialized). 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 there's no specific value to load up from the array. Instead we push a null in to that slot, thereby // keeping the same 'Lnull;' type originally assigned to that slot (it doesn't make sense to do a CHECKCAST because 'null' is // not a real class and can never be a real class -- null is a reserved word in Java). if (type.getSort() == Type.OBJECT && "Lnull;".equals(type.getDescriptor())) { ret.add(debugMarker(markerType, "Putting null value at " + i)); ret.add(new InsnNode(Opcodes.ACONST_NULL)); ret.add(new VarInsnNode(Opcodes.ASTORE, i)); continue; } // Load the locals switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: ret.add(debugMarker(markerType, "Loading int to LVT index " + i + " from storage index " + intsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, intsVar.getIndex())); // [int[]] ret.add(new LdcInsnNode(intsCounter)); // [int[], idx] ret.add(new InsnNode(Opcodes.IALOAD)); // [val] ret.add(new VarInsnNode(Opcodes.ISTORE, i)); // [] intsCounter++; break; case Type.FLOAT: ret.add(debugMarker(markerType, "Loading float to LVT index " + i + " from storage index " + floatsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, floatsVar.getIndex())); // [float[]] ret.add(new LdcInsnNode(floatsCounter)); // [float[], idx] ret.add(new InsnNode(Opcodes.FALOAD)); // [val] ret.add(new VarInsnNode(Opcodes.FSTORE, i)); // [] floatsCounter++; break; case Type.LONG: ret.add(debugMarker(markerType, "Loading long to LVT index " + i + " from storage index " + longsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, longsVar.getIndex())); // [long[]] ret.add(new LdcInsnNode(longsCounter)); // [long[], idx] ret.add(new InsnNode(Opcodes.LALOAD)); // [val_PART1, val_PART2] ret.add(new VarInsnNode(Opcodes.LSTORE, i)); // [] longsCounter++; break; case Type.DOUBLE: ret.add(debugMarker(markerType, "Loading double to LVT index " + i + " from storage index " + doublesCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, doublesVar.getIndex())); // [double[]] ret.add(new LdcInsnNode(doublesCounter)); // [double[], idx] ret.add(new InsnNode(Opcodes.DALOAD)); // [val_PART1, val_PART2] ret.add(new VarInsnNode(Opcodes.DSTORE, i)); // [] doublesCounter++; break; case Type.ARRAY: case Type.OBJECT: ret.add(debugMarker(markerType, "Loading object to LVT index " + i + " from storage index " + objectsCounter)); ret.add(new VarInsnNode(Opcodes.ALOAD, objectsVar.getIndex())); // [Object[]] ret.add(new LdcInsnNode(objectsCounter)); // [Object[], idx] ret.add(new InsnNode(Opcodes.AALOAD)); // [val] // must cast, otherwise the jvm won't know the type that's in the localvariable slot and it'll fail when the code tries // to access a method/field on it ret.add(new TypeInsnNode(Opcodes.CHECKCAST, basicValue.getType().getInternalName())); ret.add(new VarInsnNode(Opcodes.ASTORE, i)); // [] objectsCounter++; break; case Type.METHOD: case Type.VOID: default: throw new IllegalStateException(); } } return ret; }