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