+ updateFlowGraphPCReturnLocInheritance();
+ }
+
+ private void updateFlowGraphPCReturnLocInheritance() {
+ Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
+
+ if (mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc).size() == 1) {
+ continue;
+ }
+
+ Set<MethodDescriptor> methodDescSet =
+ mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
+
+ NTuple<Descriptor> highestPCLoc =
+ mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc);
+
+ NTuple<Descriptor> highestRETURNLoc =
+ mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc);
+
+ System.out.println("---highestMethodDesc=" + highestMethodDesc);
+
+ for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+ MethodDescriptor md = (MethodDescriptor) iterator2.next();
+ FlowGraph flowGraph = getFlowGraph(md);
+
+ MethodSummary summary = getMethodSummary(md);
+ CompositeLocation curPCLoc = summary.getPCLoc();
+
+ // update PCLOC
+ if (highestPCLoc != null) {
+ // handle the case that PCLOC is started with 'this'...
+ NTuple<Descriptor> newPCLoc = new NTuple<Descriptor>();
+ if (highestPCLoc.size() == 1) {
+ newPCLoc.add(highestPCLoc.get(0));
+ } else {
+ newPCLoc.add(md.getThis());
+ newPCLoc.add(highestPCLoc.get(1));
+ }
+
+ FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(curPCLoc.getTuple()));
+ pcFlowNode.setBaseTuple(newPCLoc);
+
+ CompositeLocation newPCLocCompLoc =
+ new CompositeLocation(translateToLocTuple(md, newPCLoc));
+ summary.setPCLoc(newPCLocCompLoc);
+ } else {
+ // need to remove PCLOC if the overridden method defines it
+ if (curPCLoc != null && !curPCLoc.get(0).isTop()) {
+ System.out.println("md=" + md + " curPCLoc=" + curPCLoc);
+ FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(curPCLoc.getTuple()));
+ System.out.println("#######REMOVE PCLOCNODE=" + pcFlowNode);
+ flowGraph.removeNode(pcFlowNode);
+ }
+ }
+
+ // need to update RETURNLOC
+ if (highestRETURNLoc != null) {
+
+ CompositeLocation curRETURNLoc = summary.getRETURNLoc();
+ System.out.println("curRETURNLoc=" + curRETURNLoc);
+
+ // handle the case that RETURNLOC is started with 'this'...
+ NTuple<Descriptor> newRETURNLoc = new NTuple<Descriptor>();
+ if (highestRETURNLoc.size() == 1) {
+ newRETURNLoc.add(highestRETURNLoc.get(0));
+ } else {
+ newRETURNLoc.add(md.getThis());
+ newRETURNLoc.add(highestRETURNLoc.get(1));
+ }
+
+ FlowNode returnFlowNode =
+ flowGraph.getFlowNode(translateToDescTuple(curRETURNLoc.getTuple()));
+ returnFlowNode.setBaseTuple(newRETURNLoc);
+
+ CompositeLocation newRETURNLocCompLoc =
+ new CompositeLocation(translateToLocTuple(md, newRETURNLoc));
+ summary.setPCLoc(newRETURNLocCompLoc);
+ System.out.println("md=" + md + "###newRETURNLocCompLoc=" + newRETURNLocCompLoc);
+
+ }
+
+ }
+ }
+ }
+
+ private void calculateHighestPCLocInheritance() {
+
+ Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+ next: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
+
+ NTuple<Descriptor> tempTuple = null;
+
+ if (getMethodSummary(highestMethodDesc).getPCLoc() != null) {
+
+ Set<MethodDescriptor> methodDescSet =
+ mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
+
+ for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+ MethodDescriptor md = (MethodDescriptor) iterator2.next();
+
+ FlowGraph flowGraph = getFlowGraph(md);
+ if (flowGraph == null) {
+ continue;
+ }
+ Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
+ System.out.println("###md=" + md + " paramNodeSet=" + paramNodeSet);
+
+ CompositeLocation pcLOC = getMethodSummary(md).getPCLoc();
+
+ if (!pcLOC.get(0).isTop()) {
+ if (pcLOC.getSize() == 1) {
+ // return location is not started with 'this'
+ // check whether the return location is lower than all parameters.
+
+ FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(pcLOC.getTuple()));
+
+ int count = 0;
+ for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
+ FlowNode paramNode = (FlowNode) iterator3.next();
+ if (flowGraph.getReachableSetFrom(pcFlowNode.getCurrentDescTuple().subList(0, 1))
+ .contains(paramNode)) {
+ count++;
+ System.out.println("-------" + pcFlowNode + " -> " + paramNode);
+ }
+ }
+
+ int offset = 0;
+ if (!md.isStatic()) {
+ offset = 1;
+ }
+
+ NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
+ rTuple.add(pcLOC.get(0).getLocDescriptor());
+ if (count == (md.numParameters() + offset)) {
+ // means return loc is lower than a composite location starting with 'this'
+ mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, rTuple);
+ } else {
+ if (tempTuple == null) {
+ tempTuple = rTuple;
+ }
+ }
+ } else {
+ // if the current overridden method has a composite pc loc(size>1)
+ // and it has not yet finalized the pc location,
+ // the highest overridden method would have the composite pc location starting with
+ // 'this'
+ NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
+ for (int i = 0; i < pcLOC.getSize(); i++) {
+ rTuple.add(pcLOC.get(i).getLocDescriptor());
+ }
+ tempTuple = rTuple;
+ }
+ } else {
+ mapHighestOverriddenMethodDescToPCLocTuple.remove(highestMethodDesc);
+ System.out.println("highest=" + highestMethodDesc + " HIGHEST PCLOC="
+ + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+ continue next;
+ }
+ }
+
+ }
+
+ if (!mapHighestOverriddenMethodDescToPCLocTuple.containsKey(highestMethodDesc)
+ && tempTuple != null) {
+ mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, tempTuple);
+ }
+ System.out.println("highest=" + highestMethodDesc + " HIGHEST PCLOC="
+ + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+ }
+