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