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

Cannot programmatically retrieve Metaspace max set via JAVA_TOOL_OPTIONS

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b97
    • Introduced In Version:
      8
    • Resolved In Build:
      b08

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        macOS 10.14.6

        $ java -version
        openjdk version "16-ea" 2021-03-16
        OpenJDK Runtime Environment (build 16-ea+32-2190)
        OpenJDK 64-Bit Server VM (build 16-ea+32-2190, mixed mode, sharing)


        A DESCRIPTION OF THE PROBLEM :
        When setting the Metaspace max option -XX:MaxMetaspaceSize=256m via the JAVA_TOOL_OPTIONS environment variable, the Metaspace max is not programmatically retrievable from the MemoryPoolMXBean for the Metaspace. However, the MaxMetaspaceSize does appear to be configured according to the output produced by the option -XX:+PrintFlagsFinal which contains:

           size_t MaxMetaspaceSize = 268435456 {product} {environment}

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        See the provided source code which corresponds to the referenced MetaspaceMaxMain.java file below. The following command (on OSX, at least) reproduces the issue.

        JAVA_TOOL_OPTIONS="-XX:MaxMetaspaceSize=256m" java MetaspaceMaxMain.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Picked up JAVA_TOOL_OPTIONS: -XX:MaxMetaspaceSize=256m
        Metaspace pool max: 268435456
        ACTUAL -
        Picked up JAVA_TOOL_OPTIONS: -XX:MaxMetaspaceSize=256m
        Metaspace pool max: -1

        ---------- BEGIN SOURCE ----------
        import java.lang.management.ManagementFactory;
        import java.lang.management.MemoryPoolMXBean;

        public class MetaspaceMaxMain {

            public static void main(String[] args) {
                MemoryPoolMXBean metaspaceMemoryPool = ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)
                        .stream()
                        .filter(pool -> "Metaspace".equals(pool.getName()))
                        .findFirst()
                        .orElseThrow();
                System.out.println("Metaspace pool max: " + metaspaceMemoryPool.getUsage().getMax());
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Using the JDK_JAVA_OPTIONS environment variable instead of JAVA_TOOL_OPTIONS has the expected behavior. Alternatively, setting the MaxMetaspaceSize on the command line works as expected.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                dholmes David Holmes
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: