3 ms·
When you have a really good JIT, as Java does, this tradeoff is gone Is there a way to visualize the machine code generated by the JVM when optimizing the same
by chpill 1y ago
When you have a really good JIT, as Java does, this tradeoff is gone
Is there a way to visualize the machine code generated by the JVM when optimizing the same kind of code as the examples shown in the talk you mention? I tried putting the following into godbolt.org, but i'm not sure I'm doing it right:
public class DontForgetToFlush {
public static void example(java.io.BufferedWriter w) throws java.io.IOException {
w.write("a");
w.write("b");
w.write("c");
w.write("d");
w.write("e");
w.write("f");
w.write("g");
w.flush();
}
public static void main(String... args) throws java.io.IOException {
var os = new java.io.OutputStreamWriter(System.out);
var writer = new java.io.BufferedWriter(os, 100);
example(writer);
}
}
- vips7L 1y agoYou can use jit watch: https://github.com/AdoptOpenJDK/jitwatch https://github.com/AdoptOpenJDK/jitwatch
- pron 1y agoYou can ask the JVM to dump the actual instructions (https://javanexus.com/blog/printing-assembly-code-hotspot-jit https://javanexus.com/blog/printing-assembly-code-hotspot-ji...). Just note that there may be differences between the very old APIs (as in your example), and the newer NIO (https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/channels/package-summary.html https://docs.oracle.com/en/java/javase/24/docs/api/java.base...), and you need to pay attention to text output that undergoes characeter set encoding (as in your example) vs binary output.