RFR: 8251850: Simplify ResourceMark constructors using delegation

Kim Barrett kim.barrett at oracle.com
Tue Aug 18 08:05:37 UTC 2020


> On Aug 17, 2020, at 12:52 PM, Liu, Xin <xxinliu at amazon.com> wrote:
> 
> Hi, Kim, 
> 
> You patch looks good to me.

Thanks.

>  I have a relevant question about constructor. 
> 
> In opto, there's another candidate to use delegating constructor.
> https://hg.openjdk.java.net/jdk/jdk/file/b6475f411b98/src/hotspot/share/opto/node.cpp#l361
> 
> It's pretty annoying when I attempt to add a new member variable to Node. 
> To well initialize it,  I have to modify all different constructors. needless to say, it's error-prone because C++ can't promise you that all constructors are in a same file.  
> 
> I have two options here. 
> 1) use delegate constructor like you did here. 
> 2) use default initializers for member variables(c++11)
> eg. http://cr.openjdk.java.net/~phh/8251464/webrev.00/src/hotspot/share/opto/node.hpp.udiff.html
> 
> I am not sure if the second option is endorsed.  Quote from hotspot coding style (https://hg.openjdk.java.net/jdk/jdk/raw-file/b6475f411b98/doc/hotspot-style.html)
> "Initialize all variables and data structures to a known state. If a class has a constructor, initialize it there.”

2) default initializers for member variables is not (yet) an approved feature.  That could change.
I’m not sure it really helps here anyway though.

But I think this particular case is more likely a candidate for a variadic template as the constructor,
rather than constructor delegation.  I’ve not worked through the details to see what that would look
like, but I suspect it would be a lot simpler.






More information about the hotspot-runtime-dev mailing list