annotate src/share/vm/runtime/synchronizer.cpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents 78bbf4d43a14
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14422
diff changeset
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 702
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 702
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 702
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
26 #include "classfile/vmSymbols.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
27 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
28 #include "oops/markOop.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
29 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
30 #include "runtime/biasedLocking.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
31 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
32 #include "runtime/interfaceSupport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
33 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
34 #include "runtime/objectMonitor.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
35 #include "runtime/objectMonitor.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
36 #include "runtime/osThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
37 #include "runtime/stubRoutines.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
38 #include "runtime/synchronizer.hpp"
7180
f34d701e952e 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 6983
diff changeset
39 #include "runtime/thread.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
40 #include "utilities/dtrace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
41 #include "utilities/events.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
42 #include "utilities/preserveException.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
43 #ifdef TARGET_OS_FAMILY_linux
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
44 # include "os_linux.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
45 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
46 #ifdef TARGET_OS_FAMILY_solaris
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
47 # include "os_solaris.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
48 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
49 #ifdef TARGET_OS_FAMILY_windows
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
50 # include "os_windows.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
51 #endif
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2426
diff changeset
52 #ifdef TARGET_OS_FAMILY_bsd
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2426
diff changeset
53 # include "os_bsd.inline.hpp"
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2426
diff changeset
54 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55
14403
75ef1a499665 8019973: PPC64 (part 11): Fix IA64 preprocessor conditionals on AIX.
goetz
parents: 10405
diff changeset
56 #if defined(__GNUC__) && !defined(PPC64)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Need to inhibit inlining for older versions of GCC to avoid build-time failures
a61af66fc99e Initial load
duke
parents:
diff changeset
58 #define ATTR __attribute__((noinline))
a61af66fc99e Initial load
duke
parents:
diff changeset
59 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
60 #define ATTR
a61af66fc99e Initial load
duke
parents:
diff changeset
61 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
62
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14422
diff changeset
63 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14422
diff changeset
64
0
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // The "core" versions of monitor enter and exit reside in this file.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // The interpreter and compilers contain specialized transliterated
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // variants of the enter-exit fast-path operations. See i486.ad fast_lock(),
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // for instance. If you make changes here, make sure to modify the
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // interpreter, and both C1 and C2 fast-path inline locking code emission.
a61af66fc99e Initial load
duke
parents:
diff changeset
70 //
a61af66fc99e Initial load
duke
parents:
diff changeset
71 //
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // -----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 #ifdef DTRACE_ENABLED
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Only bother with this argument setup if dtrace is available
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // TODO-FIXME: probes should not fire when caller is _blocked. assert() accordingly.
a61af66fc99e Initial load
duke
parents:
diff changeset
78
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
79 #define DTRACE_MONITOR_PROBE_COMMON(obj, thread) \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 char* bytes = NULL; \
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int len = 0; \
a61af66fc99e Initial load
duke
parents:
diff changeset
82 jlong jtid = SharedRuntime::get_java_tid(thread); \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
83 Symbol* klassname = ((oop)(obj))->klass()->name(); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (klassname != NULL) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
85 bytes = (char*)klassname->bytes(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
86 len = klassname->utf8_length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
89 #ifndef USDT2
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
90 HS_DTRACE_PROBE_DECL5(hotspot, monitor__wait,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
91 jlong, uintptr_t, char*, int, long);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
92 HS_DTRACE_PROBE_DECL4(hotspot, monitor__waited,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
93 jlong, uintptr_t, char*, int);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
94
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
95 #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (DTraceMonitorProbes) { \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
98 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 HS_DTRACE_PROBE5(hotspot, monitor__wait, jtid, \
a61af66fc99e Initial load
duke
parents:
diff changeset
100 (monitor), bytes, len, (millis)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
104 #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (DTraceMonitorProbes) { \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
107 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 HS_DTRACE_PROBE4(hotspot, monitor__##probe, jtid, \
a61af66fc99e Initial load
duke
parents:
diff changeset
109 (uintptr_t)(monitor), bytes, len); \
a61af66fc99e Initial load
duke
parents:
diff changeset
110 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
113 #else /* USDT2 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
114
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
115 #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
116 { \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
117 if (DTraceMonitorProbes) { \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
118 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
119 HOTSPOT_MONITOR_WAIT(jtid, \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
120 (uintptr_t)(monitor), bytes, len, (millis)); \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
121 } \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
122 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
123
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
124 #define HOTSPOT_MONITOR_PROBE_waited HOTSPOT_MONITOR_PROBE_WAITED
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
125
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
126 #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
127 { \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
128 if (DTraceMonitorProbes) { \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
129 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
130 HOTSPOT_MONITOR_PROBE_##probe(jtid, /* probe = waited */ \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
131 (uintptr_t)(monitor), bytes, len); \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
132 } \
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
133 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
134
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents: 3960
diff changeset
135 #endif /* USDT2 */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
136 #else // ndef DTRACE_ENABLED
a61af66fc99e Initial load
duke
parents:
diff changeset
137
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
138 #define DTRACE_MONITOR_WAIT_PROBE(obj, thread, millis, mon) {;}
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4006
diff changeset
139 #define DTRACE_MONITOR_PROBE(probe, obj, thread, mon) {;}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #endif // ndef DTRACE_ENABLED
a61af66fc99e Initial load
duke
parents:
diff changeset
142
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
143 // This exists only as a workaround of dtrace bug 6254741
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
144 int dtrace_waited_probe(ObjectMonitor* monitor, Handle obj, Thread* thr) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
145 DTRACE_MONITOR_PROBE(waited, monitor, obj(), thr);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
146 return 0;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
147 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
148
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
149 #define NINFLATIONLOCKS 256
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
150 static volatile intptr_t InflationLocks [NINFLATIONLOCKS] ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
151
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
152 ObjectMonitor * ObjectSynchronizer::gBlockList = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
153 ObjectMonitor * volatile ObjectSynchronizer::gFreeList = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
154 ObjectMonitor * volatile ObjectSynchronizer::gOmInUseList = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
155 int ObjectSynchronizer::gOmInUseCount = 0;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
156 static volatile intptr_t ListLock = 0 ; // protects global monitor free-list cache
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
157 static volatile int MonitorFreeCount = 0 ; // # on gFreeList
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
158 static volatile int MonitorPopulation = 0 ; // # Extant -- in circulation
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
159 #define CHAINMARKER (cast_to_oop<intptr_t>(-1))
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
160
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
161 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
162 // Fast Monitor Enter/Exit
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
163 // This the fast monitor enter. The interpreter and compiler use
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
164 // some assembly copies of this code. Make sure update those code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
165 // if the following function is changed. The implementation is
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
166 // extremely sensitive to race condition. Be careful.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
167
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
168 void ObjectSynchronizer::fast_enter(Handle obj, BasicLock* lock, bool attempt_rebias, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
169 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
170 if (!SafepointSynchronize::is_at_safepoint()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
171 BiasedLocking::Condition cond = BiasedLocking::revoke_and_rebias(obj, attempt_rebias, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
172 if (cond == BiasedLocking::BIAS_REVOKED_AND_REBIASED) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
173 return;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
174 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
175 } else {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
176 assert(!attempt_rebias, "can not rebias toward VM thread");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
177 BiasedLocking::revoke_at_safepoint(obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
178 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
179 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
180 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
181
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
182 slow_enter (obj, lock, THREAD) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
183 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
184
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
185 void ObjectSynchronizer::fast_exit(oop object, BasicLock* lock, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
186 assert(!object->mark()->has_bias_pattern(), "should not see bias pattern here");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
187 // if displaced header is null, the previous enter is recursive enter, no-op
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
188 markOop dhw = lock->displaced_header();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
189 markOop mark ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
190 if (dhw == NULL) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
191 // Recursive stack-lock.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
192 // Diagnostics -- Could be: stack-locked, inflating, inflated.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
193 mark = object->mark() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
194 assert (!mark->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
195 if (mark->has_locker() && mark != markOopDesc::INFLATING()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
196 assert(THREAD->is_lock_owned((address)mark->locker()), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
197 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
198 if (mark->has_monitor()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
199 ObjectMonitor * m = mark->monitor() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
200 assert(((oop)(m->object()))->mark() == mark, "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
201 assert(m->is_entered(THREAD), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
202 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
203 return ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
204 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
205
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
206 mark = object->mark() ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
207
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
208 // If the object is stack-locked by the current thread, try to
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
209 // swing the displaced header from the box back to the mark.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
210 if (mark == (markOop) lock) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
211 assert (dhw->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
212 if ((markOop) Atomic::cmpxchg_ptr (dhw, object->mark_addr(), mark) == mark) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
213 TEVENT (fast_exit: release stacklock) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
214 return;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
215 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
216 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
217
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10161
diff changeset
218 ObjectSynchronizer::inflate(THREAD, object)->exit (true, THREAD) ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
219 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
220
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
221 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
222 // Interpreter/Compiler Slow Case
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
223 // This routine is used to handle interpreter/compiler slow case
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
224 // We don't need to use fast path here, because it must have been
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
225 // failed in the interpreter/compiler code.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
226 void ObjectSynchronizer::slow_enter(Handle obj, BasicLock* lock, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
227 markOop mark = obj->mark();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
228 assert(!mark->has_bias_pattern(), "should not see bias pattern here");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
229
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
230 if (mark->is_neutral()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
231 // Anticipate successful CAS -- the ST of the displaced mark must
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
232 // be visible <= the ST performed by the CAS.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
233 lock->set_displaced_header(mark);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
234 if (mark == (markOop) Atomic::cmpxchg_ptr(lock, obj()->mark_addr(), mark)) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
235 TEVENT (slow_enter: release stacklock) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
236 return ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
237 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
238 // Fall through to inflate() ...
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
239 } else
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
240 if (mark->has_locker() && THREAD->is_lock_owned((address)mark->locker())) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
241 assert(lock != mark->locker(), "must not re-lock the same lock");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
242 assert(lock != (BasicLock*)obj->mark(), "don't relock with same BasicLock");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
243 lock->set_displaced_header(NULL);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
244 return;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
245 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
246
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
247 #if 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
248 // The following optimization isn't particularly useful.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
249 if (mark->has_monitor() && mark->monitor()->is_entered(THREAD)) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
250 lock->set_displaced_header (NULL) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
251 return ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
252 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
253 #endif
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
254
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
255 // The object header will never be displaced to this lock,
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
256 // so it does not matter what the value is, except that it
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
257 // must be non-zero to avoid looking like a re-entrant lock,
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
258 // and must not look locked either.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
259 lock->set_displaced_header(markOopDesc::unused_mark());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
260 ObjectSynchronizer::inflate(THREAD, obj())->enter(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
261 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
262
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
263 // This routine is used to handle interpreter/compiler slow case
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
264 // We don't need to use fast path here, because it must have
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
265 // failed in the interpreter/compiler code. Simply use the heavy
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
266 // weight monitor should be ok, unless someone find otherwise.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
267 void ObjectSynchronizer::slow_exit(oop object, BasicLock* lock, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
268 fast_exit (object, lock, THREAD) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
269 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
270
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
271 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
272 // Class Loader support to workaround deadlocks on the class loader lock objects
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
273 // Also used by GC
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
274 // complete_exit()/reenter() are used to wait on a nested lock
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
275 // i.e. to give up an outer lock completely and then re-enter
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
276 // Used when holding nested locks - lock acquisition order: lock1 then lock2
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
277 // 1) complete_exit lock1 - saving recursion count
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
278 // 2) wait on lock2
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
279 // 3) when notified on lock2, unlock lock2
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
280 // 4) reenter lock1 with original recursion count
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
281 // 5) lock lock2
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
282 // NOTE: must use heavy weight monitor to handle complete_exit/reenter()
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
283 intptr_t ObjectSynchronizer::complete_exit(Handle obj, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
284 TEVENT (complete_exit) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
285 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
286 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
287 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
290 ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
291
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
292 return monitor->complete_exit(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
293 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
294
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
295 // NOTE: must use heavy weight monitor to handle complete_exit/reenter()
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
296 void ObjectSynchronizer::reenter(Handle obj, intptr_t recursion, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
297 TEVENT (reenter) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
298 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
299 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
300 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
301 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
302
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
303 ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
304
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
305 monitor->reenter(recursion, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
306 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
307 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
308 // JNI locks on java objects
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
309 // NOTE: must use heavy weight monitor to handle jni monitor enter
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
310 void ObjectSynchronizer::jni_enter(Handle obj, TRAPS) { // possible entry from jni enter
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
311 // the current locking is from JNI instead of Java code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
312 TEVENT (jni_enter) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
313 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
314 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
315 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
316 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
317 THREAD->set_current_pending_monitor_is_from_java(false);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
318 ObjectSynchronizer::inflate(THREAD, obj())->enter(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
319 THREAD->set_current_pending_monitor_is_from_java(true);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
320 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
321
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
322 // NOTE: must use heavy weight monitor to handle jni monitor enter
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
323 bool ObjectSynchronizer::jni_try_enter(Handle obj, Thread* THREAD) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
324 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
325 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
326 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
329 ObjectMonitor* monitor = ObjectSynchronizer::inflate_helper(obj());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
330 return monitor->try_enter(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
331 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
332
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
333
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
334 // NOTE: must use heavy weight monitor to handle jni monitor exit
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
335 void ObjectSynchronizer::jni_exit(oop obj, Thread* THREAD) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
336 TEVENT (jni_exit) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
337 if (UseBiasedLocking) {
7628
f3184f32ce0b 6444286: Possible naked oop related to biased locking revocation safepoint in jni_exit()
dcubed
parents: 7180
diff changeset
338 Handle h_obj(THREAD, obj);
f3184f32ce0b 6444286: Possible naked oop related to biased locking revocation safepoint in jni_exit()
dcubed
parents: 7180
diff changeset
339 BiasedLocking::revoke_and_rebias(h_obj, false, THREAD);
f3184f32ce0b 6444286: Possible naked oop related to biased locking revocation safepoint in jni_exit()
dcubed
parents: 7180
diff changeset
340 obj = h_obj();
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
341 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
342 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
343
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
344 ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
345 // If this thread has locked the object, exit the monitor. Note: can't use
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
346 // monitor->check(CHECK); must exit even if an exception is pending.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
347 if (monitor->check(THREAD)) {
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10161
diff changeset
348 monitor->exit(true, THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
350 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
351
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
352 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
353 // Internal VM locks on java objects
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
354 // standard constructor, allows locking failures
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
355 ObjectLocker::ObjectLocker(Handle obj, Thread* thread, bool doLock) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
356 _dolock = doLock;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
357 _thread = thread;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
358 debug_only(if (StrictSafepointChecks) _thread->check_for_valid_safepoint_state(false);)
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
359 _obj = obj;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
360
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
361 if (_dolock) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
362 TEVENT (ObjectLocker) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
363
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
364 ObjectSynchronizer::fast_enter(_obj, &_lock, false, _thread);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
365 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
366 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
367
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
368 ObjectLocker::~ObjectLocker() {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
369 if (_dolock) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
370 ObjectSynchronizer::fast_exit(_obj(), &_lock, _thread);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
371 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
372 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
375 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
376 // Wait/Notify/NotifyAll
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
377 // NOTE: must use heavy weight monitor to handle wait()
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
378 void ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
379 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
380 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
381 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
382 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
383 if (millis < 0) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
384 TEVENT (wait - throw IAX) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
385 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
386 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
387 ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
388 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), THREAD, millis);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
389 monitor->wait(millis, true, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
390
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
391 /* This dummy call is in place to get around dtrace bug 6254741. Once
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
392 that's fixed we can uncomment the following line and remove the call */
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
393 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
394 dtrace_waited_probe(monitor, obj, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
395 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
396
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
397 void ObjectSynchronizer::waitUninterruptibly (Handle obj, jlong millis, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
398 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
399 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
400 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
401 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
402 if (millis < 0) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
403 TEVENT (wait - throw IAX) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
404 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
405 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
406 ObjectSynchronizer::inflate(THREAD, obj()) -> wait(millis, false, THREAD) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
407 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
408
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
409 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
410 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
411 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
412 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
413 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
414
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
415 markOop mark = obj->mark();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
416 if (mark->has_locker() && THREAD->is_lock_owned((address)mark->locker())) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
417 return;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
418 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
419 ObjectSynchronizer::inflate(THREAD, obj())->notify(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
420 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
421
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
422 // NOTE: see comment of notify()
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
423 void ObjectSynchronizer::notifyall(Handle obj, TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
424 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
425 BiasedLocking::revoke_and_rebias(obj, false, THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
426 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
427 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
428
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
429 markOop mark = obj->mark();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
430 if (mark->has_locker() && THREAD->is_lock_owned((address)mark->locker())) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
431 return;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
432 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
433 ObjectSynchronizer::inflate(THREAD, obj())->notifyAll(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
434 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
435
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
436 // -----------------------------------------------------------------------------
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
437 // Hash Code handling
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
438 //
0
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // Performance concern:
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // OrderAccess::storestore() calls release() which STs 0 into the global volatile
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // OrderAccess::Dummy variable. This store is unnecessary for correctness.
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // Many threads STing into a common location causes considerable cache migration
a61af66fc99e Initial load
duke
parents:
diff changeset
443 // or "sloshing" on large SMP system. As such, I avoid using OrderAccess::storestore()
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // until it's repaired. In some cases OrderAccess::fence() -- which incurs local
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // latency on the executing processor -- is a better choice as it scales on SMP
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // systems. See http://blogs.sun.com/dave/entry/biased_locking_in_hotspot for a
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // discussion of coherency costs. Note that all our current reference platforms
a61af66fc99e Initial load
duke
parents:
diff changeset
448 // provide strong ST-ST order, so the issue is moot on IA32, x64, and SPARC.
a61af66fc99e Initial load
duke
parents:
diff changeset
449 //
a61af66fc99e Initial load
duke
parents:
diff changeset
450 // As a general policy we use "volatile" to control compiler-based reordering
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // and explicit fences (barriers) to control for architectural reordering performed
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // by the CPU(s) or platform.
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 struct SharedGlobals {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // These are highly shared mostly-read variables.
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // To avoid false-sharing they need to be the sole occupants of a $ line.
a61af66fc99e Initial load
duke
parents:
diff changeset
457 double padPrefix [8];
a61af66fc99e Initial load
duke
parents:
diff changeset
458 volatile int stwRandom ;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 volatile int stwCycle ;
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // Hot RW variables -- Sequester to avoid false-sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
462 double padSuffix [16];
a61af66fc99e Initial load
duke
parents:
diff changeset
463 volatile int hcSequence ;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 double padFinal [8] ;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 } ;
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 static SharedGlobals GVars ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
468 static int MonitorScavengeThreshold = 1000000 ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
469 static volatile int ForceMonitorScavenge = 0 ; // Scavenge required and pending
0
a61af66fc99e Initial load
duke
parents:
diff changeset
470
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
471 static markOop ReadStableMark (oop obj) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
472 markOop mark = obj->mark() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
473 if (!mark->is_being_inflated()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
474 return mark ; // normal fast-path return
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
475 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
476
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
477 int its = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
478 for (;;) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
479 markOop mark = obj->mark() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
480 if (!mark->is_being_inflated()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
481 return mark ; // normal fast-path return
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
482 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
483
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
484 // The object is being inflated by some other thread.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
485 // The caller of ReadStableMark() must wait for inflation to complete.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
486 // Avoid live-lock
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
487 // TODO: consider calling SafepointSynchronize::do_call_back() while
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
488 // spinning to see if there's a safepoint pending. If so, immediately
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
489 // yielding or blocking would be appropriate. Avoid spinning while
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
490 // there is a safepoint pending.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
491 // TODO: add inflation contention performance counters.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
492 // TODO: restrict the aggregate number of spinners.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
493
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
494 ++its ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
495 if (its > 10000 || !os::is_MP()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
496 if (its & 1) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
497 os::NakedYield() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
498 TEVENT (Inflate: INFLATING - yield) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
499 } else {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
500 // Note that the following code attenuates the livelock problem but is not
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
501 // a complete remedy. A more complete solution would require that the inflating
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
502 // thread hold the associated inflation lock. The following code simply restricts
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
503 // the number of spinners to at most one. We'll have N-2 threads blocked
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
504 // on the inflationlock, 1 thread holding the inflation lock and using
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
505 // a yield/park strategy, and 1 thread in the midst of inflation.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
506 // A more refined approach would be to change the encoding of INFLATING
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
507 // to allow encapsulation of a native thread pointer. Threads waiting for
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
508 // inflation to complete would use CAS to push themselves onto a singly linked
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
509 // list rooted at the markword. Once enqueued, they'd loop, checking a per-thread flag
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
510 // and calling park(). When inflation was complete the thread that accomplished inflation
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
511 // would detach the list and set the markword to inflated with a single CAS and
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
512 // then for each thread on the list, set the flag and unpark() the thread.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
513 // This is conceptually similar to muxAcquire-muxRelease, except that muxRelease
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
514 // wakes at most one thread whereas we need to wake the entire list.
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
515 int ix = (cast_from_oop<intptr_t>(obj) >> 5) & (NINFLATIONLOCKS-1) ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
516 int YieldThenBlock = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
517 assert (ix >= 0 && ix < NINFLATIONLOCKS, "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
518 assert ((NINFLATIONLOCKS & (NINFLATIONLOCKS-1)) == 0, "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
519 Thread::muxAcquire (InflationLocks + ix, "InflationLock") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
520 while (obj->mark() == markOopDesc::INFLATING()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
521 // Beware: NakedYield() is advisory and has almost no effect on some platforms
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
522 // so we periodically call Self->_ParkEvent->park(1).
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
523 // We use a mixed spin/yield/block mechanism.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
524 if ((YieldThenBlock++) >= 16) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
525 Thread::current()->_ParkEvent->park(1) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
526 } else {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
527 os::NakedYield() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
528 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
529 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
530 Thread::muxRelease (InflationLocks + ix ) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
531 TEVENT (Inflate: INFLATING - yield/park) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
532 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
533 } else {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
534 SpinPause() ; // SMP-polite spinning
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
535 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
536 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
537 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
538
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // hashCode() generation :
a61af66fc99e Initial load
duke
parents:
diff changeset
540 //
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Possibilities:
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // * MD5Digest of {obj,stwRandom}
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // * CRC32 of {obj,stwRandom} or any linear-feedback shift register function.
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // * A DES- or AES-style SBox[] mechanism
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // * One of the Phi-based schemes, such as:
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // 2654435761 = 2^32 * Phi (golden ratio)
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // HashCodeValue = ((uintptr_t(obj) >> 3) * 2654435761) ^ GVars.stwRandom ;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // * A variation of Marsaglia's shift-xor RNG scheme.
a61af66fc99e Initial load
duke
parents:
diff changeset
549 // * (obj ^ stwRandom) is appealing, but can result
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // in undesirable regularity in the hashCode values of adjacent objects
a61af66fc99e Initial load
duke
parents:
diff changeset
551 // (objects allocated back-to-back, in particular). This could potentially
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // result in hashtable collisions and reduced hashtable efficiency.
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // There are simple ways to "diffuse" the middle address bits over the
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // generated hashCode values:
a61af66fc99e Initial load
duke
parents:
diff changeset
555 //
a61af66fc99e Initial load
duke
parents:
diff changeset
556
a61af66fc99e Initial load
duke
parents:
diff changeset
557 static inline intptr_t get_next_hash(Thread * Self, oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 intptr_t value = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
559 if (hashCode == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // This form uses an unguarded global Park-Miller RNG,
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // so it's possible for two threads to race and generate the same RNG.
a61af66fc99e Initial load
duke
parents:
diff changeset
562 // On MP system we'll have lots of RW access to a global, so the
a61af66fc99e Initial load
duke
parents:
diff changeset
563 // mechanism induces lots of coherency traffic.
a61af66fc99e Initial load
duke
parents:
diff changeset
564 value = os::random() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
566 if (hashCode == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // This variation has the property of being stable (idempotent)
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // between STW operations. This can be useful in some of the 1-0
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // synchronization schemes.
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
570 intptr_t addrBits = cast_from_oop<intptr_t>(obj) >> 3 ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
571 value = addrBits ^ (addrBits >> 5) ^ GVars.stwRandom ;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
573 if (hashCode == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 value = 1 ; // for sensitivity testing
a61af66fc99e Initial load
duke
parents:
diff changeset
575 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
576 if (hashCode == 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
577 value = ++GVars.hcSequence ;
a61af66fc99e Initial load
duke
parents:
diff changeset
578 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if (hashCode == 4) {
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
580 value = cast_from_oop<intptr_t>(obj) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
581 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // Marsaglia's xor-shift scheme with thread-specific state
a61af66fc99e Initial load
duke
parents:
diff changeset
583 // This is probably the best overall implementation -- we'll
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // likely make this the default in future releases.
a61af66fc99e Initial load
duke
parents:
diff changeset
585 unsigned t = Self->_hashStateX ;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 t ^= (t << 11) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 Self->_hashStateX = Self->_hashStateY ;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 Self->_hashStateY = Self->_hashStateZ ;
a61af66fc99e Initial load
duke
parents:
diff changeset
589 Self->_hashStateZ = Self->_hashStateW ;
a61af66fc99e Initial load
duke
parents:
diff changeset
590 unsigned v = Self->_hashStateW ;
a61af66fc99e Initial load
duke
parents:
diff changeset
591 v = (v ^ (v >> 19)) ^ (t ^ (t >> 8)) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
592 Self->_hashStateW = v ;
a61af66fc99e Initial load
duke
parents:
diff changeset
593 value = v ;
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595
a61af66fc99e Initial load
duke
parents:
diff changeset
596 value &= markOopDesc::hash_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (value == 0) value = 0xBAD ;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 assert (value != markOopDesc::no_hash, "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 TEVENT (hashCode: GENERATE) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
600 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
602 //
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
603 intptr_t ObjectSynchronizer::FastHashCode (Thread * Self, oop obj) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
604 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
605 // NOTE: many places throughout the JVM do not expect a safepoint
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
606 // to be taken here, in particular most operations on perm gen
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
607 // objects. However, we only ever bias Java instances and all of
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
608 // the call sites of identity_hash that might revoke biases have
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
609 // been checked to make sure they can handle a safepoint. The
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
610 // added check of the bias pattern is to avoid useless calls to
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
611 // thread-local storage.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
612 if (obj->mark()->has_bias_pattern()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
613 // Box and unbox the raw reference just in case we cause a STW safepoint.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
614 Handle hobj (Self, obj) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
615 // Relaxing assertion for bug 6320749.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
616 assert (Universe::verify_in_progress() ||
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
617 !SafepointSynchronize::is_at_safepoint(),
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
618 "biases should not be seen by VM thread here");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
619 BiasedLocking::revoke_and_rebias(hobj, false, JavaThread::current());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
620 obj = hobj() ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
621 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
622 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
623 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
624
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
625 // hashCode() is a heap mutator ...
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
626 // Relaxing assertion for bug 6320749.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
627 assert (Universe::verify_in_progress() ||
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
628 !SafepointSynchronize::is_at_safepoint(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
629 assert (Universe::verify_in_progress() ||
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
630 Self->is_Java_thread() , "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
631 assert (Universe::verify_in_progress() ||
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
632 ((JavaThread *)Self)->thread_state() != _thread_blocked, "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
633
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
634 ObjectMonitor* monitor = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
635 markOop temp, test;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
636 intptr_t hash;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
637 markOop mark = ReadStableMark (obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
638
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
639 // object should remain ineligible for biased locking
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
640 assert (!mark->has_bias_pattern(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
641
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
642 if (mark->is_neutral()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
643 hash = mark->hash(); // this is a normal header
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
644 if (hash) { // if it has hash, just return it
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
645 return hash;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
646 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
647 hash = get_next_hash(Self, obj); // allocate a new hash code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
648 temp = mark->copy_set_hash(hash); // merge the hash code into header
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
649 // use (machine word version) atomic operation to install the hash
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
650 test = (markOop) Atomic::cmpxchg_ptr(temp, obj->mark_addr(), mark);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
651 if (test == mark) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
652 return hash;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
653 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
654 // If atomic operation failed, we must inflate the header
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
655 // into heavy weight monitor. We could add more code here
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
656 // for fast path, but it does not worth the complexity.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
657 } else if (mark->has_monitor()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
658 monitor = mark->monitor();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
659 temp = monitor->header();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
660 assert (temp->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
661 hash = temp->hash();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
662 if (hash) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
663 return hash;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
664 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
665 // Skip to the following code to reduce code size
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
666 } else if (Self->is_lock_owned((address)mark->locker())) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
667 temp = mark->displaced_mark_helper(); // this is a lightweight monitor owned
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
668 assert (temp->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
669 hash = temp->hash(); // by current thread, check if the displaced
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
670 if (hash) { // header contains hash code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
671 return hash;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
672 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
673 // WARNING:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
674 // The displaced header is strictly immutable.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
675 // It can NOT be changed in ANY cases. So we have
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
676 // to inflate the header into heavyweight monitor
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
677 // even the current thread owns the lock. The reason
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
678 // is the BasicLock (stack slot) will be asynchronously
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
679 // read by other threads during the inflate() function.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
680 // Any change to stack may not propagate to other threads
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
681 // correctly.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
682 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
683
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
684 // Inflate the monitor to set hash code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
685 monitor = ObjectSynchronizer::inflate(Self, obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
686 // Load displaced header and check it has hash code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
687 mark = monitor->header();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
688 assert (mark->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
689 hash = mark->hash();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
690 if (hash == 0) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
691 hash = get_next_hash(Self, obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
692 temp = mark->copy_set_hash(hash); // merge hash code into header
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
693 assert (temp->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
694 test = (markOop) Atomic::cmpxchg_ptr(temp, monitor, mark);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
695 if (test != mark) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
696 // The only update to the header in the monitor (outside GC)
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
697 // is install the hash code. If someone add new usage of
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
698 // displaced header, please update this code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
699 hash = test->hash();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
700 assert (test->is_neutral(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
701 assert (hash != 0, "Trivial unexpected object/monitor header usage.");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
702 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
703 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
704 // We finally get the hash
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
705 return hash;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
708 // Deprecated -- use FastHashCode() instead.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
709
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
710 intptr_t ObjectSynchronizer::identity_hash_value_for(Handle obj) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
711 return FastHashCode (Thread::current(), obj()) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
715 bool ObjectSynchronizer::current_thread_holds_lock(JavaThread* thread,
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
716 Handle h_obj) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
717 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
718 BiasedLocking::revoke_and_rebias(h_obj, false, thread);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
719 assert(!h_obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
720 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
721
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
722 assert(thread == JavaThread::current(), "Can only be called on current thread");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
723 oop obj = h_obj();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
724
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
725 markOop mark = ReadStableMark (obj) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
726
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
727 // Uncontended case, header points to stack
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
728 if (mark->has_locker()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
729 return thread->is_lock_owned((address)mark->locker());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
731 // Contended case, header points to ObjectMonitor (tagged pointer)
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
732 if (mark->has_monitor()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
733 ObjectMonitor* monitor = mark->monitor();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
734 return monitor->is_entered(thread) != 0 ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
735 }
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
736 // Unlocked case, header in place
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
737 assert(mark->is_neutral(), "sanity check");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
738 return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
739 }
a61af66fc99e Initial load
duke
parents:
diff changeset
740
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
741 // Be aware of this method could revoke bias of the lock object.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
742 // This method querys the ownership of the lock handle specified by 'h_obj'.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
743 // If the current thread owns the lock, it returns owner_self. If no
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
744 // thread owns the lock, it returns owner_none. Otherwise, it will return
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
745 // ower_other.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
746 ObjectSynchronizer::LockOwnership ObjectSynchronizer::query_lock_ownership
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
747 (JavaThread *self, Handle h_obj) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
748 // The caller must beware this method can revoke bias, and
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
749 // revocation can result in a safepoint.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
750 assert (!SafepointSynchronize::is_at_safepoint(), "invariant") ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
751 assert (self->thread_state() != _thread_blocked , "invariant") ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
752
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
753 // Possible mark states: neutral, biased, stack-locked, inflated
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
754
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
755 if (UseBiasedLocking && h_obj()->mark()->has_bias_pattern()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
756 // CASE: biased
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
757 BiasedLocking::revoke_and_rebias(h_obj, false, self);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
758 assert(!h_obj->mark()->has_bias_pattern(),
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
759 "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
760 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
761
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
762 assert(self == JavaThread::current(), "Can only be called on current thread");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
763 oop obj = h_obj();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
764 markOop mark = ReadStableMark (obj) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
765
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
766 // CASE: stack-locked. Mark points to a BasicLock on the owner's stack.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
767 if (mark->has_locker()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
768 return self->is_lock_owned((address)mark->locker()) ?
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
769 owner_self : owner_other;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
770 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
771
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
772 // CASE: inflated. Mark (tagged pointer) points to an objectMonitor.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
773 // The Object:ObjectMonitor relationship is stable as long as we're
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
774 // not at a safepoint.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
775 if (mark->has_monitor()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
776 void * owner = mark->monitor()->_owner ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
777 if (owner == NULL) return owner_none ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
778 return (owner == self ||
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
779 self->is_lock_owned((address)owner)) ? owner_self : owner_other;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
780 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
781
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
782 // CASE: neutral
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
783 assert(mark->is_neutral(), "sanity check");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
784 return owner_none ; // it's unlocked
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
785 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
786
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
787 // FIXME: jvmti should call this
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
788 JavaThread* ObjectSynchronizer::get_lock_owner(Handle h_obj, bool doLock) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
789 if (UseBiasedLocking) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
790 if (SafepointSynchronize::is_at_safepoint()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
791 BiasedLocking::revoke_at_safepoint(h_obj);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
792 } else {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
793 BiasedLocking::revoke_and_rebias(h_obj, false, JavaThread::current());
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
794 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
795 assert(!h_obj->mark()->has_bias_pattern(), "biases should be revoked by now");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
796 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
797
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
798 oop obj = h_obj();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
799 address owner = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
800
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
801 markOop mark = ReadStableMark (obj) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
802
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
803 // Uncontended case, header points to stack
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
804 if (mark->has_locker()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
805 owner = (address) mark->locker();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
806 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
807
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
808 // Contended case, header points to ObjectMonitor (tagged pointer)
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
809 if (mark->has_monitor()) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
810 ObjectMonitor* monitor = mark->monitor();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
811 assert(monitor != NULL, "monitor should be non-null");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
812 owner = (address) monitor->owner();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
813 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
814
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
815 if (owner != NULL) {
8673
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7994
diff changeset
816 // owning_thread_from_monitor_owner() may also return NULL here
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
817 return Threads::owning_thread_from_monitor_owner(owner, doLock);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
818 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
819
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
820 // Unlocked case, header in place
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
821 // Cannot have assertion since this object may have been
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
822 // locked by another thread when reaching here.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
823 // assert(mark->is_neutral(), "sanity check");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
824
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
825 return NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
826 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
827 // Visitors ...
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
828
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
829 void ObjectSynchronizer::monitors_iterate(MonitorClosure* closure) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
830 ObjectMonitor* block = gBlockList;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
831 ObjectMonitor* mid;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
832 while (block) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
833 assert(block->object() == CHAINMARKER, "must be a block header");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
834 for (int i = _BLOCKSIZE - 1; i > 0; i--) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
835 mid = block + i;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
836 oop object = (oop) mid->object();
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
837 if (object != NULL) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
838 closure->do_monitor(mid);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
839 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
840 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
841 block = (ObjectMonitor*) block->FreeNext;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
844
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
845 // Get the next block in the block list.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
846 static inline ObjectMonitor* next(ObjectMonitor* block) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
847 assert(block->object() == CHAINMARKER, "must be a block header");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
848 block = block->FreeNext ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
849 assert(block == NULL || block->object() == CHAINMARKER, "must be a block header");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
850 return block;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852
a61af66fc99e Initial load
duke
parents:
diff changeset
853
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
854 void ObjectSynchronizer::oops_do(OopClosure* f) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
855 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
856 for (ObjectMonitor* block = gBlockList; block != NULL; block = next(block)) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
857 assert(block->object() == CHAINMARKER, "must be a block header");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
858 for (int i = 1; i < _BLOCKSIZE; i++) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
859 ObjectMonitor* mid = &block[i];
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
860 if (mid->object() != NULL) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
861 f->do_oop((oop*)mid->object_addr());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866
a61af66fc99e Initial load
duke
parents:
diff changeset
867
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
868 // -----------------------------------------------------------------------------
0
a61af66fc99e Initial load
duke
parents:
diff changeset
869 // ObjectMonitor Lifecycle
a61af66fc99e Initial load
duke
parents:
diff changeset
870 // -----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
871 // Inflation unlinks monitors from the global gFreeList and
a61af66fc99e Initial load
duke
parents:
diff changeset
872 // associates them with objects. Deflation -- which occurs at
a61af66fc99e Initial load
duke
parents:
diff changeset
873 // STW-time -- disassociates idle monitors from objects. Such
a61af66fc99e Initial load
duke
parents:
diff changeset
874 // scavenged monitors are returned to the gFreeList.
a61af66fc99e Initial load
duke
parents:
diff changeset
875 //
a61af66fc99e Initial load
duke
parents:
diff changeset
876 // The global list is protected by ListLock. All the critical sections
a61af66fc99e Initial load
duke
parents:
diff changeset
877 // are short and operate in constant-time.
a61af66fc99e Initial load
duke
parents:
diff changeset
878 //
a61af66fc99e Initial load
duke
parents:
diff changeset
879 // ObjectMonitors reside in type-stable memory (TSM) and are immortal.
a61af66fc99e Initial load
duke
parents:
diff changeset
880 //
a61af66fc99e Initial load
duke
parents:
diff changeset
881 // Lifecycle:
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // -- unassigned and on the global free list
a61af66fc99e Initial load
duke
parents:
diff changeset
883 // -- unassigned and on a thread's private omFreeList
a61af66fc99e Initial load
duke
parents:
diff changeset
884 // -- assigned to an object. The object is inflated and the mark refers
a61af66fc99e Initial load
duke
parents:
diff changeset
885 // to the objectmonitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
886 //
a61af66fc99e Initial load
duke
parents:
diff changeset
887
a61af66fc99e Initial load
duke
parents:
diff changeset
888
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
889 // Constraining monitor pool growth via MonitorBound ...
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
890 //
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
891 // The monitor pool is grow-only. We scavenge at STW safepoint-time, but the
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
892 // the rate of scavenging is driven primarily by GC. As such, we can find
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
893 // an inordinate number of monitors in circulation.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
894 // To avoid that scenario we can artificially induce a STW safepoint
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
895 // if the pool appears to be growing past some reasonable bound.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
896 // Generally we favor time in space-time tradeoffs, but as there's no
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
897 // natural back-pressure on the # of extant monitors we need to impose some
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
898 // type of limit. Beware that if MonitorBound is set to too low a value
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
899 // we could just loop. In addition, if MonitorBound is set to a low value
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
900 // we'll incur more safepoints, which are harmful to performance.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
901 // See also: GuaranteedSafepointInterval
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
902 //
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
903 // The current implementation uses asynchronous VM operations.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
904 //
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
905
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
906 static void InduceScavenge (Thread * Self, const char * Whence) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
907 // Induce STW safepoint to trim monitors
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
908 // Ultimately, this results in a call to deflate_idle_monitors() in the near future.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
909 // More precisely, trigger an asynchronous STW safepoint as the number
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
910 // of active monitors passes the specified threshold.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
911 // TODO: assert thread state is reasonable
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
912
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
913 if (ForceMonitorScavenge == 0 && Atomic::xchg (1, &ForceMonitorScavenge) == 0) {
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
914 if (ObjectMonitor::Knob_Verbose) {
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
915 ::printf ("Monitor scavenge - Induced STW @%s (%d)\n", Whence, ForceMonitorScavenge) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
916 ::fflush(stdout) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
917 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
918 // Induce a 'null' safepoint to scavenge monitors
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
919 // Must VM_Operation instance be heap allocated as the op will be enqueue and posted
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
920 // to the VMthread and have a lifespan longer than that of this activation record.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
921 // The VMThread will delete the op when completed.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
922 VMThread::execute (new VM_ForceAsyncSafepoint()) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
923
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
924 if (ObjectMonitor::Knob_Verbose) {
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
925 ::printf ("Monitor scavenge - STW posted @%s (%d)\n", Whence, ForceMonitorScavenge) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
926 ::fflush(stdout) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
927 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
928 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
929 }
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
930 /* Too slow for general assert or debug
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
931 void ObjectSynchronizer::verifyInUse (Thread *Self) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
932 ObjectMonitor* mid;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
933 int inusetally = 0;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
934 for (mid = Self->omInUseList; mid != NULL; mid = mid->FreeNext) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
935 inusetally ++;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
936 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
937 assert(inusetally == Self->omInUseCount, "inuse count off");
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
938
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
939 int freetally = 0;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
940 for (mid = Self->omFreeList; mid != NULL; mid = mid->FreeNext) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
941 freetally ++;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
942 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
943 assert(freetally == Self->omFreeCount, "free count off");
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
944 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
945 */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
946 ObjectMonitor * ATTR ObjectSynchronizer::omAlloc (Thread * Self) {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 // A large MAXPRIVATE value reduces both list lock contention
a61af66fc99e Initial load
duke
parents:
diff changeset
948 // and list coherency traffic, but also tends to increase the
a61af66fc99e Initial load
duke
parents:
diff changeset
949 // number of objectMonitors in circulation as well as the STW
a61af66fc99e Initial load
duke
parents:
diff changeset
950 // scavenge costs. As usual, we lean toward time in space-time
a61af66fc99e Initial load
duke
parents:
diff changeset
951 // tradeoffs.
a61af66fc99e Initial load
duke
parents:
diff changeset
952 const int MAXPRIVATE = 1024 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
953 for (;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 ObjectMonitor * m ;
a61af66fc99e Initial load
duke
parents:
diff changeset
955
a61af66fc99e Initial load
duke
parents:
diff changeset
956 // 1: try to allocate from the thread's local omFreeList.
a61af66fc99e Initial load
duke
parents:
diff changeset
957 // Threads will attempt to allocate first from their local list, then
a61af66fc99e Initial load
duke
parents:
diff changeset
958 // from the global list, and only after those attempts fail will the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
959 // attempt to instantiate new monitors. Thread-local free lists take
a61af66fc99e Initial load
duke
parents:
diff changeset
960 // heat off the ListLock and improve allocation latency, as well as reducing
a61af66fc99e Initial load
duke
parents:
diff changeset
961 // coherency traffic on the shared global list.
a61af66fc99e Initial load
duke
parents:
diff changeset
962 m = Self->omFreeList ;
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (m != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 Self->omFreeList = m->FreeNext ;
a61af66fc99e Initial load
duke
parents:
diff changeset
965 Self->omFreeCount -- ;
a61af66fc99e Initial load
duke
parents:
diff changeset
966 // CONSIDER: set m->FreeNext = BAD -- diagnostic hygiene
a61af66fc99e Initial load
duke
parents:
diff changeset
967 guarantee (m->object() == NULL, "invariant") ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
968 if (MonitorInUseLists) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
969 m->FreeNext = Self->omInUseList;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
970 Self->omInUseList = m;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
971 Self->omInUseCount ++;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
972 // verifyInUse(Self);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
973 } else {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
974 m->FreeNext = NULL;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
975 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
976 return m ;
a61af66fc99e Initial load
duke
parents:
diff changeset
977 }
a61af66fc99e Initial load
duke
parents:
diff changeset
978
a61af66fc99e Initial load
duke
parents:
diff changeset
979 // 2: try to allocate from the global gFreeList
a61af66fc99e Initial load
duke
parents:
diff changeset
980 // CONSIDER: use muxTry() instead of muxAcquire().
a61af66fc99e Initial load
duke
parents:
diff changeset
981 // If the muxTry() fails then drop immediately into case 3.
a61af66fc99e Initial load
duke
parents:
diff changeset
982 // If we're using thread-local free lists then try
a61af66fc99e Initial load
duke
parents:
diff changeset
983 // to reprovision the caller's free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
984 if (gFreeList != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 // Reprovision the thread's omFreeList.
a61af66fc99e Initial load
duke
parents:
diff changeset
986 // Use bulk transfers to reduce the allocation rate and heat
a61af66fc99e Initial load
duke
parents:
diff changeset
987 // on various locks.
a61af66fc99e Initial load
duke
parents:
diff changeset
988 Thread::muxAcquire (&ListLock, "omAlloc") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
989 for (int i = Self->omFreeProvision; --i >= 0 && gFreeList != NULL; ) {
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
990 MonitorFreeCount --;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
991 ObjectMonitor * take = gFreeList ;
a61af66fc99e Initial load
duke
parents:
diff changeset
992 gFreeList = take->FreeNext ;
a61af66fc99e Initial load
duke
parents:
diff changeset
993 guarantee (take->object() == NULL, "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
994 guarantee (!take->is_busy(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
995 take->Recycle() ;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
996 omRelease (Self, take, false) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998 Thread::muxRelease (&ListLock) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
999 Self->omFreeProvision += 1 + (Self->omFreeProvision/2) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 if (Self->omFreeProvision > MAXPRIVATE ) Self->omFreeProvision = MAXPRIVATE ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 TEVENT (omFirst - reprovision) ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1002
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1003 const int mx = MonitorBound ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1004 if (mx > 0 && (MonitorPopulation-MonitorFreeCount) > mx) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1005 // We can't safely induce a STW safepoint from omAlloc() as our thread
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1006 // state may not be appropriate for such activities and callers may hold
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1007 // naked oops, so instead we defer the action.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1008 InduceScavenge (Self, "omAlloc") ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1009 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1010 continue;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1012
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 // 3: allocate a block of new ObjectMonitors
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 // Both the local and global free lists are empty -- resort to malloc().
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 // In the current implementation objectMonitors are TSM - immortal.
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 assert (_BLOCKSIZE > 1, "invariant") ;
10135
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
1017 ObjectMonitor * temp = new ObjectMonitor[_BLOCKSIZE];
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1018
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 // NOTE: (almost) no way to recover if allocation failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 // We might be able to induce a STW safepoint and scavenge enough
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 // objectMonitors to permit progress.
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (temp == NULL) {
10161
746b070f5022 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 10135
diff changeset
1023 vm_exit_out_of_memory (sizeof (ObjectMonitor[_BLOCKSIZE]), OOM_MALLOC_ERROR,
746b070f5022 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 10135
diff changeset
1024 "Allocate ObjectMonitors");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1026
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 // Format the block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 // initialize the linked list, each monitor points to its next
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 // forming the single linked free list, the very first monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 // will points to next block, which forms the block list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 // The trick of using the 1st element in the block as gBlockList
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 // linkage should be reconsidered. A better implementation would
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 // look like: class Block { Block * next; int N; ObjectMonitor Body [N] ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 for (int i = 1; i < _BLOCKSIZE ; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 temp[i].FreeNext = &temp[i+1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1038
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 // terminate the last monitor as the end of list
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 temp[_BLOCKSIZE - 1].FreeNext = NULL ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 // Element [0] is reserved for global list linkage
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 temp[0].set_object(CHAINMARKER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1044
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 // Consider carving out this thread's current request from the
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 // block in hand. This avoids some lock traffic and redundant
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 // list activity.
a61af66fc99e Initial load
duke
parents:
diff changeset
1048
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 // Acquire the ListLock to manipulate BlockList and FreeList.
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 // An Oyama-Taura-Yonezawa scheme might be more efficient.
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 Thread::muxAcquire (&ListLock, "omAlloc [2]") ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1052 MonitorPopulation += _BLOCKSIZE-1;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1053 MonitorFreeCount += _BLOCKSIZE-1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1054
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 // Add the new block to the list of extant blocks (gBlockList).
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 // The very first objectMonitor in a block is reserved and dedicated.
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 // It serves as blocklist "next" linkage.
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 temp[0].FreeNext = gBlockList;
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 gBlockList = temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1060
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 // Add the new string of objectMonitors to the global free list
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 temp[_BLOCKSIZE - 1].FreeNext = gFreeList ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 gFreeList = temp + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 Thread::muxRelease (&ListLock) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 TEVENT (Allocate block of monitors) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1068
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 // Place "m" on the caller's private per-thread omFreeList.
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 // In practice there's no need to clamp or limit the number of
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 // monitors on a thread's omFreeList as the only time we'll call
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 // omRelease is to return a monitor to the free list after a CAS
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 // attempt failed. This doesn't allow unbounded #s of monitors to
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 // accumulate on a thread's free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1076
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1077 void ObjectSynchronizer::omRelease (Thread * Self, ObjectMonitor * m, bool fromPerThreadAlloc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 guarantee (m->object() == NULL, "invariant") ;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1079
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1080 // Remove from omInUseList
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1081 if (MonitorInUseLists && fromPerThreadAlloc) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1082 ObjectMonitor* curmidinuse = NULL;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1083 for (ObjectMonitor* mid = Self->omInUseList; mid != NULL; ) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1084 if (m == mid) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1085 // extract from per-thread in-use-list
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1086 if (mid == Self->omInUseList) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1087 Self->omInUseList = mid->FreeNext;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1088 } else if (curmidinuse != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1089 curmidinuse->FreeNext = mid->FreeNext; // maintain the current thread inuselist
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1090 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1091 Self->omInUseCount --;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1092 // verifyInUse(Self);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1093 break;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1094 } else {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1095 curmidinuse = mid;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1096 mid = mid->FreeNext;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1097 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1098 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1099 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1100
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1101 // FreeNext is used for both onInUseList and omFreeList, so clear old before setting new
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1102 m->FreeNext = Self->omFreeList ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1103 Self->omFreeList = m ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1104 Self->omFreeCount ++ ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 // Return the monitors of a moribund thread's local free list to
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 // the global free list. Typically a thread calls omFlush() when
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 // it's dying. We could also consider having the VM thread steal
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 // monitors from threads that have not run java code over a few
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 // consecutive STW safepoints. Relatedly, we might decay
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 // omFreeProvision at STW safepoints.
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 //
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1114 // Also return the monitors of a moribund thread"s omInUseList to
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1115 // a global gOmInUseList under the global list lock so these
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1116 // will continue to be scanned.
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1117 //
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 // We currently call omFlush() from the Thread:: dtor _after the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 // has been excised from the thread list and is no longer a mutator.
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 // That means that omFlush() can run concurrently with a safepoint and
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 // the scavenge operator. Calling omFlush() from JavaThread::exit() might
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 // be a better choice as we could safely reason that that the JVM is
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 // not at a safepoint at the time of the call, and thus there could
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 // be not inopportune interleavings between omFlush() and the scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 // operator.
a61af66fc99e Initial load
duke
parents:
diff changeset
1126
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 void ObjectSynchronizer::omFlush (Thread * Self) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 ObjectMonitor * List = Self->omFreeList ; // Null-terminated SLL
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 Self->omFreeList = NULL ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 ObjectMonitor * Tail = NULL ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1131 int Tally = 0;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1132 if (List != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1133 ObjectMonitor * s ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1134 for (s = List ; s != NULL ; s = s->FreeNext) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1135 Tally ++ ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1136 Tail = s ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1137 guarantee (s->object() == NULL, "invariant") ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1138 guarantee (!s->is_busy(), "invariant") ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1139 s->set_owner (NULL) ; // redundant but good hygiene
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1140 TEVENT (omFlush - Move one) ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1141 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1142 guarantee (Tail != NULL && List != NULL, "invariant") ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1144
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1145 ObjectMonitor * InUseList = Self->omInUseList;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1146 ObjectMonitor * InUseTail = NULL ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1147 int InUseTally = 0;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1148 if (InUseList != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1149 Self->omInUseList = NULL;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1150 ObjectMonitor *curom;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1151 for (curom = InUseList; curom != NULL; curom = curom->FreeNext) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1152 InUseTail = curom;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1153 InUseTally++;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1154 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1155 // TODO debug
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1156 assert(Self->omInUseCount == InUseTally, "inuse count off");
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1157 Self->omInUseCount = 0;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1158 guarantee (InUseTail != NULL && InUseList != NULL, "invariant");
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1159 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1160
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 Thread::muxAcquire (&ListLock, "omFlush") ;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1162 if (Tail != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1163 Tail->FreeNext = gFreeList ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1164 gFreeList = List ;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1165 MonitorFreeCount += Tally;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1166 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1167
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1168 if (InUseTail != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1169 InUseTail->FreeNext = gOmInUseList;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1170 gOmInUseList = InUseList;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1171 gOmInUseCount += InUseTally;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1172 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1173
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 Thread::muxRelease (&ListLock) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 TEVENT (omFlush) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1177
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 // Fast path code shared by multiple functions
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 ObjectMonitor* ObjectSynchronizer::inflate_helper(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 markOop mark = obj->mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 if (mark->has_monitor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 assert(ObjectSynchronizer::verify_objmon_isinpool(mark->monitor()), "monitor is invalid");
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 assert(mark->monitor()->header()->is_neutral(), "monitor must record a good object header");
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 return mark->monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 return ObjectSynchronizer::inflate(Thread::current(), obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1188
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1189
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 // Note that we could encounter some performance loss through false-sharing as
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 // multiple locks occupy the same $ line. Padding might be appropriate.
a61af66fc99e Initial load
duke
parents:
diff changeset
1192
a61af66fc99e Initial load
duke
parents:
diff changeset
1193
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 ObjectMonitor * ATTR ObjectSynchronizer::inflate (Thread * Self, oop object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 // Inflate mutates the heap ...
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 // Relaxing assertion for bug 6320749.
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 assert (Universe::verify_in_progress() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 !SafepointSynchronize::is_at_safepoint(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1199
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 for (;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 const markOop mark = object->mark() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 assert (!mark->has_bias_pattern(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1203
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 // The mark can be in one of the following states:
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 // * Inflated - just return
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 // * Stack-locked - coerce it to inflated
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 // * INFLATING - busy wait for conversion to complete
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 // * Neutral - aggressively inflate the object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 // * BIASED - Illegal. We should never see this
a61af66fc99e Initial load
duke
parents:
diff changeset
1210
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 // CASE: inflated
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 if (mark->has_monitor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 ObjectMonitor * inf = mark->monitor() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 assert (inf->header()->is_neutral(), "invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 assert (inf->object() == object, "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 assert (ObjectSynchronizer::verify_objmon_isinpool(inf), "monitor is invalid");
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 return inf ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1219
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 // CASE: inflation in progress - inflating over a stack-lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // Some other thread is converting from stack-locked to inflated.
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // Only that thread can complete inflation -- other threads must wait.
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 // The INFLATING value is transient.
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 // Currently, we spin/yield/park and poll the markword, waiting for inflation to finish.
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 // We could always eliminate polling by parking the thread on some auxiliary list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 if (mark == markOopDesc::INFLATING()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 TEVENT (Inflate: spin while INFLATING) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 ReadStableMark(object) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 continue ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1231
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 // CASE: stack-locked
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 // Could be stack-locked either by this thread or by some other thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 // Note that we allocate the objectmonitor speculatively, _before_ attempting
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 // to install INFLATING into the mark word. We originally installed INFLATING,
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 // allocated the objectmonitor, and then finally STed the address of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 // objectmonitor into the mark. This was correct, but artificially lengthened
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 // the interval in which INFLATED appeared in the mark, thus increasing
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 // the odds of inflation contention.
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 // We now use per-thread private objectmonitor free lists.
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 // These list are reprovisioned from the global free list outside the
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 // critical INFLATING...ST interval. A thread can transfer
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 // multiple objectmonitors en-mass from the global free list to its local free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 // This reduces coherency traffic and lock contention on the global free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 // Using such local free lists, it doesn't matter if the omAlloc() call appears
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 // before or after the CAS(INFLATING) operation.
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 // See the comments in omAlloc().
a61af66fc99e Initial load
duke
parents:
diff changeset
1250
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 if (mark->has_locker()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 ObjectMonitor * m = omAlloc (Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 // Optimistically prepare the objectmonitor - anticipate successful CAS
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 // We do this before the CAS in order to minimize the length of time
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 // in which INFLATING appears in the mark.
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 m->Recycle();
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 m->_Responsible = NULL ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 m->OwnerIsThread = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 m->_recursions = 0 ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1260 m->_SpinDuration = ObjectMonitor::Knob_SpinLimit ; // Consider: maintain by type/class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1261
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 markOop cmp = (markOop) Atomic::cmpxchg_ptr (markOopDesc::INFLATING(), object->mark_addr(), mark) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 if (cmp != mark) {
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1264 omRelease (Self, m, true) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 continue ; // Interference -- just retry
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1267
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 // We've successfully installed INFLATING (0) into the mark-word.
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 // This is the only case where 0 will appear in a mark-work.
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 // Only the singular thread that successfully swings the mark-word
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 // to 0 can perform (or more precisely, complete) inflation.
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 // Why do we CAS a 0 into the mark-word instead of just CASing the
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 // mark-word from the stack-locked value directly to the new inflated state?
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 // Consider what happens when a thread unlocks a stack-locked object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 // It attempts to use CAS to swing the displaced header value from the
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 // on-stack basiclock back into the object header. Recall also that the
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 // header value (hashcode, etc) can reside in (a) the object header, or
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 // (b) a displaced header associated with the stack-lock, or (c) a displaced
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 // header in an objectMonitor. The inflate() routine must copy the header
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 // value from the basiclock on the owner's stack to the objectMonitor, all
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // the while preserving the hashCode stability invariants. If the owner
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 // decides to release the lock while the value is 0, the unlock will fail
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 // and control will eventually pass from slow_exit() to inflate. The owner
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 // will then spin, waiting for the 0 value to disappear. Put another way,
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 // the 0 causes the owner to stall if the owner happens to try to
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 // drop the lock (restoring the header from the basiclock to the object)
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 // while inflation is in-progress. This protocol avoids races that might
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 // would otherwise permit hashCode values to change or "flicker" for an object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 // Critically, while object->mark is 0 mark->displaced_mark_helper() is stable.
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 // 0 serves as a "BUSY" inflate-in-progress indicator.
a61af66fc99e Initial load
duke
parents:
diff changeset
1292
a61af66fc99e Initial load
duke
parents:
diff changeset
1293
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 // fetch the displaced mark from the owner's stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 // The owner can't die or unwind past the lock while our INFLATING
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 // object is in the mark. Furthermore the owner can't complete
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 // an unlock on the object, either.
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 markOop dmw = mark->displaced_mark_helper() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 assert (dmw->is_neutral(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1300
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 // Setup monitor fields to proper values -- prepare the monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 m->set_header(dmw) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1303
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // Optimization: if the mark->locker stack address is associated
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 // with this thread we could simply set m->_owner = Self and
702
b9fba36710f2 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 579
diff changeset
1306 // m->OwnerIsThread = 1. Note that a thread can inflate an object
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 // that it has stack-locked -- as might happen in wait() -- directly
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 // with CAS. That is, we can avoid the xchg-NULL .... ST idiom.
702
b9fba36710f2 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 579
diff changeset
1309 m->set_owner(mark->locker());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 m->set_object(object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 // TODO-FIXME: assert BasicLock->dhw != 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
1312
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 // Must preserve store ordering. The monitor state must
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 // be stable at the time of publishing the monitor address.
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 guarantee (object->mark() == markOopDesc::INFLATING(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 object->release_set_mark(markOopDesc::encode(m));
a61af66fc99e Initial load
duke
parents:
diff changeset
1317
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 // Hopefully the performance counters are allocated on distinct cache lines
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 // to avoid false sharing on MP systems ...
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1320 if (ObjectMonitor::_sync_Inflations != NULL) ObjectMonitor::_sync_Inflations->inc() ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 TEVENT(Inflate: overwrite stacklock) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 if (TraceMonitorInflation) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 if (object->is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
1326 (void *) object, (intptr_t) object->mark(),
6983
070d523b96a7 8001471: Klass::cast() does nothing
hseigel
parents: 6725
diff changeset
1327 object->klass()->external_name());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 return m ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1332
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 // CASE: neutral
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 // TODO-FIXME: for entry we currently inflate and then try to CAS _owner.
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 // If we know we're inflating for entry it's better to inflate by swinging a
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 // pre-locked objectMonitor pointer into the object header. A successful
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 // CAS inflates the object *and* confers ownership to the inflating thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 // In the current implementation we use a 2-step mechanism where we CAS()
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 // to inflate and then CAS() again to try to swing _owner from NULL to Self.
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 // An inflateTry() method that we could call from fast_enter() and slow_enter()
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 // would be useful.
a61af66fc99e Initial load
duke
parents:
diff changeset
1342
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 assert (mark->is_neutral(), "invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 ObjectMonitor * m = omAlloc (Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 // prepare m for installation - set monitor to initial state
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 m->Recycle();
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 m->set_header(mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 m->set_owner(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 m->set_object(object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 m->OwnerIsThread = 1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 m->_recursions = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 m->_Responsible = NULL ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1353 m->_SpinDuration = ObjectMonitor::Knob_SpinLimit ; // consider: keep metastats by type/class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1354
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 if (Atomic::cmpxchg_ptr (markOopDesc::encode(m), object->mark_addr(), mark) != mark) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 m->set_object (NULL) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 m->set_owner (NULL) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 m->OwnerIsThread = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 m->Recycle() ;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1360 omRelease (Self, m, true) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 m = NULL ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 continue ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 // interference - the markword changed - just retry.
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 // The state-transitions are one-way, so there's no chance of
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 // live-lock -- "Inflated" is an absorbing state.
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1367
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 // Hopefully the performance counters are allocated on distinct
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 // cache lines to avoid false sharing on MP systems ...
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1370 if (ObjectMonitor::_sync_Inflations != NULL) ObjectMonitor::_sync_Inflations->inc() ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 TEVENT(Inflate: overwrite neutral) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 if (TraceMonitorInflation) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 if (object->is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
1376 (void *) object, (intptr_t) object->mark(),
6983
070d523b96a7 8001471: Klass::cast() does nothing
hseigel
parents: 6725
diff changeset
1377 object->klass()->external_name());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 return m ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1383
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1384 // Note that we could encounter some performance loss through false-sharing as
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1385 // multiple locks occupy the same $ line. Padding might be appropriate.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1386
a61af66fc99e Initial load
duke
parents:
diff changeset
1387
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 // Deflate_idle_monitors() is called at all safepoints, immediately
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 // after all mutators are stopped, but before any objects have moved.
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 // It traverses the list of known monitors, deflating where possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 // The scavenged monitor are returned to the monitor free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 // Beware that we scavenge at *every* stop-the-world point.
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 // Having a large number of monitors in-circulation negatively
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 // impacts the performance of some applications (e.g., PointBase).
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 // Broadly, we want to minimize the # of monitors in circulation.
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1397 //
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1398 // We have added a flag, MonitorInUseLists, which creates a list
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1399 // of active monitors for each thread. deflate_idle_monitors()
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1400 // only scans the per-thread inuse lists. omAlloc() puts all
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1401 // assigned monitors on the per-thread list. deflate_idle_monitors()
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1402 // returns the non-busy monitors to the global free list.
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1403 // When a thread dies, omFlush() adds the list of active monitors for
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1404 // that thread to a global gOmInUseList acquiring the
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1405 // global list lock. deflate_idle_monitors() acquires the global
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1406 // list lock to scan for non-busy monitors to the global free list.
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1407 // An alternative could have used a single global inuse list. The
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1408 // downside would have been the additional cost of acquiring the global list lock
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1409 // for every omAlloc().
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 // Perversely, the heap size -- and thus the STW safepoint rate --
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 // typically drives the scavenge rate. Large heaps can mean infrequent GC,
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 // which in turn can mean large(r) numbers of objectmonitors in circulation.
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 // This is an unfortunate aspect of this design.
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1416
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1417 enum ManifestConstants {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1418 ClearResponsibleAtSTW = 0,
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1419 MaximumRecheckInterval = 1000
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1420 } ;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1421
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1422 // Deflate a single monitor if not in use
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1423 // Return true if deflated, false if in use
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1424 bool ObjectSynchronizer::deflate_monitor(ObjectMonitor* mid, oop obj,
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1425 ObjectMonitor** FreeHeadp, ObjectMonitor** FreeTailp) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1426 bool deflated;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1427 // Normal case ... The monitor is associated with obj.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1428 guarantee (obj->mark() == markOopDesc::encode(mid), "invariant") ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1429 guarantee (mid == obj->mark()->monitor(), "invariant");
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1430 guarantee (mid->header()->is_neutral(), "invariant");
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1431
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1432 if (mid->is_busy()) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1433 if (ClearResponsibleAtSTW) mid->_Responsible = NULL ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1434 deflated = false;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1435 } else {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1436 // Deflate the monitor if it is no longer being used
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1437 // It's idle - scavenge and return to the global free list
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1438 // plain old deflation ...
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1439 TEVENT (deflate_idle_monitors - scavenge1) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1440 if (TraceMonitorInflation) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1441 if (obj->is_instance()) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1442 ResourceMark rm;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1443 tty->print_cr("Deflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
12316
190899198332 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 10405
diff changeset
1444 (void *) obj, (intptr_t) obj->mark(), obj->klass()->external_name());
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1445 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1446 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1447
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1448 // Restore the header back to obj
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1449 obj->release_set_mark(mid->header());
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1450 mid->clear();
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1451
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1452 assert (mid->object() == NULL, "invariant") ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1453
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1454 // Move the object to the working free list defined by FreeHead,FreeTail.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1455 if (*FreeHeadp == NULL) *FreeHeadp = mid;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1456 if (*FreeTailp != NULL) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1457 ObjectMonitor * prevtail = *FreeTailp;
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1458 assert(prevtail->FreeNext == NULL, "cleaned up deflated?"); // TODO KK
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1459 prevtail->FreeNext = mid;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1460 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1461 *FreeTailp = mid;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1462 deflated = true;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1463 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1464 return deflated;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1465 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1466
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1467 // Caller acquires ListLock
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1468 int ObjectSynchronizer::walk_monitor_list(ObjectMonitor** listheadp,
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1469 ObjectMonitor** FreeHeadp, ObjectMonitor** FreeTailp) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1470 ObjectMonitor* mid;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1471 ObjectMonitor* next;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1472 ObjectMonitor* curmidinuse = NULL;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1473 int deflatedcount = 0;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1474
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1475 for (mid = *listheadp; mid != NULL; ) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1476 oop obj = (oop) mid->object();
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1477 bool deflated = false;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1478 if (obj != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1479 deflated = deflate_monitor(mid, obj, FreeHeadp, FreeTailp);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1480 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1481 if (deflated) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1482 // extract from per-thread in-use-list
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1483 if (mid == *listheadp) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1484 *listheadp = mid->FreeNext;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1485 } else if (curmidinuse != NULL) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1486 curmidinuse->FreeNext = mid->FreeNext; // maintain the current thread inuselist
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1487 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1488 next = mid->FreeNext;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1489 mid->FreeNext = NULL; // This mid is current tail in the FreeHead list
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1490 mid = next;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1491 deflatedcount++;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1492 } else {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1493 curmidinuse = mid;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1494 mid = mid->FreeNext;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1495 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1496 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1497 return deflatedcount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1498 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1499
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 void ObjectSynchronizer::deflate_idle_monitors() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 int nInuse = 0 ; // currently associated with objects
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 int nInCirculation = 0 ; // extant
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 int nScavenged = 0 ; // reclaimed
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1505 bool deflated = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1506
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 ObjectMonitor * FreeHead = NULL ; // Local SLL of scavenged monitors
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 ObjectMonitor * FreeTail = NULL ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1509
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1510 TEVENT (deflate_idle_monitors) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1511 // Prevent omFlush from changing mids in Thread dtor's during deflation
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1512 // And in case the vm thread is acquiring a lock during a safepoint
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1513 // See e.g. 6320749
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1514 Thread::muxAcquire (&ListLock, "scavenge - return") ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1515
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1516 if (MonitorInUseLists) {
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1517 int inUse = 0;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1518 for (JavaThread* cur = Threads::first(); cur != NULL; cur = cur->next()) {
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1519 nInCirculation+= cur->omInUseCount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1520 int deflatedcount = walk_monitor_list(cur->omInUseList_addr(), &FreeHead, &FreeTail);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1521 cur->omInUseCount-= deflatedcount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1522 // verifyInUse(cur);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1523 nScavenged += deflatedcount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1524 nInuse += cur->omInUseCount;
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1525 }
1640
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1526
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1527 // For moribund threads, scan gOmInUseList
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1528 if (gOmInUseList) {
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1529 nInCirculation += gOmInUseCount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1530 int deflatedcount = walk_monitor_list((ObjectMonitor **)&gOmInUseList, &FreeHead, &FreeTail);
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1531 gOmInUseCount-= deflatedcount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1532 nScavenged += deflatedcount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1533 nInuse += gOmInUseCount;
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1534 }
bfc89697cccb 6964164: MonitorInUseLists leak of contended objects
acorn
parents: 1589
diff changeset
1535
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1536 } else for (ObjectMonitor* block = gBlockList; block != NULL; block = next(block)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 // Iterate over all extant monitors - Scavenge all idle monitors.
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 assert(block->object() == CHAINMARKER, "must be a block header");
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 nInCirculation += _BLOCKSIZE ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 for (int i = 1 ; i < _BLOCKSIZE; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 ObjectMonitor* mid = &block[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 oop obj = (oop) mid->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1543
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 if (obj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 // The monitor is not associated with an object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 // The monitor should either be a thread-specific private
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 // free list or the global free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 // obj == NULL IMPLIES mid->is_busy() == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 guarantee (!mid->is_busy(), "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 continue ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 }
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1552 deflated = deflate_monitor(mid, obj, &FreeHead, &FreeTail);
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1553
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1554 if (deflated) {
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1555 mid->FreeNext = NULL ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1556 nScavenged ++ ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 } else {
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1558 nInuse ++;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1562
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1563 MonitorFreeCount += nScavenged;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1564
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1565 // Consider: audit gFreeList to ensure that MonitorFreeCount and list agree.
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1566
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1567 if (ObjectMonitor::Knob_Verbose) {
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1568 ::printf ("Deflate: InCirc=%d InUse=%d Scavenged=%d ForceMonitorScavenge=%d : pop=%d free=%d\n",
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1569 nInCirculation, nInuse, nScavenged, ForceMonitorScavenge,
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1570 MonitorPopulation, MonitorFreeCount) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1571 ::fflush(stdout) ;
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1572 }
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1573
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1574 ForceMonitorScavenge = 0; // Reset
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1575
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 // Move the scavenged monitors back to the global free list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 if (FreeHead != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 guarantee (FreeTail != NULL && nScavenged > 0, "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 assert (FreeTail->FreeNext == NULL, "invariant") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 // constant-time list splice - prepend scavenged segment to gFreeList
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 FreeTail->FreeNext = gFreeList ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 gFreeList = FreeHead ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 }
1587
b96a3e44582f 6852873: Reduce safepoint cleanup time
acorn
parents: 702
diff changeset
1584 Thread::muxRelease (&ListLock) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1585
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1586 if (ObjectMonitor::_sync_Deflations != NULL) ObjectMonitor::_sync_Deflations->inc(nScavenged) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1587 if (ObjectMonitor::_sync_MonExtant != NULL) ObjectMonitor::_sync_MonExtant ->set_value(nInCirculation);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1588
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 // TODO: Add objectMonitor leak detection.
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 // Audit/inventory the objectMonitors -- make sure they're all accounted for.
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 GVars.stwRandom = os::random() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 GVars.stwCycle ++ ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1594
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1595 // Monitor cleanup on JavaThread::exit
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1596
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1597 // Iterate through monitor cache and attempt to release thread's monitors
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1598 // Gives up on a particular monitor if an exception occurs, but continues
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1599 // the overall iteration, swallowing the exception.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1600 class ReleaseJavaMonitorsClosure: public MonitorClosure {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1601 private:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1602 TRAPS;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1603
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1604 public:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1605 ReleaseJavaMonitorsClosure(Thread* thread) : THREAD(thread) {}
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1606 void do_monitor(ObjectMonitor* mid) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1607 if (mid->owner() == THREAD) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1608 (void)mid->complete_exit(CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 }
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1611 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1612
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1613 // Release all inflated monitors owned by THREAD. Lightweight monitors are
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1614 // ignored. This is meant to be called during JNI thread detach which assumes
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1615 // all remaining monitors are heavyweight. All exceptions are swallowed.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1616 // Scanning the extant monitor list can be time consuming.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1617 // A simple optimization is to add a per-thread flag that indicates a thread
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1618 // called jni_monitorenter() during its lifetime.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1619 //
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1620 // Instead of No_Savepoint_Verifier it might be cheaper to
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1621 // use an idiom of the form:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1622 // auto int tmp = SafepointSynchronize::_safepoint_counter ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1623 // <code that must not run at safepoint>
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1624 // guarantee (((tmp ^ _safepoint_counter) | (tmp & 1)) == 0) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1625 // Since the tests are extremely cheap we could leave them enabled
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1626 // for normal product builds.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1627
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1628 void ObjectSynchronizer::release_monitors_owned_by_thread(TRAPS) {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1629 assert(THREAD == JavaThread::current(), "must be current Java thread");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1630 No_Safepoint_Verifier nsv ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1631 ReleaseJavaMonitorsClosure rjmc(THREAD);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1632 Thread::muxAcquire(&ListLock, "release_monitors_owned_by_thread");
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1633 ObjectSynchronizer::monitors_iterate(&rjmc);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1634 Thread::muxRelease(&ListLock);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1640
diff changeset
1635 THREAD->clear_pending_exception();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1637
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 //------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
1640
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1642
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 // Verify all monitors in the monitor cache, the verification is weak.
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 void ObjectSynchronizer::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 ObjectMonitor* block = gBlockList;
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 ObjectMonitor* mid;
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 while (block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 assert(block->object() == CHAINMARKER, "must be a block header");
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 for (int i = 1; i < _BLOCKSIZE; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 mid = block + i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 oop object = (oop) mid->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 if (object != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 mid->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 block = (ObjectMonitor*) block->FreeNext;
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1659
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 // Check if monitor belongs to the monitor cache
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 // The list is grow-only so it's *relatively* safe to traverse
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 // the list of extant blocks without taking a lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
1663
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 int ObjectSynchronizer::verify_objmon_isinpool(ObjectMonitor *monitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 ObjectMonitor* block = gBlockList;
a61af66fc99e Initial load
duke
parents:
diff changeset
1666
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 while (block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 assert(block->object() == CHAINMARKER, "must be a block header");
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 if (monitor > &block[0] && monitor < &block[_BLOCKSIZE]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 address mon = (address) monitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 address blk = (address) block;
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 size_t diff = mon - blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 assert((diff % sizeof(ObjectMonitor)) == 0, "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 block = (ObjectMonitor*) block->FreeNext;
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1680
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 #endif