RFR: 8251850: Simplify ResourceMark constructors using delegation
Liu, Xin
xxinliu at amazon.com
Mon Aug 17 16:52:56 UTC 2020
Hi, Kim,
You patch looks good to me. 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."
My understanding is if multiple constructors exist, prefer to use delegate constructor. Use default initializer if and only if a class doesn't have any custom constructor. is that correct?
If it's correct, do we have a style for default initializer? for scalar variables, both assignment and {} work. eg.
int _depth = 0; or
int _depth {0};
thanks,
--lx
_______________________________________
From: hotspot-runtime-dev <hotspot-runtime-dev-retn at openjdk.java.net> on behalf of Kim Barrett <kim.barrett at oracle.com>
Sent: Friday, August 14, 2020 7:29 PM
To: hotspot-runtime-dev at openjdk.java.net runtime
Subject: [EXTERNAL] RFR: 8251850: Simplify ResourceMark constructors using delegation
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Please review this simplification of the constructors for ResourceMark,
accomplished using delegating constructors.
Also made the constructors "explicit" and the class non-copyable.
CR:
https://bugs.openjdk.java.net/browse/JDK-8251850
Webrev:
https://cr.openjdk.java.net/~kbarrett/8251850/open.00/
Testing:
mach5 tier1
More information about the hotspot-runtime-dev
mailing list