Description
Describe the issue
When enabling a native image with --enable-monitoring=jfr
and then run the resulting image with JFR on, the emitted jdk.PhysicalMemory
event unconditionally sets the value of usedSize
to 0
. This should be fixed. Aside: if the value isn't available it should set it to -1
to make it clear it's not supported or not possible. 0
might be a real value.
Steps to reproduce the issue
$ cat CheckOperatingSystemMXBean.java
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
public class CheckOperatingSystemMXBean {
public static void main(String[] args) throws Exception {
OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println(String.format("Runtime.availableProcessors: %d", Runtime.getRuntime().availableProcessors()));
System.out.println(String.format("OperatingSystemMXBean.getAvailableProcessors: %d", osBean.getAvailableProcessors()));
System.out.println(String.format("OperatingSystemMXBean.getTotalPhysicalMemorySize: %d", osBean.getTotalPhysicalMemorySize()));
int count = 0;
while (count < 10) {
Thread.sleep(1000);
count++;
}
}
}
$ javac CheckOperatingSystemMXBean.java
$ native-image --enable-monitoring=jfr CheckOperatingSystemMXBean
$ ./checkoperatingsystemmxbean -XX:+FlightRecorder -XX:StartFlightRecording=filename=flight-native.jfr -XX:FlightRecorderLogging=jfr
[info][jfr] Added periodic task for EveryChunkPeriodEvents(11884)
[info][jfr] Added periodic task for EndChunkPeriodEvents(11903)
[info][jfr] Flight Recorder initialized
[info][jfr] Repository base directory: /tmp
[warn][jfr,setting] @Deprecated JFR events, and leak profiling are not yet supported.
[warn][jfr,setting] @Deprecated JFR events, and leak profiling are not yet supported.
[info][jfr ] Started recording "1" (1) {dumponexit=true, filename=[...]/flight-native.jfr}
Runtime.availableProcessors: 12
OperatingSystemMXBean.getAvailableProcessors: 12
OperatingSystemMXBean.getTotalPhysicalMemorySize: 67167309824
[info][jfr ] Stopped recording "1" (1). Reason "Dump on exit".
[info][jfr ] Transferred 130602 bytes from the disk repository
[info][jfr ] Wrote recording "1" (1) to /[...]/flight-native.jfr
[info][jfr ] Closed recording "1" (1)
[info][jfr ] Removed repository /tmp/2024_03_01_11_41_17_13462
$ jfr print --events jdk.PhysicalMemory flight-native.jfr
jdk.PhysicalMemory {
startTime = 11:41:17.240 (2024-03-01)
totalSize = 62.6 GB
usedSize = 0 bytes
}
jdk.PhysicalMemory {
startTime = 11:41:27.246 (2024-03-01)
totalSize = 62.6 GB
usedSize = 0 bytes
}
Expected Behaviour
'usedSize' actually sets the used memory on the system. The Hotspot implementation is here:
https://github.com/openjdk/jdk/blob/b972997af76a506ffd79ee8c6043e7a8db836b33/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp#L522-L528
To quote what usedSize
is supposed to show:
/**
* PhysicalMemory event represents:
*
* @totalSize == The amount of physical memory (hw) installed and reported by the OS, in bytes.
* @usedSize == The amount of physical memory currently in use in the system (reserved/committed), in bytes.
*
* Both fields are systemwide, i.e. represents the entire OS/HW environment.
* These fields do not include virtual memory.
*
* If running inside a guest OS on top of a hypervisor in a virtualized environment,
* the total memory reported is the amount of memory configured for the guest OS by the hypervisor.
*/
jdk.PhysicalMemory {
startTime = 18:54:30.298 (2024-02-29)
totalSize = 62.6 GB
usedSize = 16.6 GB
}
Actual Behaviour
usedSize = 0 bytes
.
Additional Information
It might be acceptable to set it to -1
instead to indicate it's not a real value.
Describe GraalVM and your environment:
- GraalVM build from master (rev 2334a13), with JDK
23+11
. - JDK major version: JDK 23+11
- OS: Linux
- Architecture: AMD64