本文整理汇总了Java中edu.umd.cs.findbugs.ba.LockSet类的典型用法代码示例。如果您正苦于以下问题:Java LockSet类的具体用法?Java LockSet怎么用?Java LockSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LockSet类属于edu.umd.cs.findbugs.ba包,在下文中一共展示了LockSet类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLocked
import edu.umd.cs.findbugs.ba.LockSet; //导入依赖的package包/类
/**
* @param isLocked
* @return
*/
private boolean isLocked() {
try {
if (currentMethod != null && currentLockDataFlow != null && currentCFG != null) {
Collection<Location> tLocations = currentCFG.getLocationsContainingInstructionWithOffset(getPC());
for (Location tLoc : tLocations) {
LockSet lockSet = currentLockDataFlow.getFactAtLocation(tLoc);
if (lockSet.getNumLockedObjects() > 0) {
// within a synchronized block
return true;
}
}
}
} catch (DataflowAnalysisException e) {
reporter.logError("Synchronization check in Static Calendar Detector caught an error.", e);
}
return false;
}
示例2: isLocked
import edu.umd.cs.findbugs.ba.LockSet; //导入依赖的package包/类
/**
* @return
*/
private boolean isLocked() {
try {
if (currentMethod != null && currentLockDataFlow != null && currentCFG != null) {
Collection<Location> tLocations = currentCFG.getLocationsContainingInstructionWithOffset(getPC());
for (Location tLoc : tLocations) {
LockSet lockSet = currentLockDataFlow.getFactAtLocation(tLoc);
if (lockSet.getNumLockedObjects() > 0) {
// within a synchronized block
return true;
}
}
}
} catch (DataflowAnalysisException e) {
reporter.logError("Synchronization check in Static Calendar Detector caught an error.", e);
}
return false;
}
示例3: analyzeMethod
import edu.umd.cs.findbugs.ba.LockSet; //导入依赖的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();
}
示例4: analyzeMethod
import edu.umd.cs.findbugs.ba.LockSet; //导入依赖的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();
}