Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268460

getTotalPhysicalMemorySize() returns 0

    XMLWordPrintable

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      The following program prints "ramSize = 0" on one of my machines:

      ```java
      import java.lang.management.ManagementFactory;
      import java.lang.management.OperatingSystemMXBvaean;

      public class Main {
          private static OperatingSystemMXBean osMXBean;
          public static void main(String[] args) {
              osMXBean = ManagementFactory.getOperatingSystemMXBean();
              long ramSize = ((com.sun.management.OperatingSystemMXBean) osMXBean).getTotalPhysicalMemorySize();
              System.out.println("ramSize = " + ramSize);
          }
      }
      ```

      Interestingly, this really only happens on this one machine; all other machines report correct values. On that one machine, 0 is returned also if I run inside Docker, both with OpenJDK 8 and 11. With OpenJDK 16 and 17 (current 11-jdk-slim-buster docker tags), the correct value is displayed.

      Some information about the system; I can report more if told what to report:

      ```
      $ uname -ar
      Linux bach01 4.14.150-U #1 SMP Sun Oct 20 05:44:32 CEST 2019 x86_64 GNU/Linux
      $ cat /etc/*release
      PRETTY_NAME="Debian GNU/Linux 10 (buster)"
      NAME="Debian GNU/Linux"
      VERSION_ID="10"
      VERSION="10 (buster)"
      VERSION_CODENAME=buster
      ID=debian
      HOME_URL="https://www.debian.org/"
      SUPPORT_URL="https://www.debian.org/support"
      BUG_REPORT_URL="https://bugs.debian.org/"
      ```


        Attachments

          Activity

            People

            Assignee:
            tongwan Andrew Wang
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: