本文整理汇总了Java中edu.umd.cs.findbugs.ba.ClassContext.getLockDataflow方法的典型用法代码示例。如果您正苦于以下问题:Java ClassContext.getLockDataflow方法的具体用法?Java ClassContext.getLockDataflow怎么用?Java ClassContext.getLockDataflow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.ba.ClassContext
的用法示例。
在下文中一共展示了ClassContext.getLockDataflow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
CFG cfg = classContext.getCFG(method);
LockDataflow dataflow = classContext.getLockDataflow(method);
for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) {
Location location = j.next();
visitLocation(classContext, location, methodGen, dataflow);
}
}
示例2: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
// System.out.println("Checking " + method);
CFG cfg = classContext.getCFG(method);
LockDataflow lockDataflow = classContext.getLockDataflow(method);
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
Instruction ins = location.getHandle().getInstruction();
if (!(ins instanceof INVOKESTATIC))
continue;
if (!isSleep((INVOKESTATIC) ins, classContext.getConstantPoolGen()))
continue;
// System.out.println("Found sleep at " + location.getHandle());
LockSet lockSet = lockDataflow.getFactAtLocation(location);
if (lockSet.getNumLockedObjects() > 0) {
bugAccumulator.accumulateBug(
new BugInstance(this, "SWL_SLEEP_WITH_LOCK_HELD", NORMAL_PRIORITY).addClassAndMethod(
classContext.getJavaClass(), method), classContext, method, location);
}
}
bugAccumulator.reportAccumulatedBugs();
}
示例3: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null)
return;
ConstantPoolGen cpg = methodGen.getConstantPool();
CFG cfg = classContext.getCFG(method);
ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
LockDataflow dataflow = classContext.getLockDataflow(method);
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
InstructionHandle handle = location.getHandle();
Instruction ins = handle.getInstruction();
if (!(ins instanceof INVOKEVIRTUAL))
continue;
INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
String methodName = inv.getName(cpg);
String methodSig = inv.getSignature(cpg);
if (Hierarchy.isMonitorWait(methodName, methodSig) || Hierarchy.isMonitorNotify(methodName, methodSig)) {
int numConsumed = inv.consumeStack(cpg);
if (numConsumed == Constants.UNPREDICTABLE)
throw new DataflowAnalysisException("Unpredictable stack consumption", methodGen, handle);
ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);
if (!frame.isValid())
// Probably dead code
continue;
if (frame.getStackDepth() - numConsumed < 0)
throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
ValueNumber ref = frame.getValue(frame.getNumSlots() - numConsumed);
LockSet lockSet = dataflow.getFactAtLocation(location);
int lockCount = lockSet.getLockCount(ref.getNumber());
if (lockCount == 0) {
Collection<ValueNumber> lockedValueNumbers = lockSet.getLockedValueNumbers(frame);
boolean foundMatch = false;
for (ValueNumber v : lockedValueNumbers)
if (frame.veryFuzzyMatch(ref, v)) {
foundMatch = true;
break;
}
if (!foundMatch) {
String type = methodName.equals("wait") ? "MWN_MISMATCHED_WAIT" : "MWN_MISMATCHED_NOTIFY";
String sourceFile = classContext.getJavaClass().getSourceFileName();
// Report as medium priority only if the method is
// public.
// Non-public methods may be properly locked in a
// calling context.
int priority = method.isPublic() ? NORMAL_PRIORITY : LOW_PRIORITY;
bugAccumulator.accumulateBug(
new BugInstance(this, type, priority).addClassAndMethod(methodGen, sourceFile),
SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
}
}
}
}
bugAccumulator.reportAccumulatedBugs();
}