str.append("Oups "+e.getMessage());
@Override public void visitDUP(DUP obj) { try { Value value = frame.popValue(); frame.pushValue(value); frame.pushValue(value); } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException(e.toString()); } }
/** * Get the value on the top of the Java operand stack. * * @throws DataflowAnalysisException * if the Java operand stack is empty */ public ValueType getTopValue() throws DataflowAnalysisException { if (!isValid()) { throw new DataflowAnalysisException("accessing top or bottom frame"); } assert slotList.size() >= numLocals; if (slotList.size() == numLocals) { throw new DataflowAnalysisException("operand stack is empty"); } return slotList.get(slotList.size() - 1); }
/** * Constructor from message, method and instruction, and Throwable object * (cause). * * @param message * reason for the error * @param methodGen * the method * @param handle * the instruction * @param cause * a Throwable which is the cause of the exception */ public DataflowAnalysisException(String message, MethodGen methodGen, InstructionHandle handle, Throwable cause) { this(message, methodGen, handle); this.initCause(cause); } }
public static CodeExceptionGen merge(@CheckForNull TypeMerger m, CodeExceptionGen e1, CodeExceptionGen e2) { if (e1 == null) { return e2; } if (e2 == null) { return e1; } if (m == null) { return e1; } if ( ! e1.getHandlerPC().equals( e2.getHandlerPC() ) ){ // log error return e1; } try { Type t = m.mergeTypes(e1.getCatchType(), e2.getCatchType()); return new CodeExceptionGen(e1.getStartPC(), e1.getEndPC(), e1.getHandlerPC(), (ObjectType) t); } catch (DataflowAnalysisException e) { // TODO Auto-generated catch block e.printStackTrace(); return e1; } }
/** * Constructor from message, method and instruction, and Throwable object * (cause). * * @param message * reason for the error * @param methodGen * the method * @param handle * the instruction * @param cause * a Throwable which is the cause of the exception */ public DataflowAnalysisException(String message, MethodGen methodGen, InstructionHandle handle, Throwable cause) { this(message, methodGen, handle); this.initCause(cause); } }
public static CodeExceptionGen merge(@CheckForNull TypeMerger m, CodeExceptionGen e1, CodeExceptionGen e2) { if (e1 == null) { return e2; } if (e2 == null) { return e1; } if (m == null) { return e1; } if ( ! e1.getHandlerPC().equals( e2.getHandlerPC() ) ){ // log error return e1; } try { Type t = m.mergeTypes(e1.getCatchType(), e2.getCatchType()); return new CodeExceptionGen(e1.getStartPC(), e1.getEndPC(), e1.getHandlerPC(), (ObjectType) t); } catch (DataflowAnalysisException e) { // TODO Auto-generated catch block e.printStackTrace(); return e1; } }
@Override public void visitSWAP(SWAP obj) { try { Value value1 = frame.popValue(); Value value2 = frame.popValue(); frame.pushValue(value1); frame.pushValue(value2); } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException(e.toString()); } }
@Override public void visitCHECKCAST(CHECKCAST obj) { try { Type t = getFrame().popValue(); if (t instanceof NullType) { pushValue(t); } else { pushValue(obj.getType(getCPG())); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow for " + obj + ": " + e.getMessage()); } }
/** * Pop a value off of the Java operand stack. * * @return the value that was popped * @throws DataflowAnalysisException * if the Java operand stack is empty */ public ValueType popValue() throws DataflowAnalysisException { if (!isValid()) { throw new DataflowAnalysisException("accessing top or bottom frame"); } if (slotList.size() == numLocals) { throw new DataflowAnalysisException("operand stack empty"); } return slotList.remove(slotList.size() - 1); }
@Override public void visitDUP_X1(DUP_X1 obj) { try { Value value1 = frame.popValue(); Value value2 = frame.popValue(); frame.pushValue(value1); frame.pushValue(value2); frame.pushValue(value1); } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException(e.toString()); } }
@Override public void visitAALOAD(AALOAD obj) { // To determine the type pushed on the stack, // we look at the type of the array reference which was // popped off of the stack. TypeFrame frame = getFrame(); try { frame.popValue(); // index Type arrayType = frame.popValue(); // arrayref if (arrayType instanceof ArrayType) { ArrayType arr = (ArrayType) arrayType; pushValue(arr.getElementType()); } else { pushValue(TypeFrame.getBottomType()); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow: " + e.getMessage()); } }
/** * @return true if the method can return normally at this location, false * otherwise */ public boolean canReturnNormally() throws DataflowAnalysisException { if (!isValid()) { throw new DataflowAnalysisException("Checking invalid ReturnPathType"); } return type == CAN_RETURN_NORMALLY; }
@Override public String instructionAnnotate(InstructionHandle handle, BasicBlock bb) { try { boolean flip = isForwards() != dataflow.getAnalysis().isForwards(); Location loc = new Location(handle, bb); Fact fact = flip ? dataflow.getAnalysis().getFactAfterLocation(loc) : dataflow.getAnalysis().getFactAtLocation(loc); return " " + dataflow.getAnalysis().factToString(fact); } catch (DataflowAnalysisException e) { throw new IllegalStateException("Caught exception: " + e.toString()); } }
/** * Consume stack. This is a convenience method for instructions where the * types of popped operands can be ignored. */ protected void consumeStack(Instruction ins) { ConstantPoolGen cpg = getCPG(); TypeFrame frame = getFrame(); int numWordsConsumed = ins.consumeStack(cpg); if (numWordsConsumed == Const.UNPREDICTABLE) { throw new InvalidBytecodeException("Unpredictable stack consumption for " + ins); } if (numWordsConsumed > frame.getStackDepth()) { throw new InvalidBytecodeException("Stack underflow for " + ins + ", " + numWordsConsumed + " needed, " + frame.getStackDepth() + " avail, frame is " + frame); } try { while (numWordsConsumed-- > 0) { frame.popValue(); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow for " + ins + ": " + e.getMessage()); } }
/** * Get a the location in the frame of a value on the operand stack. * * @param loc * the stack location, counting downwards from the top (location * 0) */ public int getStackLocation(int loc) throws DataflowAnalysisException { int stackDepth = getStackDepth(); if (loc >= stackDepth) { throw new DataflowAnalysisException("not enough values on stack: access=" + loc + ", avail=" + stackDepth); } return slotList.size() - (loc + 1); }
@Override public void visitDUP2(DUP2 obj) { try { Value value1 = frame.popValue(); Value value2 = frame.popValue(); frame.pushValue(value2); frame.pushValue(value1); frame.pushValue(value2); frame.pushValue(value1); } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException(e.toString()); } }
assert false : e.getMessage();
/** * Get the values on the top of the Java operand stack. The top stack item * is placed at the end of the array, so that to restore the values to the * stack, you would push them in the order they appear in the array. */ public void getTopStackWords(ValueType[] valueList) throws DataflowAnalysisException { int stackDepth = getStackDepth(); if (valueList.length > stackDepth) { throw new DataflowAnalysisException("not enough values on stack"); } int numSlots = slotList.size(); for (int i = numSlots - valueList.length, j = 0; i < numSlots; ++i, ++j) { valueList[j] = slotList.get(i); } }
/** * Handler for all instructions which pop values from the stack and store * them in a local variable. Note that two locals are stored into for long * and double stores. */ public void handleStoreInstruction(StoreInstruction obj) { try { int numConsumed = obj.consumeStack(cpg); if (numConsumed == Const.UNPREDICTABLE) { throw new InvalidBytecodeException("Unpredictable stack consumption"); } int index = obj.getIndex(); // Store values into consecutive locals corresponding // to the order in which the values appeared on the stack. while (numConsumed-- > 0) { Value value = frame.popValue(); frame.setValue(index++, value); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException(e.toString()); } }