private void writtenAnalysis_nodeAction(FlatNode fn,
Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr, FlatNode loopEntrance) {
+
if (fn.equals(loopEntrance)) {
// it reaches loop entrance: changes all flag to true
Set<NTuple<Descriptor>> keySet = curr.keySet();
break;
case FKind.FlatCall: {
-
FlatCall fc = (FlatCall) fn;
bindHeapPathCallerArgWithCaleeParam(fc);
if (currentStatus == null) {
gen.put(fn, Boolean.FALSE);
} else {
- checkFlag(currentStatus.booleanValue(), fn);
+ checkFlag(currentStatus.booleanValue(), fn, read);
}
}
if (currentStatus == null) {
gen.put(fn, Boolean.FALSE);
} else {
- checkFlag(currentStatus.booleanValue(), fn);
+ checkFlag(currentStatus.booleanValue(), fn, hp);
}
}
new Hashtable<Integer, NTuple<Descriptor>>();
// arg idx is starting from 'this' arg
- NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
- thisHeapPath.add(fc.getThis());
+ NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
+ if (thisHeapPath == null) {
+ // method is called without creating new flat node representing 'this'
+ thisHeapPath = new NTuple<Descriptor>();
+ thisHeapPath.add(fc.getThis());
+ }
+
mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
for (int i = 0; i < fc.numArgs(); i++) {
}
- private void checkFlag(boolean booleanValue, FlatNode fn) {
+ private void checkFlag(boolean booleanValue, FlatNode fn, NTuple<Descriptor> hp) {
if (booleanValue) {
throw new Error(
- "There is a variable who comes back to the same read statement without being overwritten at the out-most iteration at "
- + methodContainingSSJavaLoop.getClassDesc().getSourceFileName()
- + "::"
+ "There is a variable, which is reachable through references "
+ + hp
+ + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
+ + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
+ fn.getNumLine());
}
}
// set up heap path
NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
- NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
- readingHeapPath.add(fld);
- mapHeapPath.put(lhs, readingHeapPath);
-
- // read (x.f)
- if (fld.getType().isImmutable()) {
- // if WT doesnot have hp(x.f), add hp(x.f) to READ
- if (!writtenSet.contains(readingHeapPath)) {
- readSet.add(readingHeapPath);
+ if (srcHeapPath != null) {
+ // if lhs srcHeapPath is null, it means that it is not reachable from
+ // callee's parameters. so just ignore it
+
+ NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
+ readingHeapPath.add(fld);
+ mapHeapPath.put(lhs, readingHeapPath);
+
+ // read (x.f)
+ if (fld.getType().isImmutable()) {
+ // if WT doesnot have hp(x.f), add hp(x.f) to READ
+ if (!writtenSet.contains(readingHeapPath)) {
+ readSet.add(readingHeapPath);
+ }
}
- }
- // need to kill hp(x.f) from WT
- writtenSet.remove(readingHeapPath);
+ // need to kill hp(x.f) from WT
+ writtenSet.remove(readingHeapPath);
+ }
}
break;
// set up heap path
NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
- NTuple<Descriptor> newHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
- newHeapPath.add(fld);
- mapHeapPath.put(fld, newHeapPath);
-
- // write(x.f)
- // need to add hp(y) to WT
- writtenSet.add(newHeapPath);
+ if (lhsHeapPath != null) {
+ // if lhs heap path is null, it means that it is not reachable from
+ // callee's parameters. so just ignore it
+ NTuple<Descriptor> newHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
+ newHeapPath.add(fld);
+ mapHeapPath.put(fld, newHeapPath);
+
+ // write(x.f)
+ // need to add hp(y) to WT
+ writtenSet.add(newHeapPath);
+ }
}
break;
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, nametable, ln.getCondition(), new CompositeLocation());
- addTypeLocation(ln.getCondition().getType(), (condLoc));
+ addLocationType(ln.getCondition().getType(), (condLoc));
CompositeLocation bodyLoc = checkLocationFromBlockNode(md, nametable, ln.getBody());
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, bn.getVarTable(), ln.getCondition(),
new CompositeLocation());
- addTypeLocation(ln.getCondition().getType(), condLoc);
+ addLocationType(ln.getCondition().getType(), condLoc);
CompositeLocation updateLoc =
checkLocationFromBlockNode(md, bn.getVarTable(), ln.getUpdate());
Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
glbInputSet.add(condLoc);
- glbInputSet.add(updateLoc);
+// glbInputSet.add(updateLoc);
CompositeLocation glbLocOfForLoopCond = CompositeLattice.calculateGLB(glbInputSet);
// check location of 'forloop' body
CompositeLocation blockLoc = checkLocationFromBlockNode(md, bn.getVarTable(), ln.getBody());
+ // compute glb of body including loop body and update statement
+ glbInputSet.clear();
+
if (blockLoc == null) {
// when there is no statement in the loop body
- return glbLocOfForLoopCond;
+
+ if(updateLoc==null){
+ // also there is no update statement in the loop body
+ return glbLocOfForLoopCond;
+ }
+ glbInputSet.add(updateLoc);
+
+ }else{
+ glbInputSet.add(blockLoc);
+ glbInputSet.add(updateLoc);
}
+
+ CompositeLocation loopBodyLoc = CompositeLattice.calculateGLB(glbInputSet);
- if (!CompositeLattice.isGreaterThan(glbLocOfForLoopCond, blockLoc)) {
+ if (!CompositeLattice.isGreaterThan(glbLocOfForLoopCond, loopBodyLoc)) {
throw new Error(
"The location of the for-condition statement is lower than the for-loop body at "
+ cd.getSourceFileName() + ":" + ln.getCondition().getNumLine());
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation());
- addTypeLocation(isn.getCondition().getType(), condLoc);
+ addLocationType(isn.getCondition().getType(), condLoc);
glbInputSet.add(condLoc);
CompositeLocation locTrueBlock = checkLocationFromBlockNode(md, nametable, isn.getTrueBlock());
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, nametable, tn.getCond(), new CompositeLocation());
- addTypeLocation(tn.getCond().getType(), condLoc);
+ addLocationType(tn.getCond().getType(), condLoc);
CompositeLocation trueLoc =
checkLocationFromExpressionNode(md, nametable, tn.getTrueExpr(), new CompositeLocation());
- addTypeLocation(tn.getTrueExpr().getType(), trueLoc);
+ addLocationType(tn.getTrueExpr().getType(), trueLoc);
CompositeLocation falseLoc =
checkLocationFromExpressionNode(md, nametable, tn.getFalseExpr(), new CompositeLocation());
- addTypeLocation(tn.getFalseExpr().getType(), falseLoc);
+ addLocationType(tn.getFalseExpr().getType(), falseLoc);
// check if condLoc is higher than trueLoc & falseLoc
if (!CompositeLattice.isGreaterThan(condLoc, trueLoc)) {
CompositeLocation argLoc =
checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation());
glbInputSet.add(argLoc);
- addTypeLocation(en.getType(), argLoc);
+ addLocationType(en.getType(), argLoc);
}
// check array initializers
ExpressionNode left = fan.getExpression();
loc = checkLocationFromExpressionNode(md, nametable, left, loc);
- // addTypeLocation(left.getType(), loc);
if (!left.getType().isPrimitive()) {
FieldDescriptor fd = fan.getField();
if (locDec.startsWith(SSJavaAnalysis.DELTA)) {
DeltaLocation deltaLoc = parseDeltaDeclaration(md, n, locDec);
d2loc.put(vd, deltaLoc);
- addTypeLocation(vd.getType(), deltaLoc);
+ addLocationType(vd.getType(), deltaLoc);
} else {
CompositeLocation compLoc = parseLocationDeclaration(md, n, locDec);
d2loc.put(vd, compLoc);
- addTypeLocation(vd.getType(), compLoc);
+ addLocationType(vd.getType(), compLoc);
}
}
+ cd.getSourceFileName() + ".");
}
Location loc = new Location(cd, locationID);
- // d2loc.put(fd, loc);
- addTypeLocation(fd.getType(), loc);
+ addLocationType(fd.getType(), loc);
}
}
}
- private void addTypeLocation(TypeDescriptor type, CompositeLocation loc) {
+ private void addLocationType(TypeDescriptor type, CompositeLocation loc) {
if (type != null) {
type.setExtension(loc);
}
}
- private void addTypeLocation(TypeDescriptor type, Location loc) {
+ private void addLocationType(TypeDescriptor type, Location loc) {
if (type != null) {
type.setExtension(loc);
}