src/share/vm/runtime/objectMonitor.cpp

changeset 9858
b985cbb00e68
parent 8887
b55756ea22d8
child 9931
fd44df5e3bc3
     1.1 --- a/src/share/vm/runtime/objectMonitor.cpp	Thu Aug 01 03:44:03 2019 +0100
     1.2 +++ b/src/share/vm/runtime/objectMonitor.cpp	Mon Aug 12 18:30:40 2019 +0300
     1.3 @@ -24,6 +24,8 @@
     1.4  
     1.5  #include "precompiled.hpp"
     1.6  #include "classfile/vmSymbols.hpp"
     1.7 +#include "jfr/jfrEvents.hpp"
     1.8 +#include "jfr/support/jfrThreadId.hpp"
     1.9  #include "memory/resourceArea.hpp"
    1.10  #include "oops/markOop.hpp"
    1.11  #include "oops/oop.inline.hpp"
    1.12 @@ -37,8 +39,6 @@
    1.13  #include "runtime/stubRoutines.hpp"
    1.14  #include "runtime/thread.inline.hpp"
    1.15  #include "services/threadService.hpp"
    1.16 -#include "trace/tracing.hpp"
    1.17 -#include "trace/traceMacros.hpp"
    1.18  #include "utilities/dtrace.hpp"
    1.19  #include "utilities/macros.hpp"
    1.20  #include "utilities/preserveException.hpp"
    1.21 @@ -54,6 +54,9 @@
    1.22  #ifdef TARGET_OS_FAMILY_bsd
    1.23  # include "os_bsd.inline.hpp"
    1.24  #endif
    1.25 +#if INCLUDE_JFR
    1.26 +#include "jfr/support/jfrFlush.hpp"
    1.27 +#endif
    1.28  
    1.29  #if defined(__GNUC__) && !defined(IA64) && !defined(PPC64)
    1.30    // Need to inhibit inlining for older versions of GCC to avoid build-time failures
    1.31 @@ -376,7 +379,12 @@
    1.32    // Ensure the object-monitor relationship remains stable while there's contention.
    1.33    Atomic::inc_ptr(&_count);
    1.34  
    1.35 +  JFR_ONLY(JfrConditionalFlushWithStacktrace<EventJavaMonitorEnter> flush(jt);)
    1.36    EventJavaMonitorEnter event;
    1.37 +  if (event.should_commit()) {
    1.38 +    event.set_monitorClass(((oop)this->object())->klass());
    1.39 +    event.set_address((uintptr_t)(this->object_addr()));
    1.40 +  }
    1.41  
    1.42    { // Change java thread status to indicate blocked on monitor enter.
    1.43      JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this);
    1.44 @@ -465,9 +473,7 @@
    1.45    }
    1.46  
    1.47    if (event.should_commit()) {
    1.48 -    event.set_klass(((oop)this->object())->klass());
    1.49 -    event.set_previousOwner((TYPE_JAVALANGTHREAD)_previous_owner_tid);
    1.50 -    event.set_address((TYPE_ADDRESS)(uintptr_t)(this->object_addr()));
    1.51 +    event.set_previousOwner((uintptr_t)_previous_owner_tid);
    1.52      event.commit();
    1.53    }
    1.54  
    1.55 @@ -990,11 +996,11 @@
    1.56        _Responsible = NULL ;
    1.57     }
    1.58  
    1.59 -#if INCLUDE_TRACE
    1.60 +#if INCLUDE_JFR
    1.61     // get the owner's thread id for the MonitorEnter event
    1.62     // if it is enabled and the thread isn't suspended
    1.63 -   if (not_suspended && Tracing::is_event_enabled(TraceJavaMonitorEnterEvent)) {
    1.64 -     _previous_owner_tid = SharedRuntime::get_java_tid(Self);
    1.65 +   if (not_suspended && EventJavaMonitorEnter::is_enabled()) {
    1.66 +    _previous_owner_tid = JFR_THREAD_ID(Self);
    1.67     }
    1.68  #endif
    1.69  
    1.70 @@ -1443,15 +1449,17 @@
    1.71  }
    1.72  
    1.73  // helper method for posting a monitor wait event
    1.74 -void ObjectMonitor::post_monitor_wait_event(EventJavaMonitorWait* event,
    1.75 -                                                           jlong notifier_tid,
    1.76 -                                                           jlong timeout,
    1.77 -                                                           bool timedout) {
    1.78 -  event->set_klass(((oop)this->object())->klass());
    1.79 -  event->set_timeout((TYPE_ULONG)timeout);
    1.80 -  event->set_address((TYPE_ADDRESS)(uintptr_t)(this->object_addr()));
    1.81 -  event->set_notifier((TYPE_OSTHREAD)notifier_tid);
    1.82 -  event->set_timedOut((TYPE_BOOLEAN)timedout);
    1.83 +static void post_monitor_wait_event(EventJavaMonitorWait* event,
    1.84 +                                    ObjectMonitor* monitor,
    1.85 +                                    jlong notifier_tid,
    1.86 +                                    jlong timeout,
    1.87 +                                    bool timedout) {
    1.88 +  assert(monitor != NULL, "invariant");
    1.89 +  event->set_monitorClass(((oop)monitor->object())->klass());
    1.90 +  event->set_timeout(timeout);
    1.91 +  event->set_address((uintptr_t)monitor->object_addr());
    1.92 +  event->set_notifier((u8)notifier_tid);
    1.93 +  event->set_timedOut(timedout);
    1.94    event->commit();
    1.95  }
    1.96  
    1.97 @@ -1489,7 +1497,7 @@
    1.98          // this ObjectMonitor.
    1.99       }
   1.100       if (event.should_commit()) {
   1.101 -       post_monitor_wait_event(&event, 0, millis, false);
   1.102 +       post_monitor_wait_event(&event, this, 0, millis, false);
   1.103       }
   1.104       TEVENT (Wait - Throw IEX) ;
   1.105       THROW(vmSymbols::java_lang_InterruptedException());
   1.106 @@ -1633,7 +1641,7 @@
   1.107       }
   1.108  
   1.109       if (event.should_commit()) {
   1.110 -       post_monitor_wait_event(&event, node._notifier_tid, millis, ret == OS_TIMEOUT);
   1.111 +       post_monitor_wait_event(&event, this, node._notifier_tid, millis, ret == OS_TIMEOUT);
   1.112       }
   1.113  
   1.114       OrderAccess::fence() ;
   1.115 @@ -1716,7 +1724,7 @@
   1.116       }
   1.117       iterator->_notified = 1 ;
   1.118       Thread * Self = THREAD;
   1.119 -     iterator->_notifier_tid = Self->osthread()->thread_id();
   1.120 +     iterator->_notifier_tid = JFR_THREAD_ID(Self);
   1.121  
   1.122       ObjectWaiter * List = _EntryList ;
   1.123       if (List != NULL) {
   1.124 @@ -1842,7 +1850,7 @@
   1.125       guarantee (iterator->_notified == 0, "invariant") ;
   1.126       iterator->_notified = 1 ;
   1.127       Thread * Self = THREAD;
   1.128 -     iterator->_notifier_tid = Self->osthread()->thread_id();
   1.129 +     iterator->_notifier_tid = JFR_THREAD_ID(Self);
   1.130       if (Policy != 4) {
   1.131          iterator->TState = ObjectWaiter::TS_ENTER ;
   1.132       }

mercurial