--- old/src/hotspot/share/runtime/vframe.cpp 2020-05-06 20:09:18.000000000 -0400 +++ new/src/hotspot/share/runtime/vframe.cpp 2020-05-06 20:09:18.000000000 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -122,8 +122,14 @@ if (mons->is_empty()) return result; bool found_first_monitor = false; - ObjectMonitor *pending_monitor = thread()->current_pending_monitor(); + // The ObjectMonitor* can't be async deflated since we are either + // at a safepoint or the calling thread is operating on itself so + // it cannot leave the underlying wait()/enter() call. ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor(); + ObjectMonitor *pending_monitor = NULL; + if (waiting_monitor == NULL) { + pending_monitor = thread()->current_pending_monitor(); + } oop pending_obj = (pending_monitor != NULL ? (oop) pending_monitor->object() : (oop) NULL); oop waiting_obj = (waiting_monitor != NULL ? (oop) waiting_monitor->object() : (oop) NULL); @@ -231,6 +237,8 @@ // an inflated monitor that is first on the monitor list in // the first frame can block us on a monitor enter. markWord mark = monitor->owner()->mark(); + // The first stage of async deflation does not affect any field + // used by this comparison so the ObjectMonitor* is usable here. if (mark.has_monitor() && ( // we have marked ourself as pending on this monitor mark.monitor() == thread()->current_pending_monitor() ||