84 HOTSPOT_MONITOR_WAIT(jtid, \ |
84 HOTSPOT_MONITOR_WAIT(jtid, \ |
85 (uintptr_t)(monitor), bytes, len, (millis)); \ |
85 (uintptr_t)(monitor), bytes, len, (millis)); \ |
86 } \ |
86 } \ |
87 } |
87 } |
88 |
88 |
|
89 #define HOTSPOT_MONITOR_PROBE_notify HOTSPOT_MONITOR_NOTIFY |
|
90 #define HOTSPOT_MONITOR_PROBE_notifyAll HOTSPOT_MONITOR_NOTIFYALL |
89 #define HOTSPOT_MONITOR_PROBE_waited HOTSPOT_MONITOR_WAITED |
91 #define HOTSPOT_MONITOR_PROBE_waited HOTSPOT_MONITOR_WAITED |
90 |
92 |
91 #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \ |
93 #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \ |
92 { \ |
94 { \ |
93 if (DTraceMonitorProbes) { \ |
95 if (DTraceMonitorProbes) { \ |
144 // returns false -- to indicate the call needs the services of the slow-path. |
146 // returns false -- to indicate the call needs the services of the slow-path. |
145 // A no-loitering ordinance is in effect for code in the quick_* family |
147 // A no-loitering ordinance is in effect for code in the quick_* family |
146 // operators: safepoints or indefinite blocking (blocking that might span a |
148 // operators: safepoints or indefinite blocking (blocking that might span a |
147 // safepoint) are forbidden. Generally the thread_state() is _in_Java upon |
149 // safepoint) are forbidden. Generally the thread_state() is _in_Java upon |
148 // entry. |
150 // entry. |
|
151 // |
|
152 // Consider: An interesting optimization is to have the JIT recognize the |
|
153 // following common idiom: |
|
154 // synchronized (someobj) { .... ; notify(); } |
|
155 // That is, we find a notify() or notifyAll() call that immediately precedes |
|
156 // the monitorexit operation. In that case the JIT could fuse the operations |
|
157 // into a single notifyAndExit() runtime primitive. |
|
158 |
|
159 bool ObjectSynchronizer::quick_notify(oopDesc * obj, Thread * self, bool all) { |
|
160 assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
161 assert(self->is_Java_thread(), "invariant"); |
|
162 assert(((JavaThread *) self)->thread_state() == _thread_in_Java, "invariant"); |
|
163 No_Safepoint_Verifier nsv; |
|
164 if (obj == NULL) return false; // slow-path for invalid obj |
|
165 const markOop mark = obj->mark(); |
|
166 |
|
167 if (mark->has_locker() && self->is_lock_owned((address)mark->locker())) { |
|
168 // Degenerate notify |
|
169 // stack-locked by caller so by definition the implied waitset is empty. |
|
170 return true; |
|
171 } |
|
172 |
|
173 if (mark->has_monitor()) { |
|
174 ObjectMonitor * const mon = mark->monitor(); |
|
175 assert(mon->object() == obj, "invariant"); |
|
176 if (mon->owner() != self) return false; // slow-path for IMS exception |
|
177 |
|
178 if (mon->first_waiter() != NULL) { |
|
179 // We have one or more waiters. Since this is an inflated monitor |
|
180 // that we own, we can transfer one or more threads from the waitset |
|
181 // to the entrylist here and now, avoiding the slow-path. |
|
182 if (all) { |
|
183 DTRACE_MONITOR_PROBE(notifyAll, mon, obj, self); |
|
184 } else { |
|
185 DTRACE_MONITOR_PROBE(notify, mon, obj, self); |
|
186 } |
|
187 int tally = 0; |
|
188 do { |
|
189 mon->INotify(self); |
|
190 ++tally; |
|
191 } while (mon->first_waiter() != NULL && all); |
|
192 if (ObjectMonitor::_sync_Notifications != NULL) { |
|
193 ObjectMonitor::_sync_Notifications->inc(tally); |
|
194 } |
|
195 } |
|
196 return true; |
|
197 } |
|
198 |
|
199 // biased locking and any other IMS exception states take the slow-path |
|
200 return false; |
|
201 } |
|
202 |
149 |
203 |
150 // The LockNode emitted directly at the synchronization site would have |
204 // The LockNode emitted directly at the synchronization site would have |
151 // been too big if it were to have included support for the cases of inflated |
205 // been too big if it were to have included support for the cases of inflated |
152 // recursive enter and exit, so they go here instead. |
206 // recursive enter and exit, so they go here instead. |
153 // Note that we can't safely call AsyncPrintJavaStack() from within |
207 // Note that we can't safely call AsyncPrintJavaStack() from within |
1449 // typically drives the scavenge rate. Large heaps can mean infrequent GC, |
1503 // typically drives the scavenge rate. Large heaps can mean infrequent GC, |
1450 // which in turn can mean large(r) numbers of objectmonitors in circulation. |
1504 // which in turn can mean large(r) numbers of objectmonitors in circulation. |
1451 // This is an unfortunate aspect of this design. |
1505 // This is an unfortunate aspect of this design. |
1452 |
1506 |
1453 enum ManifestConstants { |
1507 enum ManifestConstants { |
1454 ClearResponsibleAtSTW = 0, |
1508 ClearResponsibleAtSTW = 0 |
1455 MaximumRecheckInterval = 1000 |
|
1456 }; |
1509 }; |
1457 |
1510 |
1458 // Deflate a single monitor if not in-use |
1511 // Deflate a single monitor if not in-use |
1459 // Return true if deflated, false if in-use |
1512 // Return true if deflated, false if in-use |
1460 bool ObjectSynchronizer::deflate_monitor(ObjectMonitor* mid, oop obj, |
1513 bool ObjectSynchronizer::deflate_monitor(ObjectMonitor* mid, oop obj, |