RFR: 8355635: Do not collect C strings in C2 scratch buffer

Vladimir Kozlov kvn at openjdk.org
Sat Apr 26 02:44:55 UTC 2025


[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.

-------------

Commit messages:
 - 8355635: Do not collect C strings in C2 scratch buffer

Changes: https://git.openjdk.org/jdk/pull/24893/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24893&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8355635
  Stats: 6 lines in 1 file changed: 6 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/24893.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24893/head:pull/24893

PR: https://git.openjdk.org/jdk/pull/24893


More information about the hotspot-compiler-dev mailing list