src/share/vm/runtime/serviceThread.cpp

Tue, 08 Feb 2011 09:11:37 -0800

author
mchung
date
Tue, 08 Feb 2011 09:11:37 -0800
changeset 2518
f36c9fe788b8
parent 2511
bf8517f4e4d0
child 2623
216d916d5c12
permissions
-rw-r--r--

7017673: Remove setting of the sun.jkernel.DownloadManager as a boot classloader hook
Reviewed-by: alanb, dcubed, coleenp

kamg@2511 1 /*
kamg@2511 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
kamg@2511 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kamg@2511 4 *
kamg@2511 5 * This code is free software; you can redistribute it and/or modify it
kamg@2511 6 * under the terms of the GNU General Public License version 2 only, as
kamg@2511 7 * published by the Free Software Foundation.
kamg@2511 8 *
kamg@2511 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kamg@2511 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kamg@2511 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kamg@2511 12 * version 2 for more details (a copy is included in the LICENSE file that
kamg@2511 13 * accompanied this code).
kamg@2511 14 *
kamg@2511 15 * You should have received a copy of the GNU General Public License version
kamg@2511 16 * 2 along with this work; if not, write to the Free Software Foundation,
kamg@2511 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kamg@2511 18 *
kamg@2511 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
kamg@2511 20 * or visit www.oracle.com if you need additional information or have any
kamg@2511 21 * questions.
kamg@2511 22 *
kamg@2511 23 */
kamg@2511 24
kamg@2511 25 #include "precompiled.hpp"
kamg@2511 26 #include "runtime/interfaceSupport.hpp"
kamg@2511 27 #include "runtime/javaCalls.hpp"
kamg@2511 28 #include "runtime/serviceThread.hpp"
kamg@2511 29 #include "runtime/mutexLocker.hpp"
kamg@2511 30 #include "prims/jvmtiImpl.hpp"
kamg@2511 31
kamg@2511 32 ServiceThread* ServiceThread::_instance = NULL;
kamg@2511 33
kamg@2511 34 void ServiceThread::initialize() {
kamg@2511 35 EXCEPTION_MARK;
kamg@2511 36
kamg@2511 37 instanceKlassHandle klass (THREAD, SystemDictionary::Thread_klass());
kamg@2511 38 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
kamg@2511 39
kamg@2511 40 const char* name = JDK_Version::is_gte_jdk17x_version() ?
kamg@2511 41 "Service Thread" : "Low Memory Detector";
kamg@2511 42
kamg@2511 43 Handle string = java_lang_String::create_from_str(name, CHECK);
kamg@2511 44
kamg@2511 45 // Initialize thread_oop to put it into the system threadGroup
kamg@2511 46 Handle thread_group (THREAD, Universe::system_thread_group());
kamg@2511 47 JavaValue result(T_VOID);
kamg@2511 48 JavaCalls::call_special(&result, thread_oop,
kamg@2511 49 klass,
kamg@2511 50 vmSymbols::object_initializer_name(),
kamg@2511 51 vmSymbols::threadgroup_string_void_signature(),
kamg@2511 52 thread_group,
kamg@2511 53 string,
kamg@2511 54 CHECK);
kamg@2511 55
kamg@2511 56 {
kamg@2511 57 MutexLocker mu(Threads_lock);
kamg@2511 58 ServiceThread* thread = new ServiceThread(&service_thread_entry);
kamg@2511 59
kamg@2511 60 // At this point it may be possible that no osthread was created for the
kamg@2511 61 // JavaThread due to lack of memory. We would have to throw an exception
kamg@2511 62 // in that case. However, since this must work and we do not allow
kamg@2511 63 // exceptions anyway, check and abort if this fails.
kamg@2511 64 if (thread == NULL || thread->osthread() == NULL) {
kamg@2511 65 vm_exit_during_initialization("java.lang.OutOfMemoryError",
kamg@2511 66 "unable to create new native thread");
kamg@2511 67 }
kamg@2511 68
kamg@2511 69 java_lang_Thread::set_thread(thread_oop(), thread);
kamg@2511 70 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
kamg@2511 71 java_lang_Thread::set_daemon(thread_oop());
kamg@2511 72 thread->set_threadObj(thread_oop());
kamg@2511 73
kamg@2511 74 Threads::add(thread);
kamg@2511 75 Thread::start(thread);
kamg@2511 76
kamg@2511 77 _instance = thread;
kamg@2511 78 }
kamg@2511 79 }
kamg@2511 80
kamg@2511 81 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
kamg@2511 82 while (true) {
kamg@2511 83 bool sensors_changed = false;
kamg@2511 84 bool has_jvmti_events = false;
kamg@2511 85 JvmtiDeferredEvent jvmti_event;
kamg@2511 86 {
kamg@2511 87 // Need state transition ThreadBlockInVM so that this thread
kamg@2511 88 // will be handled by safepoint correctly when this thread is
kamg@2511 89 // notified at a safepoint.
kamg@2511 90
kamg@2511 91 // This ThreadBlockInVM object is not also considered to be
kamg@2511 92 // suspend-equivalent because ServiceThread is not visible to
kamg@2511 93 // external suspension.
kamg@2511 94
kamg@2511 95 ThreadBlockInVM tbivm(jt);
kamg@2511 96
kamg@2511 97 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
kamg@2511 98 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
kamg@2511 99 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events())) {
kamg@2511 100 // wait until one of the sensors has pending requests, or there is a
kamg@2511 101 // pending JVMTI event to post
kamg@2511 102 Service_lock->wait(Mutex::_no_safepoint_check_flag);
kamg@2511 103 }
kamg@2511 104
kamg@2511 105 if (has_jvmti_events) {
kamg@2511 106 jvmti_event = JvmtiDeferredEventQueue::dequeue();
kamg@2511 107 }
kamg@2511 108 }
kamg@2511 109
kamg@2511 110 if (has_jvmti_events) {
kamg@2511 111 jvmti_event.post();
kamg@2511 112 }
kamg@2511 113
kamg@2511 114 if (sensors_changed) {
kamg@2511 115 LowMemoryDetector::process_sensor_changes(jt);
kamg@2511 116 }
kamg@2511 117 }
kamg@2511 118 }
kamg@2511 119
kamg@2511 120 bool ServiceThread::is_service_thread(Thread* thread) {
kamg@2511 121 return thread == _instance;
kamg@2511 122 }

mercurial