RFR: 8186838: Generalize Atomic::inc/dec with templates
Mario Torre
neugens at redhat.com
Fri Sep 1 12:20:37 UTC 2017
On Fri, Sep 1, 2017 at 1:42 PM, Erik Österlund
<erik.osterlund at oracle.com> wrote:
>> Isn't that a lot more slower than the current inline?
>
>
> What makes you think so? Everything is inlined all the way to the underlying
> platform layer. Achieving that is the very reason why CRTP is used instead
> of virtual calls.
I'm not familiar with the CRTP so that's probably what confuses me,
but I assume the templates are inlined, but the actual function call
aren't, are they? I understand that inline is just a suggestion and
with more aggressive optimisation the compiler will probably inline
those anyway, but have you done some measurement to see what's the
cost of all those templates?
>> 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.
>
>
> Sorry, I am not sure I am following what you mean here.
I mean this:
+template<typename Adjustment>
+struct Atomic::PlatformInc<4, Adjustment>:
Atomic::IncUsingConstant<4, Adjustment> {
I need to look at atomic.hpp to find out that this 4 is a sizeof. I
would rather make that more explicit, also hard coding numbers is
error prone, since you are refactoring this code anyway, I think this
is a nice touch that makes things a bit easier, especially given that
those templates are quite cryptic to the untrained.
Cheers,
Mario
More information about the hotspot-dev
mailing list