List of usage examples for org.objectweb.asm Opcodes ALOAD
int ALOAD
To view the source code for org.objectweb.asm Opcodes ALOAD.
Click Source Link
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * Initializes a classField of type Array in the default lastConstructor with the given length. * (eg: if fieldType of field "field" is "double[]", field = new double[length] is called). * //from www . j a v a 2s . c o m * @param length * the length * @return the abstract optimizer test */ public ClassNodeBuilder initArray(final int... length) { if (isInterface) { return this; } final InsnList list = new InsnList(); list.add(new VarInsnNode(Opcodes.ALOAD, 0)); final AbstractInsnNode node; if (length.length == 1) { final Type elementType = Type.getType(lastField.desc).getElementType(); list.add(NodeHelper.getInsnNodeFor(Integer.valueOf(length[0]))); if (elementType.getDescriptor().startsWith("L")) { node = new TypeInsnNode(Opcodes.ANEWARRAY, elementType.getInternalName()); } else { node = new IntInsnNode(Opcodes.NEWARRAY, getSort(elementType)); } } else { for (final int currentLength : length) { list.add(NodeHelper.getInsnNodeFor(Integer.valueOf(currentLength))); } node = new MultiANewArrayInsnNode(lastField.desc, length.length); } list.add(node); list.add(new VarInsnNode(Opcodes.ASTORE, constructorVarIndex)); list.add(new VarInsnNode(Opcodes.ALOAD, constructorVarIndex)); lastConstructorVarIndex = constructorVarIndex; constructorVarIndex++; list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); addToConstructor(list); return this; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * Stores the given value of type Number or String in the array created before at index indexes... * /* w w w .j a v a 2 s . com*/ * @param value * the value * @param indexes * the indexes * @return the class node builder */ public ClassNodeBuilder withValue(final Object value, final int... indexes) { if (isInterface) { return this; } addInsn(new VarInsnNode(Opcodes.ALOAD, lastMethodVarIndex)); for (int i = 0; i < indexes.length - 1; ++i) { addInsn(NodeHelper.getInsnNodeFor(indexes[i])); addInsn(new InsnNode(Opcodes.AALOAD)); } addInsn(NodeHelper.getInsnNodeFor(indexes[indexes.length - 1])); addInsn(NodeHelper.getInsnNodeFor(value)); if (lastVarElementType.getDescriptor().startsWith("L")) { addInsn(new InsnNode(Opcodes.AASTORE)); } else { addInsn(new InsnNode(toPrimitive(Type.getType(value.getClass())).getOpcode(Opcodes.IASTORE))); } return this; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * adds a FieldInsnNode for the given Field. * // ww w.j a v a2 s. co m * @param field * the field * @return the abstract optimizer test */ public ClassNodeBuilder addGetClassField(final String field) { addInsn(new VarInsnNode(Opcodes.ALOAD, 0)); return addGetField(this, field); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
private int getOpcode(final Type type) { if (Type.BOOLEAN_TYPE.equals(type)) { return Opcodes.ILOAD; }//from w w w. j a va 2 s . c o m if (Type.INT_TYPE.equals(type)) { return Opcodes.ILOAD; } if (Type.FLOAT_TYPE.equals(type)) { return Opcodes.FLOAD; } if (Type.LONG_TYPE.equals(type)) { return Opcodes.LLOAD; } if (Type.DOUBLE_TYPE.equals(type)) { return Opcodes.DLOAD; } if (Type.CHAR_TYPE.equals(type)) { return Opcodes.ILOAD; } return Opcodes.ALOAD; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
/** * Objects that are not parameters and not written before * these can be:/* w ww . ja v a 2 s. co m*/ * getField * getStatic * new * new array * new multi array * return type of method call */ private Type resolveType(final AbstractInsnNode node) { int arrayCount = 0; AbstractInsnNode currentNode = NodeHelper.getPrevious(node); while (currentNode != null) { final int opcode2 = currentNode.getOpcode(); if (opcode2 == Opcodes.NEWARRAY) { final int operand = ((IntInsnNode) currentNode).operand; return getObjectType(operand); } else if (opcode2 == Opcodes.ANEWARRAY) { return getObjectType(((TypeInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.MULTIANEWARRAY) { return getObjectType(((MultiANewArrayInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.NEW) { final String desc = ((TypeInsnNode) currentNode).desc; return getObjectType(desc); } else if ((opcode2 >= Opcodes.IALOAD) && (opcode2 <= Opcodes.AALOAD)) { arrayCount++; } else if ((opcode2 == Opcodes.GETFIELD) || (opcode2 == Opcodes.GETSTATIC)) { final String desc = ((FieldInsnNode) currentNode).desc; return getObjectType(removeArrayType(desc, arrayCount)); } else if ((opcode2 == Opcodes.ALOAD)) { final Type type2 = readers.getFirstVar(((VarInsnNode) currentNode).var).getParameterType(); return getObjectType(removeArrayType(type2.getDescriptor(), arrayCount)); } else if ((opcode2 >= Opcodes.INVOKEVIRTUAL) && (opcode2 <= Opcodes.INVOKEDYNAMIC)) { return Type.getReturnType(((MethodInsnNode) currentNode).desc); } currentNode = NodeHelper.getPrevious(currentNode); } return Type.VOID_TYPE; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
private static boolean isLoad(final AbstractInsnNode currentNode) { if (currentNode == null) { return false; }//from w w w .ja v a 2 s . c o m if ((currentNode.getOpcode() >= Opcodes.ILOAD) && (currentNode.getOpcode() <= Opcodes.ALOAD)) { return true; } return false; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.BlockTest.java
License:Open Source License
/** * Tests the type erasure.//from w w w . j a v a 2 s . c o m */ @Test public void testTypeErasure() { final InsnList list = new InsnList(); list.add(new InsnNode(Opcodes.ICONST_5)); list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT)); list.add(new VarInsnNode(Opcodes.ASTORE, 3)); list.add(new VarInsnNode(Opcodes.ILOAD, 1)); list.add(new VarInsnNode(Opcodes.ILOAD, 2)); list.add(new InsnNode(Opcodes.IADD)); list.add(new InsnNode(Opcodes.ICONST_0)); list.add(new VarInsnNode(Opcodes.ALOAD, 3)); list.add(new InsnNode(Opcodes.IASTORE)); list.add(new InsnNode(Opcodes.ICONST_5)); list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT)); list.add(new VarInsnNode(Opcodes.ASTORE, 4)); list.add(new VarInsnNode(Opcodes.ILOAD, 1)); list.add(new VarInsnNode(Opcodes.ILOAD, 2)); list.add(new InsnNode(Opcodes.IADD)); list.add(new InsnNode(Opcodes.ICONST_1)); final VarInsnNode insn = new VarInsnNode(Opcodes.ALOAD, 3); list.add(insn); list.add(new InsnNode(Opcodes.IASTORE)); list.add(new InsnNode(Opcodes.RETURN)); final ListIterator<AbstractInsnNode> iterator = list.iterator(); final Block block = new Block(1, new Type[] { Type.INT_TYPE, Type.INT_TYPE }, Type.INT_TYPE); while (iterator.hasNext()) { block.addInsn(iterator.next(), true); } final Type findType = block.findType(insn); assertEquals(Type.getType("[I"), findType); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.MethodSplitter.java
License:Open Source License
@Override public InsnList optimize(final InsnList original, final MethodNode methodNode) throws JBOPClassException { LocalVariablesSorter sorter = new LocalVariablesSorter(methodNode.access, methodNode.desc, new EmptyMethodVisitor(Opcodes.ASM5)); methodNode.accept(sorter);//from w w w.j a v a 2 s. c om if (getLength(methodNode) < maxInsns) { return clean(original); } final List<Block> blocks = getBlocks(original, methodNode); final String baseName = methodNode.name; final String[] exceptions = getExceptions(methodNode); final InsnList returnList = new InsnList(); InsnList list = returnList; Block block = blocks.get(0); block.renameInsns(block.getVarMap()); final String name = baseName + "__split__part__"; final Type endType = Type.getReturnType(methodNode.desc); for (int i = 1; i < blocks.size(); ++i) { final Map<Integer, Integer> paramRenameMap = block.getVarMap(); add(list, block.getInstructions(), original); block = blocks.get(i); block.renameInsns(paramRenameMap); final String methodDescriptor = block.getDescriptor(); final String newMethodName = name + block.getBlockNumber(); final MethodNode splitMethod = new MethodNode(Opcodes.ASM5, ACCESS, newMethodName, methodDescriptor, null, exceptions); additionalMethods.add(splitMethod); list.add(new VarInsnNode(Opcodes.ALOAD, 0)); list.add(block.getPushParameters()); list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.name, splitMethod.name, methodDescriptor)); list.add(new InsnNode(endType.getOpcode(IRETURN))); sorter = new LocalVariablesSorter(splitMethod.access, splitMethod.desc, new EmptyMethodVisitor(Opcodes.ASM5)); splitMethod.accept(sorter); list = splitMethod.instructions; } add(list, block.getInstructions(), original); return returnList; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.MethodSplitterTest.java
License:Open Source License
private ClassNodeBuilder fillArray() { for (int i = 0; i < arrayLength; ++i) { builder.addInsn(new VarInsnNode(Opcodes.ALOAD, 1)).// arrayref addInsn(NodeHelper.getInsnNodeFor(i)).// index addInsn(NodeHelper.getInsnNodeFor((i + 1) * 2)).// value addInsn(new InsnNode(Opcodes.IASTORE)).// addInsn(new SplitMarkNode()); }/*from w ww .j a v a2 s . c o m*/ builder.addInsn(new VarInsnNode(Opcodes.ALOAD, 1)); return builder; }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java
License:Open Source License
/** * Checks if node is aload.// w ww . java 2 s . co m * * @param node * the node * @return true if node is aload */ public static boolean isAload(final AbstractInsnNode node) { if (node == null) { return false; } return node.getOpcode() == Opcodes.ALOAD; }