private static Set < CallSite > findObviouslyLockedCallSites ( ClassContext classContext , SelfCalls selfCalls ) throws CFGBuilderException , DataflowAnalysisException { ConstantPoolGen cpg = classContext . getConstantPoolGen ( ) ; // Find all obviously locked call sites Set < CallSite > obviouslyLockedSites = new HashSet <> ( ) ; for ( Iterator < CallSite > i = selfCalls . callSiteIterator ( ) ; i . hasNext ( ) ; ) { CallSite callSite = i . next ( ) ; Method method = callSite . getMethod ( ) ; Location location = callSite . getLocation ( ) ; InstructionHandle handle = location . getHandle ( ) ; // Only instance method calls qualify as candidates for // "obviously locked" Instruction ins = handle . getInstruction ( ) ; if ( ins . getOpcode ( ) == Const . INVOKESTATIC ) { continue ; } // Get lock set for site LockChecker lockChecker = classContext . getLockChecker ( method ) ; LockSet lockSet = lockChecker . getFactAtLocation ( location ) ; // Get value number frame for site ValueNumberDataflow vnaDataflow = classContext . getValueNumberDataflow ( method ) ; ValueNumberFrame frame = vnaDataflow . getFactAtLocation ( location ) ; // NOTE: if the CFG on which the value number analysis was performed // was pruned, there may be unreachable instructions. Therefore, // we can't assume the frame is valid. if ( ! frame . isValid ( ) ) { continue ; } // Find the ValueNumber of the receiver object int numConsumed = ins . consumeStack ( cpg ) ; MethodGen methodGen = classContext . getMethodGen ( method ) ; assert methodGen != null ; if ( numConsumed == Const . UNPREDICTABLE ) { throw new DataflowAnalysisException ( "Unpredictable stack consumption" , methodGen , handle ) ; } // if (DEBUG) System.out.println("Getting receiver for frame: " + // frame); ValueNumber instance = frame . getStackValue ( numConsumed - 1 ) ; // Is the instance locked? int lockCount = lockSet . getLockCount ( instance . getNumber ( ) ) ; if ( lockCount > 0 ) { // This is a locked call site obviouslyLockedSites . add ( callSite ) ; } } return obviouslyLockedSites ; }
Find all self - call sites that are obviously locked .