RFR: 8261731: shallow copy the internal buffer of a scalar-replaced java.lang.String object [v6]
Xin Liu
xliu at openjdk.java.net
Sat Mar 13 18:36:25 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.
Xin Liu has updated the pull request incrementally with one additional commit since the last revision:
Handle more StrIntrinsic nodes which use AllocateArray of String.
There are a few subclasses of StrIntrinsicNode. They may be users of
j.l.String::value, eg StrEqualsNode and StrCompNode etc. This patch
treats them as general nodes.
This patch fixes TestOptimizeSubstring.java failure with -Xcomp.
The test methods were not properly inlined or pruned in presence of -Xcomp.
This patch provides more fine-grained control to make sure those methods are compiled more reliablely.
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/2570/files
- new: https://git.openjdk.java.net/jdk/pull/2570/files/6bd99e8a..94626e87
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2570&range=05
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2570&range=04-05
Stats: 68 lines in 4 files changed: 36 ins; 25 del; 7 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 hotspot-compiler-dev
mailing list