From d696ae77eafea29262b9906802e68501a320328a Mon Sep 17 00:00:00 2001 From: Evan Battaglia Date: Tue, 8 Jan 2008 13:07:47 -0800 Subject: [PATCH] cgview update. getting ready to work on new bfsliceview --- .../cs/bodik/svelte/castthinslicer/CISlicer.java | 1 + .../cs/bodik/svelte/plugin/SlicingJob.java | 166 +++++++++++---------- .../bodik/svelte/plugin/cgview/CallGraphSlice.java | 7 +- 3 files changed, 92 insertions(+), 82 deletions(-) diff --git a/Svelte/src/edu/berkeley/cs/bodik/svelte/castthinslicer/CISlicer.java b/Svelte/src/edu/berkeley/cs/bodik/svelte/castthinslicer/CISlicer.java index d288dfb..d802396 100644 --- a/Svelte/src/edu/berkeley/cs/bodik/svelte/castthinslicer/CISlicer.java +++ b/Svelte/src/edu/berkeley/cs/bodik/svelte/castthinslicer/CISlicer.java @@ -99,6 +99,7 @@ public class CISlicer { } HashSet result = HashSetFactory.make(); BFSIterator bfs = new BFSIterator(G, C.iterator()); + System.out.println("level="+level); if ( level < 0 ) { while (bfs.hasNext()) { result.add(bfs.next()); diff --git a/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/SlicingJob.java b/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/SlicingJob.java index c32561e..91771be 100644 --- a/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/SlicingJob.java +++ b/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/SlicingJob.java @@ -41,7 +41,7 @@ public class SlicingJob extends Job { private int slicerType; private String markerType; private int depth; - + public SlicingJob(String name, IJavaProject proj, IFile resource, String filename, String packageAndClass, int line_num_starting_at_one, int slicerType, @@ -67,20 +67,20 @@ public class SlicingJob extends Job { long start; System.err.println("slicestart:" + (start=System.currentTimeMillis())); - + IStatus status = run(); MonitorKeeper.removeProgressMonitor(); - + System.err.println("sliceend:" + System.currentTimeMillis()); System.err.println("sliceendtook " + (System.currentTimeMillis()-start)); - + return status; } catch ( CancelException e ) { } MonitorKeeper.removeProgressMonitor(); Runtime.getRuntime().gc(); return Status.CANCEL_STATUS; } - + protected IStatus run() { // find the slice ArrayList poss_tmp = null; @@ -91,7 +91,7 @@ public class SlicingJob extends Job { } catch (Exception e) { e.printStackTrace(); } - + final Slice slice = slic; // ArrayList poss = poss_tmp; @@ -103,80 +103,83 @@ public class SlicingJob extends Job { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) { - // clear old markers - try { - proj.getResource().deleteMarkers(markerType, true, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - e.printStackTrace(); - } - - - Hashtable markersAdded = new Hashtable(); - Boolean markersAddedDummyValue = new Boolean(true); - - // TODO: lots of resource change signals could cause slow down. temporarily remove listener? or some other way? - for ( Statement ss: slice ) { - SourcePosition s = CGNodeUtils.getSourcePositionOfInstructionIndex(ss.getNode(), ((NormalStatement)ss).getInstructionIndex() ); - if ( s == null ) - continue; - try { - - // get source filename from classname. start with project and chek required projects. - if ( s.filename == null ) { - s.filename = EclipseUtils.findSourceFileForClass(s.classname, proj); - if ( s.filename == null ) { - IClasspathEntry[] classpaths = proj.getResolvedClasspath(true); - for ( IClasspathEntry cpe: classpaths ) { - if ( cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT ) { - IJavaProject reqdproj = JavaCore.create((IProject)ResourcesPlugin.getWorkspace().getRoot().findMember(cpe.getPath())); - s.filename = EclipseUtils.findSourceFileForClass(s.classname,reqdproj); - if ( s.filename != null ) - break; - } - } - if ( s.filename == null ) { - System.err.println("Can't find source file for " + s.classname); - continue; - } + // clear old markers + try { + proj.getResource().deleteMarkers(markerType, true, IResource.DEPTH_INFINITE); + } catch (CoreException e) { + e.printStackTrace(); } - } - - - // watch for duplicate lines; only for Shrike (no coilumn info) - // may want to do for CAst, too -- use minimum & maximum column #s on that line. - if ( s.offsetStart <= 0 ) { - String tohash = s.lineStart + " " + s.filename; - if ( markersAdded.containsKey(tohash) ) - continue; - markersAdded.put(tohash, markersAddedDummyValue); - } - IFile f = EclipseUtils.findIFileForFilename(s.filename); - if ( f != null ) { - IMarker marker = f.createMarker(markerType); - if ( s.offsetStart > 0 ) { - marker.setAttribute(IMarker.CHAR_START, s.offsetStart); - marker.setAttribute(IMarker.CHAR_END, s.offsetEnd); + + Hashtable markersAdded = new Hashtable(); + Boolean markersAddedDummyValue = new Boolean(true); + + + // TODO: lots of resource change signals could cause slow down. temporarily remove listener? or some other way? + for ( Statement ss: slice ) { + SourcePosition s = CGNodeUtils.getSourcePositionOfInstructionIndex(ss.getNode(), ((NormalStatement)ss).getInstructionIndex() ); + if ( s == null ) + continue; + try { + + // get source filename from classname. start with project and chek required projects. + if ( s.filename == null ) { + s.filename = EclipseUtils.findSourceFileForClass(s.classname, proj); + if ( s.filename == null ) { + IClasspathEntry[] classpaths = proj.getResolvedClasspath(true); + for ( IClasspathEntry cpe: classpaths ) { + if ( cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT ) { + IJavaProject reqdproj = JavaCore.create((IProject)ResourcesPlugin.getWorkspace().getRoot().findMember(cpe.getPath())); + s.filename = EclipseUtils.findSourceFileForClass(s.classname,reqdproj); + if ( s.filename != null ) + break; + } + } + if ( s.filename == null ) { + System.err.println("Can't find source file for " + s.classname); + continue; + } + } + } + + + // watch for duplicate lines; only for Shrike (no coilumn info) + // may want to do for CAst, too -- use minimum & maximum column #s on that line. + if ( s.offsetStart <= 0 ) { + String tohash = s.lineStart + " " + s.filename; + if ( markersAdded.containsKey(tohash) ) + continue; + markersAdded.put(tohash, markersAddedDummyValue); + } + + IFile f = EclipseUtils.findIFileForFilename(s.filename); + if ( f != null ) { + IMarker marker = f.createMarker(markerType); + if ( s.offsetStart > 0 ) { + marker.setAttribute(IMarker.CHAR_START, s.offsetStart); + marker.setAttribute(IMarker.CHAR_END, s.offsetEnd); + } + marker.setAttribute(IMarker.LINE_NUMBER, s.lineStart); + marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); + + String descr = ss.toString().replaceFirst("[^:]*:", ""); + if ( line_num_starting_at_one == s.lineStart ) + marker.setAttribute(IMarker.MESSAGE, "Seed: " + descr); + else + marker.setAttribute(IMarker.MESSAGE, "Slice: " + descr); + marker.setAttribute(IMarker.SEVERITY, 0); + } else + System.err.println("couldn't find filename "+s.filename); + } catch (JavaModelException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - marker.setAttribute(IMarker.LINE_NUMBER, s.lineStart); - marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); - - String descr = ss.toString().replaceFirst("[^:]*:", ""); - if ( line_num_starting_at_one == s.lineStart ) - marker.setAttribute(IMarker.MESSAGE, "Seed: " + descr); - else - marker.setAttribute(IMarker.MESSAGE, "Slice: " + descr); - marker.setAttribute(IMarker.SEVERITY, 0); - } else - System.err.println("couldn't find filename "+s.filename); - } catch (JavaModelException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + + System.out.println("! slice size: "+slice.getStatements().size()); } }, null); @@ -184,9 +187,10 @@ public class SlicingJob extends Job { // TODO Auto-generated catch block e1.printStackTrace(); } - - return new Status(Status.OK,Activator.PLUGIN_ID,0, - "Finished", null); - } + + + return new Status(Status.OK,Activator.PLUGIN_ID,0, + "Finished", null); + } } diff --git a/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/cgview/CallGraphSlice.java b/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/cgview/CallGraphSlice.java index ec82a91..222ca07 100644 --- a/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/cgview/CallGraphSlice.java +++ b/Svelte/src/edu/berkeley/cs/bodik/svelte/plugin/cgview/CallGraphSlice.java @@ -223,6 +223,7 @@ public class CallGraphSlice { TypeReference newInstType = StatementUtils.getNewInstructionDeclaredType(ss); if ( newInstType != null ) { // if it's a SSANewInstruction +// System.out.println("fakenewnode from " + ss + " --to-- " + s); Node fakenewnode = getOrMakeFakeNewNode(newInstType); addEdge ( new Edge(Edge.TYPE_THRU_ALIASING, fakenewnode, tonode), true ); // don't count duplicity for this edge addEdge ( new Edge(Edge.TYPE_THRU_PARAM, fromnode, fakenewnode), false ); @@ -236,6 +237,10 @@ public class CallGraphSlice { } } + System.out.println("! total # of nodes: "+allnodes.size()); + System.out.println("! total # of edges: "+alledges.size()); + System.out.println("! total # of statements: "+index); + } @@ -326,7 +331,7 @@ public class CallGraphSlice { } catch (Exception e) { } - String color=""; + String color="lightgrey"; if ( colorindex != null ) color = colors[colorindex.intValue() % colors.length]; -- 2.11.4.GIT