0N/A/*
1988N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_SERVICES_THREADSERVICE_HPP
1879N/A#define SHARE_VM_SERVICES_THREADSERVICE_HPP
1879N/A
1879N/A#include "classfile/javaClasses.hpp"
1879N/A#include "runtime/handles.hpp"
1879N/A#include "runtime/init.hpp"
1879N/A#include "runtime/jniHandles.hpp"
1879N/A#include "runtime/objectMonitor.hpp"
1879N/A#include "runtime/objectMonitor.inline.hpp"
1879N/A#include "runtime/perfData.hpp"
1879N/A#include "services/management.hpp"
1879N/A#include "services/serviceUtil.hpp"
1879N/A
0N/Aclass OopClosure;
0N/Aclass ThreadDumpResult;
0N/Aclass ThreadStackTrace;
0N/Aclass ThreadSnapshot;
0N/Aclass StackFrameInfo;
0N/Aclass ThreadConcurrentLocks;
0N/Aclass DeadlockCycle;
0N/A
0N/A// VM monitoring and management support for the thread and
0N/A// synchronization subsystem
0N/A//
0N/A// Thread contention monitoring is disabled by default.
0N/A// When enabled, the VM will begin measuring the accumulated
0N/A// elapsed time a thread blocked on synchronization.
0N/A//
0N/Aclass ThreadService : public AllStatic {
0N/Aprivate:
0N/A // These counters could be moved to Threads class
0N/A static PerfCounter* _total_threads_count;
0N/A static PerfVariable* _live_threads_count;
0N/A static PerfVariable* _peak_threads_count;
0N/A static PerfVariable* _daemon_threads_count;
0N/A
0N/A // These 2 counters are atomically incremented once the thread is exiting.
0N/A // They will be atomically decremented when ThreadService::remove_thread is called.
0N/A static volatile int _exiting_threads_count;
0N/A static volatile int _exiting_daemon_threads_count;
0N/A
0N/A static bool _thread_monitoring_contention_enabled;
0N/A static bool _thread_cpu_time_enabled;
1988N/A static bool _thread_allocated_memory_enabled;
0N/A
0N/A // Need to keep the list of thread dump result that
0N/A // keep references to methodOop since thread dump can be
0N/A // requested by multiple threads concurrently.
0N/A static ThreadDumpResult* _threaddump_list;
0N/A
0N/Apublic:
0N/A static void init();
0N/A static void add_thread(JavaThread* thread, bool daemon);
0N/A static void remove_thread(JavaThread* thread, bool daemon);
0N/A static void current_thread_exiting(JavaThread* jt);
0N/A
0N/A static bool set_thread_monitoring_contention(bool flag);
0N/A static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; }
0N/A
0N/A static bool set_thread_cpu_time_enabled(bool flag);
0N/A static bool is_thread_cpu_time_enabled() { return _thread_cpu_time_enabled; }
0N/A
1988N/A static bool set_thread_allocated_memory_enabled(bool flag);
1988N/A static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; }
1988N/A
0N/A static jlong get_total_thread_count() { return _total_threads_count->get_value(); }
0N/A static jlong get_peak_thread_count() { return _peak_threads_count->get_value(); }
0N/A static jlong get_live_thread_count() { return _live_threads_count->get_value() - _exiting_threads_count; }
0N/A static jlong get_daemon_thread_count() { return _daemon_threads_count->get_value() - _exiting_daemon_threads_count; }
0N/A
0N/A static int exiting_threads_count() { return _exiting_threads_count; }
0N/A static int exiting_daemon_threads_count() { return _exiting_daemon_threads_count; }
0N/A
0N/A // Support for thread dump
0N/A static void add_thread_dump(ThreadDumpResult* dump);
0N/A static void remove_thread_dump(ThreadDumpResult* dump);
0N/A
0N/A static Handle get_current_contended_monitor(JavaThread* thread);
0N/A
0N/A // This function is called by JVM_DumpThreads.
0N/A static Handle dump_stack_traces(GrowableArray<instanceHandle>* threads,
0N/A int num_threads, TRAPS);
0N/A
0N/A static void reset_peak_thread_count();
0N/A static void reset_contention_count_stat(JavaThread* thread);
0N/A static void reset_contention_time_stat(JavaThread* thread);
0N/A
0N/A static DeadlockCycle* find_deadlocks_at_safepoint(bool object_monitors_only);
0N/A
0N/A // GC support
0N/A static void oops_do(OopClosure* f);
0N/A};
0N/A
0N/A// Per-thread Statistics for synchronization
3863N/Aclass ThreadStatistics : public CHeapObj<mtInternal> {
0N/Aprivate:
0N/A // The following contention statistics are only updated by
0N/A // the thread owning these statistics when contention occurs.
0N/A
0N/A jlong _contended_enter_count;
0N/A elapsedTimer _contended_enter_timer;
0N/A jlong _monitor_wait_count;
0N/A elapsedTimer _monitor_wait_timer;
0N/A jlong _sleep_count;
0N/A elapsedTimer _sleep_timer;
0N/A
0N/A
0N/A // These two reset flags are set to true when another thread
0N/A // requests to reset the statistics. The actual statistics
0N/A // are reset when the thread contention occurs and attempts
0N/A // to update the statistics.
0N/A bool _count_pending_reset;
0N/A bool _timer_pending_reset;
0N/A
0N/A // Keep accurate times for potentially recursive class operations
875N/A int _perf_recursion_counts[6];
875N/A elapsedTimer _perf_timers[6];
0N/A
0N/A // utility functions
0N/A void check_and_reset_count() {
0N/A if (!_count_pending_reset) return;
0N/A _contended_enter_count = 0;
0N/A _monitor_wait_count = 0;
0N/A _sleep_count = 0;
0N/A _count_pending_reset = 0;
0N/A }
0N/A void check_and_reset_timer() {
0N/A if (!_timer_pending_reset) return;
0N/A _contended_enter_timer.reset();
0N/A _monitor_wait_timer.reset();
0N/A _sleep_timer.reset();
0N/A _timer_pending_reset = 0;
0N/A }
0N/A
0N/Apublic:
0N/A ThreadStatistics();
0N/A
0N/A jlong contended_enter_count() { return (_count_pending_reset ? 0 : _contended_enter_count); }
0N/A jlong contended_enter_ticks() { return (_timer_pending_reset ? 0 : _contended_enter_timer.active_ticks()); }
0N/A jlong monitor_wait_count() { return (_count_pending_reset ? 0 : _monitor_wait_count); }
0N/A jlong monitor_wait_ticks() { return (_timer_pending_reset ? 0 : _monitor_wait_timer.active_ticks()); }
0N/A jlong sleep_count() { return (_count_pending_reset ? 0 : _sleep_count); }
0N/A jlong sleep_ticks() { return (_timer_pending_reset ? 0 : _sleep_timer.active_ticks()); }
0N/A
0N/A void monitor_wait() { check_and_reset_count(); _monitor_wait_count++; }
0N/A void monitor_wait_begin() { check_and_reset_timer(); _monitor_wait_timer.start(); }
0N/A void monitor_wait_end() { _monitor_wait_timer.stop(); check_and_reset_timer(); }
0N/A
0N/A void thread_sleep() { check_and_reset_count(); _sleep_count++; }
0N/A void thread_sleep_begin() { check_and_reset_timer(); _sleep_timer.start(); }
0N/A void thread_sleep_end() { _sleep_timer.stop(); check_and_reset_timer(); }
0N/A
0N/A void contended_enter() { check_and_reset_count(); _contended_enter_count++; }
0N/A void contended_enter_begin() { check_and_reset_timer(); _contended_enter_timer.start(); }
0N/A void contended_enter_end() { _contended_enter_timer.stop(); check_and_reset_timer(); }
0N/A
0N/A void reset_count_stat() { _count_pending_reset = true; }
0N/A void reset_time_stat() { _timer_pending_reset = true; }
0N/A
875N/A int* perf_recursion_counts_addr() { return _perf_recursion_counts; }
875N/A elapsedTimer* perf_timers_addr() { return _perf_timers; }
0N/A};
0N/A
0N/A// Thread snapshot to represent the thread state and statistics
3863N/Aclass ThreadSnapshot : public CHeapObj<mtInternal> {
0N/Aprivate:
0N/A JavaThread* _thread;
0N/A oop _threadObj;
0N/A java_lang_Thread::ThreadStatus _thread_status;
0N/A
0N/A bool _is_ext_suspended;
0N/A bool _is_in_native;
0N/A
0N/A jlong _contended_enter_ticks;
0N/A jlong _contended_enter_count;
0N/A jlong _monitor_wait_ticks;
0N/A jlong _monitor_wait_count;
0N/A jlong _sleep_ticks;
0N/A jlong _sleep_count;
0N/A oop _blocker_object;
0N/A oop _blocker_object_owner;
0N/A
0N/A ThreadStackTrace* _stack_trace;
0N/A ThreadConcurrentLocks* _concurrent_locks;
0N/A ThreadSnapshot* _next;
0N/A
0N/Apublic:
0N/A // Dummy snapshot
0N/A ThreadSnapshot() : _thread(NULL), _threadObj(NULL), _stack_trace(NULL), _concurrent_locks(NULL), _next(NULL),
0N/A _blocker_object(NULL), _blocker_object_owner(NULL) {};
0N/A ThreadSnapshot(JavaThread* thread);
0N/A ~ThreadSnapshot();
0N/A
0N/A java_lang_Thread::ThreadStatus thread_status() { return _thread_status; }
0N/A
0N/A oop threadObj() const { return _threadObj; }
0N/A
0N/A void set_next(ThreadSnapshot* n) { _next = n; }
0N/A
0N/A bool is_ext_suspended() { return _is_ext_suspended; }
0N/A bool is_in_native() { return _is_in_native; }
0N/A
0N/A jlong contended_enter_count() { return _contended_enter_count; }
0N/A jlong contended_enter_ticks() { return _contended_enter_ticks; }
0N/A jlong monitor_wait_count() { return _monitor_wait_count; }
0N/A jlong monitor_wait_ticks() { return _monitor_wait_ticks; }
0N/A jlong sleep_count() { return _sleep_count; }
0N/A jlong sleep_ticks() { return _sleep_ticks; }
0N/A
0N/A
0N/A oop blocker_object() { return _blocker_object; }
0N/A oop blocker_object_owner() { return _blocker_object_owner; }
0N/A
0N/A ThreadSnapshot* next() const { return _next; }
0N/A ThreadStackTrace* get_stack_trace() { return _stack_trace; }
0N/A ThreadConcurrentLocks* get_concurrent_locks() { return _concurrent_locks; }
0N/A
0N/A void dump_stack_at_safepoint(int max_depth, bool with_locked_monitors);
0N/A void set_concurrent_locks(ThreadConcurrentLocks* l) { _concurrent_locks = l; }
0N/A void oops_do(OopClosure* f);
0N/A};
0N/A
3863N/Aclass ThreadStackTrace : public CHeapObj<mtInternal> {
0N/A private:
0N/A JavaThread* _thread;
0N/A int _depth; // number of stack frames added
0N/A bool _with_locked_monitors;
0N/A GrowableArray<StackFrameInfo*>* _frames;
0N/A GrowableArray<oop>* _jni_locked_monitors;
0N/A
0N/A public:
0N/A
0N/A ThreadStackTrace(JavaThread* thread, bool with_locked_monitors);
0N/A ~ThreadStackTrace();
0N/A
396N/A JavaThread* thread() { return _thread; }
0N/A StackFrameInfo* stack_frame_at(int i) { return _frames->at(i); }
0N/A int get_stack_depth() { return _depth; }
0N/A
0N/A void add_stack_frame(javaVFrame* jvf);
0N/A void dump_stack_at_safepoint(int max_depth);
0N/A Handle allocate_fill_stack_trace_element_array(TRAPS);
0N/A void oops_do(OopClosure* f);
0N/A GrowableArray<oop>* jni_locked_monitors() { return _jni_locked_monitors; }
0N/A int num_jni_locked_monitors() { return (_jni_locked_monitors != NULL ? _jni_locked_monitors->length() : 0); }
0N/A
0N/A bool is_owned_monitor_on_stack(oop object);
0N/A void add_jni_locked_monitor(oop object) { _jni_locked_monitors->append(object); }
0N/A};
0N/A
0N/A// StackFrameInfo for keeping methodOop and bci during
0N/A// stack walking for later construction of StackTraceElement[]
0N/A// Java instances
3863N/Aclass StackFrameInfo : public CHeapObj<mtInternal> {
0N/A private:
0N/A methodOop _method;
0N/A int _bci;
0N/A GrowableArray<oop>* _locked_monitors; // list of object monitors locked by this frame
0N/A
0N/A public:
0N/A
0N/A StackFrameInfo(javaVFrame* jvf, bool with_locked_monitors);
0N/A ~StackFrameInfo() {
0N/A if (_locked_monitors != NULL) {
0N/A delete _locked_monitors;
0N/A }
0N/A };
0N/A methodOop method() const { return _method; }
0N/A int bci() const { return _bci; }
0N/A void oops_do(OopClosure* f);
0N/A
0N/A int num_locked_monitors() { return (_locked_monitors != NULL ? _locked_monitors->length() : 0); }
0N/A GrowableArray<oop>* locked_monitors() { return _locked_monitors; }
0N/A
0N/A void print_on(outputStream* st) const;
0N/A};
0N/A
3863N/Aclass ThreadConcurrentLocks : public CHeapObj<mtInternal> {
0N/Aprivate:
0N/A GrowableArray<instanceOop>* _owned_locks;
0N/A ThreadConcurrentLocks* _next;
0N/A JavaThread* _thread;
0N/A public:
0N/A ThreadConcurrentLocks(JavaThread* thread);
0N/A ~ThreadConcurrentLocks();
0N/A
0N/A void add_lock(instanceOop o);
0N/A void set_next(ThreadConcurrentLocks* n) { _next = n; }
0N/A ThreadConcurrentLocks* next() { return _next; }
0N/A JavaThread* java_thread() { return _thread; }
0N/A GrowableArray<instanceOop>* owned_locks() { return _owned_locks; }
0N/A void oops_do(OopClosure* f);
0N/A};
0N/A
0N/Aclass ConcurrentLocksDump : public StackObj {
0N/A private:
0N/A ThreadConcurrentLocks* _map;
0N/A ThreadConcurrentLocks* _last; // Last ThreadConcurrentLocks in the map
0N/A bool _retain_map_on_free;
0N/A
0N/A void build_map(GrowableArray<oop>* aos_objects);
0N/A void add_lock(JavaThread* thread, instanceOop o);
0N/A
0N/A public:
0N/A ConcurrentLocksDump(bool retain_map_on_free) : _map(NULL), _last(NULL), _retain_map_on_free(retain_map_on_free) {};
0N/A ConcurrentLocksDump() : _map(NULL), _last(NULL), _retain_map_on_free(false) {};
0N/A ~ConcurrentLocksDump();
0N/A
0N/A void dump_at_safepoint();
0N/A ThreadConcurrentLocks* thread_concurrent_locks(JavaThread* thread);
0N/A void print_locks_on(JavaThread* t, outputStream* st);
0N/A};
0N/A
0N/Aclass ThreadDumpResult : public StackObj {
0N/A private:
0N/A int _num_threads;
0N/A int _num_snapshots;
0N/A ThreadSnapshot* _snapshots;
0N/A ThreadSnapshot* _last;
0N/A ThreadDumpResult* _next;
0N/A public:
0N/A ThreadDumpResult();
0N/A ThreadDumpResult(int num_threads);
0N/A ~ThreadDumpResult();
0N/A
0N/A void add_thread_snapshot(ThreadSnapshot* ts);
0N/A void set_next(ThreadDumpResult* next) { _next = next; }
0N/A ThreadDumpResult* next() { return _next; }
0N/A int num_threads() { return _num_threads; }
0N/A int num_snapshots() { return _num_snapshots; }
0N/A ThreadSnapshot* snapshots() { return _snapshots; }
0N/A void oops_do(OopClosure* f);
0N/A};
0N/A
3863N/Aclass DeadlockCycle : public CHeapObj<mtInternal> {
0N/A private:
0N/A bool _is_deadlock;
0N/A GrowableArray<JavaThread*>* _threads;
0N/A DeadlockCycle* _next;
0N/A public:
0N/A DeadlockCycle();
0N/A ~DeadlockCycle();
0N/A
0N/A DeadlockCycle* next() { return _next; }
0N/A void set_next(DeadlockCycle* d) { _next = d; }
0N/A void add_thread(JavaThread* t) { _threads->append(t); }
0N/A void reset() { _is_deadlock = false; _threads->clear(); }
0N/A void set_deadlock(bool value) { _is_deadlock = value; }
0N/A bool is_deadlock() { return _is_deadlock; }
0N/A int num_threads() { return _threads->length(); }
0N/A GrowableArray<JavaThread*>* threads() { return _threads; }
0N/A void print_on(outputStream* st) const;
0N/A};
0N/A
0N/A// Utility class to get list of java threads.
0N/Aclass ThreadsListEnumerator : public StackObj {
0N/Aprivate:
0N/A GrowableArray<instanceHandle>* _threads_array;
0N/Apublic:
0N/A ThreadsListEnumerator(Thread* cur_thread,
0N/A bool include_jvmti_agent_threads = false,
0N/A bool include_jni_attaching_threads = true);
0N/A int num_threads() { return _threads_array->length(); }
0N/A instanceHandle get_threadObj(int index) { return _threads_array->at(index); }
0N/A};
0N/A
0N/A
0N/A// abstract utility class to set new thread states, and restore previous after the block exits
0N/Aclass JavaThreadStatusChanger : public StackObj {
0N/A private:
0N/A java_lang_Thread::ThreadStatus _old_state;
0N/A JavaThread* _java_thread;
0N/A bool _is_alive;
0N/A
0N/A void save_old_state(JavaThread* java_thread) {
0N/A _java_thread = java_thread;
0N/A _is_alive = is_alive(java_thread);
0N/A if (is_alive()) {
0N/A _old_state = java_lang_Thread::get_thread_status(_java_thread->threadObj());
0N/A }
0N/A }
0N/A
0N/A public:
0N/A static void set_thread_status(JavaThread* java_thread,
0N/A java_lang_Thread::ThreadStatus state) {
0N/A java_lang_Thread::set_thread_status(java_thread->threadObj(), state);
0N/A }
0N/A
0N/A void set_thread_status(java_lang_Thread::ThreadStatus state) {
0N/A if (is_alive()) {
0N/A set_thread_status(_java_thread, state);
0N/A }
0N/A }
0N/A
0N/A JavaThreadStatusChanger(JavaThread* java_thread,
0N/A java_lang_Thread::ThreadStatus state) {
0N/A save_old_state(java_thread);
0N/A set_thread_status(state);
0N/A }
0N/A
0N/A JavaThreadStatusChanger(JavaThread* java_thread) {
0N/A save_old_state(java_thread);
0N/A }
0N/A
0N/A ~JavaThreadStatusChanger() {
0N/A set_thread_status(_old_state);
0N/A }
0N/A
0N/A static bool is_alive(JavaThread* java_thread) {
0N/A return java_thread != NULL && java_thread->threadObj() != NULL;
0N/A }
0N/A
0N/A bool is_alive() {
0N/A return _is_alive;
0N/A }
0N/A};
0N/A
0N/A// Change status to waiting on an object (timed or indefinite)
0N/Aclass JavaThreadInObjectWaitState : public JavaThreadStatusChanger {
0N/A private:
0N/A ThreadStatistics* _stat;
0N/A bool _active;
0N/A
0N/A public:
0N/A JavaThreadInObjectWaitState(JavaThread *java_thread, bool timed) :
0N/A JavaThreadStatusChanger(java_thread,
0N/A timed ? java_lang_Thread::IN_OBJECT_WAIT_TIMED : java_lang_Thread::IN_OBJECT_WAIT) {
0N/A if (is_alive()) {
0N/A _stat = java_thread->get_thread_stat();
0N/A _active = ThreadService::is_thread_monitoring_contention();
0N/A _stat->monitor_wait();
0N/A if (_active) {
0N/A _stat->monitor_wait_begin();
0N/A }
0N/A } else {
0N/A _active = false;
0N/A }
0N/A }
0N/A
0N/A ~JavaThreadInObjectWaitState() {
0N/A if (_active) {
0N/A _stat->monitor_wait_end();
0N/A }
0N/A }
0N/A};
0N/A
0N/A// Change status to parked (timed or indefinite)
0N/Aclass JavaThreadParkedState : public JavaThreadStatusChanger {
0N/A private:
0N/A ThreadStatistics* _stat;
0N/A bool _active;
0N/A
0N/A public:
0N/A JavaThreadParkedState(JavaThread *java_thread, bool timed) :
0N/A JavaThreadStatusChanger(java_thread,
0N/A timed ? java_lang_Thread::PARKED_TIMED : java_lang_Thread::PARKED) {
0N/A if (is_alive()) {
0N/A _stat = java_thread->get_thread_stat();
0N/A _active = ThreadService::is_thread_monitoring_contention();
0N/A _stat->monitor_wait();
0N/A if (_active) {
0N/A _stat->monitor_wait_begin();
0N/A }
0N/A } else {
0N/A _active = false;
0N/A }
0N/A }
0N/A
0N/A ~JavaThreadParkedState() {
0N/A if (_active) {
0N/A _stat->monitor_wait_end();
0N/A }
0N/A }
0N/A};
0N/A
0N/A// Change status to blocked on (re-)entering a synchronization block
0N/Aclass JavaThreadBlockedOnMonitorEnterState : public JavaThreadStatusChanger {
0N/A private:
0N/A ThreadStatistics* _stat;
0N/A bool _active;
0N/A
0N/A static bool contended_enter_begin(JavaThread *java_thread) {
0N/A set_thread_status(java_thread, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
0N/A ThreadStatistics* stat = java_thread->get_thread_stat();
0N/A stat->contended_enter();
0N/A bool active = ThreadService::is_thread_monitoring_contention();
0N/A if (active) {
0N/A stat->contended_enter_begin();
0N/A }
0N/A return active;
0N/A }
0N/A
0N/A public:
0N/A // java_thread is waiting thread being blocked on monitor reenter.
0N/A // Current thread is the notifying thread which holds the monitor.
0N/A static bool wait_reenter_begin(JavaThread *java_thread, ObjectMonitor *obj_m) {
0N/A assert((java_thread != NULL), "Java thread should not be null here");
0N/A bool active = false;
0N/A if (is_alive(java_thread) && ServiceUtil::visible_oop((oop)obj_m->object())) {
0N/A active = contended_enter_begin(java_thread);
0N/A }
0N/A return active;
0N/A }
0N/A
0N/A static void wait_reenter_end(JavaThread *java_thread, bool active) {
0N/A if (active) {
0N/A java_thread->get_thread_stat()->contended_enter_end();
0N/A }
0N/A set_thread_status(java_thread, java_lang_Thread::RUNNABLE);
0N/A }
0N/A
0N/A JavaThreadBlockedOnMonitorEnterState(JavaThread *java_thread, ObjectMonitor *obj_m) :
0N/A JavaThreadStatusChanger(java_thread) {
0N/A assert((java_thread != NULL), "Java thread should not be null here");
0N/A // Change thread status and collect contended enter stats for monitor contended
0N/A // enter done for external java world objects and it is contended. All other cases
0N/A // like for vm internal objects and for external objects which are not contended
0N/A // thread status is not changed and contended enter stat is not collected.
0N/A _active = false;
0N/A if (is_alive() && ServiceUtil::visible_oop((oop)obj_m->object()) && obj_m->contentions() > 0) {
0N/A _stat = java_thread->get_thread_stat();
0N/A _active = contended_enter_begin(java_thread);
0N/A }
0N/A }
0N/A
0N/A ~JavaThreadBlockedOnMonitorEnterState() {
0N/A if (_active) {
0N/A _stat->contended_enter_end();
0N/A }
0N/A }
0N/A};
0N/A
0N/A// Change status to sleeping
0N/Aclass JavaThreadSleepState : public JavaThreadStatusChanger {
0N/A private:
0N/A ThreadStatistics* _stat;
0N/A bool _active;
0N/A public:
0N/A JavaThreadSleepState(JavaThread *java_thread) :
0N/A JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
0N/A if (is_alive()) {
0N/A _stat = java_thread->get_thread_stat();
0N/A _active = ThreadService::is_thread_monitoring_contention();
0N/A _stat->thread_sleep();
0N/A if (_active) {
0N/A _stat->thread_sleep_begin();
0N/A }
0N/A } else {
0N/A _active = false;
0N/A }
0N/A }
0N/A
0N/A ~JavaThreadSleepState() {
0N/A if (_active) {
0N/A _stat->thread_sleep_end();
0N/A }
0N/A }
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_SERVICES_THREADSERVICE_HPP