Integrated: 8303150: DCmd framework unnecessarily creates a DCmd instance on registration

David Holmes dholmes at openjdk.org
Thu Mar 16 21:04:17 UTC 2023


On Mon, 13 Mar 2023 01:19:50 GMT, David Holmes <dholmes at openjdk.org> wrote:

> When DCmd factories are registered, the factory is passed the number of arguments taken by the DCmd - using a template method `get_num_arguments`. For DCmds that don't extend DCmdWithParser there has to be a static `num_arguments()` method in that class. For DCmds that do extend DCmdWithParser the logic instantiates an instance of the DCmd, extracts its parser and calls its `num_arguments` method which dynamically counts the number of defined arguments.
> 
> Creating an instance of each DCmd and dynamically counting arguments is inefficient and unnecessary, the number of arguments is statically known and easily expressed (in fact many of the JFR DCmds already statically define this). So we add the static `num_arguments()` method to each class that needs it and return the statically counted number of arguments. To ensure the static number and actual number don't get out-of-sync, we keep the original dynamic logic for use in debug builds to assert that the static and dynamic counts are the same. The assert will trigger during a debug build if something does get out of sync, for example if a new DCmd (extending DCmdWithParser) were added but didn't define the static `num_arguments()` method.
> 
> A number of DCmd classes were unnecessarily defining their own dynamic version of `num_arguments` and these are now removed.
> 
> In the template method I use `ENABLE_IF(std::is_convertible<T, DCmd>::value)` to check we only call this on DCmd classes. This may be unnecessary but it seemed consistent with the other template methods. Note that `std::is_base_of` only works for immediate super types.
> 
> Testing: tiers 1-4
> 
> Performance: in theory we should see some improvement in startup; in practice it is barely noticeable.
> 
> Thanks.

This pull request has now been integrated.

Changeset: a487a270
Author:    David Holmes <dholmes at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/a487a270dcd6d6a6b5ea49dece515334a0e48efc
Stats:     104 lines in 12 files changed: 36 ins; 59 del; 9 mod

8303150: DCmd framework unnecessarily creates a DCmd instance on registration

Reviewed-by: fparain, stuefe, kevinw

-------------

PR: https://git.openjdk.org/jdk/pull/12994


More information about the hotspot-dev mailing list