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 #ifndef SHARE_RUNTIME_LIGHTWEIGHTSYNCHRONIZER_HPP 26 #define SHARE_RUNTIME_LIGHTWEIGHTSYNCHRONIZER_HPP 27 28 #include "memory/allStatic.hpp" 29 #include "runtime/javaThread.hpp" 30 #include "runtime/objectMonitor.hpp" 31 #include "runtime/synchronizer.hpp" 32 33 class ObjectMonitorWorld; 34 35 class LightweightSynchronizer : AllStatic { 36 private: 37 static ObjectMonitorWorld* _omworld; 38 39 static ObjectMonitor* get_or_insert_monitor_from_table(oop object, JavaThread* current, bool try_read, bool* inserted); 40 static ObjectMonitor* get_or_insert_monitor(oop object, JavaThread* current, const ObjectSynchronizer::InflateCause cause, bool try_read); 41 42 static ObjectMonitor* add_monitor(JavaThread* current, ObjectMonitor* monitor, oop obj); 43 static bool remove_monitor(Thread* current, oop obj, ObjectMonitor* monitor); 44 45 static void deflate_mark_word(oop object); 46 47 static void ensure_lock_stack_space(JavaThread* current); 48 49 class CacheSetter; 50 class LockStackInflateContendedLocks; 51 class VerifyThreadState; 52 53 public: 54 static void initialize(); 55 56 static bool needs_resize(); 57 static bool resize_table(JavaThread* current); 58 59 private: 60 static inline bool fast_lock_try_enter(oop obj, LockStack& lock_stack, JavaThread* current); 61 static bool fast_lock_spin_enter(oop obj, LockStack& lock_stack, JavaThread* current, bool observed_deflation); 62 63 public: 64 static void enter_for(Handle obj, BasicLock* lock, JavaThread* locking_thread); 65 static void enter(Handle obj, BasicLock* lock, JavaThread* current); 66 static void exit(oop object, JavaThread* current); 67 68 static ObjectMonitor* inflate_into_object_header(Thread* current, JavaThread* inflating_thread, oop object, const ObjectSynchronizer::InflateCause cause); 69 static ObjectMonitor* inflate_locked_or_imse(oop object, const ObjectSynchronizer::InflateCause cause, TRAPS); 70 static ObjectMonitor* inflate_fast_locked_object(oop object, JavaThread* locking_thread, JavaThread* current, const ObjectSynchronizer::InflateCause cause); 71 static ObjectMonitor* inflate_and_enter(oop object, JavaThread* locking_thread, JavaThread* current, const ObjectSynchronizer::InflateCause cause); 72 73 static void deflate_monitor(Thread* current, oop obj, ObjectMonitor* monitor); 74 75 static ObjectMonitor* get_monitor_from_table(Thread* current, oop obj); 76 77 static bool contains_monitor(Thread* current, ObjectMonitor* monitor); 78 79 static bool quick_enter(oop obj, JavaThread* current, BasicLock* Lock); 80 }; 81 82 #endif // SHARE_RUNTIME_LIGHTWEIGHTSYNCHRONIZER_HPP