Skip to content

Commit ae0918d

Browse files
committed
JBR-4442 ClipFlatOval test hangs on M1 mac
Performed measurements for each frame
1 parent ff6e3d9 commit ae0918d

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

test/jdk/performance/client/RenderPerfTest/src/renderperf/RenderPerfTest.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
import java.util.HashSet;
5656
import java.util.Objects;
5757
import java.util.concurrent.CountDownLatch;
58-
import java.util.concurrent.atomic.AtomicBoolean;
5958

59+
import java.util.concurrent.atomic.AtomicInteger;
6060
import java.util.concurrent.atomic.AtomicLong;
6161
import javax.imageio.ImageIO;
6262
import javax.swing.JFrame;
@@ -80,9 +80,10 @@ public class RenderPerfTest {
8080
private final static int BH = 50;
8181
private final static int COUNT = 600;
8282
private final static int CYCLE_DELAY = 3;
83-
private final static int CYCLES_TILL_PAINT = 10;
83+
private final static int MAX_FRAME_CYCLES = 3000/CYCLE_DELAY;
84+
8485
private final static int COLOR_TOLERANCE = 10;
85-
private final static int MAX_MEASURE_TIME = 5000;
86+
private final static int MAX_MEASURE_CYCLES = 6000/CYCLE_DELAY;
8687

8788
private final static Color[] marker = {Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW, Color.ORANGE, Color.MAGENTA};
8889

@@ -608,19 +609,18 @@ static class PerfMeter {
608609
private JPanel panel;
609610

610611
private double execTime = 0;
611-
private int markerIdx = 0;
612-
private AtomicBoolean paintOccurred = new AtomicBoolean(false);
612+
private AtomicInteger markerIdx = new AtomicInteger(0);
613613
private AtomicLong markerPaintTime = new AtomicLong(0);
614614

615615
private double fps;
616+
private int skippedFrame = 0;
616617

617618
PerfMeter(String name) {
618619
this.name = name;
619620
}
620621

621622
PerfMeter exec(final Renderable renderable) throws Exception {
622623
final CountDownLatch latchFrame = new CountDownLatch(1);
623-
final long endTime = System.currentTimeMillis() + MAX_MEASURE_TIME;
624624

625625
final JFrame f = new JFrame();
626626
f.addWindowListener(new WindowAdapter() {
@@ -638,19 +638,15 @@ public void run() {
638638
@Override
639639
protected void paintComponent(Graphics g) {
640640
super.paintComponent(g);
641-
if (markerIdx == 0) {
642-
markerPaintTime.set(System.nanoTime());
643-
}
644-
paintOccurred.set(true);
641+
markerPaintTime.set(System.nanoTime());
645642

646643
Graphics2D g2d = (Graphics2D) g.create();
647644
renderable.setup(g2d);
648645
renderable.render(g2d);
649646
g2d.setClip(null);
650647
g2d.setPaintMode();
651-
g2d.setColor(marker[markerIdx]);
648+
g2d.setColor(marker[markerIdx.get()]);
652649
g2d.fillRect(0, 0, BW, BH);
653-
markerIdx = (markerIdx + 1) % marker.length;
654650
}
655651
};
656652

@@ -665,19 +661,14 @@ protected void paintComponent(Graphics g) {
665661

666662
Robot robot = new Robot();
667663
int cycle = 0;
668-
int cycleToPaint = -1;
669664
int frame = 0;
670665
long paintTime = 0;
666+
int maxFrameCycle = -1;
671667
while (frame < COUNT) {
672-
if (paintOccurred.compareAndSet(true, false)) {
673-
long t = markerPaintTime.getAndSet(0);
674-
paintTime = t > 0 ? t : paintTime;
675-
cycleToPaint = cycle + CYCLES_TILL_PAINT;
676-
}
677-
678-
if (cycle == cycleToPaint) {
679-
renderable.update();
680-
panel.getParent().repaint();
668+
long t;
669+
if ((t = markerPaintTime.getAndSet(0)) > 0) {
670+
paintTime = t;
671+
maxFrameCycle = cycle + MAX_FRAME_CYCLES;
681672
}
682673

683674
if (paintTime > 0) {
@@ -692,18 +683,28 @@ protected void paintComponent(Graphics g) {
692683
}
693684
}
694685

695-
if (currIdx == 0) {
686+
if (currIdx == markerIdx.get()) {
696687
execTime += System.nanoTime() - paintTime;
697688
frame++;
698689
paintTime = 0;
690+
maxFrameCycle = -1;
691+
markerIdx.accumulateAndGet(marker.length, (x, y) -> (x + 1) % y);
692+
renderable.update();
693+
panel.getParent().repaint();
694+
} else if (cycle >= maxFrameCycle) {
695+
skippedFrame++;
696+
paintTime = 0;
697+
maxFrameCycle = -1;
698+
markerIdx.accumulateAndGet(marker.length, (x, y) -> (x + 1) % y);
699+
panel.getParent().repaint();
699700
}
700701
}
701702
try {
702703
Thread.sleep(CYCLE_DELAY);
703704
} catch (InterruptedException ex) {
704705
ex.printStackTrace();
705706
}
706-
if (System.currentTimeMillis() >= endTime) {
707+
if (cycle >= MAX_MEASURE_CYCLES) {
707708
break;
708709
}
709710
cycle++;
@@ -724,6 +725,9 @@ protected void paintComponent(Graphics g) {
724725
}
725726

726727
private void report() {
728+
if (skippedFrame > 0) {
729+
System.err.println(skippedFrame + " frame(s) skipped");
730+
}
727731
System.err.println(name + " : " + String.format("%.2f FPS", fps));
728732
}
729733

0 commit comments

Comments
 (0)