On Wed, 16 Apr 2025 00:01:18 GMT, Chen Liang <li...@openjdk.org> wrote:

>> This PR proposes to add the `@Stable` annotation to `j.l.String.hash` and 
>> `j.l.String.hashIsZero`. This means the VM can trust these fields to never 
>> change which enables constant folding optimizations.
>> 
>> This PR is tested in tier1, tier2, tier3, and tier4 which all pass.
>
> src/java.base/share/classes/java/lang/String.java line 183:
> 
>> 181:      * us to avoid recalculating this.
>> 182:      */
>> 183:     @Stable
> 
> Suggestion:
> 
>     // Marking hashIsZero stable is meaningless, as a read of `0` on hash 
> blocks
>     // constant folding of reading hashIsZero
> 
> A compromise. A stable on the hash field is a net improvement; we can 
> investigate constant folding the zero hashes later.

yes ! I would write
"given the current implementation of hashCode(), marking hasIsZero @Stable is 
not useful for constant folding, as the field `hash` of value '0' is read 
first."

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24625#discussion_r2046079733

Reply via email to