RFR: 8324881: ObjectSynchronizer::inflate(Thread* current...) is invoked for non-current thread [v3]
Richard Reingruber
rrich at openjdk.org
Wed Jan 31 13:24:02 UTC 2024
On Wed, 31 Jan 2024 09:04:09 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
>> The `ObjectSynchronizer` has always assumed that the `current` parameters are both the current thread as well as the thread that is doing the locking. The only time that we are entering on behalf of another thread is when doing re-locking in deoptimization. This has worked because the deoptee thread is suspended. However ResourceMarks have been using the wrong thread when logging is enabled.
>>
>> This change `ObjectSynchronizer` instruments the relevant methods with both a `JavaThread* locking_thread` as well as `[Java]Thread* current` to be able to use the correct thread for ResourceMarks.
>>
>> Having the `inflate` care about a `locking_thread` is a little unpleasant in my opinion. But it is required for LM_LIGHTWEIGHT.
>> Would probably be cleaner if the inflate for LM_LIGHTWEIGHT was it's own thing, as it does not share the whole INFLATING protocol. But seems like a future RFE to refactor this code.
>>
>> Can reproduce a crash by modifying `test/jdk/com/sun/jdi/EATests.java` and using `-XX:DiagnoseSyncOnValueBasedClasses=2` with LM_LEGACY or running `test/jdk/com/sun/jdi/EATests.java` with LM_LIGHTWEIGHT/LM_MONITOR and `-Xlog:monitorinflation=trace`.
>>
>> Could extend this test to capture this regression in the future (or creating a new test based on the same infrastructure). Will give it an attempt, so we have a regression test for this. But these tests get rather involved as the require a lot of jvmti setup.
>
> Axel Boldt-Christmas has updated the pull request incrementally with one additional commit since the last revision:
>
> More restrictive API
`ObjectMonitor::enter(JavaThread* current)` is called near the end of `ObjectSynchronizer::enter()` like this: `monitor->enter(locking_thread)`. Here also the name `current` is not correct because `locking_thread` may be different from the current thread if nested locking was eliminated and the lock got inflated.
I see 2 solutions currently:
1. Rename the parameter from `current` to `locking_thread` and assert before contention is handled that `locking_thread` is the current thread. You could introduce a local variable `JavaThread* current` to reduce the necessary changes.
2. Introduce a dedicated new method (`relock_for` or `enter_for`?) to fixup the state of the ObjectMonitor to be called from `Deoptimization::relock_objects`. It would assert that the ObjectMonitor isn't locked by another thread than `locking_thread`, set it as owner, and increment `_recursions` if necessary.
At the moment I'd favor 1.
With 2. one would like also copy and adapt `ObjectSynchronizer::enter()`. Maybe that would be cleaner.
Thanks again Richard.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17626#issuecomment-1919092708
More information about the hotspot-dev
mailing list