Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh authored and tajila committed Dec 16, 2024
1 parent 415ba36 commit 3cf34df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
28 changes: 15 additions & 13 deletions test/functional/cmdLineTests/jfr/src/org/openj9/test/VMAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,50 @@
*
* 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
*/

package org.openj9.test;

import com.ibm.oti.vm.VM;

public class VMAPITest {

public static void main(String[] args) throws Throwable {
final WorkLoad workLoad = new WorkLoad(200, 20000, 200);

if (VM.isJFRRecordingStarted()) {
System.out.println("Failed should not be recording.");
return;
}
if (VM.isJFRRecordingStarted()) {
System.out.println("Failed should not be recording.");
return;
}

Thread app = new Thread(()->{
Thread app = new Thread(() -> {
workLoad.runWork();
});
app.start();

for (int i = 0; i < 15; i++) {
Thread.sleep(100);

if (VM.startJFR() != 0) {
System.out.println("Failed start.");
System.out.println("Failed to start.");
return;
}

if (!VM.isJFRRecordingStarted()) {
System.out.println("Failed not recording");
System.out.println("Failed to record.");
return;
}

if (!VM.setJFRRecordingFileName("sample" + i + ".jfr")) {
System.out.println("Failed set name.");
System.out.println("Failed to set name.");
return;
}

Thread.sleep(1000);
VM.jfrDump();
VM.stopJFR();

if (VM.isJFRRecordingStarted()) {
System.out.println("Failed still recording");
System.out.println("Failed to stop recording.");
return;
}
}

}
}
}
27 changes: 15 additions & 12 deletions test/functional/cmdLineTests/jfr/src/org/openj9/test/WorkLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
* 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
*/

package org.openj9.test;

import java.util.ArrayList;
Expand All @@ -29,7 +28,6 @@
import java.util.concurrent.locks.LockSupport;

public class WorkLoad {

private int numberOfThreads;
private int sizeOfNumberList;
private int repeats;
Expand All @@ -43,7 +41,6 @@ public WorkLoad(int numberOfThreads, int sizeOfNumberList, int repeats) {
this.repeats = repeats;
}


public static void main(String[] args) {
int numberOfThreads = 100;
int sizeOfNumberList = 10000;
Expand All @@ -60,8 +57,8 @@ public static void main(String[] args) {
if (args.length > 2) {
repeats = Integer.parseInt(args[2]);
}
WorkLoad workload = new WorkLoad(numberOfThreads, sizeOfNumberList, repeats);

WorkLoad workload = new WorkLoad(numberOfThreads, sizeOfNumberList, repeats);
workload.runWork();
}

Expand All @@ -70,7 +67,7 @@ public void runWork() {
Thread threads[] = new Thread[numberOfThreads];

for (int i = 0; i < numberOfThreads; i++) {
threads[i] = new Thread(()->{
threads[i] = new Thread(() -> {
workload();
completionCount.incrementAndGet();
});
Expand All @@ -86,8 +83,6 @@ public void runWork() {
}
}



System.out.println("All runs complete. " + average + " : " + stdDev);
}

Expand All @@ -106,6 +101,7 @@ private void recursiveFucntion(int depth) {
if (0 == depth) {
return;
}

recursiveFucntion(depth - 1);
}

Expand All @@ -116,11 +112,12 @@ private void recursiveFucntionWithCallable(int depth, Callable<?> c) {
} catch (Exception e) {}
return;
}

recursiveFucntionWithCallable(depth - 1, c);
}

private void generateAnonClasses() {
Callable<?> c = ()->{
Callable<?> c = () -> {
recursiveFucntion(30);
return 0;
};
Expand All @@ -131,26 +128,27 @@ private void generateAnonClasses() {
}

private void generateTimedPark() {
recursiveFucntionWithCallable(10, ()->{
recursiveFucntionWithCallable(10, () -> {
LockSupport.parkNanos(100000);
return 0;
});
}

private void generateTimedSleep() {
recursiveFucntionWithCallable(10, ()->{
recursiveFucntionWithCallable(10, () -> {
Thread.sleep(100);
return 0;
});
}

private void generateTimedWait() {
recursiveFucntionWithCallable(10, ()->{
recursiveFucntionWithCallable(10, () -> {
Object o = new Object();

synchronized(o) {
o.wait(100);
}

return 0;
});
}
Expand All @@ -162,32 +160,37 @@ private void burnCPU() {
numberList.add(Math.random());
}

/* write to public statics so this code isnt optimized away */
/* Write to public statics to avoid optimizing this code. */
average += average(numberList);
stdDev += standardDeviation(numberList);
}

private double average(List<Double> numbers) {
double sum = 0.0;

for (double number : numbers) {
sum += number;
}

return sum / numbers.size();
}

private double standardDeviation(List<Double> numbers) {
double mean = average(numbers);
double sumOfSquares = 0.0;

for (double number : numbers) {
sumOfSquares += Math.pow(number - mean, 2);
}

return Math.sqrt(sumOfSquares / (numbers.size() - 1));
}

private void throwThrowable(Class<? extends Throwable> throwable) {
try {
throw throwable.getDeclaredConstructor().newInstance();
} catch (Throwable t) {}

try {
throw throwable.getDeclaredConstructor().newInstance("random string: " + Math.random());
} catch (Throwable t) {}
Expand Down

0 comments on commit 3cf34df

Please sign in to comment.