Mercurial > hg > graal-compiler
comparison src/share/vm/runtime/objectMonitor.cpp @ 10405:f2110083203d
8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
author | sla |
---|---|
date | Mon, 10 Jun 2013 11:30:51 +0200 |
parents | 746b070f5022 |
children | 63a4eb8bcd23 75ef1a499665 d35df3079834 |
comparison
equal
deleted
inserted
replaced
10404:d0add7016434 | 10405:f2110083203d |
---|---|
34 #include "runtime/objectMonitor.inline.hpp" | 34 #include "runtime/objectMonitor.inline.hpp" |
35 #include "runtime/osThread.hpp" | 35 #include "runtime/osThread.hpp" |
36 #include "runtime/stubRoutines.hpp" | 36 #include "runtime/stubRoutines.hpp" |
37 #include "runtime/thread.inline.hpp" | 37 #include "runtime/thread.inline.hpp" |
38 #include "services/threadService.hpp" | 38 #include "services/threadService.hpp" |
39 #include "trace/tracing.hpp" | |
40 #include "trace/traceMacros.hpp" | |
39 #include "utilities/dtrace.hpp" | 41 #include "utilities/dtrace.hpp" |
42 #include "utilities/macros.hpp" | |
40 #include "utilities/preserveException.hpp" | 43 #include "utilities/preserveException.hpp" |
41 #ifdef TARGET_OS_FAMILY_linux | 44 #ifdef TARGET_OS_FAMILY_linux |
42 # include "os_linux.inline.hpp" | 45 # include "os_linux.inline.hpp" |
43 #endif | 46 #endif |
44 #ifdef TARGET_OS_FAMILY_solaris | 47 #ifdef TARGET_OS_FAMILY_solaris |
369 | 372 |
370 // Prevent deflation at STW-time. See deflate_idle_monitors() and is_busy(). | 373 // Prevent deflation at STW-time. See deflate_idle_monitors() and is_busy(). |
371 // Ensure the object-monitor relationship remains stable while there's contention. | 374 // Ensure the object-monitor relationship remains stable while there's contention. |
372 Atomic::inc_ptr(&_count); | 375 Atomic::inc_ptr(&_count); |
373 | 376 |
377 EventJavaMonitorEnter event; | |
378 | |
374 { // Change java thread status to indicate blocked on monitor enter. | 379 { // Change java thread status to indicate blocked on monitor enter. |
375 JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this); | 380 JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this); |
376 | 381 |
377 DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt); | 382 DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt); |
378 if (JvmtiExport::should_post_monitor_contended_enter()) { | 383 if (JvmtiExport::should_post_monitor_contended_enter()) { |
400 // the monitor while suspended because that would surprise the | 405 // the monitor while suspended because that would surprise the |
401 // thread that suspended us. | 406 // thread that suspended us. |
402 // | 407 // |
403 _recursions = 0 ; | 408 _recursions = 0 ; |
404 _succ = NULL ; | 409 _succ = NULL ; |
405 exit (Self) ; | 410 exit (false, Self) ; |
406 | 411 |
407 jt->java_suspend_self(); | 412 jt->java_suspend_self(); |
408 } | 413 } |
409 Self->set_current_pending_monitor(NULL); | 414 Self->set_current_pending_monitor(NULL); |
410 } | 415 } |
433 | 438 |
434 DTRACE_MONITOR_PROBE(contended__entered, this, object(), jt); | 439 DTRACE_MONITOR_PROBE(contended__entered, this, object(), jt); |
435 if (JvmtiExport::should_post_monitor_contended_entered()) { | 440 if (JvmtiExport::should_post_monitor_contended_entered()) { |
436 JvmtiExport::post_monitor_contended_entered(jt, this); | 441 JvmtiExport::post_monitor_contended_entered(jt, this); |
437 } | 442 } |
443 | |
444 if (event.should_commit()) { | |
445 event.set_klass(((oop)this->object())->klass()); | |
446 event.set_previousOwner((TYPE_JAVALANGTHREAD)_previous_owner_tid); | |
447 event.set_address((TYPE_ADDRESS)(uintptr_t)(this->object_addr())); | |
448 event.commit(); | |
449 } | |
450 | |
438 if (ObjectMonitor::_sync_ContendedLockAttempts != NULL) { | 451 if (ObjectMonitor::_sync_ContendedLockAttempts != NULL) { |
439 ObjectMonitor::_sync_ContendedLockAttempts->inc() ; | 452 ObjectMonitor::_sync_ContendedLockAttempts->inc() ; |
440 } | 453 } |
441 } | 454 } |
442 | 455 |
915 // any one time. (more precisely, we want to minimize timer-seconds, which is | 928 // any one time. (more precisely, we want to minimize timer-seconds, which is |
916 // the integral of the # of active timers at any instant over time). | 929 // the integral of the # of active timers at any instant over time). |
917 // Both impinge on OS scalability. Given that, at most one thread parked on | 930 // Both impinge on OS scalability. Given that, at most one thread parked on |
918 // a monitor will use a timer. | 931 // a monitor will use a timer. |
919 | 932 |
920 void ATTR ObjectMonitor::exit(TRAPS) { | 933 void ATTR ObjectMonitor::exit(bool not_suspended, TRAPS) { |
921 Thread * Self = THREAD ; | 934 Thread * Self = THREAD ; |
922 if (THREAD != _owner) { | 935 if (THREAD != _owner) { |
923 if (THREAD->is_lock_owned((address) _owner)) { | 936 if (THREAD->is_lock_owned((address) _owner)) { |
924 // Transmute _owner from a BasicLock pointer to a Thread address. | 937 // Transmute _owner from a BasicLock pointer to a Thread address. |
925 // We don't need to hold _mutex for this transition. | 938 // We don't need to hold _mutex for this transition. |
951 // Invariant: after setting Responsible=null an thread must execute | 964 // Invariant: after setting Responsible=null an thread must execute |
952 // a MEMBAR or other serializing instruction before fetching EntryList|cxq. | 965 // a MEMBAR or other serializing instruction before fetching EntryList|cxq. |
953 if ((SyncFlags & 4) == 0) { | 966 if ((SyncFlags & 4) == 0) { |
954 _Responsible = NULL ; | 967 _Responsible = NULL ; |
955 } | 968 } |
969 | |
970 #if INCLUDE_TRACE | |
971 // get the owner's thread id for the MonitorEnter event | |
972 // if it is enabled and the thread isn't suspended | |
973 if (not_suspended && Tracing::is_event_enabled(TraceJavaMonitorEnterEvent)) { | |
974 _previous_owner_tid = SharedRuntime::get_java_tid(Self); | |
975 } | |
976 #endif | |
956 | 977 |
957 for (;;) { | 978 for (;;) { |
958 assert (THREAD == _owner, "invariant") ; | 979 assert (THREAD == _owner, "invariant") ; |
959 | 980 |
960 | 981 |
1341 } | 1362 } |
1342 | 1363 |
1343 guarantee(Self == _owner, "complete_exit not owner"); | 1364 guarantee(Self == _owner, "complete_exit not owner"); |
1344 intptr_t save = _recursions; // record the old recursion count | 1365 intptr_t save = _recursions; // record the old recursion count |
1345 _recursions = 0; // set the recursion level to be 0 | 1366 _recursions = 0; // set the recursion level to be 0 |
1346 exit (Self) ; // exit the monitor | 1367 exit (true, Self) ; // exit the monitor |
1347 guarantee (_owner != Self, "invariant"); | 1368 guarantee (_owner != Self, "invariant"); |
1348 return save; | 1369 return save; |
1349 } | 1370 } |
1350 | 1371 |
1351 // reenter() enters a lock and sets recursion count | 1372 // reenter() enters a lock and sets recursion count |
1395 static int Adjust (volatile int * adr, int dx) { | 1416 static int Adjust (volatile int * adr, int dx) { |
1396 int v ; | 1417 int v ; |
1397 for (v = *adr ; Atomic::cmpxchg (v + dx, adr, v) != v; v = *adr) ; | 1418 for (v = *adr ; Atomic::cmpxchg (v + dx, adr, v) != v; v = *adr) ; |
1398 return v ; | 1419 return v ; |
1399 } | 1420 } |
1421 | |
1422 // helper method for posting a monitor wait event | |
1423 void ObjectMonitor::post_monitor_wait_event(EventJavaMonitorWait* event, | |
1424 jlong notifier_tid, | |
1425 jlong timeout, | |
1426 bool timedout) { | |
1427 event->set_klass(((oop)this->object())->klass()); | |
1428 event->set_timeout((TYPE_ULONG)timeout); | |
1429 event->set_address((TYPE_ADDRESS)(uintptr_t)(this->object_addr())); | |
1430 event->set_notifier((TYPE_OSTHREAD)notifier_tid); | |
1431 event->set_timedOut((TYPE_BOOLEAN)timedout); | |
1432 event->commit(); | |
1433 } | |
1434 | |
1400 // ----------------------------------------------------------------------------- | 1435 // ----------------------------------------------------------------------------- |
1401 // Wait/Notify/NotifyAll | 1436 // Wait/Notify/NotifyAll |
1402 // | 1437 // |
1403 // Note: a subset of changes to ObjectMonitor::wait() | 1438 // Note: a subset of changes to ObjectMonitor::wait() |
1404 // will need to be replicated in complete_exit above | 1439 // will need to be replicated in complete_exit above |
1409 | 1444 |
1410 DeferredInitialize () ; | 1445 DeferredInitialize () ; |
1411 | 1446 |
1412 // Throw IMSX or IEX. | 1447 // Throw IMSX or IEX. |
1413 CHECK_OWNER(); | 1448 CHECK_OWNER(); |
1449 | |
1450 EventJavaMonitorWait event; | |
1414 | 1451 |
1415 // check for a pending interrupt | 1452 // check for a pending interrupt |
1416 if (interruptible && Thread::is_interrupted(Self, true) && !HAS_PENDING_EXCEPTION) { | 1453 if (interruptible && Thread::is_interrupted(Self, true) && !HAS_PENDING_EXCEPTION) { |
1417 // post monitor waited event. Note that this is past-tense, we are done waiting. | 1454 // post monitor waited event. Note that this is past-tense, we are done waiting. |
1418 if (JvmtiExport::should_post_monitor_waited()) { | 1455 if (JvmtiExport::should_post_monitor_waited()) { |
1419 // Note: 'false' parameter is passed here because the | 1456 // Note: 'false' parameter is passed here because the |
1420 // wait was not timed out due to thread interrupt. | 1457 // wait was not timed out due to thread interrupt. |
1421 JvmtiExport::post_monitor_waited(jt, this, false); | 1458 JvmtiExport::post_monitor_waited(jt, this, false); |
1422 } | 1459 } |
1460 if (event.should_commit()) { | |
1461 post_monitor_wait_event(&event, 0, millis, false); | |
1462 } | |
1423 TEVENT (Wait - Throw IEX) ; | 1463 TEVENT (Wait - Throw IEX) ; |
1424 THROW(vmSymbols::java_lang_InterruptedException()); | 1464 THROW(vmSymbols::java_lang_InterruptedException()); |
1425 return ; | 1465 return ; |
1426 } | 1466 } |
1467 | |
1427 TEVENT (Wait) ; | 1468 TEVENT (Wait) ; |
1428 | 1469 |
1429 assert (Self->_Stalled == 0, "invariant") ; | 1470 assert (Self->_Stalled == 0, "invariant") ; |
1430 Self->_Stalled = intptr_t(this) ; | 1471 Self->_Stalled = intptr_t(this) ; |
1431 jt->set_current_waiting_monitor(this); | 1472 jt->set_current_waiting_monitor(this); |
1453 _Responsible = NULL ; | 1494 _Responsible = NULL ; |
1454 } | 1495 } |
1455 intptr_t save = _recursions; // record the old recursion count | 1496 intptr_t save = _recursions; // record the old recursion count |
1456 _waiters++; // increment the number of waiters | 1497 _waiters++; // increment the number of waiters |
1457 _recursions = 0; // set the recursion level to be 1 | 1498 _recursions = 0; // set the recursion level to be 1 |
1458 exit (Self) ; // exit the monitor | 1499 exit (true, Self) ; // exit the monitor |
1459 guarantee (_owner != Self, "invariant") ; | 1500 guarantee (_owner != Self, "invariant") ; |
1460 | 1501 |
1461 // As soon as the ObjectMonitor's ownership is dropped in the exit() | 1502 // As soon as the ObjectMonitor's ownership is dropped in the exit() |
1462 // call above, another thread can enter() the ObjectMonitor, do the | 1503 // call above, another thread can enter() the ObjectMonitor, do the |
1463 // notify(), and exit() the ObjectMonitor. If the other thread's | 1504 // notify(), and exit() the ObjectMonitor. If the other thread's |
1553 | 1594 |
1554 // post monitor waited event. Note that this is past-tense, we are done waiting. | 1595 // post monitor waited event. Note that this is past-tense, we are done waiting. |
1555 if (JvmtiExport::should_post_monitor_waited()) { | 1596 if (JvmtiExport::should_post_monitor_waited()) { |
1556 JvmtiExport::post_monitor_waited(jt, this, ret == OS_TIMEOUT); | 1597 JvmtiExport::post_monitor_waited(jt, this, ret == OS_TIMEOUT); |
1557 } | 1598 } |
1599 | |
1600 if (event.should_commit()) { | |
1601 post_monitor_wait_event(&event, node._notifier_tid, millis, ret == OS_TIMEOUT); | |
1602 } | |
1603 | |
1558 OrderAccess::fence() ; | 1604 OrderAccess::fence() ; |
1559 | 1605 |
1560 assert (Self->_Stalled != 0, "invariant") ; | 1606 assert (Self->_Stalled != 0, "invariant") ; |
1561 Self->_Stalled = 0 ; | 1607 Self->_Stalled = 0 ; |
1562 | 1608 |
1632 guarantee (iterator->_notified == 0, "invariant") ; | 1678 guarantee (iterator->_notified == 0, "invariant") ; |
1633 if (Policy != 4) { | 1679 if (Policy != 4) { |
1634 iterator->TState = ObjectWaiter::TS_ENTER ; | 1680 iterator->TState = ObjectWaiter::TS_ENTER ; |
1635 } | 1681 } |
1636 iterator->_notified = 1 ; | 1682 iterator->_notified = 1 ; |
1683 Thread * Self = THREAD; | |
1684 iterator->_notifier_tid = Self->osthread()->thread_id(); | |
1637 | 1685 |
1638 ObjectWaiter * List = _EntryList ; | 1686 ObjectWaiter * List = _EntryList ; |
1639 if (List != NULL) { | 1687 if (List != NULL) { |
1640 assert (List->_prev == NULL, "invariant") ; | 1688 assert (List->_prev == NULL, "invariant") ; |
1641 assert (List->TState == ObjectWaiter::TS_ENTER, "invariant") ; | 1689 assert (List->TState == ObjectWaiter::TS_ENTER, "invariant") ; |
1756 // For now we use (a). | 1804 // For now we use (a). |
1757 | 1805 |
1758 guarantee (iterator->TState == ObjectWaiter::TS_WAIT, "invariant") ; | 1806 guarantee (iterator->TState == ObjectWaiter::TS_WAIT, "invariant") ; |
1759 guarantee (iterator->_notified == 0, "invariant") ; | 1807 guarantee (iterator->_notified == 0, "invariant") ; |
1760 iterator->_notified = 1 ; | 1808 iterator->_notified = 1 ; |
1809 Thread * Self = THREAD; | |
1810 iterator->_notifier_tid = Self->osthread()->thread_id(); | |
1761 if (Policy != 4) { | 1811 if (Policy != 4) { |
1762 iterator->TState = ObjectWaiter::TS_ENTER ; | 1812 iterator->TState = ObjectWaiter::TS_ENTER ; |
1763 } | 1813 } |
1764 | 1814 |
1765 ObjectWaiter * List = _EntryList ; | 1815 ObjectWaiter * List = _EntryList ; |