8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
authordholmes
Mon, 11 Mar 2019 21:26:19 -0400
changeset 54065 f984aca565c1
parent 54064 d3888a37ad03
child 54066 1dbe0c210134
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied Summary: fix compatibility issue caused by jmap update of 8215622 Reviewed-by: dholmes, ysuenaga, phh, sspitsyn Contributed-by: zanglin5@jd.com
src/hotspot/share/services/attachListener.cpp
src/hotspot/share/services/attachListener.hpp
src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java
src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java
src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java
src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java
src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java
src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
test/jdk/java/util/logging/TestLoggerWeakRefLeak.java
--- a/src/hotspot/share/services/attachListener.cpp	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/hotspot/share/services/attachListener.cpp	Mon Mar 11 21:26:19 2019 -0400
@@ -257,13 +257,22 @@
 // See also: ClassHistogramDCmd class
 //
 // Input arguments :-
-//   arg0: Name of the dump file or NULL
-//   arg1: "-live" or "-all"
+//   arg0: "-live" or "-all"
+//   arg1: Name of the dump file or NULL
 static jint heap_inspection(AttachOperation* op, outputStream* out) {
   bool live_objects_only = true;   // default is true to retain the behavior before this change is made
   outputStream* os = out;   // if path not specified or path is NULL, use out
   fileStream* fs = NULL;
-  const char* path = op->arg(0);
+  const char* arg0 = op->arg(0);
+  if (arg0 != NULL && (strlen(arg0) > 0)) {
+    if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
+      out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
+      return JNI_ERR;
+    }
+    live_objects_only = strcmp(arg0, "-live") == 0;
+  }
+
+  const char* path = op->arg(1);
   if (path != NULL) {
     if (path[0] == '\0') {
       out->print_cr("No dump file specified");
@@ -277,14 +286,7 @@
       os = fs;
     }
   }
-  const char* arg1 = op->arg(1);
-  if (arg1 != NULL && (strlen(arg1) > 0)) {
-    if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
-      out->print_cr("Invalid argument to inspectheap operation: %s", arg1);
-      return JNI_ERR;
-    }
-    live_objects_only = strcmp(arg1, "-live") == 0;
-  }
+
   VM_GC_HeapInspection heapop(os, live_objects_only /* request full gc */);
   VMThread::execute(&heapop);
   if (os != NULL && os != out) {
--- a/src/hotspot/share/services/attachListener.hpp	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/hotspot/share/services/attachListener.hpp	Mon Mar 11 21:26:19 2019 -0400
@@ -106,7 +106,7 @@
   enum {
     name_length_max = 16,       // maximum length of  name
     arg_length_max = 1024,      // maximum length of argument
-    arg_count_max = 4           // maximum number of arguments
+    arg_count_max = 3           // maximum number of arguments
   };
 
   // name of special operation that can be enqueued when all
--- a/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java	Mon Mar 11 21:26:19 2019 -0400
@@ -138,7 +138,7 @@
      * Execute the given command in the target VM.
      */
     InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
-        assert args.length <= 4;                // includes null
+        assert args.length <= 3;                // includes null
 
         // did we detach?
         synchronized (this) {
@@ -166,7 +166,7 @@
             writeString(s, PROTOCOL_VERSION);
             writeString(s, cmd);
 
-            for (int i = 0; i < 4; i++) {
+            for (int i = 0; i < 3; i++) {
                 if (i < args.length && args[i] != null) {
                     writeString(s, (String)args[i]);
                 } else {
--- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java	Mon Mar 11 21:26:19 2019 -0400
@@ -143,7 +143,7 @@
      * Execute the given command in the target VM.
      */
     InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
-        assert args.length <= 4;                // includes null
+        assert args.length <= 3;                // includes null
 
         // did we detach?
         synchronized (this) {
@@ -171,7 +171,7 @@
             writeString(s, PROTOCOL_VERSION);
             writeString(s, cmd);
 
-            for (int i = 0; i < 4; i++) {
+            for (int i = 0; i < 3; i++) {
                 if (i < args.length && args[i] != null) {
                     writeString(s, (String)args[i]);
                 } else {
--- a/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java	Mon Mar 11 21:26:19 2019 -0400
@@ -139,7 +139,7 @@
      * Execute the given command in the target VM.
      */
     InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
-        assert args.length <= 4;                // includes null
+        assert args.length <= 3;                // includes null
 
         // did we detach?
         synchronized (this) {
@@ -167,7 +167,7 @@
             writeString(s, PROTOCOL_VERSION);
             writeString(s, cmd);
 
-            for (int i = 0; i < 4; i++) {
+            for (int i = 0; i < 3; i++) {
                 if (i < args.length && args[i] != null) {
                     writeString(s, (String)args[i]);
                 } else {
--- a/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java	Mon Mar 11 21:26:19 2019 -0400
@@ -126,7 +126,7 @@
      * Execute the given command in the target VM.
      */
     InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
-        assert args.length <= 4;                // includes null
+        assert args.length <= 3;                // includes null
 
         // first check that we are still attached
         int door;
--- a/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java	Mon Mar 11 21:26:19 2019 -0400
@@ -77,7 +77,7 @@
     InputStream execute(String cmd, Object ... args)
         throws AgentLoadException, IOException
     {
-        assert args.length <= 4;        // includes null
+        assert args.length <= 3;        // includes null
 
         // create a pipe using a random name
         Random rnd = new Random();
--- a/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java	Mon Mar 11 21:26:19 2019 -0400
@@ -190,7 +190,7 @@
         System.out.flush();
 
         // inspectHeap is not the same as jcmd GC.class_histogram
-        executeCommandForPid(pid, "inspectheap", filename, liveopt);
+        executeCommandForPid(pid, "inspectheap", liveopt, filename);
     }
 
     private static void dump(String pid, String options)
--- a/test/jdk/java/util/logging/TestLoggerWeakRefLeak.java	Tue Mar 12 02:13:02 2019 +0100
+++ b/test/jdk/java/util/logging/TestLoggerWeakRefLeak.java	Mon Mar 11 21:26:19 2019 -0400
@@ -123,7 +123,7 @@
     }
 
     /**
-     * 'vm.heapHisto("", "-live")' will request a full GC
+     * 'vm.heapHisto("-live")' will request a full GC
      */
     private static int getInstanceCountFromHeapHisto() throws AttachNotSupportedException, Exception {
         int instanceCount = 0;
@@ -131,7 +131,7 @@
         HotSpotVirtualMachine vm = (HotSpotVirtualMachine) VirtualMachine
                 .attach(Long.toString(ProcessTools.getProcessId()));
         try {
-            try (InputStream heapHistoStream = vm.heapHisto("", "-live");
+            try (InputStream heapHistoStream = vm.heapHisto("-live");
                     BufferedReader in = new BufferedReader(new InputStreamReader(heapHistoStream))) {
                 String inputLine;
                 while ((inputLine = in.readLine()) != null) {