AdoptOpenJDK / jitwatch

Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.
Other
3.04k stars 435 forks source link

Optimize the javap's search path. #353

Closed hutupro closed 2 years ago

hutupro commented 2 years ago

When we install Java on Windows, both the JDK and the JRE are typically installed. The JRE may be installed in a subdirectory of the JDK or in a different directory, which is the user's choice. Javap is a part of the JDK. If JRE is not installed in the subdirectory of the JDK, the available javap will not be found according to the current javap search logic, resulting in an error on the console, as shown in the following text.

11:39:19.171 [Thread-5] ERROR o.a.j.l.BytecodeLoader - Could not fetch bytecode for SimpleInliningTest java.io.FileNotFoundException: Could not find javap.exe at org.adoptopenjdk.jitwatch.process.javap.JavapProcess.(JavapProcess.java:46) at org.adoptopenjdk.jitwatch.loader.BytecodeLoader.fetchBytecodeForClass(BytecodeLoader.java:149) ...

See the source code https://github.com/AdoptOpenJDK/jitwatch/blob/1.4.2/core/src/main/java/org/adoptopenjdk/jitwatch/process/javap/JavapProcess.java#L39-L51,we know that System.getProperty("java.home") gets the installation directory of the JRE, not JDK。 The installation path of jdk is generally specified by the environment variable JAVA_HOME. By increasing the search for JAVA_HOME, we can enrich the way to find javap and improve compatibility.

chriswhocodes commented 2 years ago

Thanks for the patch! Merged :)