Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,45 @@
* @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 {
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 && 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
+ " 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);
} catch(InterruptedException e) {
e.printStackTrace();
}
}

if (ex != null) {
throw ex;
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,6 +25,7 @@
* @test
* @bug 4858522
* @summary Basic unit test of OperatingSystemMXBean.getProcessCpuTime()
* @library /test/lib
* @author Steve Bohne
*/

Expand All @@ -45,6 +46,7 @@

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.*;
import jdk.test.lib.Platform;

public class GetProcessCpuTime {

Expand All @@ -55,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;

// No max time.
private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE / 10_000_000;

private static boolean trace = false;

Expand All @@ -74,9 +74,22 @@ public static void main(String args[]) throws Exception {
}

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) {
System.out.println("getProcessCpuTime() is not supported");
return;
throw new RuntimeException("getProcessCpuTime() is not supported");
}

if (trace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,47 @@
/*
* @test
* @bug 7028071
* @summary Basic unit test of OperatingSystemMXBean.getSystemCpuLoad()
*
* @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 {
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 && 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
+ " 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);
} catch(InterruptedException e) {
e.printStackTrace();
}
}

if (ex != null) {
throw ex;
}
}
}