RFR: 8264565: Templatize num_arguments() functions of DCmd subclasses
Ioi Lam
iklam at openjdk.java.net
Thu Apr 1 18:26:15 UTC 2021
On Thu, 1 Apr 2021 17:46:22 GMT, Ioi Lam <iklam at openjdk.org> wrote:
> We have many version of `num_arguments()` for the `DCmd` subclasses. They all have identical structure. We should templatize them to reduce duplicated code and avoid cut-and-paste errors.
>
> It's still possible to write a customized `num_arguments()` function (although none of the existing cases needs to do that). The rules are described here:
>
> class DCmd : public ResourceObj {
> ...
> // num_arguments() is used by the DCmdFactoryImpl::get_num_arguments() template functions.
> // - For subclasses of DCmdWithParser, it's calculated by DCmdParser::num_arguments().
> // - Other subclasses of DCmd have zero arguments by default. You can change this
> // by defining your own version of MyDCmd::num_arguments().
> static int num_arguments() { return 0; }
For verification, I added code in an earlier commit (hence removed) to print out the `num_arguments()` of each `DCmd`. The results are identical with and without this patch.
https://github.com/openjdk/jdk/blob/25920cdd8296901bcd64d5cf277a616bc90bea90/src/hotspot/share/services/diagnosticFramework.cpp#L521-L523
-------------
PR: https://git.openjdk.java.net/jdk/pull/3312
More information about the hotspot-dev
mailing list