/* * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
template <typename T> class GrowableArray; class LogStream; class ObjectMonitor; class ThreadsList;
// Hash table of void* to a list of ObjectMonitor* owned by the JavaThread. // The JavaThread's owner key is either a JavaThread* or a stack lock // address in the JavaThread so we use "void*". // class ObjectMonitorsHashtable { private: staticunsignedint ptr_hash(void* const& s1) { // 2654435761 = 2^32 * Phi (golden ratio) return (unsignedint)(((uint32_t)(uintptr_t)s1) * 2654435761u);
}
public: class PtrList;
private: // ResourceHashtable SIZE is specified at compile time so we // use 1031 which is the first prime after 1024. typedef ResourceHashtable<void*, PtrList*, 1031, AnyObj::C_HEAP, mtThread,
&ObjectMonitorsHashtable::ptr_hash> PtrTable;
PtrTable* _ptrs;
size_t _key_count;
size_t _om_count;
public: // ResourceHashtable is passed to various functions and populated in // different places so we allocate it using C_HEAP to make it immune // from any ResourceMarks that happen to be in the code paths.
ObjectMonitorsHashtable() : _ptrs(new (mtThread) PtrTable), _key_count(0), _om_count(0) {}
// exit must be implemented non-blocking, since the compiler cannot easily handle // deoptimization at monitor exit. Hence, it does not take a Handle argument.
// This is the "slow path" version of monitor enter and exit. staticvoid enter(Handle obj, BasicLock* lock, JavaThread* current); staticvoidexit(oop obj, BasicLock* lock, JavaThread* current);
// Used only to handle jni locks or other unmatched monitor enter/exit // Internally they will use heavy weight monitor. staticvoid jni_enter(Handle obj, JavaThread* current); staticvoid jni_exit(oop obj, TRAPS);
// used by classloading to free classloader object lock, // wait on an internal lock, and reclaim original lock // with original recursion count static intx complete_exit(Handle obj, JavaThread* current); staticvoid reenter (Handle obj, intx recursions, JavaThread* current);
// Inflate light weight monitor to heavy weight monitor static ObjectMonitor* inflate(Thread* current, oop obj, const InflateCause cause); // This version is only for internal use staticvoid inflate_helper(oop obj); staticconstchar* inflate_cause_name(const InflateCause cause);
// Returns the identity hash value for an oop // NOTE: It may cause monitor inflation static intptr_t FastHashCode(Thread* current, oop obj);
// java.lang.Thread support staticbool current_thread_holds_lock(JavaThread* current, Handle h_obj);
// JNI detach support staticvoid release_monitors_owned_by_thread(JavaThread* current);
// Iterate ObjectMonitors where the owner == thread; this does NOT include // ObjectMonitors where owner is set to a stack lock address in thread: // // This version of monitors_iterate() works with the in-use monitor list. staticvoid monitors_iterate(MonitorClosure* m, JavaThread* thread); // This version of monitors_iterate() works with the specified linked list. staticvoid monitors_iterate(MonitorClosure* closure,
ObjectMonitorsHashtable::PtrList* list,
JavaThread* thread);
// Initialize the gInflationLocks staticvoid initialize();
// GC: we currently use aggressive monitor deflation policy // Basically we try to deflate all monitors that are not busy. static size_t deflate_idle_monitors(ObjectMonitorsHashtable* table);
// ObjectLocker enforces balanced locking and can never throw an // IllegalMonitorStateException. However, a pending exception may // have to pass through, and we must also be able to deal with // asynchronous exceptions. The caller is responsible for checking // the thread's pending exception if needed. class ObjectLocker : public StackObj { private:
JavaThread* _thread;
Handle _obj;
BasicLock _lock; public:
ObjectLocker(Handle obj, JavaThread* current);
~ObjectLocker();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.