RFR: 8278518: String(byte[], int, int, Charset) constructor and String.translateEscapes() miss bounds check elimination

amirhadadi duke at openjdk.java.net
Tue Dec 14 15:14:08 UTC 2021


On Tue, 14 Dec 2021 13:20:46 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>>> Originally this was spotted by by Amir Hadadi in https://stackoverflow.com/questions/70272651/missing-bounds-checking-elimination-in-string-constructor
>> 
>> Before anyone looks at this, can you confirm that the patch does not include any code or tests/benchmarks that were taken from SO?
>
>> @AlanBateman the benchmark is mine along with the changes for `translateEscapes` and `newStringUTF8NoRepl`, the change for constructor is from SO.
> 
> I don't know how we can progress this PR if the patch includes code copied from SO. Maybe the PR should be closed, the JBS issue unassigned, and leave it to someone else to start again? Maybe you could get Amit to sign the OCA and you co-contribute/author the PR? I can't look at the patch so I don't know how significant the changes, maybe there are other options.

@AlanBateman @stsypanov I have no problem signing the OCA.
However like @stsypanov mentioned, I don't think this is the right approach.
Adding explicit check that the offset is non negative makes no semantic difference, it just helps the optimizer to figure out that no bounds checking is needed.
A better approach is to improve the optimizer so that it can apply bounds checking elimination in this case (and hopefully in many other cases).

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

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


More information about the core-libs-dev mailing list