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 "logging/logStream.hpp"
27 #include "memory/allocation.inline.hpp"
28 #include "runtime/jniHandles.inline.hpp"
29 #include "runtime/thread.inline.hpp"
30 #include "runtime/threadSMR.inline.hpp"
31 #include "services/threadService.hpp"
32 #include "utilities/copy.hpp"
33 #include "utilities/globalDefinitions.hpp"
34 #include "utilities/resourceHash.hpp"
35 #include "utilities/vmError.hpp"
36
37 Monitor* ThreadsSMRSupport::_delete_lock =
38 new Monitor(Monitor::special, "Thread_SMR_delete_lock",
39 false /* allow_vm_block */,
40 Monitor::_safepoint_check_never);
41 // The '_cnt', '_max' and '_times" fields are enabled via
42 // -XX:+EnableThreadSMRStatistics:
43
44 // # of parallel threads in _delete_lock->wait().
45 // Impl note: Hard to imagine > 64K waiting threads so this could be 16-bit,
46 // but there is no nice 16-bit _FORMAT support.
47 uint ThreadsSMRSupport::_delete_lock_wait_cnt = 0;
48
49 // Max # of parallel threads in _delete_lock->wait().
50 // Impl note: See _delete_lock_wait_cnt note.
452 uint i = (uint)list->find_index_of_JavaThread(java_thread);
453 assert(i < list->_length, "did not find JavaThread on the list");
454 const uint index = i;
455 const uint new_length = list->_length - 1;
456 const uint head_length = index;
457 const uint tail_length = (new_length >= index) ? (new_length - index) : 0;
458 ThreadsList *const new_list = new ThreadsList(new_length);
459
460 if (head_length > 0) {
461 Copy::disjoint_words((HeapWord*)list->_threads, (HeapWord*)new_list->_threads, head_length);
462 }
463 if (tail_length > 0) {
464 Copy::disjoint_words((HeapWord*)list->_threads + index + 1, (HeapWord*)new_list->_threads + index, tail_length);
465 }
466
467 return new_list;
468 }
469
470 ThreadsListHandle::ThreadsListHandle(Thread *self) : _list(ThreadsSMRSupport::acquire_stable_list(self, /* is_ThreadsListSetter */ false)), _self(self) {
471 assert(self == Thread::current(), "sanity check");
472 if (EnableThreadSMRStatistics) {
473 _timer.start();
474 }
475 }
476
477 ThreadsListHandle::~ThreadsListHandle() {
478 ThreadsSMRSupport::release_stable_list(_self);
479 if (EnableThreadSMRStatistics) {
480 _timer.stop();
481 uint millis = (uint)_timer.milliseconds();
482 ThreadsSMRSupport::update_tlh_stats(millis);
483 }
484 }
485
486 // Convert an internal thread reference to a JavaThread found on the
487 // associated ThreadsList. This ThreadsListHandle "protects" the
488 // returned JavaThread *.
489 //
490 // If thread_oop_p is not NULL, then the caller wants to use the oop
491 // after this call so the oop is returned. On success, *jt_pp is set
|
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 "logging/logStream.hpp"
27 #include "memory/allocation.inline.hpp"
28 #include "runtime/jniHandles.inline.hpp"
29 #include "runtime/thread.inline.hpp"
30 #include "runtime/threadSMR.inline.hpp"
31 #include "runtime/vm_operations.hpp"
32 #include "services/threadService.hpp"
33 #include "utilities/copy.hpp"
34 #include "utilities/globalDefinitions.hpp"
35 #include "utilities/resourceHash.hpp"
36 #include "utilities/vmError.hpp"
37
38 Monitor* ThreadsSMRSupport::_delete_lock =
39 new Monitor(Monitor::special, "Thread_SMR_delete_lock",
40 false /* allow_vm_block */,
41 Monitor::_safepoint_check_never);
42 // The '_cnt', '_max' and '_times" fields are enabled via
43 // -XX:+EnableThreadSMRStatistics:
44
45 // # of parallel threads in _delete_lock->wait().
46 // Impl note: Hard to imagine > 64K waiting threads so this could be 16-bit,
47 // but there is no nice 16-bit _FORMAT support.
48 uint ThreadsSMRSupport::_delete_lock_wait_cnt = 0;
49
50 // Max # of parallel threads in _delete_lock->wait().
51 // Impl note: See _delete_lock_wait_cnt note.
453 uint i = (uint)list->find_index_of_JavaThread(java_thread);
454 assert(i < list->_length, "did not find JavaThread on the list");
455 const uint index = i;
456 const uint new_length = list->_length - 1;
457 const uint head_length = index;
458 const uint tail_length = (new_length >= index) ? (new_length - index) : 0;
459 ThreadsList *const new_list = new ThreadsList(new_length);
460
461 if (head_length > 0) {
462 Copy::disjoint_words((HeapWord*)list->_threads, (HeapWord*)new_list->_threads, head_length);
463 }
464 if (tail_length > 0) {
465 Copy::disjoint_words((HeapWord*)list->_threads + index + 1, (HeapWord*)new_list->_threads + index, tail_length);
466 }
467
468 return new_list;
469 }
470
471 ThreadsListHandle::ThreadsListHandle(Thread *self) : _list(ThreadsSMRSupport::acquire_stable_list(self, /* is_ThreadsListSetter */ false)), _self(self) {
472 assert(self == Thread::current(), "sanity check");
473 // Threads::threads_do() is used by the Thread-SMR protocol to visit all
474 // Threads in the system which ensures the safety of the ThreadsList
475 // managed by this ThreadsListHandle, but JavaThreads that are not on
476 // the Threads list cannot be included in that visit. The JavaThread that
477 // calls Threads::destroy_vm() is exempt from this check because it has
478 // to logically exit as part of the shutdown procedure. This is safe
479 // because VM_Exit::_shutdown_thread is not set until after the VMThread
480 // has started the final safepoint which holds the Threads_lock for the
481 // remainder of the VM's life.
482 assert(!self->is_Java_thread() || self == VM_Exit::shutdown_thread() || (((JavaThread*)self)->on_thread_list() && !((JavaThread*)self)->is_terminated()), "JavaThread must be on the Threads list to use a ThreadsListHandle");
483 if (EnableThreadSMRStatistics) {
484 _timer.start();
485 }
486 }
487
488 ThreadsListHandle::~ThreadsListHandle() {
489 ThreadsSMRSupport::release_stable_list(_self);
490 if (EnableThreadSMRStatistics) {
491 _timer.stop();
492 uint millis = (uint)_timer.milliseconds();
493 ThreadsSMRSupport::update_tlh_stats(millis);
494 }
495 }
496
497 // Convert an internal thread reference to a JavaThread found on the
498 // associated ThreadsList. This ThreadsListHandle "protects" the
499 // returned JavaThread *.
500 //
501 // If thread_oop_p is not NULL, then the caller wants to use the oop
502 // after this call so the oop is returned. On success, *jt_pp is set
|