1 /*
2 * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
200 // objects which can happen at normal VM shutdown.
201 //
202 #define OM_PERFDATA_OP(f, op_str) \
203 do { \
204 if (ObjectMonitor::_sync_ ## f != nullptr && \
205 PerfDataManager::has_PerfData()) { \
206 ObjectMonitor::_sync_ ## f->op_str; \
207 } \
208 } while (0)
209
210 static PerfCounter * _sync_ContendedLockAttempts;
211 static PerfCounter * _sync_FutileWakeups;
212 static PerfCounter * _sync_Parks;
213 static PerfCounter * _sync_Notifications;
214 static PerfCounter * _sync_Inflations;
215 static PerfCounter * _sync_Deflations;
216 static PerfLongVariable * _sync_MonExtant;
217
218 static int Knob_SpinLimit;
219
220 static ByteSize owner_offset() { return byte_offset_of(ObjectMonitor, _owner); }
221 static ByteSize recursions_offset() { return byte_offset_of(ObjectMonitor, _recursions); }
222 static ByteSize cxq_offset() { return byte_offset_of(ObjectMonitor, _cxq); }
223 static ByteSize succ_offset() { return byte_offset_of(ObjectMonitor, _succ); }
224 static ByteSize EntryList_offset() { return byte_offset_of(ObjectMonitor, _EntryList); }
225
226 // ObjectMonitor references can be ORed with markWord::monitor_value
227 // as part of the ObjectMonitor tagging mechanism. When we combine an
228 // ObjectMonitor reference with an offset, we need to remove the tag
229 // value in order to generate the proper address.
230 //
231 // We can either adjust the ObjectMonitor reference and then add the
232 // offset or we can adjust the offset that is added to the ObjectMonitor
233 // reference. The latter avoids an AGI (Address Generation Interlock)
234 // stall so the helper macro adjusts the offset value that is returned
235 // to the ObjectMonitor reference manipulation code:
236 //
237 #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
238 ((in_bytes(ObjectMonitor::f ## _offset())) - markWord::monitor_value)
239
281 }
282
283 bool is_owner_anonymous() const {
284 return owner_raw() == anon_owner_ptr();
285 }
286
287 void set_owner_from_anonymous(Thread* owner) {
288 set_owner_from(anon_owner_ptr(), owner);
289 }
290
291 // Simply get _next_om field.
292 ObjectMonitor* next_om() const;
293 // Simply set _next_om field to new_value.
294 void set_next_om(ObjectMonitor* new_value);
295
296 int waiters() const;
297
298 int contentions() const;
299 void add_to_contentions(int value);
300 intx recursions() const { return _recursions; }
301
302 // JVM/TI GetObjectMonitorUsage() needs this:
303 ObjectWaiter* first_waiter() { return _WaitSet; }
304 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
305 JavaThread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
306
307 ObjectMonitor(oop object);
308 ~ObjectMonitor();
309
310 oop object() const;
311 oop object_peek() const;
312
313 // Returns true if the specified thread owns the ObjectMonitor. Otherwise
314 // returns false and throws IllegalMonitorStateException (IMSE).
315 bool check_owner(TRAPS);
316
317 private:
318 class ExitOnSuspend {
319 protected:
320 ObjectMonitor* _om;
321 bool _om_exited;
322 public:
323 ExitOnSuspend(ObjectMonitor* om) : _om(om), _om_exited(false) {}
324 void operator()(JavaThread* current);
325 bool exited() { return _om_exited; }
326 };
327 class ClearSuccOnSuspend {
328 protected:
329 ObjectMonitor* _om;
330 public:
331 ClearSuccOnSuspend(ObjectMonitor* om) : _om(om) {}
332 void operator()(JavaThread* current);
333 };
334 public:
335 bool enter(JavaThread* current);
336 void exit(JavaThread* current, bool not_suspended = true);
337 void wait(jlong millis, bool interruptible, TRAPS);
338 void notify(TRAPS);
339 void notifyAll(TRAPS);
340
341 void print() const;
342 #ifdef ASSERT
343 void print_debug_style_on(outputStream* st) const;
344 #endif
345 void print_on(outputStream* st) const;
346
347 // Use the following at your own risk
348 intx complete_exit(JavaThread* current);
349
350 private:
351 void AddWaiter(ObjectWaiter* waiter);
352 void INotify(JavaThread* current);
353 ObjectWaiter* DequeueWaiter();
354 void DequeueSpecificWaiter(ObjectWaiter* waiter);
|
1 /*
2 * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
200 // objects which can happen at normal VM shutdown.
201 //
202 #define OM_PERFDATA_OP(f, op_str) \
203 do { \
204 if (ObjectMonitor::_sync_ ## f != nullptr && \
205 PerfDataManager::has_PerfData()) { \
206 ObjectMonitor::_sync_ ## f->op_str; \
207 } \
208 } while (0)
209
210 static PerfCounter * _sync_ContendedLockAttempts;
211 static PerfCounter * _sync_FutileWakeups;
212 static PerfCounter * _sync_Parks;
213 static PerfCounter * _sync_Notifications;
214 static PerfCounter * _sync_Inflations;
215 static PerfCounter * _sync_Deflations;
216 static PerfLongVariable * _sync_MonExtant;
217
218 static int Knob_SpinLimit;
219
220 static ByteSize header_offset() { return byte_offset_of(ObjectMonitor, _header); }
221 static ByteSize owner_offset() { return byte_offset_of(ObjectMonitor, _owner); }
222 static ByteSize recursions_offset() { return byte_offset_of(ObjectMonitor, _recursions); }
223 static ByteSize cxq_offset() { return byte_offset_of(ObjectMonitor, _cxq); }
224 static ByteSize succ_offset() { return byte_offset_of(ObjectMonitor, _succ); }
225 static ByteSize EntryList_offset() { return byte_offset_of(ObjectMonitor, _EntryList); }
226
227 // ObjectMonitor references can be ORed with markWord::monitor_value
228 // as part of the ObjectMonitor tagging mechanism. When we combine an
229 // ObjectMonitor reference with an offset, we need to remove the tag
230 // value in order to generate the proper address.
231 //
232 // We can either adjust the ObjectMonitor reference and then add the
233 // offset or we can adjust the offset that is added to the ObjectMonitor
234 // reference. The latter avoids an AGI (Address Generation Interlock)
235 // stall so the helper macro adjusts the offset value that is returned
236 // to the ObjectMonitor reference manipulation code:
237 //
238 #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
239 ((in_bytes(ObjectMonitor::f ## _offset())) - markWord::monitor_value)
240
282 }
283
284 bool is_owner_anonymous() const {
285 return owner_raw() == anon_owner_ptr();
286 }
287
288 void set_owner_from_anonymous(Thread* owner) {
289 set_owner_from(anon_owner_ptr(), owner);
290 }
291
292 // Simply get _next_om field.
293 ObjectMonitor* next_om() const;
294 // Simply set _next_om field to new_value.
295 void set_next_om(ObjectMonitor* new_value);
296
297 int waiters() const;
298
299 int contentions() const;
300 void add_to_contentions(int value);
301 intx recursions() const { return _recursions; }
302 void set_recursions(size_t recursions);
303
304 // JVM/TI GetObjectMonitorUsage() needs this:
305 ObjectWaiter* first_waiter() { return _WaitSet; }
306 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
307 JavaThread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
308
309 ObjectMonitor(oop object);
310 ~ObjectMonitor();
311
312 oop object() const;
313 oop object_peek() const;
314
315 // Returns true if the specified thread owns the ObjectMonitor. Otherwise
316 // returns false and throws IllegalMonitorStateException (IMSE).
317 bool check_owner(TRAPS);
318
319 private:
320 class ExitOnSuspend {
321 protected:
322 ObjectMonitor* _om;
323 bool _om_exited;
324 public:
325 ExitOnSuspend(ObjectMonitor* om) : _om(om), _om_exited(false) {}
326 void operator()(JavaThread* current);
327 bool exited() { return _om_exited; }
328 };
329 class ClearSuccOnSuspend {
330 protected:
331 ObjectMonitor* _om;
332 public:
333 ClearSuccOnSuspend(ObjectMonitor* om) : _om(om) {}
334 void operator()(JavaThread* current);
335 };
336 public:
337 bool enter_for(JavaThread* locking_thread);
338 bool enter(JavaThread* current);
339 void exit(JavaThread* current, bool not_suspended = true);
340 void wait(jlong millis, bool interruptible, TRAPS);
341 void notify(TRAPS);
342 void notifyAll(TRAPS);
343
344 void print() const;
345 #ifdef ASSERT
346 void print_debug_style_on(outputStream* st) const;
347 #endif
348 void print_on(outputStream* st) const;
349
350 // Use the following at your own risk
351 intx complete_exit(JavaThread* current);
352
353 private:
354 void AddWaiter(ObjectWaiter* waiter);
355 void INotify(JavaThread* current);
356 ObjectWaiter* DequeueWaiter();
357 void DequeueSpecificWaiter(ObjectWaiter* waiter);
|