changeset 21:d36d1debfbf5

Rehash ShenandoahVisualizer methods.
author shade
date Sat, 04 Feb 2017 16:51:45 +0100
parents 391245b793a0
children 237d9a00203a
files src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java
diffstat 1 files changed, 40 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java	Sat Feb 04 15:49:51 2017 +0100
+++ b/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java	Sat Feb 04 16:51:45 2017 +0100
@@ -46,21 +46,6 @@
     private static volatile int width;
     private static volatile int height;
 
-    static class VisPanel extends JPanel {
-        public void paint(Graphics g) {
-            if (renderedImage != null) {
-                g.drawImage(renderedImage, 0, 0, this);
-            }
-        }
-    }
-
-    static class VisPanelListener extends ComponentAdapter {
-        public void componentResized(ComponentEvent ev) {
-            width = ev.getComponent().getWidth();
-            height = ev.getComponent().getHeight();
-        }
-    }
-
     public static void main(String[] args) throws Exception {
         if (args.length < 1) {
             System.err.println("missing VM identifier");
@@ -69,8 +54,19 @@
 
         DataProvider data = new DataProvider(args[0]);
 
-        VisPanel p = new VisPanel();
-        p.addComponentListener(new VisPanelListener());
+        JPanel p = new JPanel() {
+            public void paint(Graphics g) {
+                if (renderedImage != null) {
+                    g.drawImage(renderedImage, 0, 0, this);
+                }
+            }
+        };
+        p.addComponentListener(new ComponentAdapter() {
+            public void componentResized(ComponentEvent ev) {
+                width = ev.getComponent().getWidth();
+                height = ev.getComponent().getHeight();
+            }
+        });
 
         JFrame frame = new JFrame();
         frame.setTitle("Shenandoah GC Visualizer");
@@ -79,18 +75,8 @@
         frame.setVisible(true);
 
         ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
-        ScheduledFuture<?> f = service.scheduleAtFixedRate(() -> {
-            Snapshot cur = data.snapshot();
-            if (!cur.equals(lastSnapshot)) {
-                renderedImage = render(cur, lastSnapshots, width, height);
-                lastSnapshot = cur;
-                lastSnapshots.add(new SnapshotView(cur));
-                if (lastSnapshots.size() > 2500) {
-                    lastSnapshots.removeFirst();
-                }
-            }
-            frame.repaint();
-        }, 0, 10, TimeUnit.MILLISECONDS);
+        ScheduledFuture<?> f = service.scheduleAtFixedRate(new RenderTask(data, frame),
+                0, 10, TimeUnit.MILLISECONDS);
 
         frame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
@@ -102,9 +88,32 @@
         f.get();
     }
 
-    static final LinkedList<SnapshotView> lastSnapshots = new LinkedList<>();
+    public static class RenderTask implements Runnable {
+        final DataProvider data;
+        final JFrame frame;
+        final LinkedList<SnapshotView> lastSnapshots;
+        volatile Snapshot lastSnapshot;
+
+        public RenderTask(DataProvider data, JFrame frame) {
+            this.data = data;
+            this.frame = frame;
+            this.lastSnapshots = new LinkedList<>();
+        }
 
-    static volatile Snapshot lastSnapshot;
+        @Override
+        public void run() {
+            Snapshot cur = data.snapshot();
+            if (!cur.equals(lastSnapshot)) {
+                renderedImage = render(cur, lastSnapshots, width, height);
+                lastSnapshot = cur;
+                lastSnapshots.add(new SnapshotView(cur));
+                if (lastSnapshots.size() > 2500) {
+                    lastSnapshots.removeFirst();
+                }
+                frame.repaint();
+            }
+        }
+    }
 
     public static BufferedImage render(Snapshot snapshot, LinkedList<SnapshotView> lastSnapshots, int width, int height) {
         BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);