src/share/vm/services/threadService.hpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2009, 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 class OopClosure;
  26 class ThreadDumpResult;
  27 class ThreadStackTrace;
  28 class ThreadSnapshot;
  29 class StackFrameInfo;
  30 class ThreadConcurrentLocks;
  31 class DeadlockCycle;
  32 
  33 // VM monitoring and management support for the thread and
  34 // synchronization subsystem
  35 //
  36 // Thread contention monitoring is disabled by default.
  37 // When enabled, the VM will begin measuring the accumulated
  38 // elapsed time a thread blocked on synchronization.
  39 //
  40 class ThreadService : public AllStatic {
  41 private:
  42   // These counters could be moved to Threads class
  43   static PerfCounter*  _total_threads_count;
  44   static PerfVariable* _live_threads_count;


 546   JavaThreadSleepState(JavaThread *java_thread) :
 547     JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
 548     if (is_alive()) {
 549       _stat = java_thread->get_thread_stat();
 550       _active = ThreadService::is_thread_monitoring_contention();
 551       _stat->thread_sleep();
 552       if (_active) {
 553         _stat->thread_sleep_begin();
 554       }
 555     } else {
 556       _active = false;
 557     }
 558   }
 559 
 560   ~JavaThreadSleepState() {
 561     if (_active) {
 562       _stat->thread_sleep_end();
 563     }
 564   }
 565 };


   1 /*
   2  * Copyright (c) 2003, 2010, 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_VM_SERVICES_THREADSERVICE_HPP
  26 #define SHARE_VM_SERVICES_THREADSERVICE_HPP
  27 
  28 #include "classfile/javaClasses.hpp"
  29 #include "runtime/handles.hpp"
  30 #include "runtime/init.hpp"
  31 #include "runtime/jniHandles.hpp"
  32 #include "runtime/objectMonitor.hpp"
  33 #include "runtime/objectMonitor.inline.hpp"
  34 #include "runtime/perfData.hpp"
  35 #include "services/management.hpp"
  36 #include "services/serviceUtil.hpp"
  37 
  38 class OopClosure;
  39 class ThreadDumpResult;
  40 class ThreadStackTrace;
  41 class ThreadSnapshot;
  42 class StackFrameInfo;
  43 class ThreadConcurrentLocks;
  44 class DeadlockCycle;
  45 
  46 // VM monitoring and management support for the thread and
  47 // synchronization subsystem
  48 //
  49 // Thread contention monitoring is disabled by default.
  50 // When enabled, the VM will begin measuring the accumulated
  51 // elapsed time a thread blocked on synchronization.
  52 //
  53 class ThreadService : public AllStatic {
  54 private:
  55   // These counters could be moved to Threads class
  56   static PerfCounter*  _total_threads_count;
  57   static PerfVariable* _live_threads_count;


 559   JavaThreadSleepState(JavaThread *java_thread) :
 560     JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
 561     if (is_alive()) {
 562       _stat = java_thread->get_thread_stat();
 563       _active = ThreadService::is_thread_monitoring_contention();
 564       _stat->thread_sleep();
 565       if (_active) {
 566         _stat->thread_sleep_begin();
 567       }
 568     } else {
 569       _active = false;
 570     }
 571   }
 572 
 573   ~JavaThreadSleepState() {
 574     if (_active) {
 575       _stat->thread_sleep_end();
 576     }
 577   }
 578 };
 579 
 580 #endif // SHARE_VM_SERVICES_THREADSERVICE_HPP