RFR: 8320310: CompiledMethod::has_monitors flag can be incorrect [v4]
Jorn Vernee
jvernee at openjdk.org
Mon Dec 11 18:38:55 UTC 2023
> Currently, the `CompiledMethod::has_monitors` flag is set when either a `monitorenter` is parsed by C1, and `monitorexit` is parsed by C1 or C2 during method compilation. However, not necessarily every bytecode of a method is parsed, which means that we could miss all `monitorenter`/`monitorexit` byte codes in a method, while it actually does use monitors. This can lead to situations where a thread holds a monitor, but `has_monitors` for all frames is set to `false`, leading to an assertion failure in 'freeze_internal' in continuationFreezeThaw.cpp:
>
> assert(monitors_on_stack(current) == ((current->held_monitor_count() - current->jni_monitor_count()) > 0),
> "Held monitor count and locks on stack invariant: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());
>
> The proposed fix is to rely on `Method::has_monitor_bytecodes` to set the `has_monitors` flag when compiling, which is immune to issues where not all byte codes of a method are parsed during compilation. We can follow the pattern established for `has_reserved_stack_access`, which is similar.
>
> Note that this PR is based on: https://github.com/openjdk/jdk/pull/16416 which disables the assertion. The goal of this PR is to fix the issue, and then re-enable the assertion.
>
> Testing: Tier 1-4, `java/lang/Thread/virtual/stress/PinALot.java`
Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
re-enable assert again
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/16799/files
- new: https://git.openjdk.org/jdk/pull/16799/files/85b2d662..eb7f0f5a
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=16799&range=03
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=16799&range=02-03
Stats: 17 lines in 1 file changed: 0 ins; 0 del; 17 mod
Patch: https://git.openjdk.org/jdk/pull/16799.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/16799/head:pull/16799
PR: https://git.openjdk.org/jdk/pull/16799
More information about the hotspot-compiler-dev
mailing list