Mercurial > hg > graal-jvmci-8
comparison src/share/vm/runtime/objectMonitor.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | 28f281e8de1d |
children | 52b4284cb496 |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
52 #endif | 52 #endif |
53 #ifdef TARGET_OS_FAMILY_bsd | 53 #ifdef TARGET_OS_FAMILY_bsd |
54 # include "os_bsd.inline.hpp" | 54 # include "os_bsd.inline.hpp" |
55 #endif | 55 #endif |
56 | 56 |
57 #if defined(__GNUC__) && !defined(IA64) && !defined(PPC64) | 57 #if defined(__GNUC__) && !defined(IA64) |
58 // Need to inhibit inlining for older versions of GCC to avoid build-time failures | 58 // Need to inhibit inlining for older versions of GCC to avoid build-time failures |
59 #define ATTR __attribute__((noinline)) | 59 #define ATTR __attribute__((noinline)) |
60 #else | 60 #else |
61 #define ATTR | 61 #define ATTR |
62 #endif | 62 #endif |
76 if (klassname != NULL) { \ | 76 if (klassname != NULL) { \ |
77 bytes = (char*)klassname->bytes(); \ | 77 bytes = (char*)klassname->bytes(); \ |
78 len = klassname->utf8_length(); \ | 78 len = klassname->utf8_length(); \ |
79 } | 79 } |
80 | 80 |
81 #ifndef USDT2 | |
82 | |
83 HS_DTRACE_PROBE_DECL4(hotspot, monitor__notify, | |
84 jlong, uintptr_t, char*, int); | |
85 HS_DTRACE_PROBE_DECL4(hotspot, monitor__notifyAll, | |
86 jlong, uintptr_t, char*, int); | |
87 HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__enter, | |
88 jlong, uintptr_t, char*, int); | |
89 HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__entered, | |
90 jlong, uintptr_t, char*, int); | |
91 HS_DTRACE_PROBE_DECL4(hotspot, monitor__contended__exit, | |
92 jlong, uintptr_t, char*, int); | |
93 | |
94 #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \ | |
95 { \ | |
96 if (DTraceMonitorProbes) { \ | |
97 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ | |
98 HS_DTRACE_PROBE5(hotspot, monitor__wait, jtid, \ | |
99 (monitor), bytes, len, (millis)); \ | |
100 } \ | |
101 } | |
102 | |
103 #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \ | |
104 { \ | |
105 if (DTraceMonitorProbes) { \ | |
106 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ | |
107 HS_DTRACE_PROBE4(hotspot, monitor__##probe, jtid, \ | |
108 (uintptr_t)(monitor), bytes, len); \ | |
109 } \ | |
110 } | |
111 | |
112 #else /* USDT2 */ | |
113 | |
81 #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \ | 114 #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \ |
82 { \ | 115 { \ |
83 if (DTraceMonitorProbes) { \ | 116 if (DTraceMonitorProbes) { \ |
84 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ | 117 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ |
85 HOTSPOT_MONITOR_WAIT(jtid, \ | 118 HOTSPOT_MONITOR_WAIT(jtid, \ |
100 HOTSPOT_MONITOR_##probe(jtid, \ | 133 HOTSPOT_MONITOR_##probe(jtid, \ |
101 (uintptr_t)(monitor), bytes, len); \ | 134 (uintptr_t)(monitor), bytes, len); \ |
102 } \ | 135 } \ |
103 } | 136 } |
104 | 137 |
138 #endif /* USDT2 */ | |
105 #else // ndef DTRACE_ENABLED | 139 #else // ndef DTRACE_ENABLED |
106 | 140 |
107 #define DTRACE_MONITOR_WAIT_PROBE(obj, thread, millis, mon) {;} | 141 #define DTRACE_MONITOR_WAIT_PROBE(obj, thread, millis, mon) {;} |
108 #define DTRACE_MONITOR_PROBE(probe, obj, thread, mon) {;} | 142 #define DTRACE_MONITOR_PROBE(probe, obj, thread, mon) {;} |
109 | 143 |
198 // More precisely, the CAS-based "push" onto cxq is ABA-oblivious. | 232 // More precisely, the CAS-based "push" onto cxq is ABA-oblivious. |
199 // | 233 // |
200 // * Taken together, the cxq and the EntryList constitute or form a | 234 // * Taken together, the cxq and the EntryList constitute or form a |
201 // single logical queue of threads stalled trying to acquire the lock. | 235 // single logical queue of threads stalled trying to acquire the lock. |
202 // We use two distinct lists to improve the odds of a constant-time | 236 // We use two distinct lists to improve the odds of a constant-time |
203 // dequeue operation after acquisition (in the ::enter() epilogue) and | 237 // dequeue operation after acquisition (in the ::enter() epilog) and |
204 // to reduce heat on the list ends. (c.f. Michael Scott's "2Q" algorithm). | 238 // to reduce heat on the list ends. (c.f. Michael Scott's "2Q" algorithm). |
205 // A key desideratum is to minimize queue & monitor metadata manipulation | 239 // A key desideratum is to minimize queue & monitor metadata manipulation |
206 // that occurs while holding the monitor lock -- that is, we want to | 240 // that occurs while holding the monitor lock -- that is, we want to |
207 // minimize monitor lock holds times. Note that even a small amount of | 241 // minimize monitor lock holds times. Note that even a small amount of |
208 // fixed spinning will greatly reduce the # of enqueue-dequeue operations | 242 // fixed spinning will greatly reduce the # of enqueue-dequeue operations |
346 JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this); | 380 JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this); |
347 | 381 |
348 DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt); | 382 DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt); |
349 if (JvmtiExport::should_post_monitor_contended_enter()) { | 383 if (JvmtiExport::should_post_monitor_contended_enter()) { |
350 JvmtiExport::post_monitor_contended_enter(jt, this); | 384 JvmtiExport::post_monitor_contended_enter(jt, this); |
351 | |
352 // The current thread does not yet own the monitor and does not | |
353 // yet appear on any queues that would get it made the successor. | |
354 // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event | |
355 // handler cannot accidentally consume an unpark() meant for the | |
356 // ParkEvent associated with this ObjectMonitor. | |
357 } | 385 } |
358 | 386 |
359 OSThreadContendState osts(Self->osthread()); | 387 OSThreadContendState osts(Self->osthread()); |
360 ThreadBlockInVM tbivm(jt); | 388 ThreadBlockInVM tbivm(jt); |
361 | 389 |
409 // spinning we could increment JVMStat counters, etc. | 437 // spinning we could increment JVMStat counters, etc. |
410 | 438 |
411 DTRACE_MONITOR_PROBE(contended__entered, this, object(), jt); | 439 DTRACE_MONITOR_PROBE(contended__entered, this, object(), jt); |
412 if (JvmtiExport::should_post_monitor_contended_entered()) { | 440 if (JvmtiExport::should_post_monitor_contended_entered()) { |
413 JvmtiExport::post_monitor_contended_entered(jt, this); | 441 JvmtiExport::post_monitor_contended_entered(jt, this); |
414 | |
415 // The current thread already owns the monitor and is not going to | |
416 // call park() for the remainder of the monitor enter protocol. So | |
417 // it doesn't matter if the JVMTI_EVENT_MONITOR_CONTENDED_ENTERED | |
418 // event handler consumed an unpark() issued by the thread that | |
419 // just exited the monitor. | |
420 } | 442 } |
421 | 443 |
422 if (event.should_commit()) { | 444 if (event.should_commit()) { |
423 event.set_klass(((oop)this->object())->klass()); | 445 event.set_klass(((oop)this->object())->klass()); |
424 event.set_previousOwner((TYPE_JAVALANGTHREAD)_previous_owner_tid); | 446 event.set_previousOwner((TYPE_JAVALANGTHREAD)_previous_owner_tid); |
653 // by LDing cxq|EntryList. Newly arrived threads -- that is, threads | 675 // by LDing cxq|EntryList. Newly arrived threads -- that is, threads |
654 // that arrive on cxq after the ST:MEMBAR, above -- will set Responsible | 676 // that arrive on cxq after the ST:MEMBAR, above -- will set Responsible |
655 // non-null and elect a new "Responsible" timer thread. | 677 // non-null and elect a new "Responsible" timer thread. |
656 // | 678 // |
657 // This thread executes: | 679 // This thread executes: |
658 // ST Responsible=null; MEMBAR (in enter epilogue - here) | 680 // ST Responsible=null; MEMBAR (in enter epilog - here) |
659 // LD cxq|EntryList (in subsequent exit) | 681 // LD cxq|EntryList (in subsequent exit) |
660 // | 682 // |
661 // Entering threads in the slow/contended path execute: | 683 // Entering threads in the slow/contended path execute: |
662 // ST cxq=nonnull; MEMBAR; LD Responsible (in enter prolog) | 684 // ST cxq=nonnull; MEMBAR; LD Responsible (in enter prolog) |
663 // The (ST cxq; MEMBAR) is accomplished with CAS(). | 685 // The (ST cxq; MEMBAR) is accomplished with CAS(). |
1432 // 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. |
1433 if (JvmtiExport::should_post_monitor_waited()) { | 1455 if (JvmtiExport::should_post_monitor_waited()) { |
1434 // Note: 'false' parameter is passed here because the | 1456 // Note: 'false' parameter is passed here because the |
1435 // wait was not timed out due to thread interrupt. | 1457 // wait was not timed out due to thread interrupt. |
1436 JvmtiExport::post_monitor_waited(jt, this, false); | 1458 JvmtiExport::post_monitor_waited(jt, this, false); |
1437 | |
1438 // In this short circuit of the monitor wait protocol, the | |
1439 // current thread never drops ownership of the monitor and | |
1440 // never gets added to the wait queue so the current thread | |
1441 // cannot be made the successor. This means that the | |
1442 // JVMTI_EVENT_MONITOR_WAITED event handler cannot accidentally | |
1443 // consume an unpark() meant for the ParkEvent associated with | |
1444 // this ObjectMonitor. | |
1445 } | 1459 } |
1446 if (event.should_commit()) { | 1460 if (event.should_commit()) { |
1447 post_monitor_wait_event(&event, 0, millis, false); | 1461 post_monitor_wait_event(&event, 0, millis, false); |
1448 } | 1462 } |
1449 TEVENT (Wait - Throw IEX) ; | 1463 TEVENT (Wait - Throw IEX) ; |
1482 intptr_t save = _recursions; // record the old recursion count | 1496 intptr_t save = _recursions; // record the old recursion count |
1483 _waiters++; // increment the number of waiters | 1497 _waiters++; // increment the number of waiters |
1484 _recursions = 0; // set the recursion level to be 1 | 1498 _recursions = 0; // set the recursion level to be 1 |
1485 exit (true, Self) ; // exit the monitor | 1499 exit (true, Self) ; // exit the monitor |
1486 guarantee (_owner != Self, "invariant") ; | 1500 guarantee (_owner != Self, "invariant") ; |
1501 | |
1502 // As soon as the ObjectMonitor's ownership is dropped in the exit() | |
1503 // call above, another thread can enter() the ObjectMonitor, do the | |
1504 // notify(), and exit() the ObjectMonitor. If the other thread's | |
1505 // exit() call chooses this thread as the successor and the unpark() | |
1506 // call happens to occur while this thread is posting a | |
1507 // MONITOR_CONTENDED_EXIT event, then we run the risk of the event | |
1508 // handler using RawMonitors and consuming the unpark(). | |
1509 // | |
1510 // To avoid the problem, we re-post the event. This does no harm | |
1511 // even if the original unpark() was not consumed because we are the | |
1512 // chosen successor for this monitor. | |
1513 if (node._notified != 0 && _succ == Self) { | |
1514 node._event->unpark(); | |
1515 } | |
1487 | 1516 |
1488 // The thread is on the WaitSet list - now park() it. | 1517 // The thread is on the WaitSet list - now park() it. |
1489 // On MP systems it's conceivable that a brief spin before we park | 1518 // On MP systems it's conceivable that a brief spin before we park |
1490 // could be profitable. | 1519 // could be profitable. |
1491 // | 1520 // |
1564 // (Don't cache naked oops over safepoints, of course). | 1593 // (Don't cache naked oops over safepoints, of course). |
1565 | 1594 |
1566 // 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. |
1567 if (JvmtiExport::should_post_monitor_waited()) { | 1596 if (JvmtiExport::should_post_monitor_waited()) { |
1568 JvmtiExport::post_monitor_waited(jt, this, ret == OS_TIMEOUT); | 1597 JvmtiExport::post_monitor_waited(jt, this, ret == OS_TIMEOUT); |
1569 | |
1570 if (node._notified != 0 && _succ == Self) { | |
1571 // In this part of the monitor wait-notify-reenter protocol it | |
1572 // is possible (and normal) for another thread to do a fastpath | |
1573 // monitor enter-exit while this thread is still trying to get | |
1574 // to the reenter portion of the protocol. | |
1575 // | |
1576 // The ObjectMonitor was notified and the current thread is | |
1577 // the successor which also means that an unpark() has already | |
1578 // been done. The JVMTI_EVENT_MONITOR_WAITED event handler can | |
1579 // consume the unpark() that was done when the successor was | |
1580 // set because the same ParkEvent is shared between Java | |
1581 // monitors and JVM/TI RawMonitors (for now). | |
1582 // | |
1583 // We redo the unpark() to ensure forward progress, i.e., we | |
1584 // don't want all pending threads hanging (parked) with none | |
1585 // entering the unlocked monitor. | |
1586 node._event->unpark(); | |
1587 } | |
1588 } | 1598 } |
1589 | 1599 |
1590 if (event.should_commit()) { | 1600 if (event.should_commit()) { |
1591 post_monitor_wait_event(&event, node._notifier_tid, millis, ret == OS_TIMEOUT); | 1601 post_monitor_wait_event(&event, node._notifier_tid, millis, ret == OS_TIMEOUT); |
1592 } | 1602 } |
2019 if (MaxSpin >= 0) { | 2029 if (MaxSpin >= 0) { |
2020 if (_Spinner > MaxSpin) { | 2030 if (_Spinner > MaxSpin) { |
2021 TEVENT (Spin abort -- too many spinners) ; | 2031 TEVENT (Spin abort -- too many spinners) ; |
2022 return 0 ; | 2032 return 0 ; |
2023 } | 2033 } |
2024 // Slightly racy, but benign ... | 2034 // Slighty racy, but benign ... |
2025 Adjust (&_Spinner, 1) ; | 2035 Adjust (&_Spinner, 1) ; |
2026 } | 2036 } |
2027 | 2037 |
2028 // We're good to spin ... spin ingress. | 2038 // We're good to spin ... spin ingress. |
2029 // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades | 2039 // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades |