RFR: 8253402: Convert vmSymbols::SID to enum class
Ioi Lam
iklam at openjdk.java.net
Wed Sep 23 17:08:53 UTC 2020
On Wed, 23 Sep 2020 16:38:39 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:
>> Convert `vmSymbols::SID` to an `enum class` to provide better type safety.
>>
>> - The original enum type `vmSymbols::SID` cannot be forward-declared. I moved it out of the `vmSymbols` class and
>> renamed, so now it can be forward-declared as `enum class vmSymbolID : int;`, without including the large vmSymbols.hpp
>> file.
>> - This also breaks the mutual dependency between the `vmSymbols` and `vmIntrinsics` classes. Now the declaration of
>> `vmIntrinsics` can be moved from vmSymbols.hpp to vmIntrinsics.hpp, where it naturally belongs.
>> - Type-safe enumeration (contributed by Kim Barrett)
>> for (vmSymbolID index : vmSymbolsIterator()) {
>> vm_symbol_index[as_int(index)] = index;
>> }
>> - I moved `vmSymbols::_symbols[]` to `Symbol::_vm_symbols[]`, and made it accessible via `Symbol::vm_symbol_at()`. This
>> way, header files (e.g. fieldInfo.hpp) that need to convert from `vmSymbolID` to `Symbol*` don't need to include the
>> large vmSymbols.hpp file.
>> - I changed the `VM_SYMBOL_ENUM_NAME` macro so that the users don't need to explicitly add the `vmSymbolID::` scope.
>> - I removed many unnecessary casts between `int` and `vmSymbolID`.
>> - The remaining casts are done via `vmSymbol::as_int()` and `vmSymbols::as_SID()` with range checks.
>>
>> -----
>> If this is successful, I will do the same for `vmIntrinsics::ID`.
>
> src/hotspot/share/ci/ciObjectFactory.hpp line 32:
>
>> 30: #include "utilities/growableArray.hpp"
>> 31:
>> 32: enum class vmSymbolID : int;
>
> Do you need this declaration to avoid #include "classfile/vmSymbols.hpp" ?
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`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/276
More information about the hotspot-dev
mailing list