RFR: 8343629: More MergeStore benchmark
Shaojin Wen
swen at openjdk.org
Thu Nov 7 01:11:42 UTC 2024
On Wed, 6 Nov 2024 07:18:16 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> > ```java
> > "null".getBytes(0, 4, bytes4, off);
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Is it possible to do MergeStore in this scenario?
>
> I don't know. What do the logs say? And what does it currently compile down to, i.e. what assembly instructions?
>
> Otherwise I think this update seems reasonable.
My thinking is this:
StringBuilder buf = new StringBuilder();
// ...
buf.append("null");
The calling path is as follows:
AbstractStringBuilder::append -> AbstractStringBuilder::putStringAt -> String::getBytes(byte[], int, byte) -> System::arraycopy
In this scenario, if System::arraycopy can be optimized to use putInt or putLong, performance can be improved.
It is similar in the String concatenation scenario
String f(int i) {
return "abcd" + i;
}
Here `StringConcatHelper::prepend(int, byte, byte[], String, String)` is called, and then `String::getBytes(byte[], int, byte) -> System::arraycopy`
package java.lang;
class StringConcatHelper {
static int prepend(int index, byte coder, byte[] buf, String value, String prefix) {
index -= value.length();
if (coder == String.LATIN1) {
value.getBytes(buf, index, String.LATIN1);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
} else {
value.getBytes(buf, index, String.UTF16);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
}
return index;
}
}
Here is similar to the above, can we optimize "abcd".getBytes to putInt or putLong?
In summary, can we optimize the System::arraycopy of a stable byte[] with a length of 4 to putInt?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21659#issuecomment-2461114396
More information about the hotspot-compiler-dev
mailing list