RFR: 8253402: Convert vmSymbols::SID to enum class [v7]

Ioi Lam iklam at openjdk.java.net
Thu Oct 15 04:20:24 UTC 2020


> 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 (vmSymbolsIterator it = vmSymbolsRange.begin(); it != vmSymbolsRange.end(); ++it) {
>  vmSymbolID index = *it; ....
> }
> - 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`.

Ioi Lam has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains
13 commits:

 - Merge branch 'master' into 8253402-convert-vmsymbols-sid-to-enum-class
 - Merge branch 'master' into 8253402-convert-vmsymbols-sid-to-enum-class
 - revert NO_SID to 0 due to assert(Symbol::_vm_symbols[NO_SID] == NULL)
 - Addressed review comments by Kim Barrett
 - added missing #include <limits> from enumIterator.hpp
 - Use 2-style EnumIterator
 - Merge master into 8253402-convert-vmsymbols-sid-to-enum-class
 - more vmEnums.hpp fixes; fixed minimal VM build
 - Merge branch 'master' into 8253402-convert-vmsymbols-sid-to-enum-class
 - Moved forward declaration of vmSymbolID to vmEnums.hpp
 - ... and 3 more: https://git.openjdk.java.net/jdk/compare/038f58d4...5e939ca7

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

Changes: https://git.openjdk.java.net/jdk/pull/276/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=276&range=06
  Stats: 798 lines in 29 files changed: 478 ins; 144 del; 176 mod
  Patch: https://git.openjdk.java.net/jdk/pull/276.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/276/head:pull/276

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


More information about the hotspot-dev mailing list