RFR: 8328698: oopDesc::klass_raw() decodes without a null check

Stefan Karlsson stefank at openjdk.org
Wed Apr 3 09:31:24 UTC 2024


The oopDesc::klass_raw() function is used when the caller wants to skip asserts. Unfortunately, it skips the the check to see if the narrow klass is zero, which could lead to an incorrect Klass* being returned. This patch fixes this.

In addition to this, I'm trying to make the code a bit clearer, so the patch also contains changes for the following:

* The word raw has various different meaning in the context of oops and klasses. So, what does it mean in this context? Does it mean "read the klass pointer value without decoding it"? Or does it mean "decode the klass pointer value without any asserts"? I would like to propose that we use a name that describes that this function is used to skip performing various asserts.

* I replaced the one usage of load_klass_raw with a call to klass_raw() instead.

* I restructured the `is_oop_safe` so that we perform the null-check first. Note that `oopDesc::is_oop` performs its own verification of the klass pointer, so if we want extra klass verification in `is_oop_safe` we need to do it before calling the `is_oop` check. 

* I also renamed the _raw functions inside the CompressedKlassPointers klass and moved private functions.

Tell me if you think some of these should be split up into separate RFEs.

Tested with tier1-3.

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

Commit messages:
 - 8328698: oopDesc::klass_raw() decodes without a null check

Changes: https://git.openjdk.org/jdk/pull/18597/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18597&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8328698
  Stats: 93 lines in 10 files changed: 42 ins; 34 del; 17 mod
  Patch: https://git.openjdk.org/jdk/pull/18597.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18597/head:pull/18597

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


More information about the hotspot-dev mailing list