List of usage examples for org.objectweb.asm Opcodes DOUBLE
Integer DOUBLE
To view the source code for org.objectweb.asm Opcodes DOUBLE.
Click Source Link
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
/** * Reduce double word types into a single slot. *///from ww w. j a v a2 s. com private int reduce(final Object[] source, final int size, final Object[] target) { int targetIdx = 0; for (int sourceIdx = 0; sourceIdx < size; sourceIdx++) { final Object type = source[sourceIdx]; target[targetIdx++] = type; if (type == Opcodes.LONG || type == Opcodes.DOUBLE) { sourceIdx++; } } return targetIdx; }
From source file:org.jacoco.core.internal.instr.ProbeInserter.java
License:Open Source License
@Override public final void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack, final Object[] stack) { if (type != Opcodes.F_NEW) { // uncompressed frame throw new IllegalArgumentException("ClassReader.accept() should be called with EXPAND_FRAMES flag"); }/*from www . j av a 2 s. co m*/ final Object[] newLocal = new Object[Math.max(nLocal, variable) + 1]; int idx = 0; // Arrays index for existing locals int newIdx = 0; // Array index for new locals int pos = 0; // Current variable position while (idx < nLocal || pos <= variable) { if (pos == variable) { newLocal[newIdx++] = InstrSupport.DATAFIELD_DESC; pos++; } else { if (idx < nLocal) { final Object t = local[idx++]; newLocal[newIdx++] = t; pos++; if (t == Opcodes.LONG || t == Opcodes.DOUBLE) { pos++; } } else { // Fill unused slots with TOP newLocal[newIdx++] = Opcodes.TOP; pos++; } } } mv.visitFrame(type, newIdx, newLocal, nStack, stack); }
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testVisitFrameProbeAt0() { ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "()V", actualVisitor, arrayStrategy); pi.visitFrame(Opcodes.F_NEW, 2, new Object[] { Opcodes.DOUBLE, "Foo" }, 0, new Object[0]); expectedVisitor.visitFrame(Opcodes.F_NEW, 3, new Object[] { "[Z", Opcodes.DOUBLE, "Foo" }, 0, new Object[0]); }
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testFillPartly() { ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "(DIJ)V", actualVisitor, arrayStrategy); pi.visitFrame(Opcodes.F_NEW, 1, new Object[] { Opcodes.DOUBLE }, 0, new Object[] {}); // The locals in this frame are filled with TOP up to the probe variable expectedVisitor.visitFrame(Opcodes.F_NEW, 5, new Object[] { Opcodes.DOUBLE, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, "[Z", }, 0, new Object[] {}); }
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
private void dumpType(StringBuffer buffer, Object t) { if (t == Opcodes.TOP) { buffer.append("TOP"); } else if (t == null) { buffer.append("null"); } else if (t == Opcodes.INTEGER) { buffer.append("int"); } else if (t == Opcodes.FLOAT) { buffer.append("float"); } else if (t == Opcodes.DOUBLE) { buffer.append("double"); } else if (t == Opcodes.LONG) { buffer.append("long"); } else if (t == Opcodes.NULL) { buffer.append("null"); } else if (t == Opcodes.UNINITIALIZED_THIS) { buffer.append("uninit_this"); } else if (t instanceof String) { buffer.append((String) t); } else {//from ww w . j a v a 2 s . c om buffer.append(((Label) t).getOffset()); } }
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
public void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack, final Object[] stack) { if (type != Opcodes.F_NEW) { // uncompressed frame throw new IllegalStateException("ClassReader.accept() should be called with EXPAND_FRAMES flag"); }/*from w w w. ja v a 2 s .c o m*/ // dumpFrame(nLocal, local, nStack, stack); // adjust the local types array int toRemove = localTypes.size(); for (int i = toRemove; i > 0; i--) { localTypes.remove(i - 1); } int nextLocal = 0; for (int i = 0; i < nLocal; i++) { Object t = local[i]; if (t == Opcodes.TOP) { localTypes.add(null); } else if (t == null) { localTypes.add(null); } else if (t == Opcodes.INTEGER) { localTypes.add(Type.INT_TYPE); } else if (t == Opcodes.FLOAT) { localTypes.add(Type.FLOAT_TYPE); } else if (t == Opcodes.DOUBLE) { localTypes.add(Type.DOUBLE_TYPE); nextLocal++; localTypes.add(null); } else if (t == Opcodes.LONG) { localTypes.add(Type.LONG_TYPE); nextLocal++; localTypes.add(null); } else if (t == Opcodes.NULL) { localTypes.add(null); } else if (t == Opcodes.UNINITIALIZED_THIS) { localTypes.add(null); } else if (t instanceof String) { localTypes.add(Type.getObjectType((String) t)); } else { localTypes.add(null); } nextLocal++; } this.nextLocal = nextLocal; mv.visitFrame(type, nLocal, local, nStack, stack); }
From source file:org.spongepowered.asm.util.Locals.java
License:MIT License
/** * <p>Attempts to identify available locals at an arbitrary point in the * bytecode specified by node.</p> * /*w w w . j a va2 s . c o m*/ * <p>This method builds an approximate view of the locals available at an * arbitrary point in the bytecode by examining the following features in * the bytecode:</p> * <ul> * <li>Any available stack map frames</li> * <li>STORE opcodes</li> * <li>The local variable table</li> * </ul> * * <p>Inference proceeds by walking the bytecode from the start of the * method looking for stack frames and STORE opcodes. When either of these * is encountered, an attempt is made to cross-reference the values in the * stack map or STORE opcode with the value in the local variable table * which covers the code range. Stack map frames overwrite the entire * simulated local variable table with their own value types, STORE opcodes * overwrite only the local slot to which they pertain. Values in the * simulated locals array are spaced according to their size (unlike the * representation in FrameNode) and this TOP, NULL and UNINTITIALIZED_THIS * opcodes will be represented as null values in the simulated frame.</p> * * <p>This code does not currently simulate the prescribed JVM behaviour * where overwriting the second slot of a DOUBLE or LONG actually * invalidates the DOUBLE or LONG stored in the previous location, so we * have to hope (for now) that this behaviour isn't emitted by the compiler * or any upstream transformers. I may have to re-think this strategy if * this situation is encountered in the wild.</p> * * @param classNode ClassNode containing the method, used to initialise the * implicit "this" reference in simple methods with no stack frames * @param method MethodNode to explore * @param node Node indicating the position at which to determine the locals * state. The locals will be enumerated UP TO the specified node, so * bear in mind that if the specified node is itself a STORE opcode, * then we will be looking at the state of the locals PRIOR to its * invocation * @return A sparse array containing a view (hopefully) of the locals at the * specified location */ public static LocalVariableNode[] getLocalsAt(ClassNode classNode, MethodNode method, AbstractInsnNode node) { LocalVariableNode[] frame = new LocalVariableNode[method.maxLocals]; int local = 0, index = 0; // Initialise implicit "this" reference in non-static methods if ((method.access & Opcodes.ACC_STATIC) == 0) { frame[local++] = new LocalVariableNode("this", classNode.name, null, null, null, 0); } // Initialise method arguments for (Type argType : Type.getArgumentTypes(method.desc)) { frame[local] = new LocalVariableNode("arg" + index++, argType.toString(), null, null, null, local); local += argType.getSize(); } for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) { AbstractInsnNode insn = iter.next(); if (insn instanceof FrameNode) { FrameNode frameNode = (FrameNode) insn; // localPos tracks the location in the frame node's locals list, which doesn't leave space for TOP entries for (int localPos = 0, framePos = 0; framePos < frame.length; framePos++, localPos++) { // Get the local at the current position in the FrameNode's locals list final Object localType = (localPos < frameNode.local.size()) ? frameNode.local.get(localPos) : null; if (localType instanceof String) { // String refers to a reference type frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos); } else if (localType instanceof Integer) { // Integer refers to a primitive type or other marker boolean isMarkerType = localType == Opcodes.UNINITIALIZED_THIS || localType == Opcodes.TOP || localType == Opcodes.NULL; boolean is32bitValue = localType == Opcodes.INTEGER || localType == Opcodes.FLOAT; boolean is64bitValue = localType == Opcodes.DOUBLE || localType == Opcodes.LONG; if (isMarkerType) { frame[framePos] = null; } else if (is32bitValue || is64bitValue) { frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos); if (is64bitValue) { framePos++; frame[framePos] = null; // TOP } } else { throw new RuntimeException( "Unrecognised locals opcode " + localType + " in locals array at position " + localPos + " in " + classNode.name + "." + method.name + method.desc); } } else if (localType == null) { frame[framePos] = null; } else { throw new RuntimeException("Invalid value " + localType + " in locals array at position " + localPos + " in " + classNode.name + "." + method.name + method.desc); } } } else if (insn instanceof VarInsnNode) { VarInsnNode varNode = (VarInsnNode) insn; frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, node, varNode.var); } else if (insn == node) { break; } } return frame; }
From source file:org.yx.asm.AsmUtils.java
License:Apache License
public static List<Object> getImplicitFrame(String desc) { List<Object> locals = new ArrayList<>(); if (desc.isEmpty()) { return locals; }/* w ww . j av a 2s . c o m*/ int i = 0; while (desc.length() > i) { int j = i; switch (desc.charAt(i++)) { case 'Z': case 'C': case 'B': case 'S': case 'I': locals.add(Opcodes.INTEGER); break; case 'F': locals.add(Opcodes.FLOAT); break; case 'J': locals.add(Opcodes.LONG); break; case 'D': locals.add(Opcodes.DOUBLE); break; case '[': while (desc.charAt(i) == '[') { ++i; } if (desc.charAt(i) == 'L') { ++i; while (desc.charAt(i) != ';') { ++i; } } locals.add(desc.substring(j, ++i)); break; case 'L': while (desc.charAt(i) != ';') { ++i; } locals.add(desc.substring(j + 1, i++)); break; default: break; } } return locals; }
From source file:org.yx.asm.ProxyMethodWritor.java
License:Apache License
private static int load(MethodVisitor mv, Object type, int frameIndex) { if (Opcodes.INTEGER.equals(type)) { mv.visitVarInsn(ILOAD, frameIndex); return frameIndex + SINGLE; }// ww w. j ava 2 s . c om if (Opcodes.LONG.equals(type)) { mv.visitVarInsn(LLOAD, frameIndex); return frameIndex + WIDTH; } if (Opcodes.FLOAT.equals(type)) { mv.visitVarInsn(FLOAD, frameIndex); return frameIndex + SINGLE; } if (Opcodes.DOUBLE.equals(type)) { mv.visitVarInsn(DLOAD, frameIndex); return frameIndex + WIDTH; } mv.visitVarInsn(ALOAD, frameIndex); return frameIndex + SINGLE; }
From source file:org.yx.asm.ProxyMethodWritor.java
License:Apache License
private static void store(MethodVisitor mv, Object type, int frameIndex) { if (Opcodes.INTEGER.equals(type)) { mv.visitVarInsn(ISTORE, frameIndex); } else if (Opcodes.LONG.equals(type)) { mv.visitVarInsn(LSTORE, frameIndex); } else if (Opcodes.FLOAT.equals(type)) { mv.visitVarInsn(FSTORE, frameIndex); } else if (Opcodes.DOUBLE.equals(type)) { mv.visitVarInsn(DSTORE, frameIndex); } else {/*from w ww.j ava2s. c o m*/ mv.visitVarInsn(ASTORE, frameIndex); } }