RFR: 8278518: String(byte[], int, int, Charset) constructor and String.translateEscapes() miss bounds check elimination [v2]
amirhadadi
duke at openjdk.java.net
Wed Jan 12 15:46:33 UTC 2022
On Wed, 12 Jan 2022 12:12:33 GMT, Сергей Цыпанов <duke at openjdk.java.net> wrote:
>>> Good. Can you add JMH benchmark for this case?
>>
>> Thanks for the review.
>> I'm not the author of the benchmark. That actually came up in another PR where a library fix was discussed:
>> https://github.com/openjdk/jdk/pull/6812
>> Shouldn't the benchmark's author (that is @stsypanov or @amirhadadi) submit it (and sign the OCA if required)?
>
> @rwestrel The benchmark is mine and OCA is signed. Here's the code
>
> @State(Scope.Thread)
> @BenchmarkMode(Mode.AverageTime)
> @OutputTimeUnit(TimeUnit.NANOSECONDS)
> public class StringConstructorBenchmark {
> private byte[] array;
> private String str;
>
> @Setup
> public void setup() {
> str = "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen. Я";//Latin1 ending with Russian
> array = str.getBytes(StandardCharsets.UTF_8);
> }
>
> @Benchmark
> public String newString() {
> return new String(array, 0, array.length, StandardCharsets.UTF_8);
> }
>
> @Benchmark
> public String translateEscapes() {
> return str.translateEscapes();
> }
> }
@stsypanov @rwestrel since the fix is general and does not target String constructor or translateEscapes directly, maybe the benchmark should explicitly test code that has the shape being optimized in this fix? i.e. a loop with 2 backedges, the second one being taken less frequently.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7034
More information about the hotspot-compiler-dev
mailing list