List of usage examples for org.objectweb.asm Opcodes NEWARRAY
int NEWARRAY
To view the source code for org.objectweb.asm Opcodes NEWARRAY.
Click Source Link
From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayLengthInliner.java
License:Open Source License
/** * Registers values for local arrays that are created via NEWARRAY / ANEWARRAY or MULTIANEWARRAY. * //from w w w. j av a 2 s .c o m * @param currentNode * the current node * @param knownArrays * the known arrays * @return true, if successful */ @Override protected int registerAdditionalValues(final AbstractInsnNode currentNode, // final Map<Integer, Object> knownArrays) { final int opcode = currentNode.getOpcode(); if (!((opcode == Opcodes.NEWARRAY) || (opcode == Opcodes.ANEWARRAY) || (opcode == Opcodes.MULTIANEWARRAY))) { return 0; } int dims = 1; if (currentNode.getOpcode() == Opcodes.MULTIANEWARRAY) { final MultiANewArrayInsnNode node = (MultiANewArrayInsnNode) currentNode; dims = node.dims; } final int sizes[] = new int[dims]; AbstractInsnNode previous = currentNode; for (int i = 0; i < dims; ++i) { previous = NodeHelper.getPrevious(previous); if (!NodeHelper.isIntNode(previous)) { return 0; } try { final int value = NodeHelper.getNumberValue(previous).intValue(); sizes[i] = value; } catch (final NotANumberException nane) { return 0; } } final AbstractInsnNode next = NodeHelper.getNext(currentNode); if (!(next instanceof VarInsnNode)) { return 0; } final int index = ((VarInsnNode) next).var; knownArrays.put(Integer.valueOf(index), Array.newInstance(Object.class, sizes)); return 2; }
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 ww w . java 2 s .co 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
/** * Adds the array to the last created method. * //from w w w. jav a2 s .c om * @param desc * the desc * @param length * the length * @return the class node builder */ public ClassNodeBuilder addArray(final String desc, final int... length) { if (isInterface) { return this; } final Type elementType = Type.getType(desc).getElementType(); if (length.length == 1) { addInsn(NodeHelper.getInsnNodeFor(Integer.valueOf(length[0]))); if (elementType.getDescriptor().startsWith("L")) { addInsn(new TypeInsnNode(Opcodes.ANEWARRAY, elementType.getInternalName())); } else { addInsn(new IntInsnNode(Opcodes.NEWARRAY, getSort(elementType))); } } else { for (final int currentLength : length) { addInsn(NodeHelper.getInsnNodeFor(Integer.valueOf(currentLength))); } addInsn(new MultiANewArrayInsnNode(desc, length.length)); } addInsn(new VarInsnNode(Opcodes.ASTORE, methodVarIndex)); lastMethodVarIndex = methodVarIndex; lastVarElementType = elementType; methodVarIndex++; return this; }
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 w w . j a va2s . c om * 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.BlockTest.java
License:Open Source License
/** * Tests the type erasure.//w w w . j a v a 2s .c om */ @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.utils.ClassNodeBuilderTextifier.java
License:Open Source License
@Override public void visitIntInsn(final int opcode, final int operand) { buf.setLength(0);//from ww w . j a va 2 s .com buf.append("add(").append("Opcodes.").append(OPCODES[opcode]).append(", "); if (opcode == Opcodes.NEWARRAY) { buf.append("Opcodes.").append(TYPES[operand]); } else { buf.append(Integer.toString(operand)); } buf.append(").//\n"); text.add(buf.toString()); }
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.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; }