RFR: 8263446: Avoid unary minus over unsigned type in ObjectSynchronizer::dec_in_use_list_ceiling

Erik Österlund eosterlund at openjdk.java.net
Fri Mar 12 16:13:23 UTC 2021


On Thu, 11 Mar 2021 15:40:30 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> I also think that SonarCloud is wrong about this.
>> 
>> @fisk had good reasons to prefer Atomic::add() of a negative value over
>> using Atomic::sub() back when we were working on this ObjectMonitor code.
>> Hopefully, he can chime in on this thread.
>
>> I also think that SonarCloud is wrong about this.
>> 
>> @fisk had good reasons to prefer Atomic::add() of a negative value over
>> using Atomic::sub() back when we were working on this ObjectMonitor code.
>> Hopefully, he can chime in on this thread.
> 
> Sure. The way I see it, `Atomic::sub(loc, v)` ends up doing `Atomic::add(..., -v)` anyway, but with additional checks, and suppressing the compiler warnings there. I think it is a good choice to use clearly mark this operation as subtraction. Otherwise we would want to document how exactly `Atomic::sub` is insufficient compared to `Atomic::add`.

I don't mind changing to Atomic::sub. As @shipilev says, Atomic::sub essentially does exactly what is done on the Atomic::add callsite; it would be equivalent.

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

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


More information about the hotspot-runtime-dev mailing list