private void analyzeIfNullBranch ( BasicBlock basicBlock , InstructionHandle lastHandle ) throws DataflowAnalysisException { Location location = new Location ( lastHandle , basicBlock ) ; IsNullValueFrame frame = invDataflow . getFactAtLocation ( location ) ; if ( ! frame . isValid ( ) ) { // This is probably dead code due to an infeasible exception edge. return ; } IsNullValue top = frame . getTopValue ( ) ; // Find the line number. int lineNumber = getLineNumber ( method , lastHandle ) ; if ( lineNumber < 0 ) { return ; } if ( ! ( top . isDefinitelyNull ( ) || top . isDefinitelyNotNull ( ) ) ) { if ( DEBUG ) { System . out . println ( "Line " + lineNumber + " undetermined" ) ; } undeterminedBranchSet . set ( lineNumber ) ; return ; } // Figure out if the branch is always taken // or always not taken. short opcode = lastHandle . getInstruction ( ) . getOpcode ( ) ; boolean definitelySame = top . isDefinitelyNull ( ) ; if ( opcode != Const . IFNULL ) { definitelySame = ! definitelySame ; } if ( definitelySame ) { if ( DEBUG ) { System . out . println ( "Line " + lineNumber + " always same" ) ; } definitelySameBranchSet . set ( lineNumber ) ; } else { if ( DEBUG ) { System . out . println ( "Line " + lineNumber + " always different" ) ; } definitelyDifferentBranchSet . set ( lineNumber ) ; } RedundantBranch redundantBranch = new RedundantBranch ( location , lineNumber , top ) ; // Determine which control edge is made infeasible by the redundant // comparison boolean wantNull = ( opcode == Const . IFNULL ) ; int infeasibleEdgeType = ( wantNull == top . isDefinitelyNull ( ) ) ? EdgeTypes . FALL_THROUGH_EDGE : EdgeTypes . IFCMP_EDGE ; Edge infeasibleEdge = invDataflow . getCFG ( ) . getOutgoingEdgeWithType ( basicBlock , infeasibleEdgeType ) ; redundantBranch . setInfeasibleEdge ( infeasibleEdge ) ; if ( DEBUG ) { System . out . println ( "Adding redundant branch: " + redundantBranch ) ; } redundantBranchList . add ( redundantBranch ) ; }
This is called for both IFNULL and IFNONNULL instructions .