@Override public void visitCHECKCAST(CHECKCAST obj) { try { ResourceValueFrame frame = getFrame(); ResourceValue topValue; topValue = frame.getTopValue(); if (topValue.equals(ResourceValue.instance())) { frame.setStatus(ResourceValueFrame.ESCAPED); } } catch (DataflowAnalysisException e) { AnalysisContext.logError("Analysis error", e); } }
@Override public boolean isResourceClose(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, Lock resource, ResourceValueFrame frame) throws DataflowAnalysisException { if (!mightCloseResource(basicBlock, handle, cpg)) { return false; } ResourceValue topValue = frame.getTopValue(); return topValue.isInstance(); }
@Override protected void mergeValues(ResourceValueFrame otherFrame, ResourceValueFrame resultFrame, int slot) throws DataflowAnalysisException { ResourceValue value = ResourceValue.merge(resultFrame.getValue(slot), otherFrame.getValue(slot)); resultFrame.setValue(slot, value); }
@Override public void initEntryFact(ResourceValueFrame result) { result.setValid(); result.clearStack(); final int numSlots = result.getNumSlots(); for (int i = 0; i < numSlots; ++i) { boolean slotContainsInstance = resourceTracker.isParamInstance(resource, i); result.setValue(i, slotContainsInstance ? ResourceValue.instance() : ResourceValue.notInstance()); } }
tmpFact = modifyFrame(fact, tmpFact); tmpFact.clearStack(); tmpFact.pushValue(ResourceValue.notInstance()); ResourceValue topValue = frameAtIf.getValue(frameAtIf.getNumSlots() - 1); if (topValue.isInstance()) { if ((isNullCheck && edgeType == IFCMP_EDGE) || (isNonNullCheck && edgeType == FALL_THROUGH_EDGE)) {
@Override public ResourceValue getDefaultValue() { return ResourceValue.notInstance(); }
@Override public void initEntryFact(ResourceValueFrame result) { result.setValid(); result.clearStack(); final int numSlots = result.getNumSlots(); for (int i = 0; i < numSlots; ++i) { boolean slotContainsInstance = resourceTracker.isParamInstance(resource, i); result.setValue(i, slotContainsInstance ? ResourceValue.instance() : ResourceValue.notInstance()); } }
tmpFact = modifyFrame(fact, tmpFact); tmpFact.clearStack(); tmpFact.pushValue(ResourceValue.notInstance()); ResourceValue topValue = frameAtIf.getValue(frameAtIf.getNumSlots() - 1); if (topValue.isInstance()) { if ((isNullCheck && edgeType == IFCMP_EDGE) || (isNonNullCheck && edgeType == FALL_THROUGH_EDGE)) {
@Override public ResourceValue getDefaultValue() { return ResourceValue.notInstance(); }
private void handleFieldStore(FieldInstruction ins) { try { // If the resource instance is stored in a field, then it escapes ResourceValueFrame frame = getFrame(); ResourceValue topValue = frame.getTopValue(); if (topValue.equals(ResourceValue.instance())) { frame.setStatus(ResourceValueFrame.ESCAPED); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow", e); } handleNormalInstruction(ins); }
public boolean isStreamOpen(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, ResourceValueFrame frame) { if (isOpenOnCreation) { return false; } Instruction ins = handle.getInstruction(); if (!(ins instanceof INVOKESPECIAL)) { return false; } // Does this instruction open the stream? INVOKESPECIAL inv = (INVOKESPECIAL) ins; return frame.isValid() && getInstanceValue(frame, inv, cpg).isInstance() && matchMethod(inv, cpg, this.getResourceClass(), Const.CONSTRUCTOR_NAME); }
@Override protected void mergeValues(ResourceValueFrame otherFrame, ResourceValueFrame resultFrame, int slot) throws DataflowAnalysisException { ResourceValue value = ResourceValue.merge(resultFrame.getValue(slot), otherFrame.getValue(slot)); resultFrame.setValue(slot, value); }
@Override public void visitARETURN(ARETURN ins) { try { ResourceValueFrame frame = getFrame(); ResourceValue topValue = frame.getTopValue(); if (topValue.equals(ResourceValue.instance())) { frame.setStatus(ResourceValueFrame.ESCAPED); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow", e); } handleNormalInstruction(ins); }
if (!frame.isValid() || !getInstanceValue(frame, inv, cpg).isInstance()) { return false;
private void handleArrayStore(ArrayInstruction ins) { try { // If the resource instance is stored in an array, then we consider // it as having escaped. This is conservative; ideally we would // check whether this array is a field or gets passed out of the // method. ResourceValueFrame frame = getFrame(); ResourceValue topValue = frame.getTopValue(); if (topValue.equals(ResourceValue.instance())) { frame.setStatus(ResourceValueFrame.ESCAPED); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Stack underflow", e); } handleNormalInstruction(ins); }
@Override public boolean isResourceClose(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, Lock resource, ResourceValueFrame frame) throws DataflowAnalysisException { if (!mightCloseResource(basicBlock, handle, cpg)) { return false; } ResourceValue topValue = frame.getTopValue(); return topValue.isInstance(); }
private void handleInvoke(InvokeInstruction inv) { ResourceValueFrame frame = getFrame(); int numSlots = frame.getNumSlots(); int numConsumed = getNumWordsConsumed(inv); // See if the resource instance is passed as an argument int instanceArgNum = -1; for (int i = numSlots - numConsumed, argCount = 0; i < numSlots; ++i, ++argCount) { ResourceValue value = frame.getValue(i); if (value.equals(ResourceValue.instance())) { instanceArgNum = argCount; break; } } if (instanceArgNum >= 0 && instanceEscapes(inv, instanceArgNum)) { frame.setStatus(ResourceValueFrame.ESCAPED); } handleNormalInstruction(inv); }
public boolean isStreamOpen(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, ResourceValueFrame frame) { if (isOpenOnCreation) { return false; } Instruction ins = handle.getInstruction(); if (!(ins instanceof INVOKESPECIAL)) { return false; } // Does this instruction open the stream? INVOKESPECIAL inv = (INVOKESPECIAL) ins; return frame.isValid() && getInstanceValue(frame, inv, cpg).isInstance() && matchMethod(inv, cpg, this.getResourceClass(), "<init>"); }
System.out.println("Saw lock value!"); frame.setValue(i, ResourceValue.instance());
if (!frame.isValid() || !getInstanceValue(frame, inv, cpg).isInstance()) { return false;