1 /*
 2  * Copyright (c) 2024, 2025, 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  *
23  */
24 
25 #ifndef SHARE_RUNTIME_SYNCHRONIZER_INLINE_HPP
26 #define SHARE_RUNTIME_SYNCHRONIZER_INLINE_HPP
27 
28 #include "runtime/synchronizer.hpp"
29 
30 #include "runtime/lightweightSynchronizer.hpp"
31 #include "runtime/safepointVerifiers.hpp"
32 
33 inline ObjectMonitor* ObjectSynchronizer::read_monitor(markWord mark) {
34   return mark.monitor();
35 }
36 
37 inline ObjectMonitor* ObjectSynchronizer::read_monitor(Thread* current, oop obj, markWord mark) {
38   if (!UseObjectMonitorTable) {
39     return read_monitor(mark);
40   } else {
41     return LightweightSynchronizer::get_monitor_from_table(current, obj);
42   }
43 }
44 
45 inline void ObjectSynchronizer::enter(Handle obj, BasicLock* lock, JavaThread* current) {
46   assert(current == Thread::current(), "must be");
47 
48   LightweightSynchronizer::enter(obj, lock, current);
49 }
50 
51 inline bool ObjectSynchronizer::quick_enter(oop obj, BasicLock* lock, JavaThread* current) {
52   assert(current->thread_state() == _thread_in_Java, "invariant");
53   NoSafepointVerifier nsv;
54   if (obj == nullptr) return false;       // Need to throw NPE
55 
56   if (obj->klass()->is_value_based()) {
57     return false;
58   }
59 
60   return LightweightSynchronizer::quick_enter(obj, lock, current);
61 }
62 
63 inline void ObjectSynchronizer::exit(oop object, BasicLock* lock, JavaThread* current) {
64   current->dec_held_monitor_count();
65 
66   LightweightSynchronizer::exit(object, lock, current);
67 }
68 
69 #endif // SHARE_RUNTIME_SYNCHRONIZER_INLINE_HPP