/* * Copyright (c) 2003, 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. *
*/
class DeadlockCycle; class ObjectMonitorsHashtable; class OopClosure; class StackFrameInfo; class ThreadConcurrentLocks; class ThreadDumpResult; class ThreadSnapshot; class ThreadStackTrace;
// VM monitoring and management support for the thread and // synchronization subsystem // // Thread contention monitoring is disabled by default. // When enabled, the VM will begin measuring the accumulated // elapsed time a thread blocked on synchronization. // class ThreadService : public AllStatic { private: // These counters could be moved to Threads class static PerfCounter* _total_threads_count; static PerfVariable* _live_threads_count; static PerfVariable* _peak_threads_count; static PerfVariable* _daemon_threads_count;
// These 2 counters are like the above thread counts, but are // atomically decremented in ThreadService::current_thread_exiting instead of // ThreadService::remove_thread, so that the thread count is updated before // Thread.join() returns. staticvolatileint _atomic_threads_count; staticvolatileint _atomic_daemon_threads_count;
// Need to keep the list of thread dump result that // keep references to Method* since thread dump can be // requested by multiple threads concurrently. static ThreadDumpResult* _threaddump_list;
// Per-thread Statistics for synchronization class ThreadStatistics : public CHeapObj<mtInternal> { private: // The following contention statistics are only updated by // the thread owning these statistics when contention occurs.
// These two reset flags are set to true when another thread // requests to reset the statistics. The actual statistics // are reset when the thread contention occurs and attempts // to update the statistics. bool _count_pending_reset; bool _timer_pending_reset;
// Keep accurate times for potentially recursive class operations int _perf_recursion_counts[PerfClassTraceTime::EVENT_TYPE_COUNT];
elapsedTimer _perf_timers[PerfClassTraceTime::EVENT_TYPE_COUNT];
// Thread snapshot to represent the thread state and statistics class ThreadSnapshot : public CHeapObj<mtInternal> { private: // This JavaThread* is protected by being stored in objects that are // protected by a ThreadsListSetter (ThreadDumpResult).
JavaThread* _thread;
OopHandle _threadObj;
JavaThreadStatus _thread_status;
// ThreadSnapshot instances should only be created via // ThreadDumpResult::add_thread_snapshot. friendclass ThreadDumpResult;
ThreadSnapshot() : _thread(NULL),
_stack_trace(NULL), _concurrent_locks(NULL), _next(NULL) {}; void initialize(ThreadsList * t_list, JavaThread* thread);
class ThreadStackTrace : public CHeapObj<mtInternal> { private:
JavaThread* _thread; int _depth; // number of stack frames added bool _with_locked_monitors;
GrowableArray<StackFrameInfo*>* _frames;
GrowableArray<OopHandle>* _jni_locked_monitors;
// StackFrameInfo for keeping Method* and bci during // stack walking for later construction of StackTraceElement[] // Java instances class StackFrameInfo : public CHeapObj<mtInternal> { private:
Method* _method; int _bci;
GrowableArray<OopHandle>* _locked_monitors; // list of object monitors locked by this frame // We need to save the mirrors in the backtrace to keep the class // from being unloaded while we still have this stack trace.
OopHandle _class_holder;
class ThreadConcurrentLocks : public CHeapObj<mtInternal> { private:
GrowableArray<OopHandle>* _owned_locks;
ThreadConcurrentLocks* _next; // This JavaThread* is protected in one of two different ways // depending on the usage of the ThreadConcurrentLocks object: // 1) by being stored in objects that are only allocated and used at a // safepoint (ConcurrentLocksDump), or 2) by being stored in objects // that are protected by a ThreadsListSetter (ThreadSnapshot inside // ThreadDumpResult).
JavaThread* _thread; public:
ThreadConcurrentLocks(JavaThread* thread);
~ThreadConcurrentLocks();
class ConcurrentLocksDump : public StackObj { private:
ThreadConcurrentLocks* _map;
ThreadConcurrentLocks* _last; // Last ThreadConcurrentLocks in the map bool _retain_map_on_free;
class ThreadDumpResult : public StackObj { private: int _num_threads; int _num_snapshots;
ThreadSnapshot* _snapshots;
ThreadSnapshot* _last;
ThreadDumpResult* _next;
ThreadsListSetter _setter; // Helper to set hazard ptr in the originating thread // which protects the JavaThreads in _snapshots.
// Utility class to get list of java threads. class ThreadsListEnumerator : public StackObj { private:
GrowableArray<instanceHandle>* _threads_array; public:
ThreadsListEnumerator(Thread* cur_thread, bool include_jvmti_agent_threads = false, bool include_jni_attaching_threads = true); int num_threads() { return _threads_array->length(); }
instanceHandle get_threadObj(int index) { return _threads_array->at(index); }
};
// abstract utility class to set new thread states, and restore previous after the block exits class JavaThreadStatusChanger : public StackObj { private:
JavaThreadStatus _old_state;
JavaThread* _java_thread; bool _is_alive;
// Change status to waiting on an object (timed or indefinite) class JavaThreadInObjectWaitState : public JavaThreadStatusChanger { private:
ThreadStatistics* _stat; bool _active;
~JavaThreadInObjectWaitState() { if (_active) {
_stat->monitor_wait_end();
}
}
};
// Change status to parked (timed or indefinite) class JavaThreadParkedState : public JavaThreadStatusChanger { private:
ThreadStatistics* _stat; bool _active;
~JavaThreadParkedState() { if (_active) {
_stat->monitor_wait_end();
}
}
};
// Change status to blocked on (re-)entering a synchronization block class JavaThreadBlockedOnMonitorEnterState : public JavaThreadStatusChanger { private:
ThreadStatistics* _stat; bool _active;
staticbool contended_enter_begin(JavaThread *java_thread) {
set_thread_status(java_thread, JavaThreadStatus::BLOCKED_ON_MONITOR_ENTER);
ThreadStatistics* stat = java_thread->get_thread_stat();
stat->contended_enter(); bool active = ThreadService::is_thread_monitoring_contention(); if (active) {
stat->contended_enter_begin();
} return active;
}
public: // java_thread is waiting thread being blocked on monitor reenter. // Current thread is the notifying thread which holds the monitor. staticbool wait_reenter_begin(JavaThread *java_thread, ObjectMonitor *obj_m) {
assert((java_thread != NULL), "Java thread should not be null here"); bool active = false; if (is_alive(java_thread)) {
active = contended_enter_begin(java_thread);
} return active;
}
JavaThreadBlockedOnMonitorEnterState(JavaThread *java_thread, ObjectMonitor *obj_m) :
JavaThreadStatusChanger(java_thread), _stat(NULL), _active(false) {
assert((java_thread != NULL), "Java thread should not be null here"); // Change thread status and collect contended enter stats for monitor contended // enter done for external java world objects and it is contended. All other cases // like for vm internal objects and for external objects which are not contended // thread status is not changed and contended enter stat is not collected.
_active = false; if (is_alive() && obj_m->contentions() > 0) {
_stat = java_thread->get_thread_stat();
_active = contended_enter_begin(java_thread);
}
}
~JavaThreadBlockedOnMonitorEnterState() { if (_active) {
_stat->contended_enter_end();
}
}
};
// Change status to sleeping class JavaThreadSleepState : public JavaThreadStatusChanger { private:
ThreadStatistics* _stat; bool _active; public:
JavaThreadSleepState(JavaThread *java_thread) :
JavaThreadStatusChanger(java_thread, JavaThreadStatus::SLEEPING) { if (is_alive()) {
_stat = java_thread->get_thread_stat();
_active = ThreadService::is_thread_monitoring_contention();
_stat->thread_sleep(); if (_active) {
_stat->thread_sleep_begin();
}
} else {
_active = false;
}
}
~JavaThreadSleepState() { if (_active) {
_stat->thread_sleep_end();
}
}
};
#endif// SHARE_SERVICES_THREADSERVICE_HPP
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
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.