8217845: SA should refer const values for JVMFlag from HotSpot
authorysuenaga
Tue, 05 Feb 2019 14:24:29 +0900
changeset 53637 4366a1e4a021
parent 53636 962ed57b29c9
child 53638 e3fb7c599f83
child 57144 fff0653622aa
8217845: SA should refer const values for JVMFlag from HotSpot Reviewed-by: sspitsyn, jgeorge
src/hotspot/share/runtime/vmStructs.cpp
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VM.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JInfo.java
test/hotspot/jtreg/serviceability/sa/ClhsdbFlags.java
--- a/src/hotspot/share/runtime/vmStructs.cpp	Mon Feb 04 19:42:36 2019 -0800
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Tue Feb 05 14:24:29 2019 +0900
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -2565,7 +2565,21 @@
   /****************/                                                      \
   /*  VMRegImpl   */                                                      \
   /****************/                                                      \
-  declare_constant(VMRegImpl::stack_slot_size)
+  declare_constant(VMRegImpl::stack_slot_size)                            \
+                                                                          \
+  /******************************/                                        \
+  /*  -XX flags (value origin)  */                                        \
+  /******************************/                                        \
+  declare_constant(JVMFlag::DEFAULT)                                      \
+  declare_constant(JVMFlag::COMMAND_LINE)                                 \
+  declare_constant(JVMFlag::ENVIRON_VAR)                                  \
+  declare_constant(JVMFlag::CONFIG_FILE)                                  \
+  declare_constant(JVMFlag::MANAGEMENT)                                   \
+  declare_constant(JVMFlag::ERGONOMIC)                                    \
+  declare_constant(JVMFlag::ATTACH_ON_DEMAND)                             \
+  declare_constant(JVMFlag::INTERNAL)                                     \
+  declare_constant(JVMFlag::VALUE_ORIGIN_MASK)                            \
+  declare_constant(JVMFlag::ORIG_COMMAND_LINE)
 
 //--------------------------------------------------------------------------------
 // VM_LONG_CONSTANTS
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Mon Feb 04 19:42:36 2019 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Tue Feb 05 14:24:29 2019 +0900
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -649,11 +649,11 @@
                             VM.Flag flag = flags[f];
                             if (name == null || flag.getName().equals(name)) {
 
-                                if (nonDefault && flag.getOrigin() == 0) {
+                                if (nonDefault && (flag.getOrigin() == VM.Flags_DEFAULT)) {
                                     // only print flags which aren't their defaults
                                     continue;
                                 }
-                                out.println(flag.getName() + " = " + flag.getValue() + " " + flag.getOrigin());
+                                out.println(flag.getName() + " = " + flag.getValue() + " " + flag.getOriginString());
                                 printed = true;
                             }
                         }
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VM.java	Mon Feb 04 19:42:36 2019 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VM.java	Tue Feb 05 14:24:29 2019 +0900
@@ -105,6 +105,17 @@
   private int          klassPtrSize;
   private int          oopSize;
   private final int    IndexSetSize;
+  /** -XX flags (value origin) */
+  public static int    Flags_DEFAULT;
+  public static int    Flags_COMMAND_LINE;
+  public static int    Flags_ENVIRON_VAR;
+  public static int    Flags_CONFIG_FILE;
+  public static int    Flags_MANAGEMENT;
+  public static int    Flags_ERGONOMIC;
+  public static int    Flags_ATTACH_ON_DEMAND;
+  public static int    Flags_INTERNAL;
+  private static int   Flags_VALUE_ORIGIN_MASK;
+  private static int   Flags_ORIG_COMMAND_LINE;
   /** This is only present in a non-core build */
   private CodeCache    codeCache;
   /** This is only present in a C1 build */
@@ -163,7 +174,36 @@
      }
 
      public int getOrigin() {
-        return flags & 0xF;  // XXX can we get the mask bits from somewhere?
+        return flags & Flags_VALUE_ORIGIN_MASK;
+     }
+
+     // See JVMFlag::print_origin() in HotSpot
+     public String getOriginString() {
+        var origin = flags & Flags_VALUE_ORIGIN_MASK;
+        if (origin == Flags_DEFAULT) {
+            return "default";
+        } else if (origin == Flags_COMMAND_LINE) {
+            return "command line";
+        } else if (origin == Flags_ENVIRON_VAR) {
+            return "environment";
+        } else if (origin == Flags_CONFIG_FILE) {
+            return "config file";
+        } else if (origin == Flags_MANAGEMENT) {
+            return "management";
+        } else if (origin == Flags_ERGONOMIC) {
+            String result = "";
+            if ((flags & Flags_ORIG_COMMAND_LINE) == Flags_ORIG_COMMAND_LINE) {
+                result = "command line, ";
+            }
+            return result + "ergonomic";
+        } else if (origin == Flags_ATTACH_ON_DEMAND) {
+            return "attach";
+        } else if (origin == Flags_INTERNAL) {
+            return "internal";
+        } else {
+            throw new IllegalStateException(
+                "Unknown flag origin " + origin + " is detected in " + name);
+        }
      }
 
      public boolean isBool() {
@@ -436,6 +476,16 @@
     bytesPerLong = db.lookupIntConstant("BytesPerLong").intValue();
     bytesPerWord = db.lookupIntConstant("BytesPerWord").intValue();
     heapWordSize = db.lookupIntConstant("HeapWordSize").intValue();
+    Flags_DEFAULT = db.lookupIntConstant("JVMFlag::DEFAULT").intValue();
+    Flags_COMMAND_LINE = db.lookupIntConstant("JVMFlag::COMMAND_LINE").intValue();
+    Flags_ENVIRON_VAR = db.lookupIntConstant("JVMFlag::ENVIRON_VAR").intValue();
+    Flags_CONFIG_FILE = db.lookupIntConstant("JVMFlag::CONFIG_FILE").intValue();
+    Flags_MANAGEMENT = db.lookupIntConstant("JVMFlag::MANAGEMENT").intValue();
+    Flags_ERGONOMIC = db.lookupIntConstant("JVMFlag::ERGONOMIC").intValue();
+    Flags_ATTACH_ON_DEMAND = db.lookupIntConstant("JVMFlag::ATTACH_ON_DEMAND").intValue();
+    Flags_INTERNAL = db.lookupIntConstant("JVMFlag::INTERNAL").intValue();
+    Flags_VALUE_ORIGIN_MASK = db.lookupIntConstant("JVMFlag::VALUE_ORIGIN_MASK").intValue();
+    Flags_ORIG_COMMAND_LINE = db.lookupIntConstant("JVMFlag::ORIG_COMMAND_LINE").intValue();
     oopSize  = db.lookupIntConstant("oopSize").intValue();
     IndexSetSize = db.lookupIntConstant("CompactibleFreeListSpace::IndexSetSize").intValue();
 
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JInfo.java	Mon Feb 04 19:42:36 2019 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JInfo.java	Tue Feb 05 14:24:29 2019 +0900
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, 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
@@ -148,7 +148,7 @@
         VM.Flag[] flags = VM.getVM().getCommandLineFlags();
         System.out.print("Non-default VM flags: ");
         for (VM.Flag flag : flags) {
-            if (flag.getOrigin() == 0) {
+            if (flag.getOrigin() == VM.Flags_DEFAULT) {
                 // only print flags which aren't their defaults
                 continue;
             }
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbFlags.java	Mon Feb 04 19:42:36 2019 -0800
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbFlags.java	Tue Feb 05 14:24:29 2019 +0900
@@ -34,6 +34,7 @@
  * @test
  * @bug 8190198
  * @bug 8217612
+ * @bug 8217845
  * @summary Test clhsdb flags command
  * @requires vm.hasSA
  * @library /test/lib
@@ -63,6 +64,7 @@
 
             Map<String, List<String>> expStrMap = new HashMap<>();
             expStrMap.put("flags", List.of(
+                    "command line", "ergonomic", "default",
                     "UnlockDiagnosticVMOptions = true",
                     "MaxFDLimit = false",
                     "MaxJavaStackTraceDepth = 1024",