RFR: 8354300: Fields in String are not trusted
Per Minborg
pminborg at openjdk.org
Wed Apr 16 07:06:46 UTC 2025
On Wed, 16 Apr 2025 05:38:59 GMT, Chen Liang <liach at openjdk.org> wrote:
>> 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."
>
> Yep. To be more exact, JIT anticipates a read of `hash` to be non-zero at any future point instead of trusting it to be zero when it observes `hashIsZero == 1`.
>From a theoretical point of view, there is nothing that prevents the VM from constant folding the case where `hash = 0` as the two sub-conditions in `(h == 0 && !hashIsZero)` do not have any side effect. In theory, the VM could check both conditions and determine that `h = 0` is not trusted (as `hash` is not trusted because it is the default value) but `!hashIsZero` is trusted and `false` which means the entire expression is trusted to be `false`. However, the VM logic is not implemented in such a way.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24625#discussion_r2046225943
More information about the core-libs-dev
mailing list