src/share/vm/runtime/serviceThread.cpp

Print this page




  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 #include "precompiled.hpp"
  26 #include "runtime/interfaceSupport.hpp"
  27 #include "runtime/javaCalls.hpp"
  28 #include "runtime/serviceThread.hpp"
  29 #include "runtime/mutexLocker.hpp"

  30 #include "prims/jvmtiImpl.hpp"
  31 #include "services/gcNotifier.hpp"
  32 #include "services/diagnosticArgument.hpp"
  33 #include "services/diagnosticFramework.hpp"
  34 
  35 ServiceThread* ServiceThread::_instance = NULL;
  36 
  37 void ServiceThread::initialize() {
  38   EXCEPTION_MARK;
  39 
  40   instanceKlassHandle klass (THREAD,  SystemDictionary::Thread_klass());
  41   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
  42 
  43   const char* name = JDK_Version::is_gte_jdk17x_version() ?
  44       "Service Thread" : "Low Memory Detector";
  45 
  46   Handle string = java_lang_String::create_from_str(name, CHECK);
  47 
  48   // Initialize thread_oop to put it into the system threadGroup
  49   Handle thread_group (THREAD, Universe::system_thread_group());
  50   JavaValue result(T_VOID);
  51   JavaCalls::call_special(&result, thread_oop,
  52                           klass,
  53                           vmSymbols::object_initializer_name(),
  54                           vmSymbols::threadgroup_string_void_signature(),
  55                           thread_group,
  56                           string,
  57                           CHECK);
  58 
  59   {
  60     MutexLocker mu(Threads_lock);
  61     ServiceThread* thread =  new ServiceThread(&service_thread_entry);
  62 
  63     // At this point it may be possible that no osthread was created for the
  64     // JavaThread due to lack of memory. We would have to throw an exception
  65     // in that case. However, since this must work and we do not allow
  66     // exceptions anyway, check and abort if this fails.
  67     if (thread == NULL || thread->osthread() == NULL) {
  68       vm_exit_during_initialization("java.lang.OutOfMemoryError",
  69                                     "unable to create new native thread");
  70     }
  71 
  72     java_lang_Thread::set_thread(thread_oop(), thread);
  73     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
  74     java_lang_Thread::set_daemon(thread_oop());
  75     thread->set_threadObj(thread_oop());
  76     _instance = thread;
  77 
  78     Threads::add(thread);
  79     Thread::start(thread);
  80   }
  81 }
  82 
  83 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  84   while (true) {
  85     bool sensors_changed = false;
  86     bool has_jvmti_events = false;
  87     bool has_gc_notification_event = false;
  88     bool has_dcmd_notification_event = false;
  89     JvmtiDeferredEvent jvmti_event;




  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 #include "precompiled.hpp"
  26 #include "runtime/interfaceSupport.hpp"
  27 #include "runtime/javaCalls.hpp"
  28 #include "runtime/serviceThread.hpp"
  29 #include "runtime/mutexLocker.hpp"
  30 #include "runtime/os.hpp"
  31 #include "prims/jvmtiImpl.hpp"
  32 #include "services/gcNotifier.hpp"
  33 #include "services/diagnosticArgument.hpp"
  34 #include "services/diagnosticFramework.hpp"
  35 
  36 ServiceThread* ServiceThread::_instance = NULL;
  37 
  38 void ServiceThread::initialize() {
  39   EXCEPTION_MARK;
  40 
  41   instanceKlassHandle klass (THREAD,  SystemDictionary::Thread_klass());
  42   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
  43 
  44   const char* name = JDK_Version::is_gte_jdk17x_version() ?
  45       "Service Thread" : "Low Memory Detector";
  46 
  47   Handle string = java_lang_String::create_from_str(name, CHECK);
  48 
  49   // Initialize thread_oop to put it into the system threadGroup
  50   Handle thread_group (THREAD, Universe::system_thread_group());
  51   JavaValue result(T_VOID);
  52   JavaCalls::call_special(&result, thread_oop,
  53                           klass,
  54                           vmSymbols::object_initializer_name(),
  55                           vmSymbols::threadgroup_string_void_signature(),
  56                           thread_group,
  57                           string,
  58                           CHECK);
  59 
  60   {
  61     MutexLocker mu(Threads_lock);
  62     ServiceThread* thread =  new ServiceThread(&service_thread_entry);
  63 
  64     // At this point it may be possible that no osthread was created for the
  65     // JavaThread due to lack of memory. We would have to throw an exception
  66     // in that case. However, since this must work and we do not allow
  67     // exceptions anyway, check and abort if this fails.
  68     if (thread == NULL || thread->osthread() == NULL) {
  69       vm_exit_during_initialization("java.lang.OutOfMemoryError",
  70                                     os::native_thread_creation_failed_msg());
  71     }
  72 
  73     java_lang_Thread::set_thread(thread_oop(), thread);
  74     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
  75     java_lang_Thread::set_daemon(thread_oop());
  76     thread->set_threadObj(thread_oop());
  77     _instance = thread;
  78 
  79     Threads::add(thread);
  80     Thread::start(thread);
  81   }
  82 }
  83 
  84 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  85   while (true) {
  86     bool sensors_changed = false;
  87     bool has_jvmti_events = false;
  88     bool has_gc_notification_event = false;
  89     bool has_dcmd_notification_event = false;
  90     JvmtiDeferredEvent jvmti_event;


TPATH=src/share/vm/runtime WDIR=/scratch/iklam/jdk/hotspot-rt9/webrev RTOP=../../../..