From: yeom Date: Sun, 4 Nov 2012 07:24:34 +0000 (+0000) Subject: changes: now Inference engine works fine with the EyeTracking benchmark. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=d45bb251bdc1196d7848094fa2ccd566b39e021c changes: now Inference engine works fine with the EyeTracking benchmark. --- diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index c1f48241..fabdf9db 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -1941,7 +1941,7 @@ public class DefinitelyWrittenCheck { // arg idx is starting from 'this' arg if (fc.getThis() != null) { - NTuple thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis()); + NTuple thisLocationPath = deriveLocationTuple(fc.getMethod(), fc.getThis()); if (thisLocationPath != null) { mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath); } @@ -2621,7 +2621,6 @@ public class DefinitelyWrittenCheck { } private NTuple deriveLocationTuple(MethodDescriptor md, TempDescriptor td) { - assert td.getType() != null; if (mapDescriptorToLocationPath.containsKey(td)) { diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index d9bc290e..5bce89cc 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -1743,13 +1743,10 @@ public class FlowDownCheck { Set flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an); for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) { FlatNode fn = (FlatNode) iterator.next(); - System.out.println("SAMEHEIGHT!"); ssjava.addSameHeightWriteFlatNode(fn); } - } else { - System.out.println("NOT SAME HEIGHT!"); - } + } } else { destLocation = diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index b9a39f7d..4054f701 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -318,7 +318,7 @@ public class FlowGraph { addOutEdge(fromNode, edge); addInEdge(toNode, edge); - System.out.println("add a new edge=" + edge); + // System.out.println("add a new edge=" + edge); } private void addInEdge(FlowNode toNode, FlowEdge edge) { @@ -859,4 +859,20 @@ public class FlowGraph { bw.write("}\n"); } + public void removeEdge(NTuple from, NTuple to) { + + Set toberemoved = new HashSet(); + Set edgeSet = getOutEdgeSet(getFlowNode(from)); + + for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { + FlowEdge flowEdge = (FlowEdge) iterator.next(); + if (flowEdge.getInitTuple().equals(from) && flowEdge.getEndTuple().equals(to)) { + toberemoved.add(flowEdge); + } + } + + edgeSet.removeAll(toberemoved); + + } + } \ No newline at end of file diff --git a/Robust/src/Analysis/SSJava/FlowNode.java b/Robust/src/Analysis/SSJava/FlowNode.java index 0c83d756..d170494f 100644 --- a/Robust/src/Analysis/SSJava/FlowNode.java +++ b/Robust/src/Analysis/SSJava/FlowNode.java @@ -30,6 +30,8 @@ public class FlowNode { private boolean isFormHolder = false; + private NTuple baseTuple; + public boolean isIntermediate() { return isIntermediate; } @@ -46,6 +48,14 @@ public class FlowNode { return isFormHolder; } + public void setBaseTuple(NTuple in) { + baseTuple = in; + } + + public NTuple getBaseTuple() { + return baseTuple; + } + public Set getFieldNodeSet() { return fieldNodeSet; } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 5502eb88..8c1c9792 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -586,12 +586,33 @@ public class LocationInference { System.out.println("###RETURN COMP LOC=" + returnLoc); NTuple returnLocTuple = returnLoc.getTuple(); NTuple baseTuple = mapMethodInvokeNodeToBaseTuple.get(min); + System.out.println("###basetuple=" + baseTuple); NTuple newReturnTuple = baseTuple.clone(); for (int i = 1; i < returnLocTuple.size(); i++) { newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor()); } System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple); + + FlowReturnNode holderNode = callerFlowGraph.getFlowReturnNode(min); + NodeTupleSet holderTupleSet = + getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), holderNode); + callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple); + + // then need to remove old constraints + // TODO SAT + System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode); + for (Iterator> iter = holderTupleSet.iterator(); iter.hasNext();) { + NTuple tupleFromHolder = iter.next(); + Set holderOutEdge = callerFlowGraph.getOutEdgeSet(holderNode); + for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) { + FlowEdge outEdge = (FlowEdge) iterator2.next(); + NTuple toberemovedTuple = outEdge.getEndTuple(); + System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple); + callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple); + } + } + } else { // if the return loc set was empty and later pcloc was connected to the return loc // need to make sure that return loc reflects to this changes. @@ -677,6 +698,7 @@ public class LocationInference { System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple + "-> globalParamLocTuple=" + globalParamLocTuple); hasChanges = true; + System.out.println("B1"); globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple); } } @@ -692,6 +714,8 @@ public class LocationInference { + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple=" + globalParamLocTuple); hasChanges = true; + System.out.println("B2"); + globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple); } } @@ -1308,6 +1332,7 @@ public class LocationInference { MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor(); FlowGraph flowGraph = getFlowGraph(md); + FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple()); Set reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode); @@ -1737,6 +1762,7 @@ public class LocationInference { // Location loc = new Location(md, dstVarDesc); // dstLocTuple.add(loc); // } + System.out.println("B11"); globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple); @@ -1849,6 +1875,8 @@ public class LocationInference { if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) { for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) { NTuple pcLocTuple = (NTuple) iterator2.next(); + System.out.println("B12"); + callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple); } } @@ -1864,11 +1892,11 @@ public class LocationInference { GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee); GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller); - // System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode); + System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode); NTuple callerSrcNodeLocTuple = translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple()); - // System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); + System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) { @@ -1880,7 +1908,9 @@ public class LocationInference { translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple()); // System.out.println("outNode=" + outNode + " callerDstNodeLocTuple=" // + callerDstNodeLocTuple); - if (callerDstNodeLocTuple != null) { + if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null + && callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) { + System.out.println("B3"); callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple); } } @@ -1941,7 +1971,7 @@ public class LocationInference { TypeDescriptor type = ((FieldDescriptor) desc).getType(); if (type.isArray()) { - return false; + return !type.isPrimitive(); } else { return type.isPtr(); } @@ -1949,7 +1979,7 @@ public class LocationInference { } else if (desc instanceof VarDescriptor) { TypeDescriptor type = ((VarDescriptor) desc).getType(); if (type.isArray()) { - return false; + return !type.isPrimitive(); } else { return type.isPtr(); } @@ -2338,6 +2368,60 @@ public class LocationInference { private void constructHierarchyGraph() { + LinkedList methodDescList = + (LinkedList) toanalyze_methodDescList.clone(); + + while (!methodDescList.isEmpty()) { + MethodDescriptor md = methodDescList.removeLast(); + if (state.SSJAVADEBUG) { + HierarchyGraph hierarchyGraph = new HierarchyGraph(md); + System.out.println(); + System.out.println("SSJAVA: Construcing the hierarchy graph from " + md); + constructHierarchyGraph(md, hierarchyGraph); + mapDescriptorToHierarchyGraph.put(md, hierarchyGraph); + + } + } + + setupToAnalyze(); + while (!toAnalyzeIsEmpty()) { + ClassDescriptor cd = toAnalyzeNext(); + HierarchyGraph graph = getHierarchyGraph(cd); + for (Iterator iter = cd.getFields(); iter.hasNext();) { + FieldDescriptor fieldDesc = (FieldDescriptor) iter.next(); + if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) { + graph.getHNode(fieldDesc); + } + } + } + + Set keySet = mapDescriptorToHierarchyGraph.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Descriptor key = (Descriptor) iterator.next(); + HierarchyGraph graph = getHierarchyGraph(key); + + Set nodeToBeConnected = new HashSet(); + for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) { + HNode node = (HNode) iterator2.next(); + if (!node.isSkeleton() && !node.isCombinationNode()) { + if (graph.getIncomingNodeSet(node).size() == 0) { + nodeToBeConnected.add(node); + } + } + } + + for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) { + HNode node = (HNode) iterator2.next(); + System.out.println("NEED TO BE CONNECTED TO TOP=" + node); + graph.addEdge(graph.getHNode(TOPDESC), node); + } + + } + + } + + private void constructHierarchyGraph2() { + // do fixed-point analysis LinkedList descriptorListToAnalyze = ssjava.getSortedDescriptors(); @@ -2547,6 +2631,9 @@ public class LocationInference { System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple + " srcNode=" + srcNode + " dstNode=" + dstNode); + // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple); + // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple); + if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1) && srcCurTuple.get(0).equals(dstCurTuple.get(0))) { @@ -2611,6 +2698,31 @@ public class LocationInference { } + private NTuple translateBaseTuple(FlowNode flowNode, NTuple inTuple) { + + if (flowNode.getBaseTuple() != null) { + + NTuple translatedTuple = new NTuple(); + + NTuple baseTuple = flowNode.getBaseTuple(); + + for (int i = 0; i < baseTuple.size(); i++) { + translatedTuple.add(baseTuple.get(i)); + } + + for (int i = 1; i < inTuple.size(); i++) { + translatedTuple.add(inTuple.get(i)); + } + + System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple); + return translatedTuple; + + } else { + return inTuple; + } + + } + private MethodSummary getMethodSummary(MethodDescriptor md) { if (!mapDescToLocationSummary.containsKey(md)) { mapDescToLocationSummary.put(md, new MethodSummary(md)); @@ -3262,6 +3374,8 @@ public class LocationInference { if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) { flowNodeLowerthanPCLocSet.add(node); fg.addValueFlowEdge(pcDescTuple, node.getDescTuple()); + System.out.println("B10"); + subGlobalFlowGraph.addValueFlowEdge(pcLocTuple, translateToLocTuple(md, node.getDescTuple())); } @@ -3276,7 +3390,7 @@ public class LocationInference { System.out.println("#########################################"); for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) { FlowNode lowerNode = (FlowNode) iterator.next(); - if (lowerNode.getCompositeLocation() == null) { + if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) { NTuple lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple()); CompositeLocation newComp = calculateCompositeLocationFromSubGlobalGraph(md, lowerNode); @@ -4723,6 +4837,7 @@ public class LocationInference { fn.setDeclarationNode(); if (dn.getExpression() != null) { + System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0)); NodeTupleSet nodeSetRHS = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null, @@ -4751,9 +4866,22 @@ public class LocationInference { GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md); for (Iterator> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) { NTuple calleeReturnLocTuple = iterator.next(); + System.out.println("B7"); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS)); } + for (Iterator> iterator = implicitFlowTupleSet.globalIterator(); iterator + .hasNext();) { + NTuple implicitGlobalTuple = iterator.next(); + System.out.println("B8"); + + globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS)); + } + + System.out.println("-nodeSetRHS=" + nodeSetRHS); + System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet); + } } @@ -5001,6 +5129,13 @@ public class LocationInference { assert (baseNodeSet.size() == 1); NTuple baseTuple = baseNodeSet.iterator().next(); + if (baseTuple.get(0) instanceof InterDescriptor) { + if (baseTuple.size() > 1) { + throw new Error(); + } + FlowNode interNode = getFlowGraph(mdCaller).getFlowNode(baseTuple); + baseTuple = translateBaseTuple(interNode, baseTuple); + } mapMethodInvokeNodeToBaseTuple.put(min, baseTuple); if (!min.getMethod().isStatic()) { @@ -5024,7 +5159,8 @@ public class LocationInference { // nodeSet.addTuple(inFlowTuple); System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from=" + mdCallee.getThis()); - tupleSet.addTuple(inFlowTuple); + // tupleSet.addTuple(inFlowTuple); + tupleSet.addTuple(baseTuple); } else { // TODO System.out.println("returnNode=" + returnNode); @@ -5110,7 +5246,7 @@ public class LocationInference { } if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) { - FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min); + FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min); if (needToGenerateInterLoc(tupleSet)) { System.out.println("20"); @@ -5136,17 +5272,26 @@ public class LocationInference { } } - setNode.addTuple(interTuple); - System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + setNode); + returnHolderNode.addTuple(interTuple); + // TODO + nodeSet.addTuple(interTuple); + System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode); } else { - setNode.addTupleSet(tupleSet); - System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode); - + returnHolderNode.addTupleSet(tupleSet); + System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode); } // setNode.addTupleSet(tupleSet); - nodeSet.addTuple(setNode.getDescTuple()); + // NodeTupleSet setFromReturnNode=new NodeTupleSet(); + // setFromReturnNode.addTuple(tuple); + + NodeTupleSet holderTupleSet = + getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode); + System.out.println("HOLDER TUPLe SET=" + holderTupleSet); + nodeSet.addTupleSet(holderTupleSet); + + nodeSet.addTuple(returnHolderNode.getDescTuple()); } // propagateFlowsFromCallee(min, md, min.getMethod()); @@ -5175,6 +5320,47 @@ public class LocationInference { } + private NodeTupleSet getNodeTupleSetFromReturnNode(FlowGraph fg, FlowReturnNode node) { + NodeTupleSet nts = new NodeTupleSet(); + + Set> returnSet = node.getReturnTupleSet(); + + for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) { + NTuple tuple = (NTuple) iterator.next(); + FlowNode flowNode = fg.getFlowNode(tuple); + if (flowNode instanceof FlowReturnNode) { + returnSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode)); + } else { + returnSet.add(tuple); + } + } + + for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) { + NTuple nTuple = (NTuple) iterator.next(); + nts.addTuple(nTuple); + } + + return nts; + + } + + private Set> recurGetNode(FlowGraph fg, FlowReturnNode rnode) { + + Set> tupleSet = new HashSet>(); + + Set> returnSet = rnode.getReturnTupleSet(); + for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) { + NTuple tuple = (NTuple) iterator.next(); + FlowNode flowNode = fg.getFlowNode(tuple); + if (flowNode instanceof FlowReturnNode) { + tupleSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode)); + } + tupleSet.add(tuple); + } + + return tupleSet; + } + private NTuple generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) { int size = 0; @@ -5222,7 +5408,7 @@ public class LocationInference { } // Set reachableSet = fg.getReachFlowNodeSetFrom(inNode); Set reachableSet = fg.getReachableSetFrom(inNode.getDescTuple()); - System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet); + // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet); for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) { FlowNode fn = (FlowNode) iterator.next(); @@ -5290,6 +5476,8 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) { NTuple arrTuple = arrIter.next(); + System.out.println("B4"); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple)); } } @@ -5307,7 +5495,8 @@ public class LocationInference { if (needToGenerateInterLoc(nodeSetArrayAccessExp)) { System.out.println("1"); - NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); + FlowNode interNode = getFlowGraph(md).createIntermediateNode(); + NTuple interTuple = interNode.getDescTuple(); for (Iterator> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) { NTuple higherTuple = iter.next(); @@ -5321,6 +5510,7 @@ public class LocationInference { if (base != null) { fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0), getClassTypeDescriptor(base.get(base.size() - 1))); + interNode.setBaseTuple(base); } } } @@ -5557,6 +5747,8 @@ public class LocationInference { for (Iterator> iterator = idxNodeTupleSet.globalIterator(); iterator .hasNext();) { NTuple calleeReturnLocTuple = iterator.next(); + System.out.println("B9"); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, flowFieldTuple)); } @@ -5689,6 +5881,8 @@ public class LocationInference { NTuple callerLHSTuple = iter2.next(); System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> " + translateToLocTuple(md, callerLHSTuple)); + System.out.println("B5"); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); } @@ -5699,6 +5893,8 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) { NTuple callerLHSTuple = iter2.next(); + System.out.println("B6"); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> " diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java b/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java index 851a99bd..c635d89a 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java @@ -27,11 +27,9 @@ public class DeviationScanner { @LOC("DEV") - private EyePosition eyePositions[]; - - // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0), - // RIGHT(-1, 0), LEFT_DOWN( - // +1, +1), DOWN(0, +1), RIGHT_DOWN(-1, +1); + private int x[]; + @LOC("DEV") + private int y[]; public static final int LEFT_UP = 0; public static final int UP = 1; @@ -44,23 +42,18 @@ public class DeviationScanner { public static final int RIGHT_DOWN = 8; public DeviationScanner() { - eyePositions = new EyePosition[3]; + x = new int[3]; + y = new int[3]; + SSJAVA.arrayinit(x, -1); + SSJAVA.arrayinit(y, -1); } - @LATTICE("THIS %d and %d >>> %s", - // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY, - // deviation.toString())); return deviation; } @@ -140,11 +131,6 @@ public class DeviationScanner { return -1; } - public void clear() { - System.out.println("CLEAR"); - eyePositions = new EyePosition[3]; - } - public String toStringDeviation(@LOC("IN") int dev) { if (dev == LEFT_UP) { return "LEFT_UP"; diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java index 8422220a..f5edbb88 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java @@ -29,23 +29,6 @@ public class EyePosition { private int x; @LOC("POS") private int y; - - @LOC("POS") private double facex; - @LOC("POS") private double facey; - @LOC("POS") private double facewidth; - @LOC("POS") private double faceheight; - - // private Rectangle2D faceRect; - - // public EyePosition(Point p, Rectangle2D faceRect) { - // this(p.x, p.y, faceRect); - // } - // - // public EyePosition(int x, int y, Rectangle2D faceRect) { - // this.x = x; - // this.y = y; - // this.faceRect = faceRect; - // } public EyePosition(int x, int y) { this.x = x; @@ -64,36 +47,6 @@ public class EyePosition { return "(" + x + "," + y + ")"; } - // public Deviation getDeviation(EyePosition oldEyePosition) { - // if (oldEyePosition == null) return Deviation.NONE; - // - // //first we check if the faceRects are corresponding - // double widthChange = (this.faceRect.getWidth() - - // oldEyePosition.faceRect.getWidth()) / this.faceRect.getWidth(); - // if (widthChange > 0.1) return Deviation.NONE; - // - // int maxDeviationX = (int)Math.round(this.faceRect.getWidth() / 4f); - // int maxDeviationY = (int)Math.round(this.faceRect.getWidth() / 8f); - // int minDeviation = (int)Math.round(this.faceRect.getWidth() / 16f); - // - // int deviationX = Math.abs(x - oldEyePosition.x); - // int directionX = sgn(x - oldEyePosition.x); - // if (deviationX < minDeviation || deviationX > maxDeviationX) directionX = - // 0; - // - // int deviationY = Math.abs(y - oldEyePosition.y); - // int directionY = sgn(y - oldEyePosition.y); - // if (deviationY < minDeviation || deviationY > maxDeviationY) directionY = - // 0; - // - // double deviationXPercent = deviationX / this.faceRect.getWidth(); - // double deviationYPercent = deviationY / this.faceRect.getWidth(); - // - // System.out.println(String.format("devX: %.2f | devY: %.2f", - // deviationXPercent*100f, deviationYPercent*100f)); - // return Deviation.getDirectionFor(directionX, directionY); - // } - private static int sgn(int i) { if (i > 0) return 1; diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java index 3197ac34..9e944aa2 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java @@ -1,3 +1,5 @@ +import Benchmarks.SSJava.EyeTrackingInfer.EyePosition; + /* * Copyright 2009 (c) Florian Frankenberger (darkblue.de) * @@ -20,22 +22,19 @@ /** * This is the main class of LEA. *

- * It uses a face detection algorithm to find an a face within the provided - * image(s). Then it searches for the eye in a region where it most likely - * located and traces its position relative to the face and to the last known - * position. The movements are estimated by comparing more than one movement. If - * a movement is distinctly pointing to a direction it is recognized and all - * listeners get notified. + * It uses a face detection algorithm to find an a face within the provided image(s). Then it + * searches for the eye in a region where it most likely located and traces its position relative to + * the face and to the last known position. The movements are estimated by comparing more than one + * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners + * get notified. *

* The notification is designed as observer pattern. You simply call - * addEyeMovementListener(IEyeMovementListener) to add an - * implementation of IEyeMovementListener to LEA. When a face is - * recognized/lost or whenever an eye movement is detected LEA will call the - * appropriate methods of the listener + * addEyeMovementListener(IEyeMovementListener) to add an implementation of + * IEyeMovementListener to LEA. When a face is recognized/lost or whenever an eye + * movement is detected LEA will call the appropriate methods of the listener *

- * LEA also needs an image source implementing the ICaptureDevice. - * One image source proxy to the Java Media Framework is included ( - * JMFCaptureDevice). + * LEA also needs an image source implementing the ICaptureDevice. One image source + * proxy to the Java Media Framework is included ( JMFCaptureDevice). *

* Example (for using LEA with Java Media Framework): *

@@ -43,21 +42,18 @@ * LEA lea = new LEA(new JMFCaptureDevice(), true); * *

- * This will start LEA with the first available JMF datasource with an extra - * status window showing if face/eye has been detected successfully. Please note - * that face detection needs about 2 seconds to find a face. After detection the - * following face detection is much faster. + * This will start LEA with the first available JMF datasource with an extra status window showing + * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds + * to find a face. After detection the following face detection is much faster. * * @author Florian Frankenberger */ -@LATTICE("LASTJava Media Framework just start from here. + * @METHOD To test LEA with the first capture device from the Java Media Framework + * just start from here. * * @param args * @throws Exception @@ -95,7 +90,7 @@ public class LEA { @LOC("C") int i = 0; SSJAVA: while (true) { - @LOC("IMG") Image image = ImageReader.getImage(); + @LOC("IMG") Image image = ImageReader.getImage(); if (image == null) { break; } @@ -105,12 +100,11 @@ public class LEA { System.out.println("Done."); } - private void processImage(@LOC("IN") Image image) { @LOC("THIS,LEA.POS") FaceAndEyePosition positions = implementation.getEyePosition(image); - // if (positions.getEyePosition() != null) { - deviationScanner.addEyePosition(positions.getEyePosition()); + deviationScanner.addEyePosition(positions.getEyePosition().getX(), positions.getEyePosition() + .getY()); @LOC("THIS,LEA.DEV,DeviationScanner.DEV") int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); if (deviation != DeviationScanner.NONE) { @@ -118,7 +112,6 @@ public class LEA { // notifyEyeMovementListenerEyeMoved(deviation); } // } - lastPositions = positions; } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java index 4cc353e0..412d9e23 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java @@ -23,11 +23,10 @@ * @author Florian Frankenberger */ - public class DeviationScanner { - - private EyePosition eyePositions[]; + private int x[]; + private int y[]; // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0), // RIGHT(-1, 0), LEFT_DOWN( @@ -44,55 +43,47 @@ public class DeviationScanner { public static final int RIGHT_DOWN = 8; public DeviationScanner() { - eyePositions = new EyePosition[3]; + x = new int[3]; + y = new int[3]; + SSJAVA.arrayinit(x, -1); + SSJAVA.arrayinit(y, -1); } - - public void addEyePosition( EyePosition eyePosition) { - - // for ( int i = 1; i < 3; i++) { - // eyePositions[i - 1] = eyePositions[i]; - // eyePositions[i] = null; - // } - // eyePositions[eyePositions.length - 1] = eyePosition; - - SSJAVA.append(eyePositions, eyePosition); - + public void addEyePosition(int inx, int iny) { + SSJAVA.append(x, inx); + SSJAVA.append(y, iny); } - // - - - public int scanForDeviation( Rectangle2D faceRect) { + public int scanForDeviation(Rectangle2D faceRect) { - int deviation = NONE; + int deviation = NONE; - for ( int i = 0; i < 3; i++) { - if (eyePositions[i] == null) { + for (int i = 0; i < 3; i++) { + if (x[i] == -1) { return deviation; } } - double deviationX = 0; - double deviationY = 0; + double deviationX = 0; + double deviationY = 0; - int lastIdx = -1; - for ( int i = 0; i < 3; ++i) { + int lastIdx = -1; + for (int i = 0; i < 3; ++i) { if (lastIdx != -1) { - deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX()); - deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY()); + deviationX += (x[i] - x[lastIdx]); + deviationY += (y[i] - y[lastIdx]); } lastIdx = i; } - final double deviationPercentX = 0.04; - final double deviationPercentY = 0.04; + final double deviationPercentX = 0.04; + final double deviationPercentY = 0.04; deviationX /= faceRect.getWidth(); deviationY /= faceRect.getWidth(); - int deviationAbsoluteX = 0; - int deviationAbsoluteY = 0; + int deviationAbsoluteX = 0; + int deviationAbsoluteY = 0; if (deviationX > deviationPercentX) deviationAbsoluteX = 1; if (deviationX < -deviationPercentX) @@ -105,17 +96,14 @@ public class DeviationScanner { deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY); if (deviation != NONE) { - eyePositions = new EyePosition[3]; + SSJAVA.arrayinit(x, -1); + SSJAVA.arrayinit(y, -1); } - // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s", - // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY, - // deviation.toString())); return deviation; } - - public int getDirectionFor( int directionX, int directionY) { + public int getDirectionFor(int directionX, int directionY) { if (directionX == +1 && directionY == -1) { return LEFT_UP; @@ -140,12 +128,7 @@ public class DeviationScanner { return -1; } - public void clear() { - System.out.println("CLEAR"); - eyePositions = new EyePosition[3]; - } - - public String toStringDeviation( int dev) { + public String toStringDeviation(int dev) { if (dev == LEFT_UP) { return "LEFT_UP"; } else if (dev == UP) { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java index 40479eb1..7db95e6a 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java @@ -20,22 +20,19 @@ /** * This is the main class of LEA. *

- * It uses a face detection algorithm to find an a face within the provided - * image(s). Then it searches for the eye in a region where it most likely - * located and traces its position relative to the face and to the last known - * position. The movements are estimated by comparing more than one movement. If - * a movement is distinctly pointing to a direction it is recognized and all - * listeners get notified. + * It uses a face detection algorithm to find an a face within the provided image(s). Then it + * searches for the eye in a region where it most likely located and traces its position relative to + * the face and to the last known position. The movements are estimated by comparing more than one + * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners + * get notified. *

* The notification is designed as observer pattern. You simply call - * addEyeMovementListener(IEyeMovementListener) to add an - * implementation of IEyeMovementListener to LEA. When a face is - * recognized/lost or whenever an eye movement is detected LEA will call the - * appropriate methods of the listener + * addEyeMovementListener(IEyeMovementListener) to add an implementation of + * IEyeMovementListener to LEA. When a face is recognized/lost or whenever an eye + * movement is detected LEA will call the appropriate methods of the listener *

- * LEA also needs an image source implementing the ICaptureDevice. - * One image source proxy to the Java Media Framework is included ( - * JMFCaptureDevice). + * LEA also needs an image source implementing the ICaptureDevice. One image source + * proxy to the Java Media Framework is included ( JMFCaptureDevice). *

* Example (for using LEA with Java Media Framework): *

@@ -43,22 +40,17 @@ * LEA lea = new LEA(new JMFCaptureDevice(), true); * *

- * This will start LEA with the first available JMF datasource with an extra - * status window showing if face/eye has been detected successfully. Please note - * that face detection needs about 2 seconds to find a face. After detection the - * following face detection is much faster. + * This will start LEA with the first available JMF datasource with an extra status window showing + * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds + * to find a face. After detection the following face detection is much faster. * * @author Florian Frankenberger */ - public class LEA { - private LEAImplementation implementation; - - private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null); - + private DeviationScanner deviationScanner = new DeviationScanner(); public LEA() { @@ -68,18 +60,17 @@ public class LEA { } /** - * Clears the internal movement buffer. If you just capture some of the eye - * movements you should call this every time you start recording the - * movements. Otherwise you may get notified for movements that took place - * BEFORE you started recording. + * Clears the internal movement buffer. If you just capture some of the eye movements you should + * call this every time you start recording the movements. Otherwise you may get notified for + * movements that took place BEFORE you started recording. */ public void clear() { // this.imageProcessor.clearDeviationScanner(); } /** - * @METHOD To test LEA with the first capture device from the - * Java Media Framework just start from here. + * @METHOD To test LEA with the first capture device from the Java Media Framework + * just start from here. * * @param args * @throws Exception @@ -89,13 +80,12 @@ public class LEA { lea.doRun(); } - public void doRun() { - int i = 0; + int i = 0; SSJAVA: while (true) { - Image image = ImageReader.getImage(); + Image image = ImageReader.getImage(); if (image == null) { break; } @@ -105,19 +95,16 @@ public class LEA { System.out.println("Done."); } - - private void processImage( Image image) { - FaceAndEyePosition positions = implementation.getEyePosition(image); - // if (positions.getEyePosition() != null) { - deviationScanner.addEyePosition(positions.getEyePosition()); - int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); + private void processImage(Image image) { + FaceAndEyePosition positions = implementation.getEyePosition(image); + EyePosition eye = positions.getEyePosition(); + deviationScanner.addEyePosition(eye.getX(),eye.getY()); + Rectangle2D face = positions.getFacePosition(); + int deviation = deviationScanner.scanForDeviation(face);// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); if (deviation != DeviationScanner.NONE) { System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation)); - // notifyEyeMovementListenerEyeMoved(deviation); } - // } - lastPositions = positions; } } diff --git a/Robust/src/ClassLibrary/SSJava/SSJAVA.java b/Robust/src/ClassLibrary/SSJava/SSJAVA.java index 8e49e948..19f74024 100644 --- a/Robust/src/ClassLibrary/SSJava/SSJAVA.java +++ b/Robust/src/ClassLibrary/SSJava/SSJAVA.java @@ -61,9 +61,24 @@ public class SSJAVA { static void append(Object array[], Object item) { for (int i = 1; i < array.length; i++) { array[i - 1] = array[i]; - array[i]=null; + array[i] = null; } array[array.length - 1] = item; } + + static void append(int array[], int item) { + for (int i = 1; i < array.length; i++) { + array[i - 1] = array[i]; + array[i] = 0; + } + array[array.length - 1] = item; + } + + + static void arrayinit(Object array[]) { + for (int i = 1; i < array.length; i++) { + array[i] = null; + } + } } diff --git a/Robust/src/ClassLibrary/SSJavaInfer/SSJAVA.java b/Robust/src/ClassLibrary/SSJavaInfer/SSJAVA.java index 0fe1de15..9d0e25e6 100644 --- a/Robust/src/ClassLibrary/SSJavaInfer/SSJAVA.java +++ b/Robust/src/ClassLibrary/SSJavaInfer/SSJAVA.java @@ -66,4 +66,18 @@ public class SSJAVA { array[array.length - 1] = item; } + static void append(int array[], int item) { + for (int i = 1; i < array.length; i++) { + array[i - 1] = array[i]; + array[i] = 0; + } + array[array.length - 1] = item; + } + + static void arrayinit(Object array[]) { + for (int i = 1; i < array.length; i++) { + array[i] = null; + } + } + } diff --git a/Robust/src/ClassLibrary/SSJavaInfer/String.java b/Robust/src/ClassLibrary/SSJavaInfer/String.java index e2b6d7e4..fa036589 100644 --- a/Robust/src/ClassLibrary/SSJavaInfer/String.java +++ b/Robust/src/ClassLibrary/SSJavaInfer/String.java @@ -321,7 +321,7 @@ public class String { length = length + 1; } while (tmp != 0); - char chararray[]; + char[] chararray; if (x < 0) chararray = new char[length + 1]; else