Skip to content

Commit ffb9537

Browse files
authored
Merge pull request #20850 from tajila/jfrbackport
(0.49) Add JFR test cases
2 parents f4d977c + a150036 commit ffb9537

File tree

8 files changed

+296
-2182
lines changed

8 files changed

+296
-2182
lines changed

runtime/vm/JFRConstantPoolTypes.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ class VM_JFRConstantPoolTypes {
966966
if (NULL != jfrConstantEvents) {
967967
PORT_ACCESS_FROM_JAVAVM(vm);
968968
j9mem_free_memory(jfrConstantEvents->JVMInfoEntry.jvmArguments);
969+
jfrConstantEvents->JVMInfoEntry.jvmArguments = NULL;
969970
}
970971
}
971972

@@ -1016,6 +1017,7 @@ class VM_JFRConstantPoolTypes {
10161017
if (NULL != jfrConstantEvents) {
10171018
PORT_ACCESS_FROM_JAVAVM(vm);
10181019
j9mem_free_memory(jfrConstantEvents->CPUInfoEntry.description);
1020+
jfrConstantEvents->CPUInfoEntry.description = NULL;
10191021
}
10201022
}
10211023

@@ -1099,6 +1101,7 @@ class VM_JFRConstantPoolTypes {
10991101
if (NULL != jfrConstantEvents) {
11001102
PORT_ACCESS_FROM_JAVAVM(vm);
11011103
j9mem_free_memory(jfrConstantEvents->OSInfoEntry.osVersion);
1104+
jfrConstantEvents->OSInfoEntry.osVersion = NULL;
11021105
}
11031106
}
11041107

runtime/vm/jfr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)
692692
if (NULL == vm->jfrState.constantEvents) {
693693
goto fail;
694694
}
695+
memset(vm->jfrState.constantEvents, 0, sizeof(JFRConstantEvents));
695696

696697
/* Allocate global data. */
697698
buffer = (U_8*)j9mem_allocate_memory(J9JFR_GLOBAL_BUFFER_SIZE, OMRMEM_CATEGORY_VM);

test/functional/cmdLineTests/jfr/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
3939
<contains string="${TEST_FLAG}" substring="JFR" />
4040
<!-- For the time being, JFR tests are only limited to JDK17+. -->
4141
<not>
42-
<matches string="${JDK_VERSION}" pattern="^(8|9|1[0-6])$$" />
42+
<matches string="${JDK_VERSION}" pattern="^(8|9)$$" />
4343
</not>
4444
</and>
4545
</condition>

test/functional/cmdLineTests/jfr/jfr.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,19 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
3030
<command>$EXE$ -XX:+FlightRecorder --add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED -cp $RESJAR$ org.openj9.test.TriggerExecutionSample</command>
3131
<return type="success" value="0" />
3232
</test>
33+
<test id="runWorkload - approx 30seconds">
34+
<command>$EXE$ -XX:+FlightRecorder --add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED -cp $RESJAR$ org.openj9.test.WorkLoad</command>
35+
<output type="success" caseSensitive="yes" regex="no">All runs complete.</output>
36+
<output type="failure" caseSensitive="yes" regex="no">Exception</output>
37+
</test>
38+
<test id="runWorkload 2 - approx 2mins">
39+
<command>$EXE$ -XX:+FlightRecorder --add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED -cp $RESJAR$ org.openj9.test.WorkLoad 200 20000 200</command>
40+
<output type="success" caseSensitive="yes" regex="no">All runs complete.</output>
41+
<output type="failure" caseSensitive="yes" regex="no">Exception</output>
42+
</test>
43+
<test id="runWorkload 2 - approx 2mins">
44+
<command>$EXE$ --add-exports java.base/com.ibm.oti.vm=ALL-UNNAMED -cp $RESJAR$ org.openj9.test.VMAPITest</command>
45+
<output type="success" caseSensitive="yes" regex="no">All runs complete.</output>
46+
<output type="failure" caseSensitive="yes" regex="no">Failed</output>
47+
</test>
3348
</suite>

test/functional/cmdLineTests/jfr/metadata.blob

Lines changed: 0 additions & 2180 deletions
This file was deleted.

test/functional/cmdLineTests/jfr/playlist.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
4848
</impls>
4949
<!-- For the time being, JFR tests are only limited to JDK17+. -->
5050
<versions>
51-
<version>17+</version>
51+
<version>11+</version>
5252
</versions>
5353
<features>
5454
<feature>JFR:required</feature>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright IBM Corp. and others 2024
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] https://openjdk.org/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
*/
22+
package org.openj9.test;
23+
24+
import com.ibm.oti.vm.VM;
25+
26+
public class VMAPITest {
27+
public static void main(String[] args) throws Throwable {
28+
final WorkLoad workLoad = new WorkLoad(200, 20000, 200);
29+
30+
if (VM.isJFRRecordingStarted()) {
31+
System.out.println("Failed should not be recording.");
32+
return;
33+
}
34+
35+
Thread app = new Thread(() -> {
36+
workLoad.runWork();
37+
});
38+
app.start();
39+
40+
for (int i = 0; i < 15; i++) {
41+
Thread.sleep(100);
42+
43+
if (VM.startJFR() != 0) {
44+
System.out.println("Failed to start.");
45+
return;
46+
}
47+
48+
if (!VM.isJFRRecordingStarted()) {
49+
System.out.println("Failed to record.");
50+
return;
51+
}
52+
53+
if (!VM.setJFRRecordingFileName("sample" + i + ".jfr")) {
54+
System.out.println("Failed to set name.");
55+
return;
56+
}
57+
58+
Thread.sleep(1000);
59+
VM.jfrDump();
60+
VM.stopJFR();
61+
62+
if (VM.isJFRRecordingStarted()) {
63+
System.out.println("Failed to stop recording.");
64+
return;
65+
}
66+
}
67+
}
68+
}
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*
2+
* Copyright IBM Corp. and others 2024
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] https://openjdk.org/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
*/
22+
package org.openj9.test;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.concurrent.Callable;
27+
import java.util.concurrent.atomic.AtomicLong;
28+
import java.util.concurrent.locks.LockSupport;
29+
30+
public class WorkLoad {
31+
private int numberOfThreads;
32+
private int sizeOfNumberList;
33+
private int repeats;
34+
35+
public static double average;
36+
public static double stdDev;
37+
38+
public WorkLoad(int numberOfThreads, int sizeOfNumberList, int repeats) {
39+
this.numberOfThreads = numberOfThreads;
40+
this.sizeOfNumberList = sizeOfNumberList;
41+
this.repeats = repeats;
42+
}
43+
44+
public static void main(String[] args) {
45+
int numberOfThreads = 100;
46+
int sizeOfNumberList = 10000;
47+
int repeats = 50;
48+
49+
if (args.length > 0) {
50+
numberOfThreads = Integer.parseInt(args[0]);
51+
}
52+
53+
if (args.length > 1) {
54+
sizeOfNumberList = Integer.parseInt(args[1]);
55+
}
56+
57+
if (args.length > 2) {
58+
repeats = Integer.parseInt(args[2]);
59+
}
60+
61+
WorkLoad workload = new WorkLoad(numberOfThreads, sizeOfNumberList, repeats);
62+
workload.runWork();
63+
}
64+
65+
public void runWork() {
66+
final AtomicLong completionCount = new AtomicLong(0);
67+
Thread threads[] = new Thread[numberOfThreads];
68+
69+
for (int i = 0; i < numberOfThreads; i++) {
70+
threads[i] = new Thread(() -> {
71+
workload();
72+
completionCount.incrementAndGet();
73+
});
74+
threads[i].start();
75+
}
76+
77+
while (completionCount.get() < numberOfThreads) {
78+
System.out.println(completionCount.get() + " / " + numberOfThreads + " complete.");
79+
try {
80+
Thread.sleep(numberOfThreads * 100);
81+
} catch (InterruptedException e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
86+
System.out.println("All runs complete. " + average + " : " + stdDev);
87+
}
88+
89+
private void workload() {
90+
for (int i = 0; i < repeats; i++) {
91+
generateAnonClasses();
92+
generateTimedPark();
93+
generateTimedSleep();
94+
generateTimedWait();
95+
throwThrowables();
96+
burnCPU();
97+
}
98+
}
99+
100+
private void recursiveFucntion(int depth) {
101+
if (0 == depth) {
102+
return;
103+
}
104+
105+
recursiveFucntion(depth - 1);
106+
}
107+
108+
private void recursiveFucntionWithCallable(int depth, Callable<?> c) {
109+
if (0 == depth) {
110+
try {
111+
c.call();
112+
} catch (Exception e) {}
113+
return;
114+
}
115+
116+
recursiveFucntionWithCallable(depth - 1, c);
117+
}
118+
119+
private void generateAnonClasses() {
120+
Callable<?> c = () -> {
121+
recursiveFucntion(30);
122+
return 0;
123+
};
124+
125+
try {
126+
c.call();
127+
} catch (Exception e) {}
128+
}
129+
130+
private void generateTimedPark() {
131+
recursiveFucntionWithCallable(10, () -> {
132+
LockSupport.parkNanos(100000);
133+
return 0;
134+
});
135+
}
136+
137+
private void generateTimedSleep() {
138+
recursiveFucntionWithCallable(10, () -> {
139+
Thread.sleep(100);
140+
return 0;
141+
});
142+
}
143+
144+
private void generateTimedWait() {
145+
recursiveFucntionWithCallable(10, () -> {
146+
Object o = new Object();
147+
148+
synchronized(o) {
149+
o.wait(100);
150+
}
151+
152+
return 0;
153+
});
154+
}
155+
156+
private void burnCPU() {
157+
ArrayList<Double> numberList = new ArrayList<Double>();
158+
159+
for (int i = 0; i < sizeOfNumberList; i++) {
160+
numberList.add(Math.random());
161+
}
162+
163+
/* Write to public statics to avoid optimizing this code. */
164+
average += average(numberList);
165+
stdDev += standardDeviation(numberList);
166+
}
167+
168+
private double average(List<Double> numbers) {
169+
double sum = 0.0;
170+
171+
for (double number : numbers) {
172+
sum += number;
173+
}
174+
175+
return sum / numbers.size();
176+
}
177+
178+
private double standardDeviation(List<Double> numbers) {
179+
double mean = average(numbers);
180+
double sumOfSquares = 0.0;
181+
182+
for (double number : numbers) {
183+
sumOfSquares += Math.pow(number - mean, 2);
184+
}
185+
186+
return Math.sqrt(sumOfSquares / (numbers.size() - 1));
187+
}
188+
189+
private void throwThrowable(Class<? extends Throwable> throwable) {
190+
try {
191+
throw throwable.getDeclaredConstructor().newInstance();
192+
} catch (Throwable t) {}
193+
194+
try {
195+
throw throwable.getDeclaredConstructor().newInstance("random string: " + Math.random());
196+
} catch (Throwable t) {}
197+
}
198+
199+
private void throwThrowables() {
200+
throwThrowable(Throwable.class);
201+
throwThrowable(ClassFormatError.class);
202+
throwThrowable(StackOverflowError.class);
203+
throwThrowable(Exception.class);
204+
throwThrowable(ClassCastException.class);
205+
throwThrowable(NumberFormatException.class);
206+
}
207+
}

0 commit comments

Comments
 (0)