RFR: 8261731: shallow copy the internal buffer of a scalar-replaced java.lang.String object

Xin Liu xliu at openjdk.java.net
Mon Feb 15 09:26:56 UTC 2021


There are 3 nodes involving in the construction of a java.lang.String object.
1. Allocate of itself, aka. alloc
2. AllocateArray of a byte array, which is value:byte[], aka. aa
3. ArrayCopyNode which copys in the contents of value, aka. ac

Lemma
When a String object `alloc` is scalar replaced, C2 can eliminate `aa` and `ac`.

Because `alloc` is scalar replaced, it must be non-escaped. The field value:byte[] of j.l.String cannot be seen by external world, therefore it must not be global escaped. Because the buffer is marked as stable, it is safe to assume its contents are whatever ac copies in. Because all public java.lang.String constructors clone the incoming array, the source of `ac` is stable as well.

It is possible to rewire `aa` to the source of ac with the correct offset. That is to say, we can replace both `aa` and `ac` with a “shallow copy” of the source of `ac`. It’s safe if C2 keeps a reference of the source oop for all safepoints.

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

Commit messages:
 - fix regression for x86-32
 - add a statistical counter for OptimizeTempArray.
 - [SIM-JVM-450] support deoptimization v2
 - add a unit test for deoptimization
 - [SIM-JVM-450] support deoptimization part2
 - enable OptimizeTempArray by default
 - Merge branch 'master' into optimize_substring
 - Revert "8260198: TypeInstPtr::dump2() emits multiple lines if Verbose is set"
 - Revert "add a new bucket afterea_late_inlines"
 - [SIM-JVM-450] support deoptimization
 - ... and 25 more: https://git.openjdk.java.net/jdk/compare/4619f372...fd9ca4b8

Changes: https://git.openjdk.java.net/jdk/pull/2570/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2570&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8261731
  Stats: 861 lines in 16 files changed: 844 ins; 2 del; 15 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2570.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2570/head:pull/2570

PR: https://git.openjdk.java.net/jdk/pull/2570


More information about the core-libs-dev mailing list