diff --git a/test/functional/cmdLineTests/jfr/src/org/openj9/test/VMAPITest.java b/test/functional/cmdLineTests/jfr/src/org/openj9/test/VMAPITest.java index 8ff83c58356..fdf29174aa0 100644 --- a/test/functional/cmdLineTests/jfr/src/org/openj9/test/VMAPITest.java +++ b/test/functional/cmdLineTests/jfr/src/org/openj9/test/VMAPITest.java @@ -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; } } - } -} \ No newline at end of file +} diff --git a/test/functional/cmdLineTests/jfr/src/org/openj9/test/WorkLoad.java b/test/functional/cmdLineTests/jfr/src/org/openj9/test/WorkLoad.java index 779ac81b65f..135aaf106f3 100644 --- a/test/functional/cmdLineTests/jfr/src/org/openj9/test/WorkLoad.java +++ b/test/functional/cmdLineTests/jfr/src/org/openj9/test/WorkLoad.java @@ -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; @@ -29,7 +28,6 @@ import java.util.concurrent.locks.LockSupport; public class WorkLoad { - private int numberOfThreads; private int sizeOfNumberList; private int repeats; @@ -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; @@ -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(); } @@ -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(); }); @@ -86,8 +83,6 @@ public void runWork() { } } - - System.out.println("All runs complete. " + average + " : " + stdDev); } @@ -106,6 +101,7 @@ private void recursiveFucntion(int depth) { if (0 == depth) { return; } + recursiveFucntion(depth - 1); } @@ -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; }; @@ -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; }); } @@ -162,25 +160,29 @@ 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 numbers) { double sum = 0.0; + for (double number : numbers) { sum += number; } + return sum / numbers.size(); } private double standardDeviation(List 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)); } @@ -188,6 +190,7 @@ private void throwThrowable(Class throwable) { try { throw throwable.getDeclaredConstructor().newInstance(); } catch (Throwable t) {} + try { throw throwable.getDeclaredConstructor().newInstance("random string: " + Math.random()); } catch (Throwable t) {}