RFR: 8355635: Do not collect C strings in C2 scratch buffer
Tobias Hartmann
thartmann at openjdk.org
Mon Apr 28 05:14:45 UTC 2025
On Sat, 26 Apr 2025 02:39:58 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:
> [JDK-8349479](https://bugs.openjdk.org/browse/JDK-8349479) added call to `code_string()` for Halt node mach node.
> I am observing several more creation and clearing C strings collections during C2 compilation:
> [17.405s][debug][codestrings] Clear 2 asm-remarks.
> [17.405s][debug][codestrings] Clear 1 dbg-string.
>
> Most are coming from temporary scratch buffer C2 uses for code size calculation. I suggest to not collect strings in this buffer.
>
> Note, `CodeSection::set_scratch_emit()` is only called from [PhaseOutput::scratch_emit_size()](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/output.cpp#L3368) for scratch buffer.
>
> I verified with `-XX:CompileCommand=print,<classpath>::<method>` that hsdis output is the same.
>
> Running on linux-x64 with fastdebug VM:
>
> before:
> $ java -XX:-TieredCompilation -Xlog:codestrings=debug com.sun.tools.javac.Main HelloWorld.java | grep codestrings |wc
> 1644 6576 80618
>
> after again:
> $ java -XX:-TieredCompilation -Xlog:codestrings=debug com.sun.tools.javac.Main HelloWorld.java | grep codestrings |wc
> 0 0 0
>
>
> It is more dramatic with `-Xcomp` we use for testing:
>
> Before
> $ java -XX:-TieredCompilation -Xcomp -Xlog:codestrings=debug com.sun.tools.javac.Main HelloWorld.java | grep codestrings |wc
> 70924 283696 3533261
>
> After fix
> $ java -XX:-TieredCompilation -Xcomp -Xlog:codestrings=debug com.sun.tools.javac.Main HelloWorld.java | grep codestrings |wc
> 0 0 0
>
>
> I was curious why it is 0 - we do deoptimize nmethod. But with big default CodeCache GC does not collect them.
> Reducing CodeCache to 8Mb shows deallocation:
>
> $ java -XX:-TieredCompilation -Xcomp -Xlog:codestrings=debug -Xlog:codecache=debug -XX:+PrintCodeCache -XX:ReservedCodeCacheSize=8M com.sun.tools.javac.Main HelloWorld.java
> ...
> [40.196s][debug][codestrings] Clear 42 asm-remarks.
> [40.196s][debug][codestrings] Clear 1 dbg-string.
> [40.196s][debug][codecache ] *flushing nmethod 5811/0x00007f71d74b7188. Live blobs:3370/Free CodeCache:2953Kb
>
>
> Tested tier1-5, Xcomp,comp-stress.
Good catch! The fix looks good to me.
-------------
Marked as reviewed by thartmann (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/24893#pullrequestreview-2797997868
More information about the hotspot-compiler-dev
mailing list