From e788193e5f0f1c3eec81ecef22011424b049c3d7 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 24 Mar 2025 09:59:28 +0000 Subject: [PATCH 1/7] 8351002: com/sun/management/OperatingSystemMXBean cpuLoad tests fail intermittently --- .../GetProcessCpuLoad.java | 21 +++++++++++++--- .../GetProcessCpuTime.java | 22 +++++++++++++---- .../GetSystemCpuLoad.java | 24 +++++++++++++++---- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java index ecb65b7b3eaf5..509210187421a 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java @@ -36,12 +36,23 @@ public class GetProcessCpuLoad { public static void main(String[] argv) throws Exception { OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + + Exception ex = null; double load; - for(int i=0; i<10; i++) { + + for(int i = 0; i < 10; i++) { load = mbean.getProcessCpuLoad(); - if(load<0.0 || load>1.0) { + if (load == -1.0) { + // Some Windows 2019 systems can return -1 for the first few reads. + // Remember a -1 in case it never gets better. + ex = new RuntimeException("getProcessCpuLoad() returns " + load + + " which is not in the [0.0,1.0] interval"); + } else if (load < 0.0 || load > 1.0) { throw new RuntimeException("getProcessCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); + } else { + // A good reading: forget any previous -1. + ex = null; } try { Thread.sleep(200); @@ -49,5 +60,9 @@ public static void main(String[] argv) throws Exception { e.printStackTrace(); } } + + if (ex != null) { + throw ex; + } } } diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java index f65b2616ae932..b679ffc72f86d 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ public class GetProcessCpuTime { // Careful with these values. private static final long MIN_TIME_FOR_PASS = 1; - private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE; + private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE / 1000; // No max time. @@ -73,10 +73,22 @@ public static void main(String args[]) throws Exception { sum /= i; } - long ns = mbean.getProcessCpuTime(); + long ns = 0; + // Do not skip test if first read is -1: + // Some Windows 2019 systems can return -1 for the first few reads. + for (int i = 0; i < 10; i++) { + ns = mbean.getProcessCpuTime(); + if (ns != -1) { + break; + } + try { + Thread.sleep(200); + } catch(InterruptedException e) { + e.printStackTrace(); + } + } if (ns == -1) { - System.out.println("getProcessCpuTime() is not supported"); - return; + throw new RuntimeException("getProcessCpuTime() is not supported"); } if (trace) { diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 7bd9d162cb38e..36982625d55e4 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -24,7 +24,7 @@ /* * @test * @bug 7028071 - * @summary Basic unit test of OperatingSystemMXBean.getSystemCpuLoad() + * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() * * @run main GetSystemCpuLoad */ @@ -36,12 +36,24 @@ public class GetSystemCpuLoad { public static void main(String[] argv) throws Exception { OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + + Exception ex = null; double load; - for(int i=0; i<10; i++) { + + for(int i = 0; i < 10; i++) { load = mbean.getSystemCpuLoad(); - if(load<0.0 || load>1.0) { + if (load == -1.0) { + // Some Windows 2019 systems can return -1 for the first few reads. + // Remember a -1 in case it never gets better. + ex = new RuntimeException("getSystemCpuLoad() returns " + load + + " which is not in the [0.0,1.0] interval"); + + } else if (load < 0.0 || load > 1.0) { throw new RuntimeException("getSystemCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); + } else { + // A good reading: forget any previous -1. + ex = null; } try { Thread.sleep(200); @@ -49,5 +61,9 @@ public static void main(String[] argv) throws Exception { e.printStackTrace(); } } + + if (ex != null) { + throw ex; + } } } From aaffd483906c7687bb417dc0ce10f716801cca43 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 24 Mar 2025 10:02:03 +0000 Subject: [PATCH 2/7] problemlist --- test/jdk/ProblemList.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index d954b95b52099..db2fbdb041137 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -536,9 +536,8 @@ java/io/IO/IO.java 8337935 linux-pp # jdk_management -# First bug for AIX, second for Windows -com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java 8030957,8351002 aix-all,windows-all -com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957,8351002 aix-all,windows-all +com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java 8030957 aix-all +com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all From 21ebab5b5acf75f366d104e15147fcef99d58026 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 24 Mar 2025 11:46:19 +0000 Subject: [PATCH 3/7] whitespace --- .../management/OperatingSystemMXBean/GetProcessCpuLoad.java | 2 +- .../management/OperatingSystemMXBean/GetProcessCpuTime.java | 4 ++-- .../management/OperatingSystemMXBean/GetSystemCpuLoad.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java index 509210187421a..662e1b542a8d1 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java @@ -43,7 +43,7 @@ public static void main(String[] argv) throws Exception { for(int i = 0; i < 10; i++) { load = mbean.getProcessCpuLoad(); if (load == -1.0) { - // Some Windows 2019 systems can return -1 for the first few reads. + // Some Windows 2019 systems can return -1 for the first few reads. // Remember a -1 in case it never gets better. ex = new RuntimeException("getProcessCpuLoad() returns " + load + " which is not in the [0.0,1.0] interval"); diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java index b679ffc72f86d..79a6222e37e17 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java @@ -74,8 +74,8 @@ public static void main(String args[]) throws Exception { } long ns = 0; - // Do not skip test if first read is -1: - // Some Windows 2019 systems can return -1 for the first few reads. + // Do not skip test if first read is -1: + // Some Windows 2019 systems can return -1 for the first few reads. for (int i = 0; i < 10; i++) { ns = mbean.getProcessCpuTime(); if (ns != -1) { diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 36982625d55e4..20fd9bc7ed5f0 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -43,7 +43,7 @@ public static void main(String[] argv) throws Exception { for(int i = 0; i < 10; i++) { load = mbean.getSystemCpuLoad(); if (load == -1.0) { - // Some Windows 2019 systems can return -1 for the first few reads. + // Some Windows 2019 systems can return -1 for the first few reads. // Remember a -1 in case it never gets better. ex = new RuntimeException("getSystemCpuLoad() returns " + load + " which is not in the [0.0,1.0] interval"); From 708974d71312b50285d3bdb75621e1fd2b5b115d Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 24 Mar 2025 15:02:56 +0000 Subject: [PATCH 4/7] whitespace --- .../management/OperatingSystemMXBean/GetSystemCpuLoad.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 20fd9bc7ed5f0..798432d9682bc 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -46,11 +46,11 @@ public static void main(String[] argv) throws Exception { // Some Windows 2019 systems can return -1 for the first few reads. // Remember a -1 in case it never gets better. ex = new RuntimeException("getSystemCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); } else if (load < 0.0 || load > 1.0) { throw new RuntimeException("getSystemCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); } else { // A good reading: forget any previous -1. ex = null; From 2cfd63ce851fb1d5dd76419e73ed9f31ebd1d812 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 24 Mar 2025 15:03:53 +0000 Subject: [PATCH 5/7] whitespace --- .../sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 798432d9682bc..1b924e07fa3e6 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -40,7 +40,7 @@ public static void main(String[] argv) throws Exception { Exception ex = null; double load; - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { load = mbean.getSystemCpuLoad(); if (load == -1.0) { // Some Windows 2019 systems can return -1 for the first few reads. From 453faf4d17ac0d04f55ef3327d0a357b7e6b2d25 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Tue, 25 Mar 2025 11:16:38 +0000 Subject: [PATCH 6/7] stricter check --- .../GetProcessCpuLoad.java | 7 ++--- .../GetProcessCpuTime.java | 27 ++++++++++--------- .../GetSystemCpuLoad.java | 7 ++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java index 662e1b542a8d1..3ee847b28b154 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java @@ -25,12 +25,13 @@ * @test * @bug 7028071 * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() - * + * @library /test/lib * @run main GetProcessCpuLoad */ -import java.lang.management.*; import com.sun.management.OperatingSystemMXBean; +import java.lang.management.*; +import jdk.test.lib.Platform; public class GetProcessCpuLoad { public static void main(String[] argv) throws Exception { @@ -42,7 +43,7 @@ public static void main(String[] argv) throws Exception { for(int i = 0; i < 10; i++) { load = mbean.getProcessCpuLoad(); - if (load == -1.0) { + if (load == -1.0 && Platform.isWindows()) { // Some Windows 2019 systems can return -1 for the first few reads. // Remember a -1 in case it never gets better. ex = new RuntimeException("getProcessCpuLoad() returns " + load diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java index 79a6222e37e17..4c1da76395213 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java @@ -25,6 +25,7 @@ * @test * @bug 4858522 * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuTime() + * @library /test/lib * @author Steve Bohne */ @@ -45,6 +46,7 @@ import com.sun.management.OperatingSystemMXBean; import java.lang.management.*; +import jdk.test.lib.Platform; public class GetProcessCpuTime { @@ -73,18 +75,19 @@ public static void main(String args[]) throws Exception { sum /= i; } - long ns = 0; - // Do not skip test if first read is -1: - // Some Windows 2019 systems can return -1 for the first few reads. - for (int i = 0; i < 10; i++) { - ns = mbean.getProcessCpuTime(); - if (ns != -1) { - break; - } - try { - Thread.sleep(200); - } catch(InterruptedException e) { - e.printStackTrace(); + long ns = mbean.getProcessCpuTime(); + if (ns == -1 && Platform.isWindows()) { + // Some Windows 2019 systems can return -1 for the first few reads. + for (int i = 0; i < 10; i++) { + ns = mbean.getProcessCpuTime(); + if (ns != -1) { + break; + } + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } if (ns == -1) { diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 1b924e07fa3e6..0501cbbcbd7d7 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -25,12 +25,13 @@ * @test * @bug 7028071 * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() - * + * @library /test/lib * @run main GetSystemCpuLoad */ -import java.lang.management.*; import com.sun.management.OperatingSystemMXBean; +import java.lang.management.*; +import jdk.test.lib.Platform; public class GetSystemCpuLoad { public static void main(String[] argv) throws Exception { @@ -42,7 +43,7 @@ public static void main(String[] argv) throws Exception { for (int i = 0; i < 10; i++) { load = mbean.getSystemCpuLoad(); - if (load == -1.0) { + if (load == -1.0 && Platform.isWindows()) { // Some Windows 2019 systems can return -1 for the first few reads. // Remember a -1 in case it never gets better. ex = new RuntimeException("getSystemCpuLoad() returns " + load From c420e213baf7dc9a0e5071c02641de1dc75a3197 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Tue, 25 Mar 2025 21:42:05 +0000 Subject: [PATCH 7/7] stricter max time --- .../management/OperatingSystemMXBean/GetProcessCpuTime.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java index 4c1da76395213..95d7ac9cb5dbe 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java @@ -57,9 +57,7 @@ public class GetProcessCpuTime { // Careful with these values. private static final long MIN_TIME_FOR_PASS = 1; - private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE / 1000; - - // No max time. + private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE / 10_000_000; private static boolean trace = false;