RFR: 8253402: Convert vmSymbols::SID to enum class

Ioi Lam iklam at openjdk.java.net
Thu Sep 24 20:33:41 UTC 2020


On Thu, 24 Sep 2020 10:51:08 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> Yes, that's the intention, because vmSymbols.hpp is big.
>> 
>> I am thinking whether I should move such forward declarations of enums into globalDefinitions.hpp, so header files that
>> use `vmSymbolID` don't need to know that the base type is `int`.
>
> No, don't move them to globalDefinitions.hpp, only have the forward declarations where they're used.  So this is like a
> class forward declaration?  neat.

How about having a new header file utilities/vmEnums.hpp that looks like this:

// Include this header file if you just need the following enum types and
// you don't use their members directly. This way you don't need to include the
// complex header files that have the full definitions of these enums.
enum JVMFlagsEnum : int;
enum class vmSymbolID : int;

My plan is to have at least 2 more such enums (one for `vmIntrinsics::ID`, and one for `SystemDictionary::WKID`).

`: int` is the base type of the enum. I think that's part of the type's implementation so it shouldn't be exposed to
the user of these types. If we litter `enum class vmSymbolID : int;` all over, when we decide to change the base type
to something else, we would need to edit all such places.

Worse, if your forward declaration is wrong, like

enum class vmSymbolID : char;

the compiler won't detect this if your source file doesn't *also* include vmSymbols.hpp, so it could be dangerous.

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

PR: https://git.openjdk.java.net/jdk/pull/276


More information about the hotspot-dev mailing list