From cec3e1d52d0817b08cf2a04739523233f2e410b1 Mon Sep 17 00:00:00 2001 From: jjenista Date: Mon, 7 Dec 2009 17:47:36 +0000 Subject: [PATCH] implementing --- .../Analysis/Disjoint/DescriptorQWrapper.java | 50 ++++++++++++++ .../Analysis/Disjoint/DisjointAnalysis.java | 69 ++++++++++--------- 2 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 Robust/src/Analysis/Disjoint/DescriptorQWrapper.java diff --git a/Robust/src/Analysis/Disjoint/DescriptorQWrapper.java b/Robust/src/Analysis/Disjoint/DescriptorQWrapper.java new file mode 100644 index 00000000..a459dac6 --- /dev/null +++ b/Robust/src/Analysis/Disjoint/DescriptorQWrapper.java @@ -0,0 +1,50 @@ +package Analysis.Disjoint; + +import IR.*; +import IR.Flat.*; +import java.util.*; +import java.io.*; + +public class DescriptorQWrapper implements Comparable { + + private int priority; + private Descriptor d; + + public DescriptorQWrapper( Integer p, Descriptor d ) { + priority = p.intValue(); + this.d = d; + } + + public DescriptorQWrapper( int p, Descriptor d ) { + priority = p; + this.d = d; + } + + public Descriptor getDescriptor() { + return d; + } + + public int compareTo( Object o ) throws ClassCastException { + + if( !(o instanceof DescriptorQWrapper) ) { + throw new ClassCastException(); + } + + DescriptorQWrapper dqw = (DescriptorQWrapper) o; + return priority - dqw.priority; + } + + public boolean equals(Object o) { + if( o == null ) { + return false; + } + + if( !( o instanceof DescriptorQWrapper) ) { + return false; + } + + DescriptorQWrapper dqw = (DescriptorQWrapper) o; + + return d.equals( dqw.d ); + } +} diff --git a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java index e7e53e34..1882008b 100644 --- a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java +++ b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java @@ -148,35 +148,38 @@ public class DisjointAnalysis { makeAnalysisEntryMethod( mdSourceEntry ); descriptorsToAnalyze.add( mdAnalysisEntry ); - // topologically sort according to the call graph so // leaf calls are ordered first, smarter analysis order LinkedList sortedDescriptors = topologicalSort( descriptorsToAnalyze ); + // add sorted descriptors to priority queue, and duplicate + // the queue as a set for testing whether some method + // is marked for analysis + PriorityQueue descriptorsToVisitQ + = new PriorityQueue(); - System.out.println( "topological:\n"+sortedDescriptors ); - + HashSet descriptorsToVisitSet + = new HashSet(); - /* - methodContextsToVisitQ = new PriorityQueue(); - methodContextsToVisitSet = new HashSet(); + Hashtable mapDescriptorToPriority + = new Hashtable(); int p = 0; - Iterator mcItr = sortedMethodContexts.iterator(); - while( mcItr.hasNext() ) { - MethodContext mc = mcItr.next(); - mapDescriptorToPriority.put( mc.getDescriptor(), new Integer( p ) ); - methodContextsToVisitQ.add( new MethodContextQWrapper( p, mc ) ); - methodContextsToVisitSet.add( mc ); + Iterator dItr = sortedDescriptors.iterator(); + while( dItr.hasNext() ) { + Descriptor d = dItr.next(); + mapDescriptorToPriority.put( d, new Integer( p ) ); + descriptorsToVisitQ.add( new DescriptorQWrapper( p, d ) ); + descriptorsToVisitSet.add( d ); ++p; } // analyze methods from the priority queue until it is empty - while( !methodContextsToVisitQ.isEmpty() ) { - MethodContext mc = methodContextsToVisitQ.poll().getMethodContext(); - assert methodContextsToVisitSet.contains( mc ); - methodContextsToVisitSet.remove( mc ); + while( !descriptorsToVisitQ.isEmpty() ) { + Descriptor d = descriptorsToVisitQ.poll().getDescriptor(); + assert descriptorsToVisitSet.contains( d ); + descriptorsToVisitSet.remove( d ); // because the task or method descriptor just extracted // was in the "to visit" set it either hasn't been analyzed @@ -186,37 +189,41 @@ public class DisjointAnalysis { // If there is a change detected, add any methods/tasks // that depend on this one to the "to visit" set. - System.out.println("Analyzing " + mc); + System.out.println( "Analyzing " + d ); - Descriptor d = mc.getDescriptor(); + // get the flat code for this method descriptor FlatMethod fm; - if( d instanceof MethodDescriptor ) { - fm = state.getMethodFlat( (MethodDescriptor) d); + if( d == mdAnalysisEntry ) { + fm = fmAnalysisEntry; } else { - assert d instanceof TaskDescriptor; - fm = state.getMethodFlat( (TaskDescriptor) d); + fm = state.getMethodFlat( d ); } + + /* ReachGraph og = analyzeFlatMethod(mc, fm); - ReachGraph ogPrev = mapMethodContextToCompleteReachabilityGraph.get(mc); + ReachGraph ogPrev = mapDescriptorToCompleteReachabilityGraph.get(mc); if( !og.equals(ogPrev) ) { - setGraphForMethodContext(mc, og); + setGraphForDescriptor(mc, og); - Iterator depsItr = iteratorDependents( mc ); + Iterator depsItr = iteratorDependents( mc ); while( depsItr.hasNext() ) { - MethodContext mcNext = depsItr.next(); + Descriptor mcNext = depsItr.next(); - if( !methodContextsToVisitSet.contains( mcNext ) ) { - methodContextsToVisitQ.add( new MethodContextQWrapper( mapDescriptorToPriority.get( mcNext.getDescriptor() ), + if( !descriptorsToVisitSet.contains( mcNext ) ) { + descriptorsToVisitQ.add( new DescriptorQWrapper( mapDescriptorToPriority.get( mcNext.getDescriptor() ), mcNext ) ); - methodContextsToVisitSet.add( mcNext ); + descriptorsToVisitSet.add( mcNext ); } } } + */ } - */ } + + + /* // keep passing the Descriptor of the method along for debugging // and dot file writing @@ -1072,6 +1079,6 @@ public class DisjointAnalysis { //FlatCall fc = new - this.fmAnalysisEntry = new FlatMethod( mdAnalysisEntry, fe ); + this.fmAnalysisEntry = new FlatMethod( mdAnalysisEntry, fe ); } } -- 2.34.1