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 51 public: 52 static void initialize(); 53 54 static bool needs_resize(JavaThread* current); 55 static bool resize_table(JavaThread* current); 56 static void set_table_max(JavaThread* current); 57 58 static void enter_for(Handle obj, BasicLock* lock, JavaThread* locking_thread); 59 static void enter(Handle obj, BasicLock* lock, JavaThread* current); 60 static void exit(oop object, JavaThread* current); 61 62 static ObjectMonitor* inflate_locked_or_imse(oop object, const ObjectSynchronizer::InflateCause cause, TRAPS); 63 static ObjectMonitor* inflate_fast_locked_object(oop object, JavaThread* locking_thread, JavaThread* current, const ObjectSynchronizer::InflateCause cause); 64 static ObjectMonitor* inflate_and_enter(oop object, JavaThread* locking_thread, JavaThread* current, const ObjectSynchronizer::InflateCause cause); 65 66 static void deflate_monitor(Thread* current, oop obj, ObjectMonitor* monitor); 67 static void deflate_anon_monitor(Thread* current, oop obj, ObjectMonitor* monitor); 68 69 static ObjectMonitor* read_monitor(Thread* current, oop obj); 70 71 static bool contains_monitor(Thread* current, ObjectMonitor* monitor); 72 73 // NOTE: May not cause monitor inflation 74 static intptr_t FastHashCode(Thread* current, oop obj); 75 76 static bool quick_enter(oop obj, JavaThread* current, BasicLock* Lock); 77 }; 78 79 #endif // SHARE_RUNTIME_LIGHTWEIGHTSYNCHRONIZER_HPP