Mercurial > hg > shenandoah-visualizer
changeset 4:b3656d96320f
Split out Region demarshaller and renderer.
author | shade |
---|---|
date | Wed, 14 Dec 2016 19:51:03 +0100 |
parents | d191c872c927 |
children | 98d295144a63 |
files | src/main/java/org/openjdk/shenandoah/RegionStat.java src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java |
diffstat | 2 files changed, 74 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/shenandoah/RegionStat.java Wed Dec 14 19:51:03 2016 +0100 @@ -0,0 +1,72 @@ +package org.openjdk.shenandoah; + +import java.awt.*; + +public class RegionStat { + + private static final int USED_MASK = 0x3fffffff; + private static final int USED_SHIFT = 0; + private static final int LIVE_MASK = 0x3fffffff; + private static final int LIVE_SHIFT = 30; + private static final int FLAGS_MASK = 0xf; + private static final int FLAGS_SHIFT = 60; + + private final boolean unused; + private final boolean humongous; + private final boolean inCset; + private final double liveLvl; + private final double usedLvl; + + public RegionStat(long maxSize, long data) { + long used = (data >>> USED_SHIFT) & USED_MASK; + usedLvl = Math.min(1D, 1D * used / maxSize); + + long live = (data >>> LIVE_SHIFT) & LIVE_MASK; + liveLvl = Math.min(1D, 1D * live / maxSize); + + long stat = (data >>> FLAGS_SHIFT) & FLAGS_MASK; + inCset = (stat & 0x1) > 0; + humongous = (stat & 0x2) > 0; + unused = (stat & 0x4) > 0; + } + + public void render(Graphics g, int x, int y, int width, int height) { + g.setColor(Color.WHITE); + g.fillRect(x, y, width, height); + + int usedWidth = (int) (width * usedLvl); + g.setColor(new Color(150, 150, 150)); + g.fillRect(x, y, usedWidth, height); + + int liveWidth = (int) (width * liveLvl); + g.setColor(new Color(0, 200, 0)); + g.fillRect(x, y, liveWidth, height); + + g.setColor(new Color(0, 100, 0)); + g.drawLine(x + liveWidth, y, x + liveWidth, y + height); + + if (inCset) { + g.setColor(Color.YELLOW); + g.fillRect(x, y, width, height / 3); + g.setColor(Color.BLACK); + g.drawRect(x, y, width, height / 3); + } + + if (humongous) { + g.setColor(Color.RED); + g.fillRect(x, y, width, height / 3); + g.setColor(Color.BLACK); + g.drawRect(x, y, width, height / 3); + } + + if (unused) { + g.setColor(Color.BLACK); + g.drawLine(x, y, x + width, y + height); + g.drawLine(x, y + height, x + width, y); + } + g.setColor(Color.BLACK); + g.drawRect(x, y, width, height); + } + + +}
--- a/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java Wed Dec 14 19:40:56 2016 +0100 +++ b/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java Wed Dec 14 19:51:03 2016 +0100 @@ -37,13 +37,6 @@ class ShenandoahVisualizer { - private static final int USED_MASK = 0x3fffffff; - private static final int USED_SHIFT = 0; - private static final int LIVE_MASK = 0x3fffffff; - private static final int LIVE_SHIFT = 30; - private static final int FLAGS_MASK = 0xf; - private static final int FLAGS_SHIFT = 60; - private static final int WIDTH = 1000; private static final int HEIGHT = 800; static BufferedImage img; @@ -149,51 +142,8 @@ System.exit(-1); } - long data = mons_data[i].longValue(); - long used = (data >>> USED_SHIFT) & USED_MASK; - int usedLvl = Math.min(255, (int) (used * 255 / max_size)); - - long live = (data >>> LIVE_SHIFT) & LIVE_MASK; - int liveLvl = Math.min(255, (int) (live * 255 / max_size)); - - long stat = (data >>> FLAGS_SHIFT) & FLAGS_MASK; - boolean inCset = (stat & 0x1) > 0; - boolean humongous = (stat & 0x2) > 0; - boolean unused = (stat & 0x4) > 0; - - g.setColor(Color.WHITE); - g.fillRect(rectx, recty, rectWidth, rectHeight); - - g.setColor(new Color(150, 150, 150)); - g.fillRect(rectx, recty, rectWidth * usedLvl / 255, rectHeight); - - g.setColor(new Color(0, 200, 0)); - g.fillRect(rectx, recty, rectWidth * liveLvl / 255, rectHeight); - - g.setColor(new Color(0, 100, 0)); - g.drawLine(rectx + rectWidth * liveLvl / 255, recty, rectx + rectWidth * liveLvl / 255, recty + rectHeight); - - if (inCset) { - g.setColor(new Color(255, 255, 0)); - g.fillRect(rectx, recty, rectWidth, rectHeight / 3); - g.setColor(Color.BLACK); - g.drawRect(rectx, recty, rectWidth, rectHeight / 3); - } - - if (humongous) { - g.setColor(new Color(255, 0, 0)); - g.fillRect(rectx, recty, rectWidth, rectHeight / 3); - g.setColor(Color.BLACK); - g.drawRect(rectx, recty, rectWidth, rectHeight / 3); - } - - if (unused) { - g.setColor(new Color(0, 0, 0)); - g.drawLine(rectx, recty, rectx + rectWidth, recty + rectHeight); - g.drawLine(rectx, recty + rectHeight, rectx + rectWidth, recty); - } - g.setColor(Color.BLACK); - g.drawRect(rectx, recty, rectWidth, rectHeight); + RegionStat s = new RegionStat(max_size, mons_data[i].longValue()); + s.render(g, rectx, recty, rectWidth, rectHeight); } g.dispose(); }