# HG changeset patch # User shade # Date 1486223505 -3600 # Node ID d36d1debfbf560d81b4c7079dcae314d21a29593 # Parent 391245b793a033e6f7c599d599af2ab22fae98a8 Rehash ShenandoahVisualizer methods. diff -r 391245b793a0 -r d36d1debfbf5 src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java --- 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 lastSnapshots = new LinkedList<>(); + public static class RenderTask implements Runnable { + final DataProvider data; + final JFrame frame; + final LinkedList 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 lastSnapshots, int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);