24
25 #include "precompiled.hpp"
26 #include "classfile/protectionDomainCache.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "memory/universe.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/interfaceSupport.inline.hpp"
33 #include "runtime/javaCalls.hpp"
34 #include "runtime/jniHandles.hpp"
35 #include "runtime/serviceThread.hpp"
36 #include "runtime/mutexLocker.hpp"
37 #include "runtime/os.hpp"
38 #include "prims/jvmtiImpl.hpp"
39 #include "prims/resolvedMethodTable.hpp"
40 #include "services/diagnosticArgument.hpp"
41 #include "services/diagnosticFramework.hpp"
42 #include "services/gcNotifier.hpp"
43 #include "services/lowMemoryDetector.hpp"
44
45 ServiceThread* ServiceThread::_instance = NULL;
46
47 void ServiceThread::initialize() {
48 EXCEPTION_MARK;
49
50 const char* name = "Service Thread";
51 Handle string = java_lang_String::create_from_str(name, CHECK);
52
53 // Initialize thread_oop to put it into the system threadGroup
54 Handle thread_group (THREAD, Universe::system_thread_group());
55 Handle thread_oop = JavaCalls::construct_new_instance(
56 SystemDictionary::Thread_klass(),
57 vmSymbols::threadgroup_string_void_signature(),
58 thread_group,
59 string,
60 CHECK);
61
62 {
63 MutexLocker mu(Threads_lock);
107 }
108 }
109
110 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
111 OopStorage* const oopstorages[] = {
112 JNIHandles::global_handles(),
113 JNIHandles::weak_global_handles(),
114 StringTable::weak_storage(),
115 SystemDictionary::vm_weak_oop_storage()
116 };
117 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
118
119 while (true) {
120 bool sensors_changed = false;
121 bool has_jvmti_events = false;
122 bool has_gc_notification_event = false;
123 bool has_dcmd_notification_event = false;
124 bool stringtable_work = false;
125 bool symboltable_work = false;
126 bool resolved_method_table_work = false;
127 bool protection_domain_table_work = false;
128 bool oopstorage_work = false;
129 bool oopstorages_cleanup[oopstorage_count] = {}; // Zero (false) initialize.
130 JvmtiDeferredEvent jvmti_event;
131 {
132 // Need state transition ThreadBlockInVM so that this thread
133 // will be handled by safepoint correctly when this thread is
134 // notified at a safepoint.
135
136 // This ThreadBlockInVM object is not also considered to be
137 // suspend-equivalent because ServiceThread is not visible to
138 // external suspension.
139
140 ThreadBlockInVM tbivm(jt);
141
142 MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
143 // Process all available work on each (outer) iteration, rather than
144 // only the first recognized bit of work, to avoid frequently true early
145 // tests from potentially starving later work. Hence the use of
146 // arithmetic-or to combine results; we don't want short-circuiting.
147 while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
148 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
149 (has_gc_notification_event = GCNotifier::has_event()) |
150 (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
151 (stringtable_work = StringTable::has_work()) |
152 (symboltable_work = SymbolTable::has_work()) |
153 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
154 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
155 (oopstorage_work = needs_oopstorage_cleanup(oopstorages,
156 oopstorages_cleanup,
157 oopstorage_count)))
158
159 == 0) {
160 // Wait until notified that there is some work to do.
161 ml.wait();
162 }
163
164 if (has_jvmti_events) {
165 jvmti_event = JvmtiDeferredEventQueue::dequeue();
166 }
167 }
168
169 if (stringtable_work) {
170 StringTable::do_concurrent_work(jt);
171 }
172
173 if (symboltable_work) {
177 if (has_jvmti_events) {
178 jvmti_event.post();
179 }
180
181 if (sensors_changed) {
182 LowMemoryDetector::process_sensor_changes(jt);
183 }
184
185 if(has_gc_notification_event) {
186 GCNotifier::sendNotification(CHECK);
187 }
188
189 if(has_dcmd_notification_event) {
190 DCmdFactory::send_notification(CHECK);
191 }
192
193 if (resolved_method_table_work) {
194 ResolvedMethodTable::do_concurrent_work(jt);
195 }
196
197 if (protection_domain_table_work) {
198 SystemDictionary::pd_cache_table()->unlink();
199 }
200
201 if (oopstorage_work) {
202 cleanup_oopstorages(oopstorages, oopstorages_cleanup, oopstorage_count);
203 }
204 }
205 }
206
207 bool ServiceThread::is_service_thread(Thread* thread) {
208 return thread == _instance;
209 }
|
24
25 #include "precompiled.hpp"
26 #include "classfile/protectionDomainCache.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "memory/universe.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/interfaceSupport.inline.hpp"
33 #include "runtime/javaCalls.hpp"
34 #include "runtime/jniHandles.hpp"
35 #include "runtime/serviceThread.hpp"
36 #include "runtime/mutexLocker.hpp"
37 #include "runtime/os.hpp"
38 #include "prims/jvmtiImpl.hpp"
39 #include "prims/resolvedMethodTable.hpp"
40 #include "services/diagnosticArgument.hpp"
41 #include "services/diagnosticFramework.hpp"
42 #include "services/gcNotifier.hpp"
43 #include "services/lowMemoryDetector.hpp"
44 #include "services/threadTable.hpp"
45
46 ServiceThread* ServiceThread::_instance = NULL;
47
48 void ServiceThread::initialize() {
49 EXCEPTION_MARK;
50
51 const char* name = "Service Thread";
52 Handle string = java_lang_String::create_from_str(name, CHECK);
53
54 // Initialize thread_oop to put it into the system threadGroup
55 Handle thread_group (THREAD, Universe::system_thread_group());
56 Handle thread_oop = JavaCalls::construct_new_instance(
57 SystemDictionary::Thread_klass(),
58 vmSymbols::threadgroup_string_void_signature(),
59 thread_group,
60 string,
61 CHECK);
62
63 {
64 MutexLocker mu(Threads_lock);
108 }
109 }
110
111 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
112 OopStorage* const oopstorages[] = {
113 JNIHandles::global_handles(),
114 JNIHandles::weak_global_handles(),
115 StringTable::weak_storage(),
116 SystemDictionary::vm_weak_oop_storage()
117 };
118 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
119
120 while (true) {
121 bool sensors_changed = false;
122 bool has_jvmti_events = false;
123 bool has_gc_notification_event = false;
124 bool has_dcmd_notification_event = false;
125 bool stringtable_work = false;
126 bool symboltable_work = false;
127 bool resolved_method_table_work = false;
128 bool thread_table_work = false;
129 bool protection_domain_table_work = false;
130 bool oopstorage_work = false;
131 bool oopstorages_cleanup[oopstorage_count] = {}; // Zero (false) initialize.
132 JvmtiDeferredEvent jvmti_event;
133 {
134 // Need state transition ThreadBlockInVM so that this thread
135 // will be handled by safepoint correctly when this thread is
136 // notified at a safepoint.
137
138 // This ThreadBlockInVM object is not also considered to be
139 // suspend-equivalent because ServiceThread is not visible to
140 // external suspension.
141
142 ThreadBlockInVM tbivm(jt);
143
144 MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
145 // Process all available work on each (outer) iteration, rather than
146 // only the first recognized bit of work, to avoid frequently true early
147 // tests from potentially starving later work. Hence the use of
148 // arithmetic-or to combine results; we don't want short-circuiting.
149 while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
150 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
151 (has_gc_notification_event = GCNotifier::has_event()) |
152 (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
153 (stringtable_work = StringTable::has_work()) |
154 (symboltable_work = SymbolTable::has_work()) |
155 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
156 (thread_table_work = ThreadTable::has_work()) |
157 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
158 (oopstorage_work = needs_oopstorage_cleanup(oopstorages,
159 oopstorages_cleanup,
160 oopstorage_count)))
161
162 == 0) {
163 // Wait until notified that there is some work to do.
164 ml.wait();
165 }
166
167 if (has_jvmti_events) {
168 jvmti_event = JvmtiDeferredEventQueue::dequeue();
169 }
170 }
171
172 if (stringtable_work) {
173 StringTable::do_concurrent_work(jt);
174 }
175
176 if (symboltable_work) {
180 if (has_jvmti_events) {
181 jvmti_event.post();
182 }
183
184 if (sensors_changed) {
185 LowMemoryDetector::process_sensor_changes(jt);
186 }
187
188 if(has_gc_notification_event) {
189 GCNotifier::sendNotification(CHECK);
190 }
191
192 if(has_dcmd_notification_event) {
193 DCmdFactory::send_notification(CHECK);
194 }
195
196 if (resolved_method_table_work) {
197 ResolvedMethodTable::do_concurrent_work(jt);
198 }
199
200 if (thread_table_work) {
201 ThreadTable::do_concurrent_work(jt);
202 }
203
204 if (protection_domain_table_work) {
205 SystemDictionary::pd_cache_table()->unlink();
206 }
207
208 if (oopstorage_work) {
209 cleanup_oopstorages(oopstorages, oopstorages_cleanup, oopstorage_count);
210 }
211 }
212 }
213
214 bool ServiceThread::is_service_thread(Thread* thread) {
215 return thread == _instance;
216 }
|