United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7167157 jcmd command file parsing does not respect the "stop" command
7167157 : jcmd command file parsing does not respect the "stop" command

Details
Type:
Bug
Submit Date:
2012-05-08
Status:
Closed
Updated Date:
2012-06-15
Project Name:
JDK
Resolved Date:
2012-06-15
Component:
core-svc
OS:
generic
Sub-Component:
tools
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7u6,8
Fixed Versions:
7u6

Related Reports
Backport:
Relates:

Sub Tasks

Description
running
$ echo VM.version > file
$ echo stop >> file
$ echo VM.version >> file
$ jcmd <pid> -f file
will give two printouts of VM version despite the "stop" command.

This appears to be a regression in the "jcmd" binary, 8-b37 and 8-b36 have this behavior but 8-b28 and 7u4-b20 does not.

                                    

Comments
EVALUATION

This is an unfortunate artifact of the fix for 7154822. Previously all lines in the command file were sent to the JVM as one string, but the size limit was 1024 bytes so this was changed to sending one line at a time. Problem with this is that the jcmd utility now keeps sending commands even if it has encountered a 'stop'.
                                     
2012-05-09
EVALUATION

Fix:

diff --git a/src/share/classes/sun/tools/jcmd/JCmd.java b/src/share/classes/sun/tools/jcmd/JCmd.java
--- a/src/share/classes/sun/tools/jcmd/JCmd.java
+++ b/src/share/classes/sun/tools/jcmd/JCmd.java
@@ -144,6 +144,9 @@
         HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
         String lines[] = command .split("\\n");
         for (String line : lines) {
+            if (line.startsWith("stop")) {
+                break;
+            }
             try (InputStream in = hvm.executeJCmd(line);) {
                 // read to EOF and just print output
                 byte b[] = new byte[256];
                                     
2012-05-09



Hardware and Software, Engineered to Work Together