From: jjenista Date: Mon, 1 Sep 2008 21:13:56 +0000 (+0000) Subject: Changed the top-level procedure for resolving a method call. When virtual X-Git-Tag: buildscript^6~68 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=21d56c476b03249a8860c7590a608e580510f14a;p=IRC.git Changed the top-level procedure for resolving a method call. When virtual dispatch is possible, instead of merging together every potential callee and then applying that result to the working graph, find the result of applying each callee to a copy of the working graph, and merge all of those results together. This procedure is correct. --- diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 25c7b206..0e8d465e 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -457,11 +457,11 @@ public class OwnershipAnalysis { // adding parameters labels to new heap regions for( int i = 0; i < fm.numParameters(); ++i ) { TempDescriptor tdParam = fm.getParameter(i); + og.assignTempEqualToParamAlloc(tdParam, methodDesc instanceof TaskDescriptor, new Integer(i) ); } - break; case FKind.FlatOpNode: @@ -521,43 +521,36 @@ public class OwnershipAnalysis { FlatCall fc = (FlatCall) fn; MethodDescriptor md = fc.getMethod(); FlatMethod flatm = state.getMethodFlat(md); - OwnershipGraph ogAllPossibleCallees = new OwnershipGraph(allocationDepth); + OwnershipGraph ogMergeOfAllPossibleCalleeResults = new OwnershipGraph(allocationDepth); if( md.isStatic() ) { // a static method is simply always the same, makes life easy OwnershipGraph onlyPossibleCallee = mapDescriptorToCompleteOwnershipGraph.get(md); - ogAllPossibleCallees.merge(onlyPossibleCallee); - + ogMergeOfAllPossibleCalleeResults = og; + ogMergeOfAllPossibleCalleeResults.resolveMethodCall(fc, md.isStatic(), flatm, onlyPossibleCallee); } else { // if the method descriptor is virtual, then there could be a // set of possible methods that will actually be invoked, so - // find all of them and merge all of their graphs together + // find all of them and merge all of their results together TypeDescriptor typeDesc = fc.getThis().getType(); Set possibleCallees = callGraph.getMethods(md, typeDesc); - + Iterator i = possibleCallees.iterator(); while( i.hasNext() ) { MethodDescriptor possibleMd = (MethodDescriptor) i.next(); + + // don't alter the working graph (og) until we compute a result for every + // possible callee, merge them all together, then set og to that + OwnershipGraph ogCopy = new OwnershipGraph(allocationDepth); + ogCopy.merge( og ); + OwnershipGraph ogPotentialCallee = mapDescriptorToCompleteOwnershipGraph.get(possibleMd); - ogAllPossibleCallees.merge(ogPotentialCallee); + ogCopy.resolveMethodCall(fc, md.isStatic(), flatm, ogPotentialCallee ); + ogMergeOfAllPossibleCalleeResults.merge( ogCopy ); } } - // Now we should have the following information to resolve this method call: - // - // 1. A FlatCall fc to query for the caller's context (argument labels, etc) - // - // 2. Whether the method is static; if not we need to deal with the "this" pointer - // - // ******************************************************************************************* - // 3. The original FlatMethod flatm to query for callee's context (paramter labels) - // NOTE! I assume FlatMethod before virtual dispatch accurately describes all possible methods! - // ******************************************************************************************* - // - // 4. The OwnershipGraph ogAllPossibleCallees is a merge of every ownership graph of all the possible - // methods to capture any possible references made. - // - og.resolveMethodCall(fc, md.isStatic(), flatm, ogAllPossibleCallees); + og = ogMergeOfAllPossibleCalleeResults; break; case FKind.FlatReturnNode: diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 95b7a18a..bd9cba95 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -887,7 +887,6 @@ public class OwnershipGraph { FlatMethod fm, OwnershipGraph ogCallee) { - // define rewrite rules and other structures to organize // data by parameter/argument index Hashtable paramIndex2rewriteH = @@ -1303,18 +1302,21 @@ public class OwnershipGraph { // it also has the appropriate field, otherwise prune this AllocationSite asSrc = src.getAllocationSite(); if( asSrc != null ) { - boolean foundField = false; - Iterator fieldsSrcItr = asSrc.getType().getClassDesc().getFields(); - while( fieldsSrcItr.hasNext() ) { - FieldDescriptor fd = (FieldDescriptor) fieldsSrcItr.next(); - if( fd == edgeCallee.getFieldDesc() ) { - foundField = true; - break; + boolean foundField = false; + TypeDescriptor tdSrc = asSrc.getType(); + if( tdSrc != null && tdSrc.isClass() ) { + Iterator fieldsSrcItr = tdSrc.getClassDesc().getFields(); + while( fieldsSrcItr.hasNext() ) { + FieldDescriptor fd = (FieldDescriptor) fieldsSrcItr.next(); + if( fd == edgeCallee.getFieldDesc() ) { + foundField = true; + break; + } + } + if( !foundField ) { + // prune this source node possibility + continue; } - } - if( !foundField ) { - // prune this source node possibility - continue; } } @@ -2504,6 +2506,14 @@ public class OwnershipGraph { bw.write(" graphTitle[label=\""+graphName+"\",shape=box];\n"); + Set df = paramIndex2id.entrySet(); + Iterator ih = df.iterator(); + while( ih.hasNext() ) { + Map.Entry meh = (Map.Entry)ih.next(); + Integer pi = (Integer) meh.getKey(); + Integer id = (Integer) meh.getValue(); + bw.write(" pindex"+pi+"[label=\""+pi+" to "+id+"\",shape=box];\n"); + } // then visit every label node, useful for debugging if( writeLabels ) {