[14] RFR(S): 8234617: C1: Incorrect result of field load due to missing narrowing conversion

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Fri Nov 29 14:19:52 UTC 2019


> http://cr.openjdk.java.net/~thartmann/8234617/webrev.00/

Looks good.

Best regards,
Vladimir Ivanov

> 
> Writing an (integer) value to a boolean, byte, char or short field includes an implicit narrowing
> conversion [1]. With -XX:+EliminateFieldAccess (default), C1 tries to omit field loads by caching
> and reusing the last written value. The problem is that this value is not necessarily converted to
> the field type and we end up using an incorrect value.
> 
> For example, for the field store/load in testShort, C1 emits:
>    [...]
>    0x00007f0fc582bd6c:   mov    %dx,0x12(%rsi)
>    0x00007f0fc582bd70:   mov    %rdx,%rax
>    [...]
> 
> The field load has been eliminated and the non-converted integer value (%rdx) is returned.
> 
> The fix is to emit an explicit conversion to get the correct field value after the write:
>    [...]
>    0x00007ff07982bd6c:   mov    %dx,0x12(%rsi)
>    0x00007ff07982bd70:   movswl %dx,%edx
>    0x00007ff07982bd73:   mov    %rdx,%rax
>    [...]
> 
> Thanks,
> Tobias
> 
> [1] https://docs.oracle.com/javase/specs/jvms/se13/html/jvms-6.html#jvms-6.5.putfield
> 


More information about the hotspot-compiler-dev mailing list