List of usage examples for org.objectweb.asm.tree InsnList size
int size
To view the source code for org.objectweb.asm.tree InsnList size.
Click Source Link
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVarsTest.java
License:Open Source License
/** * Tests that RemoveUnusedLocalVars is working correctly. *//*from w w w . ja v a 2 s . c o m*/ @Test public void testRemoveUnusedLocalVarsWithArray() { // INIT builder.addField("multiarr", "[[I").// selectMethod(methodNode.name, methodNode.desc).// loadFieldArrayValue("multiarr", 0).// store(Type.getType(Object.class), 1).// add(ICONST_1).// addReturn(); // RUN assertEquals(7, methodNode.instructions.size()); final InsnList optimized = optimizer.optimize(methodNode.instructions, methodNode); // ASSERT assertEquals(2, optimized.size()); assertEquals(ICONST_1, optimized.get(0).getOpcode()); assertEquals(IRETURN, optimized.get(1).getOpcode()); }
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVarsTest.java
License:Open Source License
/** * Tests that RemoveUnusedLocalVars is working correctly. *///from w ww . ja v a 2 s . co m @Test public void testRemoveUnusedLocalVarsNothingToRemove() { // INIT builder.addField("multiarr", "[[I").// selectMethod(methodNode.name, methodNode.desc).// loadFieldArrayValue("multiarr", 0).// store(Type.getType(Object.class), 1).// load(Type.getType(Object.class), 1).// add(ICONST_1).// add(IALOAD).// addReturn(); // RUN assertEquals(9, methodNode.instructions.size()); final InsnList optimized = optimizer.optimize(methodNode.instructions, methodNode); // ASSERT assertEquals(9, optimized.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVarsTest.java
License:Open Source License
/** * Tests that RemoveUnusedLocalVars is working correctly. *//*from w w w .j av a 2 s . c o m*/ @Test public void testRemoveUnusedLocalVarsWithIIncNothingToRemove() { // INIT builder.add(ICONST_1).// add(ISTORE, 1).// add(IINC, 1, 2).// add(ILOAD, 1).// addReturn(); // RUN assertEquals(5, methodNode.instructions.size()); final InsnList optimized = optimizer.optimize(methodNode.instructions, methodNode); // ASSERT assertEquals(5, optimized.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVarsTest.java
License:Open Source License
/** * Tests that RemoveUnusedLocalVars is working correctly. */// ww w . j a va2 s . c o m @Test public void testRemoveUnusedLocalVarsWithIInc() { // INIT builder.add(ICONST_1).// add(ISTORE, 1).// add(IINC, 1, 2).// add(ICONST_1).// addReturn(); // RUN assertEquals(5, methodNode.instructions.size()); final InsnList optimized = optimizer.optimize(methodNode.instructions, methodNode); // ASSERT assertEquals(2, optimized.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVarsTest.java
License:Open Source License
/** * Tests that RemoveUnusedLocalVars is working correctly. *//* w w w . ja v a 2s.c o m*/ @Test public void testRemoveUnusedLocalVarsDSRemainder() { // INIT builder.addMethod("remainder", "([D[D[D)V").// add(ALOAD, 1).// add(ICONST_0).// add(DALOAD).// add(ALOAD, 2).// add(ICONST_0).// add(DALOAD).// add(DREM).// add(DSTORE, 4).// add(ALOAD, 1).// add(ICONST_0).// add(DALOAD).// add(DLOAD, 4).// add(DSUB).// add(ALOAD, 2).// add(ICONST_0).// add(DALOAD).// add(DDIV).// addInsn(new MethodInsnNode(INVOKESTATIC, "org/apache/commons/math3/util/FastMath", "rint", "(D)D")).// add(DSTORE, 6).// add(ALOAD, 3).// add(ICONST_0).// add(DLOAD, 4).// add(DASTORE).// add(ICONST_1).// add(ISTORE, 8).// addReturn(); final MethodNode method = builder.getMethod("remainder"); assertEquals(26, method.instructions.size()); // RUN final InsnList optimized = optimizer.optimize(method.instructions, method); // ASSERT assertEquals(13, optimized.size()); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void findBlockBoundaries() { InsnList insns = methodNode.instructions; //We find the indices of any block-ending instruction and of any jump //target, sort, remove duplicates, then use pairs to define blocks. Note //these are end-exclusive indices, thus one after the block-enders, but //right on the jump targets (they're one-past-the-end of the preceding //block)./* ww w. j ava 2 s . co m*/ List<Integer> indices = new ArrayList<>(); indices.add(0); for (int i = 0; i < insns.size(); ++i) { AbstractInsnNode insn = insns.get(i); int opcode = insn.getOpcode(); //Terminator opcodes end blocks. if (insn instanceof JumpInsnNode || insn instanceof LookupSwitchInsnNode || insn instanceof TableSwitchInsnNode || opcode == Opcodes.ATHROW || opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) { indices.add(i + 1); } //Jump targets of this instruction end blocks. if (insn instanceof JumpInsnNode) indices.add(insns.indexOf(((JumpInsnNode) insn).label)); else if (insn instanceof LookupSwitchInsnNode) { indices.add(insns.indexOf(((LookupSwitchInsnNode) insn).dflt)); for (Object label : ((LookupSwitchInsnNode) insn).labels) indices.add(insns.indexOf((LabelNode) label)); } else if (insn instanceof TableSwitchInsnNode) { indices.add(insns.indexOf(((TableSwitchInsnNode) insn).dflt)); for (Object label : ((TableSwitchInsnNode) insn).labels) indices.add(insns.indexOf((LabelNode) label)); } //While we're scanning the instructions, make the UninitializedValue //values for 'new' opcodes. if (opcode == Opcodes.NEW) { Klass k = getKlassByInternalName(((TypeInsnNode) insn).desc); ReferenceType t = typeFactory.getReferenceType(k); newValues.put(insn, new UninitializedValue(t, "new" + (counter++))); } } //Remove duplicates and sort via TreeSet. indices = new ArrayList<>(new TreeSet<>(indices)); for (int i = 1; i < indices.size(); ++i) blocks.add(new BBInfo(indices.get(i - 1), indices.get(i), i - 1)); }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
/** * Removes "xLOAD N xSTORE N".//from w w w. jav a 2s. co m * @return true iff changes were made */ private boolean removeLoadStore() { InsnList insns = methodNode.instructions; for (int i = 0; i < insns.size() - 1; ++i) { AbstractInsnNode first = insns.get(i); int index = LOADS.indexOf(first.getOpcode()); if (index == -1) continue; AbstractInsnNode second = insns.get(i + 1); if (second.getOpcode() != STORES.get(index)) continue; if (((VarInsnNode) first).var != ((VarInsnNode) second).var) continue; insns.remove(first); insns.remove(second); return true; } return false; }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
/** * Removes goto instructions that go to the label immediately following * them.//from w w w .j a v a2s .c o m * @return true iff changes were made */ private boolean removeUnnecessaryGotos() { InsnList insns = methodNode.instructions; for (int i = 0; i < insns.size() - 1; ++i) { AbstractInsnNode first = insns.get(i); if (first.getOpcode() != Opcodes.GOTO) continue; AbstractInsnNode second = insns.get(i + 1); if (!(second instanceof LabelNode)) continue; if (((JumpInsnNode) first).label != second) continue; insns.remove(first); return true; } return false; }
From source file:gemlite.core.internal.admin.measurement.CheckPointService.java
License:Apache License
private void analyzeMethod(CheckPointContext ctx, ClassNode cn, MethodNode mn, ScannedMethodItem caller) { // ???//from ww w. j av a2 s . co m Set<ScannedMethodItem> methods = new HashSet<ScannedMethodItem>(); GemliteSibingsLoader loader = ctx.loader; InsnList insnList = mn.instructions; for (int j = 0; j < insnList.size(); j++) { AbstractInsnNode insn = insnList.get(j); if (insn.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode methodInsn = (MethodInsnNode) insn; if (CONSTRUCT_NAME.equals(methodInsn.name)) continue; URL url = loader.findResource(methodInsn.owner + ".class"); boolean blCurrentModule = url != null; if (blCurrentModule) { ScannedMethodItem item = new ScannedMethodItem(methodInsn.owner, methodInsn.name, methodInsn.desc); LogUtil.getCoreLog().trace("I={} owner={} name={} op={}", j, methodInsn.owner, methodInsn.name, methodInsn.getOpcode()); // ??? if (methods.contains(item)) continue; caller.children.add(item); // methods methods.add(item); if (!methodInsn.owner.equals(cn.name)) analazyClass(ctx, item.className, item.methodName, item); else analazyClass(ctx, cn, item.methodName, item); } } } }
From source file:gemlite.core.internal.measurement.MeasureHelper.java
License:Apache License
public final static void instrumentCheckPoint(String className, MethodNode mn) { if (LogUtil.getCoreLog().isTraceEnabled()) LogUtil.getCoreLog().trace("Found check point, class:" + className + " method:" + mn.name); InsnList insn = mn.instructions; List<AbstractInsnNode> returnIndex = new ArrayList<>(); // return//from ww w . ja v a2 s .co m int localVarCount = mn.localVariables.size(); for (int i = 0; i < insn.size(); i++) { AbstractInsnNode insnNode = (AbstractInsnNode) insn.get(i); switch (insnNode.getOpcode()) { case Opcodes.ARETURN: case Opcodes.IRETURN: case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: returnIndex.add(insnNode.getPrevious()); break; case Opcodes.RETURN: returnIndex.add(insnNode); break; } } // insn.insert(new VarInsnNode(Opcodes.LSTORE, localVarCount + 2)); insn.insert( new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); // ? for (AbstractInsnNode insnNode : returnIndex) { insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LSTORE, localVarCount + 4)); insn.insertBefore(insnNode, new LdcInsnNode(className)); insn.insertBefore(insnNode, new LdcInsnNode(mn.name)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 2)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 4)); insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "gemlite/core/internal/measurement/MeasureHelper", "recordCheckPoint", "(Ljava/lang/String;Ljava/lang/String;JJ)V", false)); } }