当前位置: 首页>>代码示例>>Java>>正文


Java LockSet类代码示例

本文整理汇总了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;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:22,代码来源:StaticCalendarDetector.java

示例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;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:21,代码来源:StaticCalendarDetector.java

示例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();
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:28,代码来源:FindSleepWithLockHeld.java

示例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();
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:67,代码来源:FindMismatchedWaitOrNotify.java


注:本文中的edu.umd.cs.findbugs.ba.LockSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。