<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div class="BodyFragment"><font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi,<br>
<br>
If we indeed want CRTP (which I totally agree with) then maybe somebody finds it interesting to read my patch from when I fixed this with a light-weight CRTP and closure approach (was a while ago now). It is attached to this email and following is a short description
of its main ideas for the curious. It's very straight forward!<br>
<br>
1) The DerivedSpace is passed down from the entry member functions (prepare_for_compaction(), compact() etc) where the DerivedSpace type is known (rather than using the declared type of the Space as common with CRTP). The benefit of this approach is that a
virtual call is made to the Space (of any declared type) to the entry member function. Once there, the DerivedSpace type is for sure known and determined safely (because of the virtual entry) and passed to the worker method for devirtualization - that way,
there will be no errors if the declared Space type is more abstract than the actual type (which I think there have been expressed fears about in this conversation), while the virtual calls are avoided for the expensive parts (doing stuff with blocks and objects
in the Space).<br>
<br>
2) Instead of calling methods in Space directly from the worker member functions (calling block_is_obj etc) it uses modular closures as indirection that know about the DerivedSpace and could use its member functions (or anything else). Might be over-engineering
but I thought it was pretty nice! (would prefer if the actual implementations were moved into the closures rather than indirecting non-virtual member functions of Space ideally)<br>
<br>
3) ...and changed some horrible variable names to avoid nightmares about p and q.<br>
<br>
Just throwing it in there if anyone wants to have a look and maybe gain some inspiration about the basic idea...<br>
Hope I'm not cluttering the conversation with my template propaganda! :)<br>
<br>
Cheers,<br>
/Erik<br>
</div>
</span></font></div>
<div class="BodyFragment"><font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
<br>
On 22 Oct 2014, at 00:29, Kim Barrett <kim.barrett@oracle.com> wrote:<br>
<br>
> On Oct 8, 2014, at 7:36 PM, Kim Barrett <kim.barrett@oracle.com> wrote:<br>
>> I still haven't been able to do a really thorough review ...<br>
> <br>
> Sorry about taking so long to get back to this. I decided to put it<br>
> aside for a while after noticing the sinus infection &etc was making<br>
> me even more stupid than I'd previously realized.<br>
> <br>
> I've resumed working on the review, and will try to finish this<br>
> evening or tomorrow.<br>
> <br>
>> compactibleFreeListSpace.hpp<br>
>> scanned_block_is_obj()<br>
>> scanned_block_size()<br>
>> Both call CompactibleFreeList::block_xxx() to avoid virtual function<br>
>> call overhead.<br>
>> <br>
>> Similarly in g1/heapRegion.hpp<br>
>> scanned_block_size()<br>
>> <br>
>> This "devirtualization" is an unsafe abstraction violation, since<br>
>> there is nothing that would prevent the wrong function from being<br>
>> called if a derived class were to override those directly called<br>
>> implementations.<br>
> <br>
> I still think that's true.<br>
> <br>
>> This devirtualization is also not present in the old<br>
>> code that is being replaced.<br>
> <br>
> And that is quite wrong. That devirtualization is actually much of<br>
> the point of the old macros. Like I said, I was being stupid.<br>
> <br>
>> If elimination of virtual function call overhead is a goal, then I<br>
>> think a CRTP-based approach should probably be used instead. I<br>
>> suspect that's a pretty large underdaking though. I also think that<br>
>> a CRTP-based approach could to be tackled as a separate step later,<br>
>> whilst still replacing the macros with function templates now.<br>
> <br>
> I still think CRTP is the right way to solve this, but also still<br>
> think that can be tackled as a later step.<br>
> <br>
> The removal of some space types by Bengt's recent changes to remove<br>
> iCMS might even simplify that process a bit.<br>
> <br>
> On Oct 9, 2014, at 11:08 AM, Erik Helin <erik.helin@oracle.com> wrote:<br>
>> Correct me if I'm wrong, but as I understand the above paragraph, you<br>
>> are worried about someone subclassing CompactibleFreeListSpace, say<br>
>> FooCompactibleFreeListSpace, cast a FooCompactibleFreeListSpace* to a<br>
>> CompactibleFreeListSpace* and then become surprised when<br>
>> CompactibleFreeListSpace::scanned_block_is_obj is called on the<br>
>> CompactibleFreeListSpace* instead of<br>
>> FooCompactibleFreeListSpace::scanned_block_is_obj?<br>
> <br>
> Not exactly. My issue is that the scan_and_* function templates are<br>
> being called in base class member functions, where the information<br>
> about the derived class has already been discarded (implicitly cast<br>
> away). As a result, in order to decide whether the code is correct,<br>
> one needs to go look at all the derived classes, figure out where they<br>
> get the operations in question, and determine whether that matches<br>
> where the operations will be obtained from in the scan_and_* call<br>
> sites. Similar issues arise when making changes.<br>
> <br>
>> I don't think the above is likely to become an issue, I suspect that<br>
>> someone doing the above would quite soon find out that the wrong code<br>
>> was being called.<br>
> <br>
> Code readability and maintainability are important, and what's going<br>
> on here is pretty strongly contrary to that, as it is intentionally<br>
> violating usual expectations about inheritance.<br>
> <br>
>> IMO, I prefer the current implementation (or the one<br>
>> using the proxy), since a CRTP [0] based approach might be harder to<br>
>> understand for people not familiar with that pattern.<br>
> <br>
> CRTP is a widely used (hence the "Recurring") core technique for<br>
> static polymorphism in C++. In my experience it's pretty hard to<br>
> avoid running across it in a non-trivial C++ code base these days. It<br>
> looks syntactically odd if one has never seen it before, but it is<br>
> conceptually pretty simple. So I disagree with the idea that CRTP<br>
> should be avoided on the basis of lack of familiarity by some.<br>
> <br>
> On Oct 13, 2014, at 4:01 AM, Marcus Larsson <marcus.larsson@oracle.com> wrote:<br>
>> possibly with additional comments to avoid future mistakes (for<br>
>> example further explaining that scanned_block_* methods are meant<br>
>> exclusively for scan_and_* functions).<br>
> <br>
> Yes to such comments.<br>
> <br>
<br>
</div>
</span></font></div>
</body>
</html>