RFR: 8267842: SIGSEGV in get_current_contended_monitor

Volker Simonis simonis at openjdk.java.net
Thu May 27 14:33:08 UTC 2021


On Thu, 27 May 2021 09:56:22 GMT, Martin Doerr <mdoerr at openjdk.org> wrote:

> We need a fix for crashes in get_current_contended_monitor due to concurrent modification of memory locations which are not declared volatile. See bug for details.

Hi Martin,

your fix looks good but I'm a little concerned because there are other call sites which us a similar pattern. E.g. in `jvmtiEnvBase.cpp`:

vmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
  Thread *current_thread = Thread::current();
  assert(java_thread->is_handshake_safe_for(current_thread),
         "call by myself or at handshake");
  oop obj = NULL;
  // 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 *mon = java_thread->current_waiting_monitor();
  if (mon == NULL) {
    // thread is not doing an Object.wait() call
    mon = java_thread->current_pending_monitor();
    if (mon != NULL) {
      // The thread is trying to enter() an ObjectMonitor.
      obj = mon->object();
      assert(obj != NULL, "ObjectMonitor should have a valid object!");
    }
    // implied else: no contended ObjectMonitor
  } else {
    // thread is doing an Object.wait() call
    obj = mon->object();
    assert(obj != NULL, "Object.wait() should have an object");
  }


So I wonder if we shouldn't make `current_waiting_monitor()`/`current_pending_monitor()` return volatile pointers to make it clear to the callers that these pointers can change at any time?

I'm also not that deep into `ThreadService` & al. to understand what happens after your fix. Now you don't reload the waiting monitor but you might use it although it has already been cleared out from the thread (in the case where you previously crashed). Is that still OK?

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

PR: https://git.openjdk.java.net/jdk/pull/4224


More information about the hotspot-runtime-dev mailing list