annotate src/share/vm/runtime/objectMonitor.hpp @ 1972:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents fa83ab460c54
children c760f78e0a53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
2 * Copyright (c) 1998, 2010, 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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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 #ifndef SHARE_VM_RUNTIME_OBJECTMONITOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
26 #define SHARE_VM_RUNTIME_OBJECTMONITOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
28 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
29 #include "runtime/perfData.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
30
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
31
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
32 // ObjectWaiter serves as a "proxy" or surrogate thread.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
33 // TODO-FIXME: Eliminate ObjectWaiter and use the thread-specific
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
34 // ParkEvent instead. Beware, however, that the JVMTI code
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
35 // knows about ObjectWaiters, so we'll have to reconcile that code.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
36 // See next_waiter(), first_waiter(), etc.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
37
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
38 class ObjectWaiter : public StackObj {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
39 public:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
40 enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
41 enum Sorted { PREPEND, APPEND, SORTED } ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
42 ObjectWaiter * volatile _next;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
43 ObjectWaiter * volatile _prev;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
44 Thread* _thread;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
45 ParkEvent * _event;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
46 volatile int _notified ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
47 volatile TStates TState ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
48 Sorted _Sorted ; // List placement disposition
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
49 bool _active ; // Contention monitoring is enabled
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
50 public:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
51 ObjectWaiter(Thread* thread);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
52
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
53 void wait_reenter_begin(ObjectMonitor *mon);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
54 void wait_reenter_end(ObjectMonitor *mon);
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
55 };
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
56
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // WARNING:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // This is a very sensitive and fragile class. DO NOT make any
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // change unless you are fully aware of the underlying semantics.
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // This class can not inherit from any other class, because I have
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // to let the displaced header be the very first word. Otherwise I
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // have to let markOop include this file, which would export the
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // monitor data structure to everywhere.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 //
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // The ObjectMonitor class is used to implement JavaMonitors which have
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // transformed from the lightweight structure of the thread stack to a
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // heavy weight lock due to contention
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // It is also used as RawMonitor by the JVMTI
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 class ObjectMonitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 OM_OK, // no error
a61af66fc99e Initial load
duke
parents:
diff changeset
77 OM_SYSTEM_ERROR, // operating system error
a61af66fc99e Initial load
duke
parents:
diff changeset
78 OM_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException
a61af66fc99e Initial load
duke
parents:
diff changeset
79 OM_INTERRUPTED, // Thread.interrupt()
a61af66fc99e Initial load
duke
parents:
diff changeset
80 OM_TIMED_OUT // Object.wait() timed out
a61af66fc99e Initial load
duke
parents:
diff changeset
81 };
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ...
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // ByteSize would also be an appropriate type.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 static int header_offset_in_bytes() { return offset_of(ObjectMonitor, _header); }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 static int object_offset_in_bytes() { return offset_of(ObjectMonitor, _object); }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 static int owner_offset_in_bytes() { return offset_of(ObjectMonitor, _owner); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 static int count_offset_in_bytes() { return offset_of(ObjectMonitor, _count); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 static int recursions_offset_in_bytes() { return offset_of(ObjectMonitor, _recursions); }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 static int cxq_offset_in_bytes() { return offset_of(ObjectMonitor, _cxq) ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static int succ_offset_in_bytes() { return offset_of(ObjectMonitor, _succ) ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 static int EntryList_offset_in_bytes() { return offset_of(ObjectMonitor, _EntryList); }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 static int FreeNext_offset_in_bytes() { return offset_of(ObjectMonitor, FreeNext); }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static int WaitSet_offset_in_bytes() { return offset_of(ObjectMonitor, _WaitSet) ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 static int Responsible_offset_in_bytes() { return offset_of(ObjectMonitor, _Responsible);}
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static int Spinner_offset_in_bytes() { return offset_of(ObjectMonitor, _Spinner); }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Eventaully we'll make provisions for multiple callbacks, but
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // now one will suffice.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 static int (*SpinCallbackFunction)(intptr_t, int) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 static intptr_t SpinCallbackArgument ;
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
107 markOop header() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 void set_header(markOop hdr);
a61af66fc99e Initial load
duke
parents:
diff changeset
109
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
110 intptr_t is_busy() const {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
111 // TODO-FIXME: merge _count and _waiters.
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
112 // TODO-FIXME: assert _owner == null implies _recursions = 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
113 // TODO-FIXME: assert _WaitSet != null implies _count > 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
114 return _count|_waiters|intptr_t(_owner)|intptr_t(_cxq)|intptr_t(_EntryList ) ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
115 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
116
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 intptr_t is_entered(Thread* current) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void* owner() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void set_owner(void* owner);
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 intptr_t waiters() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 intptr_t count() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void set_count(intptr_t count);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 intptr_t contentions() const ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
127 intptr_t recursions() const { return _recursions; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // JVM/DI GetMonitorInfo() needs this
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
130 ObjectWaiter* first_waiter() { return _WaitSet; }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
131 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
132 Thread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
133
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
134 // initialize the monitor, exception the semaphore, all other fields
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
135 // are simple integers or pointers
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
136 ObjectMonitor() {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
137 _header = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
138 _count = 0;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
139 _waiters = 0,
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
140 _recursions = 0;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
141 _object = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
142 _owner = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
143 _WaitSet = NULL;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
144 _WaitSetLock = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
145 _Responsible = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
146 _succ = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
147 _cxq = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
148 FreeNext = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
149 _EntryList = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
150 _SpinFreq = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
151 _SpinClock = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
152 OwnerIsThread = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
153 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
154
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
155 ~ObjectMonitor() {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
156 // TODO: Add asserts ...
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
157 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
158 // _count == 0 _EntryList == NULL etc
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
159 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
160
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
161 private:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
162 void Recycle () {
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
163 // TODO: add stronger asserts ...
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
164 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
165 // _count == 0 EntryList == NULL
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
166 // _recursions == 0 _WaitSet == NULL
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
167 // TODO: assert (is_busy()|_recursions) == 0
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
168 _succ = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
169 _EntryList = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
170 _cxq = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
171 _WaitSet = NULL ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
172 _recursions = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
173 _SpinFreq = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
174 _SpinClock = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
175 OwnerIsThread = 0 ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
176 }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
177
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
178 public:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 void* object() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 void* object_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 void set_object(void* obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 bool check(TRAPS); // true if the thread owns the monitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
185 void check_slow(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 void clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
188 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 bool try_enter (TRAPS) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 void enter(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 void exit(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 void wait(jlong millis, bool interruptable, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 void notify(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 void notifyAll(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Use the following at your own risk
a61af66fc99e Initial load
duke
parents:
diff changeset
200 intptr_t complete_exit(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 void reenter(intptr_t recursions, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void AddWaiter (ObjectWaiter * waiter) ;
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
205 static void DeferredInitialize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 ObjectWaiter * DequeueWaiter () ;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 void DequeueSpecificWaiter (ObjectWaiter * waiter) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 void EnterI (TRAPS) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 void ReenterI (Thread * Self, ObjectWaiter * SelfNode) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void UnlinkAfterAcquire (Thread * Self, ObjectWaiter * SelfNode) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 int TryLock (Thread * Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 int NotRunnable (Thread * Self, Thread * Owner) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int TrySpin_Fixed (Thread * Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 int TrySpin_VaryFrequency (Thread * Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 int TrySpin_VaryDuration (Thread * Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 void ctAsserts () ;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 void ExitEpilog (Thread * Self, ObjectWaiter * Wakee) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 bool ExitSuspendEquivalent (JavaThread * Self) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
222 friend class ObjectSynchronizer;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 friend class ObjectWaiter;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // WARNING: this must be the very first word of ObjectMonitor
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // This means this class can't use any virtual member functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // TODO-FIXME: assert that offsetof(_header) is 0 or get rid of the
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // implicit 0 offset in emitted code.
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 volatile markOop _header; // displaced object header word - mark
a61af66fc99e Initial load
duke
parents:
diff changeset
232 void* volatile _object; // backward object pointer - strong root
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 double SharingPad [1] ; // temp to reduce false sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // All the following fields must be machine word aligned
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // The VM assumes write ordering wrt these fields, which can be
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // read from other threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
239
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
240 protected: // protected for jvmtiRawMonitor
0
a61af66fc99e Initial load
duke
parents:
diff changeset
241 void * volatile _owner; // pointer to owning thread OR BasicLock
a61af66fc99e Initial load
duke
parents:
diff changeset
242 volatile intptr_t _recursions; // recursion count, 0 for first entry
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
243 private:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
244 int OwnerIsThread ; // _owner is (Thread *) vs SP/BasicLock
a61af66fc99e Initial load
duke
parents:
diff changeset
245 ObjectWaiter * volatile _cxq ; // LL of recently-arrived threads blocked on entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // The list is actually composed of WaitNodes, acting
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // as proxies for Threads.
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
248 protected:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
249 ObjectWaiter * volatile _EntryList ; // Threads blocked on entry or reentry.
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
250 private:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
251 Thread * volatile _succ ; // Heir presumptive thread - used for futile wakeup throttling
a61af66fc99e Initial load
duke
parents:
diff changeset
252 Thread * volatile _Responsible ;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 int _PromptDrain ; // rqst to drain cxq into EntryList ASAP
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 volatile int _Spinner ; // for exit->spinner handoff optimization
a61af66fc99e Initial load
duke
parents:
diff changeset
256 volatile int _SpinFreq ; // Spin 1-out-of-N attempts: success rate
a61af66fc99e Initial load
duke
parents:
diff changeset
257 volatile int _SpinClock ;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 volatile int _SpinDuration ;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 volatile intptr_t _SpinState ; // MCS/CLH list of spinners
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // TODO-FIXME: _count, _waiters and _recursions should be of
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // type int, or int32_t but not intptr_t. There's no reason
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // to use 64-bit fields for these variables on a 64-bit JVM.
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 volatile intptr_t _count; // reference count to prevent reclaimation/deflation
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // at stop-the-world time. See deflate_idle_monitors().
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // _count is approximately |_WaitSet| + |_EntryList|
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
268 protected:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
269 volatile intptr_t _waiters; // number of waiting threads
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
270 private:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
271 protected:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
272 ObjectWaiter * volatile _WaitSet; // LL of threads wait()ing on the monitor
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
273 private:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
274 volatile int _WaitSetLock; // protects Wait Queue - simple spinlock
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
277 int _QMix ; // Mixed prepend queue discipline
a61af66fc99e Initial load
duke
parents:
diff changeset
278 ObjectMonitor * FreeNext ; // Free list linkage
a61af66fc99e Initial load
duke
parents:
diff changeset
279 intptr_t StatA, StatsB ;
a61af66fc99e Initial load
duke
parents:
diff changeset
280
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
281 public:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
282 static void Initialize () ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
283 static PerfCounter * _sync_ContendedLockAttempts ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
284 static PerfCounter * _sync_FutileWakeups ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
285 static PerfCounter * _sync_Parks ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
286 static PerfCounter * _sync_EmptyNotifications ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
287 static PerfCounter * _sync_Notifications ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
288 static PerfCounter * _sync_SlowEnter ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
289 static PerfCounter * _sync_SlowExit ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
290 static PerfCounter * _sync_SlowNotify ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
291 static PerfCounter * _sync_SlowNotifyAll ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
292 static PerfCounter * _sync_FailedSpins ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
293 static PerfCounter * _sync_SuccessfulSpins ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
294 static PerfCounter * _sync_PrivateA ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
295 static PerfCounter * _sync_PrivateB ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
296 static PerfCounter * _sync_MonInCirculation ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
297 static PerfCounter * _sync_MonScavenged ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
298 static PerfCounter * _sync_Inflations ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
299 static PerfCounter * _sync_Deflations ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
300 static PerfLongVariable * _sync_MonExtant ;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
301
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
302 public:
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
303 static int Knob_Verbose;
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
304 static int Knob_SpinLimit;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
305 };
1878
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
306
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
307 #undef TEVENT
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
308 #define TEVENT(nom) {if (SyncVerbose) FEVENT(nom); }
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
309
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
310 #define FEVENT(nom) { static volatile int ctr = 0 ; int v = ++ctr ; if ((v & (v-1)) == 0) { ::printf (#nom " : %d \n", v); ::fflush(stdout); }}
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
311
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
312 #undef TEVENT
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
313 #define TEVENT(nom) {;}
fa83ab460c54 6988353: refactor contended sync subsystem
acorn
parents: 1552
diff changeset
314
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
315
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1878
diff changeset
316 #endif // SHARE_VM_RUNTIME_OBJECTMONITOR_HPP