本文整理汇总了Java中edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow.getFactAtLocation方法的典型用法代码示例。如果您正苦于以下问题:Java ValueNumberDataflow.getFactAtLocation方法的具体用法?Java ValueNumberDataflow.getFactAtLocation怎么用?Java ValueNumberDataflow.getFactAtLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow
的用法示例。
在下文中一共展示了ValueNumberDataflow.getFactAtLocation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkForSelfOperation
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow; //导入方法依赖的package包/类
/**
* @param classContext
* TODO
* @param location
* @param method
* TODO
* @param methodGen
* TODO
* @param sourceFile
* TODO
* @param string
* @throws DataflowAnalysisException
*/
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
if (!frame.isValid())
return;
Instruction ins = location.getHandle().getInstruction();
int opcode = ins.getOpcode();
int offset = 1;
if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
offset = 2;
ValueNumber v0 = frame.getStackValue(0);
ValueNumber v1 = frame.getStackValue(offset);
if (!v1.equals(v0))
return;
if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
return;
int priority = HIGH_PRIORITY;
if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
priority = NORMAL_PRIORITY;
XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
BugAnnotation annotation;
String prefix;
if (field != null) {
if (field.isVolatile())
return;
if (true)
return; // don't report these; too many false positives
annotation = FieldAnnotation.fromXField(field);
prefix = "SA_FIELD_SELF_";
} else {
annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
prefix = "SA_LOCAL_SELF_";
if (opcode == ISUB)
return; // only report this if simple detector reports it
}
if (annotation == null)
return;
SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
location.getHandle());
int line = sourceLine.getStartLine();
BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
if (line > 0 && occursMultipleTimes.get(line))
return;
BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile).add(annotation)
.addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
bugReporter.reportBug(bug);
}
示例2: analyzeMethod
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow; //导入方法依赖的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();
}
示例3: checkDataflow
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow; //导入方法依赖的package包/类
private void checkDataflow(XMethod xmethod, CFG cfg, TypeQualifierValue typeQualifierValue,
ValueNumberDataflow vnaDataflow, ForwardTypeQualifierDataflow forwardDataflow,
BackwardTypeQualifierDataflow backwardDataflow) throws DataflowAnalysisException, CheckedAnalysisException {
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location loc = i.next();
TypeQualifierValueSet forwardsFact = forwardDataflow.getFactAtLocation(loc);
TypeQualifierValueSet backwardsFact = backwardDataflow.getFactAfterLocation(loc);
if (!forwardsFact.isValid() || !backwardsFact.isValid()) {
continue;
}
if (DEBUG) {
checkLocation = "location " + loc.toCompactString();
}
checkForConflictingValues(xmethod, cfg, typeQualifierValue, forwardsFact, backwardsFact, loc,
loc, vnaDataflow.getFactAtLocation(loc));
checkForEqualityTest(xmethod, cfg, typeQualifierValue, forwardsFact, loc, vnaDataflow.getFactAtLocation(loc));
}
for (Iterator<Edge> i = cfg.edgeIterator(); i.hasNext();) {
Edge edge = i.next();
// NOTE: when checking forwards and backwards values on an edge,
// we don't want to apply BOTH edge transfer functions,
// since the purpose of the edge transfer function is to
// propagate information across phi nodes (effectively
// copying information about one value to another).
// Due to pruning of backwards values when a conflict is detected,
// we need to check backwards values as "early" as possible,
// meaning that we want to check at the edge target
// (before the backwards edge transfer function has pruned
// the backwards value.)
TypeQualifierValueSet forwardFact = forwardDataflow.getFactOnEdge(edge);
TypeQualifierValueSet backwardFact = backwardDataflow.getResultFact(edge.getTarget());
// The edge target location is where we can check
// for conflicting flow values.
Location edgeTargetLocation = getEdgeTargetLocation(cfg, edge);
ValueNumberFrame vnaFrame = (edgeTargetLocation != null) ? vnaDataflow.getFactAtLocation(edgeTargetLocation) : null;
// What location do we want to report to the user
// as where the conflict occurs?
// The edge source location is generally better,
// but edge target location is ok as a fallback.
Location locationToReport;
if (edge.getSource().getLastInstruction() != null) {
locationToReport = getEdgeSourceLocation(cfg, edge);
} else {
locationToReport = edgeTargetLocation;
}
checkForConflictingValues(xmethod, cfg, typeQualifierValue, forwardFact, backwardFact,
locationToReport, edgeTargetLocation, vnaFrame);
}
}
示例4: checkForSelfOperation
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow; //导入方法依赖的package包/类
/**
* @param classContext
* TODO
* @param location
* @param method
* TODO
* @param methodGen
* TODO
* @param sourceFile
* TODO
* @param string
* @throws DataflowAnalysisException
*/
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
if (!frame.isValid())
return;
Instruction ins = location.getHandle().getInstruction();
int opcode = ins.getOpcode();
int offset = 1;
if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
offset = 2;
ValueNumber v0 = frame.getStackValue(0);
ValueNumber v1 = frame.getStackValue(offset);
if (!v1.equals(v0))
return;
if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
return;
int priority = HIGH_PRIORITY;
if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
priority = NORMAL_PRIORITY;
XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
BugAnnotation annotation;
String prefix;
if (field != null) {
if (field.isVolatile())
return;
if (true)
return; // don't report these; too many false positives
annotation = FieldAnnotation.fromXField(field);
prefix = "SA_FIELD_SELF_";
} else {
annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
prefix = "SA_LOCAL_SELF_";
if (opcode == ISUB)
return; // only report this if simple detector reports it
}
if (annotation == null)
return;
SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
location.getHandle());
int line = sourceLine.getStartLine();
BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
if (line > 0 && occursMultipleTimes.get(line))
return;
BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile);
if (ins instanceof InvokeInstruction)
bug.addCalledMethod(classContext.getConstantPoolGen(), (InvokeInstruction) ins);
bug.add(annotation)
.addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
bugReporter.reportBug(bug);
}