120 _thread_alive = true;
121 }
122 }
123
124 if (!_thread_alive) {
125 return;
126 }
127
128 if (!UseMembar) {
129 os::serialize_thread_states();
130 }
131
132 log_trace(handshake)("Thread signaled, begin processing by VMThtread");
133 jlong start_time = os::elapsed_counter();
134 do {
135 if (handshake_has_timed_out(start_time)) {
136 handle_timeout();
137 }
138
139 // We need to re-think this with SMR ThreadsList.
140 // There is assumption in code that Threads_lock should be lock
141 // during certain phases.
142 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag);
143 ThreadsListHandle tlh;
144 if (tlh.includes(_target)) {
145 // Warning threads address might be re-used.
146 // handshake_process_by_vmthread will check the semaphore for us again
147 // Since we can't have more then one handshake in flight a reuse of thread address
148 // should be okey since the new thread will not have an operation.
149 _target->handshake_process_by_vmthread();
150 } else {
151 // We can't warn here is since the thread do cancel_handshake after it have been removed
152 // from ThreadsList. So we should just keep looping here until while below return negative
153 // If we have a bug, then we deadlock here, which is good for debugging.
154 }
155
156 } while (!poll_for_completed_thread());
157 }
158
159 VMOp_Type type() const { return VMOp_HandshakeOneThread; }
160
161 bool thread_alive() const { return _thread_alive; }
162 };
163
164 class VM_HandshakeAllThreads: public VM_Handshake {
165 public:
166 VM_HandshakeAllThreads(HandshakeThreadsOperation* op) : VM_Handshake(op) {}
167
168 void doit() {
169 TraceTime timer("Performing operation (vmoperation doit)", TRACETIME_LOG(Info, handshake));
170
171 int number_of_threads_issued = 0;
172 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
173 set_handshake(thr);
174 number_of_threads_issued++;
175 }
180 }
181
182 if (!UseMembar) {
183 os::serialize_thread_states();
184 }
185
186 log_debug(handshake)("Threads signaled, begin processing blocked threads by VMThtread");
187 const jlong start_time = os::elapsed_counter();
188 int number_of_threads_completed = 0;
189 do {
190 // Check if handshake operation has timed out
191 if (handshake_has_timed_out(start_time)) {
192 handle_timeout();
193 }
194
195 // Have VM thread perform the handshake operation for blocked threads.
196 // Observing a blocked state may of course be transient but the processing is guarded
197 // by semaphores and we optimistically begin by working on the blocked threads
198 {
199 // We need to re-think this with SMR ThreadsList.
200 // There is assumption in code that Threads_lock should be lock
201 // during certain phases.
202 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag);
203 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
204 // A new thread on the ThreadsList will not have an operation.
205 // Hence is skipped in handshake_process_by_vmthread.
206 thr->handshake_process_by_vmthread();
207 }
208 }
209
210 while (poll_for_completed_thread()) {
211 // Includes canceled operations by exiting threads.
212 number_of_threads_completed++;
213 }
214
215 } while (number_of_threads_issued != number_of_threads_completed);
216 }
217
218 VMOp_Type type() const { return VMOp_HandshakeAllThreads; }
219 };
220
221 class VM_HandshakeFallbackOperation : public VM_Operation {
222 ThreadClosure* _thread_cl;
223 Thread* _target_thread;
224 bool _all_threads;
225 bool _thread_alive;
|
120 _thread_alive = true;
121 }
122 }
123
124 if (!_thread_alive) {
125 return;
126 }
127
128 if (!UseMembar) {
129 os::serialize_thread_states();
130 }
131
132 log_trace(handshake)("Thread signaled, begin processing by VMThtread");
133 jlong start_time = os::elapsed_counter();
134 do {
135 if (handshake_has_timed_out(start_time)) {
136 handle_timeout();
137 }
138
139 // We need to re-think this with SMR ThreadsList.
140 // There is an assumption in the code that the Threads_lock should be
141 // locked during certain phases.
142 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag);
143 ThreadsListHandle tlh;
144 if (tlh.includes(_target)) {
145 // Warning _target's address might be re-used.
146 // handshake_process_by_vmthread will check the semaphore for us again.
147 // Since we can't have more then one handshake in flight a reuse of
148 // _target's address should be okay since the new thread will not have
149 // an operation.
150 _target->handshake_process_by_vmthread();
151 } else {
152 // We can't warn here since the thread does cancel_handshake after
153 // it has been removed from the ThreadsList. So we should just keep
154 // looping here until while below returns false. If we have a bug,
155 // then we hang here, which is good for debugging.
156 }
157 } while (!poll_for_completed_thread());
158 }
159
160 VMOp_Type type() const { return VMOp_HandshakeOneThread; }
161
162 bool thread_alive() const { return _thread_alive; }
163 };
164
165 class VM_HandshakeAllThreads: public VM_Handshake {
166 public:
167 VM_HandshakeAllThreads(HandshakeThreadsOperation* op) : VM_Handshake(op) {}
168
169 void doit() {
170 TraceTime timer("Performing operation (vmoperation doit)", TRACETIME_LOG(Info, handshake));
171
172 int number_of_threads_issued = 0;
173 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
174 set_handshake(thr);
175 number_of_threads_issued++;
176 }
181 }
182
183 if (!UseMembar) {
184 os::serialize_thread_states();
185 }
186
187 log_debug(handshake)("Threads signaled, begin processing blocked threads by VMThtread");
188 const jlong start_time = os::elapsed_counter();
189 int number_of_threads_completed = 0;
190 do {
191 // Check if handshake operation has timed out
192 if (handshake_has_timed_out(start_time)) {
193 handle_timeout();
194 }
195
196 // Have VM thread perform the handshake operation for blocked threads.
197 // Observing a blocked state may of course be transient but the processing is guarded
198 // by semaphores and we optimistically begin by working on the blocked threads
199 {
200 // We need to re-think this with SMR ThreadsList.
201 // There is an assumption in the code that the Threads_lock should
202 // be locked during certain phases.
203 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag);
204 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
205 // A new thread on the ThreadsList will not have an operation,
206 // hence it is skipped in handshake_process_by_vmthread.
207 thr->handshake_process_by_vmthread();
208 }
209 }
210
211 while (poll_for_completed_thread()) {
212 // Includes canceled operations by exiting threads.
213 number_of_threads_completed++;
214 }
215
216 } while (number_of_threads_issued != number_of_threads_completed);
217 }
218
219 VMOp_Type type() const { return VMOp_HandshakeAllThreads; }
220 };
221
222 class VM_HandshakeFallbackOperation : public VM_Operation {
223 ThreadClosure* _thread_cl;
224 Thread* _target_thread;
225 bool _all_threads;
226 bool _thread_alive;
|