Skip to content

Commit 16f15de

Browse files
committed
Rewrote time-to-safepoint test
1 parent d7ab642 commit 16f15de

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

test/test/jfr/JfrTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void parseMultiModeRecording(TestProcess p) throws Exception {
8888
public void ttsp(TestProcess p) throws Exception {
8989
p.profile("-d 3 -i 1ms --ttsp -f %f.jfr");
9090
assert !containsSamplesOutsideWindow(p) : "Expected no samples outside of ttsp window";
91+
92+
Output out = Output.convertJfrToCollapsed(p.getFile("%f").getAbsolutePath());
93+
assert out.samples("indexOfTest") >= 10;
9194
}
9295

9396
/**

test/test/jfr/Ttsp.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,42 @@
55

66
package test.jfr;
77

8-
import java.util.Random;
9-
10-
class Ttsp {
8+
import java.lang.management.ManagementFactory;
9+
import java.util.Arrays;
10+
11+
public class Ttsp {
12+
static volatile int sink;
13+
14+
// String.indexOf is a JVM intrinsic. When JIT-compiled, it has no safepoint check inside
15+
// and therefore may delay safepoint start.
16+
static int indexOfTest(int length) {
17+
char[] chars = new char[length * length];
18+
Arrays.fill(chars, 'a');
19+
String haystack = new String(chars);
20+
String needle = haystack.substring(0, length) + 'b' + haystack.substring(0, length);
21+
return haystack.indexOf(needle);
22+
}
1123

12-
static private byte loop() {
13-
byte[] byteArray = new byte[1024 * 1024 * 1024];
14-
for (int i = 0; i < 10000; i++) {
15-
new Random().nextBytes(byteArray);
24+
static void spoiler(int length, long count) {
25+
for (long i = 0; i < count; i++) {
26+
sink = indexOfTest(length);
1627
}
17-
return byteArray[0];
28+
}
29+
30+
static void requestSafepoint() {
31+
ManagementFactory.getThreadMXBean().dumpAllThreads(false, false);
1832
}
1933

2034
public static void main(String[] args) throws Exception {
21-
new Thread(() -> {
22-
while (true) {
23-
System.gc();
24-
try {
25-
Thread.sleep(20);
26-
} catch (InterruptedException e) {
27-
throw new RuntimeException(e);
28-
}
29-
}
30-
}).start();
31-
32-
Thread.sleep(1000);
33-
34-
new Thread(() -> {
35-
while (true) {
36-
loop();
37-
}
38-
}).start();
35+
// Warmup with small input to force JIT-compilation of indexOfTest
36+
spoiler(10, 1000000);
37+
38+
// Run actual workload with large input to cause long time-to-safepoint pauses
39+
new Thread(() -> spoiler(1000, Long.MAX_VALUE)).start();
40+
41+
while (true) {
42+
requestSafepoint();
43+
Thread.sleep(50);
44+
}
3945
}
4046
}
41-

0 commit comments

Comments
 (0)