|
Hi Daniil,
I have some secondary comment on new file: http://cr.openjdk.java.net/~dtitov/8205654/webrev.03/src/jdk.jcmd/linux/classes/sun/tools/ProcessHelper.java.html 70 for (int i = 0; i < parts.length && mainClass == null; i++) {
71 // Check the executable
72 if (i == 0) {
73 String[] executablePath = parts[i].split("/");
74 if (executablePath.length > 0) {
75 String binaryName = executablePath[executablePath.length - 1];
76 if (!"java".equals(binaryName)) {
77 // Skip the process if it is not started with java launcher
78 return null;
79 }
80 }
81 continue;
82 }
It is better execute the logic in lines 73-80 before the loop. It will simplify the code a little bit. String[] executablePath = parts[i].split("/");
if (executablePath.length > 0) {
String binaryName = executablePath[executablePath.length - 1];
if (!binaryName.equals("java") {
return null; // Skip the process if it is not started with java launcher
}
}
for (int i = 1; i < parts.length && mainClass == null; i++) {
In the fragment below:
83 // Check if the module is executed with explicitly specified main class
84 if ((parts[i].equals("-m") || parts[i].equals("--module")) && i < parts.length - 1) {
85 mainClass = getMainClassFromModuleArg(parts[i + 1]);
86 break;
87 }
would it better to just return the main class instead of having a break statement? :
85 return getMainClassFromModuleArg(parts[i + 1]);
The lines:
108 if (jarFile != null) {
109 return getMainClassFromJar(jarFile, pid);
110 }
is better to execute inside the loop the same as it is done for getMainClassFromModuleArg().
// Check if the main class needs to be read from the manifest.mf in a JAR file
if (parts[i].equals("-jar") && i < parts.length - 1) {
return getMainClassFromJar(jarFile, pid);
}
In the if statements:
84 if ((parts[i].equals("-m") || parts[i].equals("--module")) && i < parts.length - 1) {
...
93 if (parts[i].equals("-jar") && i < parts.length - 1) {
the last condition (i < parts.length - 1) is better to make the first (pre-condition).
They even can be combined together like below:
if (i < parts.length - 1) {
if ((parts[i].equals("-m") || parts[i].equals("--module"))) {
return getMainClassFromModuleArg(parts[i + 1]);
}
// Check if the main class needs to be read from the manifest.mf in a JAR file
if (parts[i].equals("-jar") ) {
return getMainClassFromJar(jarFile, pid);
}
}
The biggest concern are the fragments: 88 if (parts[i].equals("-p") || parts[i].equals("--module-path")) {
89 i++;
90 continue;
91 }
...
97 // If this is a classpath option then skip the next part as well ( the classpath itself)
98 if (parts[i].equals("-cp") || parts[i].equals("-classpath")) {
99 i++;
100 continue;
101 }
102 // Skip all other Java options
103 if (parts[i].startsWith("-")) {
104 continue;
105 }
If I understand it correctly, these statements are needed to
filter outthe parts which have nothing to do with the mainClass. The latest part[i] that was not filtered out is returned as the mainClass. I'm thinking about more general approach here. Probably, we just need to remove the fragments 88-91 and 97-101 as they are covered by the fragment 102-105. It will also simplify the code. With all the suggestion above it should converge to something like this: String[] parts = cmdLine.split(" ");
String mainClass = null;
String[] executablePath = parts[i].split("/");
if (executablePath.length > 0) {
String binaryName = executablePath[executablePath.length - 1];
if (!binaryName.equals("java") {
return null; // Skip the process if it is not started with java launcher
}
}
for (int 1 = 0; i < parts.length && mainClass == null; i++) {
if (i < parts.length - 1) {
if ((parts[i].equals("-m") || parts[i].equals("--module"))) {
return getMainClassFromModuleArg(parts[i + 1]);
}
// Check if the main class needs to be read from the manifest.mf in a JAR file
if (parts[i].equals("-jar") ) {
return getMainClassFromJar(parts[i + 1], pid);
}
}
// Skip all other Java options
if (parts[i].startsWith("-")) {
continue;
}
mainClass = parts[i];
}
return mainClass;
http://cr.openjdk.java.net/~dtitov/8205654/webrev.03/test/hotspot/jtreg/serviceability/dcmd/framework/TestJavaProcess.java.html
49 if (cmd.equals("quit")) {
50 log("'quit' received");
51
52 } else {
The empty line 51 can be removed.
Looking at this command-line processing I kind of understand the David's concern. Thanks, Serguei On 1/20/19 21:18, David Holmes wrote: Thanks for the update Daniil. I still remain concerned about the robustness of the command-line parsing - this seems like a feature that needs its own set of tests. |
- Re: RFR 8205654: serviceability/dcmd/framework/... [email protected]
- Re: RFR 8205654: serviceability/dcmd/framework/... [email protected]
- Re: RFR 8205654: serviceability/dcmd/framework/... David Holmes
- Re: RFR 8205654: serviceability/dcmd/frame... Daniil Titov
- Re: RFR 8205654: serviceability/dcmd/f... David Holmes
- Re: RFR 8205654: serviceability/dc... Daniil Titov
- Re: RFR 8205654: serviceabilit... David Holmes
- Re: RFR 8205654: servicea... Daniil Titov
- Re: RFR 8205654: serv... David Holmes
- Re: RFR 8205654: serv... [email protected]
- Re: RFR 8205654: serv... [email protected]
- Re: RFR 8205654: serv... Daniil Titov
- Re: RFR 8205654: serv... [email protected]
- Re: RFR 8205654: serv... Daniil Titov
- Re: RFR 8205654: serv... [email protected]
- Re: RFR 8205654: serv... David Holmes
- Re: RFR 8205654: serv... Daniil Titov
- Re: RFR 8205654: serv... David Holmes
- Re: RFR 8205654: serviceability/dcmd/f... Chris Plummer
- Re: RFR 8205654: serviceability/dc... Daniil Titov
- Re: RFR 8205654: serviceabilit... Chris Plummer
