RFR: 8186838: Generalize Atomic::inc/dec with templates

Mario Torre neugens at redhat.com
Fri Sep 1 10:43:41 UTC 2017


On Fri, Sep 1, 2017 at 11:29 AM, Erik Österlund
<erik.osterlund at oracle.com> wrote:
> Hi David,
>
> On 2017-09-01 02:49, David Holmes wrote:
>>
>> Hi Erik,
>>
>> Sorry but this one is really losing me.
>>
>> What is the role of Adjustment ??
>
>
> Adjustment represents the increment/decrement value as an IntegralConstant -
> your template friend for passing around a constant with both a specified
> type and value in templates. The type of the increment/decrement is the type
> of the destination when the destination is an integral type, otherwise if it
> is a pointer type, the increment/decrement type is ptrdiff_t.
>
>> How are inc/dec anything but "using constant" ??
>
>
> I was also a bit torn on that name (I assume you are referring to
> IncUsingConstant/DecUsingConstant). It was hard to find a name that depicted
> what this platform helper does. I considered calling the helper something
> with immediate in the name because it is really used to embed the constant
> as immediate values in inline assembly today. But then again that seemed too
> specific, as it is not completely obvious platform specializations will use
> it in that way. One might just want to specialize this to send it into some
> compiler Atomic::inc intrinsic for example. Do you have any other preferred
> names? Here are a few possible names for IncUsingConstant:
>
> IncUsingScaledConstant
> IncUsingAdjustedConstant
> IncUsingPlatformHelper
>
> Any favourites?
>
>> Why do we special case jshort??
>
>
> To be consistent with the special case of Atomic::add on jshort. Do you want
> it removed?
>
>> This is indecipherable to normal people ;-)
>>
>>  This()->template inc<I, Adjustment>(dest);
>>
>> For something as trivial as adding or subtracting 1 the template
>> machinations here are just mind boggling!
>
>
> This uses the CRTP (Curiously Recurring Template Pattern) C++ idiom. The
> idea is to devirtualize a virtual call by passing in the derived type as a
> template parameter to a base class, and then let the base class static_cast
> to the derived class to devirtualize the call. I hope this explanation sheds
> some light on what is going on. The same CRTP idiom was used in the
> Atomic::add implementation in a similar fashion.
>
> I will add some comments describing this in the next round after Coleen
> replies.
>

Isn't that a lot more slower than the current inline?

BTW, I think I see what those magic constants are (4, 8... rings a
bell ;), but I think a define here could make things more readable.

Cheers,
Mario


More information about the hotspot-dev mailing list