RFR: 8297389: resexhausted003 fails with assert(!thread->owns_locks()) failed: must release all locks when leaving VM

Tobias Hartmann thartmann at openjdk.org
Wed Nov 23 12:03:37 UTC 2022


`Method::build_profiling_method_data` acquires the `MethodData_lock` when initializing `Method::_method_data` to prevent multiple allocations by different threads. The problem is that when metaspace allocation fails and `JvmtiExport::should_post_resource_exhausted()` is set, we assert during the `ThreadToNativeFromVM` transition in JVMTI code.

Since concurrent initialization is a rare event, I suggest to get rid of the lock and perform the initialization with a `cmpxchg`, similar to how method counters are initialized:
https://github.com/openjdk/jdk/blob/f4b5065c37e86f4b2ca26da6ce678febe4a52950/src/hotspot/share/oops/method.cpp#L644-L646

Since [current code](https://github.com/openjdk/jdk/blob/f4b5065c37e86f4b2ca26da6ce678febe4a52950/src/hotspot/share/oops/method.inline.hpp#L41-L46) in `Method::set_method_data` uses a `Atomic::release_store`, I added a `OrderAccess::release()`.

Thanks,
Tobias

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

Commit messages:
 - 8297389: resexhausted003 fails with assert(\!thread->owns_locks()) failed: must release all locks when leaving VM

Changes: https://git.openjdk.org/jdk/pull/11316/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11316&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8297389
  Stats: 26 lines in 1 file changed: 7 ins; 4 del; 15 mod
  Patch: https://git.openjdk.org/jdk/pull/11316.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11316/head:pull/11316

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


More information about the hotspot-dev mailing list