RFR: 8253555: Make ByteSize and WordSize typed scoped enums [v3]

Stefan Karlsson stefank at openjdk.java.net
Thu Sep 24 12:57:22 UTC 2020


> It's a common bug in HotSpot that byte values are used when the code asks for words, and vice versa. One attempt to
> prevent that has been to use the classes ByteSize and WordSize, to make the compiler detect these problems. The current
> implementation is a bit problematic, because both types are int typedefs in release builds, and wrapper classes in
> debug builds. This means that we can't use these types in overload resolution. I propose that we fix that by changing
> the type to scoped enums with a fixed int type. The compiler will then be apple to completely separate ByteSize,
> WordSize, and ints. We also don't need different code in release vs debug builds.  FWIW, I once created a size_t
> versions of these classes and annotated all the metaspace code with these types. This experiment flushed out a handful
> of bugs (some of them were known and the reason for trying that experiment)  There are some controversy about having
> these classes around. See for example: JDK-8041956: remove ByteSize and WordSize classes  I hope we can stay away from
> that discussion in this PR.

Stefan Karlsson has updated the pull request incrementally with one additional commit since the last revision:

  Review 2

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/328/files
  - new: https://git.openjdk.java.net/jdk/pull/328/files/26f2695f..e798ff83

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=328&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=328&range=01-02

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/328.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/328/head:pull/328

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


More information about the hotspot-dev mailing list