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 #include "precompiled.hpp"
26 #include "runtime/interfaceSupport.inline.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/diagnosticArgument.hpp"
33 #include "services/diagnosticFramework.hpp"
34 #include "services/gcNotifier.hpp"
35 #include "services/lowMemoryDetector.hpp"
36
37 ServiceThread* ServiceThread::_instance = NULL;
38
39 void ServiceThread::initialize() {
40 EXCEPTION_MARK;
41
42 const char* name = "Service Thread";
43 Handle string = java_lang_String::create_from_str(name, CHECK);
44
45 // Initialize thread_oop to put it into the system threadGroup
65 }
66
67 java_lang_Thread::set_thread(thread_oop(), thread);
68 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
69 java_lang_Thread::set_daemon(thread_oop());
70 thread->set_threadObj(thread_oop());
71 _instance = thread;
72
73 Threads::add(thread);
74 Thread::start(thread);
75 }
76 }
77
78 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
79 while (true) {
80 bool sensors_changed = false;
81 bool has_jvmti_events = false;
82 bool has_gc_notification_event = false;
83 bool has_dcmd_notification_event = false;
84 bool acs_notify = false;
85 JvmtiDeferredEvent jvmti_event;
86 {
87 // Need state transition ThreadBlockInVM so that this thread
88 // will be handled by safepoint correctly when this thread is
89 // notified at a safepoint.
90
91 // This ThreadBlockInVM object is not also considered to be
92 // suspend-equivalent because ServiceThread is not visible to
93 // external suspension.
94
95 ThreadBlockInVM tbivm(jt);
96
97 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
98 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
99 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
100 !(has_gc_notification_event = GCNotifier::has_event()) &&
101 !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification())) {
102 // wait until one of the sensors has pending requests, or there is a
103 // pending JVMTI event or JMX GC notification to post
104 Service_lock->wait(Mutex::_no_safepoint_check_flag);
105 }
106
107 if (has_jvmti_events) {
108 jvmti_event = JvmtiDeferredEventQueue::dequeue();
109 }
110 }
111
112 if (has_jvmti_events) {
113 jvmti_event.post();
114 }
115
116 if (sensors_changed) {
117 LowMemoryDetector::process_sensor_changes(jt);
118 }
119
120 if(has_gc_notification_event) {
121 GCNotifier::sendNotification(CHECK);
122 }
123
124 if(has_dcmd_notification_event) {
125 DCmdFactory::send_notification(CHECK);
126 }
127 }
128 }
129
|
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 #include "precompiled.hpp"
26 #include "classfile/stringTable.hpp"
27 #include "runtime/interfaceSupport.inline.hpp"
28 #include "runtime/javaCalls.hpp"
29 #include "runtime/serviceThread.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/os.hpp"
32 #include "prims/jvmtiImpl.hpp"
33 #include "services/diagnosticArgument.hpp"
34 #include "services/diagnosticFramework.hpp"
35 #include "services/gcNotifier.hpp"
36 #include "services/lowMemoryDetector.hpp"
37
38 ServiceThread* ServiceThread::_instance = NULL;
39
40 void ServiceThread::initialize() {
41 EXCEPTION_MARK;
42
43 const char* name = "Service Thread";
44 Handle string = java_lang_String::create_from_str(name, CHECK);
45
46 // Initialize thread_oop to put it into the system threadGroup
66 }
67
68 java_lang_Thread::set_thread(thread_oop(), thread);
69 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
70 java_lang_Thread::set_daemon(thread_oop());
71 thread->set_threadObj(thread_oop());
72 _instance = thread;
73
74 Threads::add(thread);
75 Thread::start(thread);
76 }
77 }
78
79 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
80 while (true) {
81 bool sensors_changed = false;
82 bool has_jvmti_events = false;
83 bool has_gc_notification_event = false;
84 bool has_dcmd_notification_event = false;
85 bool acs_notify = false;
86 bool stringtable_work = false;
87 JvmtiDeferredEvent jvmti_event;
88 {
89 // Need state transition ThreadBlockInVM so that this thread
90 // will be handled by safepoint correctly when this thread is
91 // notified at a safepoint.
92
93 // This ThreadBlockInVM object is not also considered to be
94 // suspend-equivalent because ServiceThread is not visible to
95 // external suspension.
96
97 ThreadBlockInVM tbivm(jt);
98
99 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
100 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
101 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
102 !(has_gc_notification_event = GCNotifier::has_event()) &&
103 !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
104 !(stringtable_work = StringTable::has_work())) {
105 // wait until one of the sensors has pending requests, or there is a
106 // pending JVMTI event or JMX GC notification to post
107 Service_lock->wait(Mutex::_no_safepoint_check_flag);
108 }
109
110 if (has_jvmti_events) {
111 jvmti_event = JvmtiDeferredEventQueue::dequeue();
112 }
113 }
114
115 if (stringtable_work) {
116 StringTable::do_concurrent_work(jt);
117 }
118
119 if (has_jvmti_events) {
120 jvmti_event.post();
121 }
122
123 if (sensors_changed) {
124 LowMemoryDetector::process_sensor_changes(jt);
125 }
126
127 if(has_gc_notification_event) {
128 GCNotifier::sendNotification(CHECK);
129 }
130
131 if(has_dcmd_notification_event) {
132 DCmdFactory::send_notification(CHECK);
133 }
134 }
135 }
136
|