equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
345 assert(Threads_lock->owned_by_self(), "Not holding Threads_lock."); |
345 assert(Threads_lock->owned_by_self(), "Not holding Threads_lock."); |
346 return SafepointSynchronize::safepoint_safe(target, target->thread_state()) || |
346 return SafepointSynchronize::safepoint_safe(target, target->thread_state()) || |
347 target->is_ext_suspended(); |
347 target->is_ext_suspended(); |
348 } |
348 } |
349 |
349 |
|
350 static bool possibly_vmthread_can_process_handshake(JavaThread* target) { |
|
351 // An externally suspended thread cannot be resumed while the |
|
352 // Threads_lock is held so it is safe. |
|
353 // Note that this method is allowed to produce false positives. |
|
354 assert(Threads_lock->owned_by_self(), "Not holding Threads_lock."); |
|
355 if (target->is_ext_suspended()) { |
|
356 return true; |
|
357 } |
|
358 switch (target->thread_state()) { |
|
359 case _thread_in_native: |
|
360 // native threads are safe if they have no java stack or have walkable stack |
|
361 return !target->has_last_Java_frame() || target->frame_anchor()->walkable(); |
|
362 |
|
363 case _thread_blocked: |
|
364 return true; |
|
365 |
|
366 default: |
|
367 return false; |
|
368 } |
|
369 } |
|
370 |
350 bool HandshakeState::claim_handshake_for_vmthread() { |
371 bool HandshakeState::claim_handshake_for_vmthread() { |
351 if (!_semaphore.trywait()) { |
372 if (!_semaphore.trywait()) { |
352 return false; |
373 return false; |
353 } |
374 } |
354 if (has_operation()) { |
375 if (has_operation()) { |
364 if (!has_operation()) { |
385 if (!has_operation()) { |
365 // JT has already cleared its handshake |
386 // JT has already cleared its handshake |
366 return; |
387 return; |
367 } |
388 } |
368 |
389 |
369 if (!vmthread_can_process_handshake(target)) { |
390 if (!possibly_vmthread_can_process_handshake(target)) { |
370 // JT is observed in an unsafe state, it must notice the handshake itself |
391 // JT is observed in an unsafe state, it must notice the handshake itself |
371 return; |
392 return; |
372 } |
393 } |
373 |
394 |
374 // Claim the semaphore if there still an operation to be executed. |
395 // Claim the semaphore if there still an operation to be executed. |