@Override public void visitMULTIANEWARRAY(MULTIANEWARRAY obj) { consumeStack(obj); Type elementType = obj.getType(getCPG()); pushValue(elementType); // We now have an exact type for this value. setTopOfStackIsExact(); }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantClass)){ constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } int dimensions2create = o.getDimensions(); if (dimensions2create < 1){ constraintViolated(o, "Number of dimensions to create must be greater than zero."); } Type t = o.getType(cpg); if (t instanceof ArrayType){ int dimensions = ((ArrayType) t).getDimensions(); if (dimensions < dimensions2create){ constraintViolated(o, "Not allowed to create array with more dimensions ('+dimensions2create+') than the one referenced by the CONSTANT_Class '"+t+"'."); } } else{ constraintViolated(o, "Expecting a CONSTANT_Class referencing an array type. [Constraint not found in The Java Virtual Machine Specification, Second Edition, 4.8.1]"); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { for (int i=0; i<o.getDimensions(); i++) { stack().pop(); } stack().push(o.getType(cpg)); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray(Type t, short dim) { if(dim == 1) { if(t instanceof ObjectType) return new ANEWARRAY(cp.addClass((ObjectType)t)); else if(t instanceof ArrayType) return new ANEWARRAY(cp.addArrayClass((ArrayType)t)); else return new NEWARRAY(((BasicType)t).getType()); } else { ArrayType at; if(t instanceof ArrayType) at = (ArrayType)t; else at = new ArrayType(t, dim); return new MULTIANEWARRAY(cp.addArrayClass(at), dim); } }
/** * Ensures the specific preconditions of the said instruction. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ int dimensions = o.getDimensions(); // Dimensions argument is okay: see Pass 3a. for (int i=0; i<dimensions; i++){ if (stack().peek(i) != Type.INT){ constraintViolated(o, "The '"+dimensions+"' upper stack types should be 'int' but aren't."); } } // The runtime constant pool item at that index must be a symbolic reference to a class, // array, or interface type. See Pass 3a. }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { indexValid(o, o.getIndex()); final Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } final int dimensions2create = o.getDimensions(); if (dimensions2create < 1) { constraintViolated(o, "Number of dimensions to create must be greater than zero."); } final Type t = o.getType(cpg); if (t instanceof ArrayType) { final int dimensions = ((ArrayType) t).getDimensions(); if (dimensions < dimensions2create) { constraintViolated(o, "Not allowed to create array with more dimensions ('"+dimensions2create+ "') than the one referenced by the CONSTANT_Class '"+t+"'."); } } else{ constraintViolated(o, "Expecting a CONSTANT_Class referencing an array type."+ " [Constraint not found in The Java Virtual Machine Specification, Second Edition, 4.8.1]"); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ for (int i=0; i<o.getDimensions(); i++){ stack().pop(); } stack().push(o.getType(cpg)); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray( final Type t, final short dim ) { if (dim == 1) { if (t instanceof ObjectType) { return new ANEWARRAY(cp.addClass((ObjectType) t)); } else if (t instanceof ArrayType) { return new ANEWARRAY(cp.addArrayClass((ArrayType) t)); } else { return new NEWARRAY(t.getType()); } } ArrayType at; if (t instanceof ArrayType) { at = (ArrayType) t; } else { at = new ArrayType(t, dim); } return new MULTIANEWARRAY(cp.addArrayClass(at), dim); }
/** * Ensures the specific preconditions of the said instruction. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { final int dimensions = o.getDimensions(); // Dimensions argument is okay: see Pass 3a. for (int i=0; i<dimensions; i++) { if (stack().peek(i) != Type.INT) { constraintViolated(o, "The '"+dimensions+"' upper stack types should be 'int' but aren't."); } } // The runtime constant pool item at that index must be a symbolic reference to a class, // array, or interface type. See Pass 3a. }
@Override public ObjectType getLoadClassType( final ConstantPoolGen cpg ) { Type t = getType(cpg); if (t instanceof ArrayType) { t = ((ArrayType) t).getBasicType(); } return (t instanceof ObjectType) ? (ObjectType) t : null; }
break; case Const.MULTIANEWARRAY: obj = new MULTIANEWARRAY(); break; case Const.IFNULL:
public void visitAllocationInstruction(AllocationInstruction i) { Type type; if(i instanceof CPInstruction) { type = ((CPInstruction)i).getType(_cp); } else { type = ((NEWARRAY)i).getType(); } short opcode = ((Instruction)i).getOpcode(); int dim = 1; switch(opcode) { case Constants.NEW: _out.println("il.append(_factory.createNew(\"" + ((ObjectType)type).getClassName() + "\"));"); break; case Constants.MULTIANEWARRAY: dim = ((MULTIANEWARRAY)i).getDimensions(); case Constants.ANEWARRAY: case Constants.NEWARRAY: _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));"); break; default: throw new RuntimeException("Oops: " + opcode); } }
public ObjectType getLoadClassType(ConstantPoolGen cpg) { Type t = getType(cpg); if (t instanceof ArrayType){ t = ((ArrayType) t).getBasicType(); } return (t instanceof ObjectType)? (ObjectType) t : null; }
break; case Const.MULTIANEWARRAY: ins = new MULTIANEWARRAY(generateClassRef(r), r.nextShort((short) 1 , Short.MAX_VALUE)); break; case Const.IFNULL:
@Override public void visitAllocationInstruction( final AllocationInstruction i ) { Type type; if (i instanceof CPInstruction) { type = ((CPInstruction) i).getType(_cp); } else { type = ((NEWARRAY) i).getType(); } final short opcode = ((Instruction) i).getOpcode(); int dim = 1; switch (opcode) { case Const.NEW: _out.println("il.append(_factory.createNew(\"" + ((ObjectType) type).getClassName() + "\"));"); break; case Const.MULTIANEWARRAY: dim = ((MULTIANEWARRAY) i).getDimensions(); //$FALL-THROUGH$ case Const.ANEWARRAY: case Const.NEWARRAY: if (type instanceof ArrayType) { type = ((ArrayType) type).getBasicType(); } _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));"); break; default: throw new RuntimeException("Oops: " + opcode); } }
@Override public void visitMULTIANEWARRAY(MULTIANEWARRAY obj) { consumeStack(obj); Type elementType = obj.getType(getCPG()); pushValue(elementType); // We now have an exact type for this value. setTopOfStackIsExact(); }