RFR: 8358568: C2 compilation hits "must have a monitor" assert with -XX:-GenerateSynchronizationCode [v4]

Tobias Hartmann thartmann at openjdk.org
Fri Jul 4 06:15:40 UTC 2025


On Fri, 4 Jul 2025 01:30:22 GMT, hanguanqiang <duke at openjdk.org> wrote:

>> This PR fixes JDK-8358568, a JVM crash triggered when running with -XX:-GenerateSynchronizationCode
>> 
>> Problem:
>> When synchronization code generation is disabled by -XX:-GenerateSynchronizationCode, the compiler’s do_monitor_exit() method still tries to access monitor objects without checking if any monitors exist.This causes an assertion failure and JVM crash.
>> 
>> Root Cause:
>> Parse::do_monitor_exit() calls shared_unlock() using monitor info unconditionally,but with GenerateSynchronizationCode disabled, no monitor info is available, leading to invalid access.
>> 
>> Fix
>> Add a check in do_monitor_exit() to skip monitor unlocking if GenerateSynchronizationCode is false, avoiding invalid monitor access and preventing the crash.
>
> hanguanqiang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Delete .gitpod.yml

Right, my intention when filing this bug was to remove the flag:
https://bugs.openjdk.org/browse/JDK-8358568?focusedId=14786499&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14786499

I should have made that more explicit. Removal of this flag looks good to me.

Changes requested by thartmann (Reviewer).

src/hotspot/share/opto/callnode.cpp line 1456:

> 1454:   Node* top = Compile::current()->top();
> 1455:   ins_req(nextmon, top);
> 1456:   ins_req(nextmon, top);

Wait, this is wrong. The monitor inputs should not be set to top.

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

Marked as reviewed by thartmann (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/26108#pullrequestreview-2985715983
PR Review: https://git.openjdk.org/jdk/pull/26108#pullrequestreview-2985718643
PR Review Comment: https://git.openjdk.org/jdk/pull/26108#discussion_r2184500795


More information about the hotspot-compiler-dev mailing list