src/hotspot/share/runtime/threadSMR.cpp
author dcubed
Wed, 02 May 2018 16:47:40 -0400
changeset 49956 a87f2e7a527c
parent 49756 129d60b5dac7
child 50718 5698cf4e50f1
permissions -rw-r--r--
8191798: redo nested ThreadsListHandle to drop Threads_lock Summary: Refactor Thread hazard ptrs and nested ThreadsLists into SafeThreadsListPtr. Reviewed-by: dcubed, eosterlund, rehn Contributed-by: erik.osterlund@oracle.com, daniel.daugherty@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     1
/*
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     4
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     8
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    13
 * accompanied this code).
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    14
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    18
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    21
 * questions.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    22
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    23
 */
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    24
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    25
#include "precompiled.hpp"
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    26
#include "logging/logStream.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    27
#include "memory/allocation.inline.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48382
diff changeset
    28
#include "runtime/jniHandles.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    29
#include "runtime/thread.inline.hpp"
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    30
#include "runtime/threadSMR.inline.hpp"
49636
6d5bd76650df 8199813: SIGSEGV in ThreadsList::includes()
dcubed
parents: 49476
diff changeset
    31
#include "runtime/vm_operations.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    32
#include "services/threadService.hpp"
49476
1f904e305a05 8195109: ServiceUtil::visible_oop is not needed anymore
cjplummer
parents: 49192
diff changeset
    33
#include "utilities/copy.hpp"
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    34
#include "utilities/globalDefinitions.hpp"
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    35
#include "utilities/ostream.hpp"
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    36
#include "utilities/resourceHash.hpp"
49476
1f904e305a05 8195109: ServiceUtil::visible_oop is not needed anymore
cjplummer
parents: 49192
diff changeset
    37
#include "utilities/vmError.hpp"
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    38
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    39
Monitor*              ThreadsSMRSupport::_delete_lock =
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    40
                          new Monitor(Monitor::special, "Thread_SMR_delete_lock",
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    41
                                      false /* allow_vm_block */,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    42
                                      Monitor::_safepoint_check_never);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    43
// The '_cnt', '_max' and '_times" fields are enabled via
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    44
// -XX:+EnableThreadSMRStatistics:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    45
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    46
// # of parallel threads in _delete_lock->wait().
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    47
// Impl note: Hard to imagine > 64K waiting threads so this could be 16-bit,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    48
// but there is no nice 16-bit _FORMAT support.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    49
uint                  ThreadsSMRSupport::_delete_lock_wait_cnt = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    50
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    51
// Max # of parallel threads in _delete_lock->wait().
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    52
// Impl note: See _delete_lock_wait_cnt note.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    53
uint                  ThreadsSMRSupport::_delete_lock_wait_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    54
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    55
// Flag to indicate when an _delete_lock->notify() is needed.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    56
// Impl note: See _delete_lock_wait_cnt note.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    57
volatile uint         ThreadsSMRSupport::_delete_notify = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    58
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    59
// # of threads deleted over VM lifetime.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    60
// Impl note: Atomically incremented over VM lifetime so use unsigned for more
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    61
// range. Unsigned 64-bit would be more future proof, but 64-bit atomic inc
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    62
// isn't available everywhere (or is it?).
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    63
volatile uint         ThreadsSMRSupport::_deleted_thread_cnt = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    64
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    65
// Max time in millis to delete a thread.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    66
// Impl note: 16-bit might be too small on an overloaded machine. Use
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    67
// unsigned since this is a time value. Set via Atomic::cmpxchg() in a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    68
// loop for correctness.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    69
volatile uint         ThreadsSMRSupport::_deleted_thread_time_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    70
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    71
// Cumulative time in millis to delete threads.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    72
// Impl note: Atomically added to over VM lifetime so use unsigned for more
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    73
// range. Unsigned 64-bit would be more future proof, but 64-bit atomic inc
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    74
// isn't available everywhere (or is it?).
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    75
volatile uint         ThreadsSMRSupport::_deleted_thread_times = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    76
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    77
ThreadsList* volatile ThreadsSMRSupport::_java_thread_list = new ThreadsList(0);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    78
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    79
// # of ThreadsLists allocated over VM lifetime.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    80
// Impl note: We allocate a new ThreadsList for every thread create and
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    81
// every thread delete so we need a bigger type than the
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    82
// _deleted_thread_cnt field.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    83
uint64_t              ThreadsSMRSupport::_java_thread_list_alloc_cnt = 1;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    84
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    85
// # of ThreadsLists freed over VM lifetime.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    86
// Impl note: See _java_thread_list_alloc_cnt note.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    87
uint64_t              ThreadsSMRSupport::_java_thread_list_free_cnt = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    88
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    89
// Max size ThreadsList allocated.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    90
// Impl note: Max # of threads alive at one time should fit in unsigned 32-bit.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    91
uint                  ThreadsSMRSupport::_java_thread_list_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    92
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    93
// Max # of nested ThreadsLists for a thread.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    94
// Impl note: Hard to imagine > 64K nested ThreadsLists so this could be
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    95
// 16-bit, but there is no nice 16-bit _FORMAT support.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    96
uint                  ThreadsSMRSupport::_nested_thread_list_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    97
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    98
// # of ThreadsListHandles deleted over VM lifetime.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    99
// Impl note: Atomically incremented over VM lifetime so use unsigned for
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   100
// more range. There will be fewer ThreadsListHandles than threads so
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   101
// unsigned 32-bit should be fine.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   102
volatile uint         ThreadsSMRSupport::_tlh_cnt = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   103
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   104
// Max time in millis to delete a ThreadsListHandle.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   105
// Impl note: 16-bit might be too small on an overloaded machine. Use
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   106
// unsigned since this is a time value. Set via Atomic::cmpxchg() in a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   107
// loop for correctness.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   108
volatile uint         ThreadsSMRSupport::_tlh_time_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   109
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   110
// Cumulative time in millis to delete ThreadsListHandles.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   111
// Impl note: Atomically added to over VM lifetime so use unsigned for more
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   112
// range. Unsigned 64-bit would be more future proof, but 64-bit atomic inc
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   113
// isn't available everywhere (or is it?).
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   114
volatile uint         ThreadsSMRSupport::_tlh_times = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   115
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   116
ThreadsList*          ThreadsSMRSupport::_to_delete_list = NULL;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   117
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   118
// # of parallel ThreadsLists on the to-delete list.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   119
// Impl note: Hard to imagine > 64K ThreadsLists needing to be deleted so
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   120
// this could be 16-bit, but there is no nice 16-bit _FORMAT support.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   121
uint                  ThreadsSMRSupport::_to_delete_list_cnt = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   122
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   123
// Max # of parallel ThreadsLists on the to-delete list.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   124
// Impl note: See _to_delete_list_cnt note.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   125
uint                  ThreadsSMRSupport::_to_delete_list_max = 0;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   126
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   127
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   128
// 'inline' functions first so the definitions are before first use:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   129
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   130
inline void ThreadsSMRSupport::add_deleted_thread_times(uint add_value) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   131
  Atomic::add(add_value, &_deleted_thread_times);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   132
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   133
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   134
inline void ThreadsSMRSupport::inc_deleted_thread_cnt() {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   135
  Atomic::inc(&_deleted_thread_cnt);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   136
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   137
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   138
inline void ThreadsSMRSupport::inc_java_thread_list_alloc_cnt() {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   139
  _java_thread_list_alloc_cnt++;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   140
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   141
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   142
inline void ThreadsSMRSupport::update_deleted_thread_time_max(uint new_value) {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   143
  while (true) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   144
    uint cur_value = _deleted_thread_time_max;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   145
    if (new_value <= cur_value) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   146
      // No need to update max value so we're done.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   147
      break;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   148
    }
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   149
    if (Atomic::cmpxchg(new_value, &_deleted_thread_time_max, cur_value) == cur_value) {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   150
      // Updated max value so we're done. Otherwise try it all again.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   151
      break;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   152
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   153
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   154
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   155
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   156
inline void ThreadsSMRSupport::update_java_thread_list_max(uint new_value) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   157
  if (new_value > _java_thread_list_max) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   158
    _java_thread_list_max = new_value;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   159
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   160
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   161
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   162
inline ThreadsList* ThreadsSMRSupport::xchg_java_thread_list(ThreadsList* new_list) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   163
  return (ThreadsList*)Atomic::xchg(new_list, &_java_thread_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   164
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   165
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   166
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   167
// Hash table of pointers found by a scan. Used for collecting hazard
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   168
// pointers (ThreadsList references). Also used for collecting JavaThreads
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   169
// that are indirectly referenced by hazard ptrs. An instance of this
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   170
// class only contains one type of pointer.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   171
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   172
class ThreadScanHashtable : public CHeapObj<mtThread> {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   173
 private:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   174
  static bool ptr_equals(void * const& s1, void * const& s2) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   175
    return s1 == s2;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   176
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   177
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   178
  static unsigned int ptr_hash(void * const& s1) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   179
    // 2654435761 = 2^32 * Phi (golden ratio)
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   180
    return (unsigned int)(((uint32_t)(uintptr_t)s1) * 2654435761u);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   181
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   182
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   183
  int _table_size;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   184
  // ResourceHashtable SIZE is specified at compile time so our
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   185
  // dynamic _table_size is unused for now; 1031 is the first prime
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   186
  // after 1024.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   187
  typedef ResourceHashtable<void *, int, &ThreadScanHashtable::ptr_hash,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   188
                            &ThreadScanHashtable::ptr_equals, 1031,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   189
                            ResourceObj::C_HEAP, mtThread> PtrTable;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   190
  PtrTable * _ptrs;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   191
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   192
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   193
  // ResourceHashtable is passed to various functions and populated in
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   194
  // different places so we allocate it using C_HEAP to make it immune
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   195
  // from any ResourceMarks that happen to be in the code paths.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   196
  ThreadScanHashtable(int table_size) : _table_size(table_size), _ptrs(new (ResourceObj::C_HEAP, mtThread) PtrTable()) {}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   197
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   198
  ~ThreadScanHashtable() { delete _ptrs; }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   199
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   200
  bool has_entry(void *pointer) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   201
    int *val_ptr = _ptrs->get(pointer);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   202
    return val_ptr != NULL && *val_ptr == 1;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   203
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   204
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   205
  void add_entry(void *pointer) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   206
    _ptrs->put(pointer, 1);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   207
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   208
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   209
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   210
// Closure to gather JavaThreads indirectly referenced by hazard ptrs
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   211
// (ThreadsList references) into a hash table. This closure handles part 2
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   212
// of the dance - adding all the JavaThreads referenced by the hazard
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   213
// pointer (ThreadsList reference) to the hash table.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   214
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   215
class AddThreadHazardPointerThreadClosure : public ThreadClosure {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   216
 private:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   217
  ThreadScanHashtable *_table;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   218
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   219
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   220
  AddThreadHazardPointerThreadClosure(ThreadScanHashtable *table) : _table(table) {}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   221
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   222
  virtual void do_thread(Thread *thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   223
    if (!_table->has_entry((void*)thread)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   224
      // The same JavaThread might be on more than one ThreadsList or
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   225
      // more than one thread might be using the same ThreadsList. In
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   226
      // either case, we only need a single entry for a JavaThread.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   227
      _table->add_entry((void*)thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   228
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   229
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   230
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   231
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   232
// Closure to gather JavaThreads indirectly referenced by hazard ptrs
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   233
// (ThreadsList references) into a hash table. This closure handles part 1
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   234
// of the dance - hazard ptr chain walking and dispatch to another
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   235
// closure.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   236
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   237
class ScanHazardPtrGatherProtectedThreadsClosure : public ThreadClosure {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   238
 private:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   239
  ThreadScanHashtable *_table;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   240
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   241
  ScanHazardPtrGatherProtectedThreadsClosure(ThreadScanHashtable *table) : _table(table) {}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   242
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   243
  virtual void do_thread(Thread *thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   244
    assert_locked_or_safepoint(Threads_lock);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   245
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   246
    if (thread == NULL) return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   247
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   248
    // This code races with ThreadsSMRSupport::acquire_stable_list() which
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   249
    // is lock-free so we have to handle some special situations.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   250
    //
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   251
    ThreadsList *current_list = NULL;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   252
    while (true) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   253
      current_list = thread->get_threads_hazard_ptr();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   254
      // No hazard ptr so nothing more to do.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   255
      if (current_list == NULL) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   256
        return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   257
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   258
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   259
      // If the hazard ptr is verified as stable (since it is not tagged),
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   260
      // then it is safe to use.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   261
      if (!Thread::is_hazard_ptr_tagged(current_list)) break;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   262
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   263
      // The hazard ptr is tagged as not yet verified as being stable
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   264
      // so we are racing with acquire_stable_list(). This exchange
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   265
      // attempts to invalidate the hazard ptr. If we win the race,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   266
      // then we can ignore this unstable hazard ptr and the other
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   267
      // thread will retry the attempt to publish a stable hazard ptr.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   268
      // If we lose the race, then we retry our attempt to look at the
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   269
      // hazard ptr.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   270
      if (thread->cmpxchg_threads_hazard_ptr(NULL, current_list) == current_list) return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   271
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   272
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   273
    // The current JavaThread has a hazard ptr (ThreadsList reference)
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   274
    // which might be _java_thread_list or it might be an older
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   275
    // ThreadsList that has been removed but not freed. In either case,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   276
    // the hazard ptr is protecting all the JavaThreads on that
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   277
    // ThreadsList.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   278
    AddThreadHazardPointerThreadClosure add_cl(_table);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   279
    current_list->threads_do(&add_cl);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   280
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   281
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   282
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   283
// Closure to gather hazard ptrs (ThreadsList references) into a hash table.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   284
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   285
class ScanHazardPtrGatherThreadsListClosure : public ThreadClosure {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   286
 private:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   287
  ThreadScanHashtable *_table;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   288
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   289
  ScanHazardPtrGatherThreadsListClosure(ThreadScanHashtable *table) : _table(table) {}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   290
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   291
  virtual void do_thread(Thread* thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   292
    assert_locked_or_safepoint(Threads_lock);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   293
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   294
    if (thread == NULL) return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   295
    ThreadsList *threads = thread->get_threads_hazard_ptr();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   296
    if (threads == NULL) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   297
      return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   298
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   299
    // In this closure we always ignore the tag that might mark this
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   300
    // hazard ptr as not yet verified. If we happen to catch an
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   301
    // unverified hazard ptr that is subsequently discarded (not
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   302
    // published), then the only side effect is that we might keep a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   303
    // to-be-deleted ThreadsList alive a little longer.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   304
    threads = Thread::untag_hazard_ptr(threads);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   305
    if (!_table->has_entry((void*)threads)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   306
      _table->add_entry((void*)threads);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   307
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   308
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   309
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   310
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   311
// Closure to print JavaThreads that have a hazard ptr (ThreadsList
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   312
// reference) that contains an indirect reference to a specific JavaThread.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   313
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   314
class ScanHazardPtrPrintMatchingThreadsClosure : public ThreadClosure {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   315
 private:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   316
  JavaThread *_thread;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   317
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   318
  ScanHazardPtrPrintMatchingThreadsClosure(JavaThread *thread) : _thread(thread) {}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   319
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   320
  virtual void do_thread(Thread *thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   321
    assert_locked_or_safepoint(Threads_lock);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   322
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   323
    if (thread == NULL) return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   324
    ThreadsList *current_list = thread->get_threads_hazard_ptr();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   325
    if (current_list == NULL) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   326
      return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   327
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   328
    // If the hazard ptr is unverified, then ignore it.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   329
    if (Thread::is_hazard_ptr_tagged(current_list)) return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   330
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   331
    // The current JavaThread has a hazard ptr (ThreadsList reference)
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   332
    // which might be _java_thread_list or it might be an older
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   333
    // ThreadsList that has been removed but not freed. In either case,
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   334
    // the hazard ptr is protecting all the JavaThreads on that
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   335
    // ThreadsList, but we only care about matching a specific JavaThread.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   336
    JavaThreadIterator jti(current_list);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   337
    for (JavaThread *p = jti.first(); p != NULL; p = jti.next()) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   338
      if (p == _thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   339
        log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::smr_delete: thread1=" INTPTR_FORMAT " has a hazard pointer for thread2=" INTPTR_FORMAT, os::current_thread_id(), p2i(thread), p2i(_thread));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   340
        break;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   341
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   342
    }
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   343
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   344
};
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   345
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   346
// Closure to determine if the specified JavaThread is found by
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   347
// threads_do().
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   348
//
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   349
class VerifyHazardPtrThreadClosure : public ThreadClosure {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   350
 private:
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   351
  bool _found;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   352
  Thread *_self;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   353
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   354
 public:
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   355
  VerifyHazardPtrThreadClosure(Thread *self) : _found(false), _self(self) {}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   356
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   357
  bool found() const { return _found; }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   358
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   359
  virtual void do_thread(Thread *thread) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   360
    if (thread == _self) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   361
      _found = true;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   362
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   363
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   364
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   365
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   366
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   367
// Acquire a stable ThreadsList.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   368
//
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   369
void SafeThreadsListPtr::acquire_stable_list() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   370
  assert(_thread != NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   371
  _needs_release = true;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   372
  _previous = _thread->_threads_list_ptr;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   373
  _thread->_threads_list_ptr = this;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   374
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   375
  if (_thread->get_threads_hazard_ptr() == NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   376
    // The typical case is first.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   377
    acquire_stable_list_fast_path();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   378
    return;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   379
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   380
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   381
  // The nested case is rare.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   382
  acquire_stable_list_nested_path();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   383
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   384
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   385
// Fast path way to acquire a stable ThreadsList.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   386
//
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   387
void SafeThreadsListPtr::acquire_stable_list_fast_path() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   388
  assert(_thread != NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   389
  assert(_thread->get_threads_hazard_ptr() == NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   390
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   391
  ThreadsList* threads;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   392
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   393
  // Stable recording of a hazard ptr for SMR. This code does not use
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   394
  // locks so its use of the _smr_java_thread_list & _threads_hazard_ptr
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   395
  // fields is racy relative to code that uses those fields with locks.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   396
  // OrderAccess and Atomic functions are used to deal with those races.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   397
  //
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   398
  while (true) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   399
    threads = ThreadsSMRSupport::get_java_thread_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   400
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   401
    // Publish a tagged hazard ptr to denote that the hazard ptr is not
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   402
    // yet verified as being stable. Due to the fence after the hazard
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   403
    // ptr write, it will be sequentially consistent w.r.t. the
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   404
    // sequentially consistent writes of the ThreadsList, even on
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   405
    // non-multiple copy atomic machines where stores can be observed
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   406
    // in different order from different observer threads.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   407
    ThreadsList* unverified_threads = Thread::tag_hazard_ptr(threads);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   408
    _thread->set_threads_hazard_ptr(unverified_threads);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   409
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   410
    // If _smr_java_thread_list has changed, we have lost a race with
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   411
    // Threads::add() or Threads::remove() and have to try again.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   412
    if (ThreadsSMRSupport::get_java_thread_list() != threads) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   413
      continue;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   414
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   415
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   416
    // We try to remove the tag which will verify the hazard ptr as
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   417
    // being stable. This exchange can race with a scanning thread
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   418
    // which might invalidate the tagged hazard ptr to keep it from
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   419
    // being followed to access JavaThread ptrs. If we lose the race,
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   420
    // we simply retry. If we win the race, then the stable hazard
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   421
    // ptr is officially published.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   422
    if (_thread->cmpxchg_threads_hazard_ptr(threads, unverified_threads) == unverified_threads) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   423
      break;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   424
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   425
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   426
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   427
  // A stable hazard ptr has been published letting other threads know
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   428
  // that the ThreadsList and the JavaThreads reachable from this list
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   429
  // are protected and hence they should not be deleted until everyone
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   430
  // agrees it is safe to do so.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   431
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   432
  _list = threads;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   433
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   434
  verify_hazard_ptr_scanned();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   435
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   436
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   437
// Acquire a nested stable ThreadsList; this is rare so it uses
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   438
// reference counting.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   439
//
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   440
void SafeThreadsListPtr::acquire_stable_list_nested_path() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   441
  assert(_thread != NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   442
  assert(_thread->get_threads_hazard_ptr() != NULL,
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   443
         "cannot have a NULL regular hazard ptr when acquiring a nested hazard ptr");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   444
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   445
  // The thread already has a hazard ptr (ThreadsList ref) so we need
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   446
  // to create a nested ThreadsListHandle with the current ThreadsList
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   447
  // since it might be different than our current hazard ptr. To remedy
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   448
  // the situation, the ThreadsList pointed to by the pre-existing
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   449
  // stable hazard ptr is reference counted before the hazard ptr may
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   450
  // be released and moved to a new ThreadsList. The old ThreadsList
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   451
  // is remembered in the ThreadsListHandle.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   452
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   453
  ThreadsList* current_list = _previous->_list;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   454
  if (EnableThreadSMRStatistics) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   455
    _thread->inc_nested_threads_hazard_ptr_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   456
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   457
  current_list->inc_nested_handle_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   458
  _previous->_has_ref_count = true;  // promote SafeThreadsListPtr to be reference counted
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   459
  _thread->_threads_hazard_ptr = NULL;  // clear the hazard ptr so we can go through the fast path below
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   460
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   461
  if (EnableThreadSMRStatistics && _thread->nested_threads_hazard_ptr_cnt() > ThreadsSMRSupport::_nested_thread_list_max) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   462
    ThreadsSMRSupport::_nested_thread_list_max = _thread->nested_threads_hazard_ptr_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   463
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   464
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   465
  acquire_stable_list_fast_path();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   466
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   467
  verify_hazard_ptr_scanned();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   468
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   469
  log_debug(thread, smr)("tid=" UINTX_FORMAT ": SafeThreadsListPtr::acquire_stable_list: add nested list pointer to ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(_list));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   470
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   471
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   472
// Release a stable ThreadsList.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   473
//
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   474
void SafeThreadsListPtr::release_stable_list() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   475
  assert(_thread != NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   476
  assert(_thread->_threads_list_ptr == this, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   477
  _thread->_threads_list_ptr = _previous;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   478
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   479
  if (_has_ref_count) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   480
    // If a SafeThreadsListPtr has been promoted to use reference counting
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   481
    // due to nesting of ThreadsListHandles, then the reference count must be
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   482
    // decremented, at which point it may be freed. The forgotten value of
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   483
    // the list no longer matters at this point and should already be NULL.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   484
    assert(_thread->get_threads_hazard_ptr() == NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   485
    if (EnableThreadSMRStatistics) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   486
      _thread->dec_nested_threads_hazard_ptr_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   487
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   488
    _list->dec_nested_handle_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   489
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   490
    log_debug(thread, smr)("tid=" UINTX_FORMAT ": SafeThreadsListPtr::release_stable_list: delete nested list pointer to ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(_list));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   491
  } else {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   492
    // The normal case: a leaf ThreadsListHandle. This merely requires setting
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   493
    // the thread hazard ptr back to NULL.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   494
    assert(_thread->get_threads_hazard_ptr() != NULL, "sanity check");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   495
    _thread->set_threads_hazard_ptr(NULL);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   496
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   497
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   498
  // After releasing the hazard ptr, other threads may go ahead and
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   499
  // free up some memory temporarily used by a ThreadsList snapshot.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   500
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   501
  // We use double-check locking to reduce traffic on the system
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   502
  // wide Thread-SMR delete_lock.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   503
  if (ThreadsSMRSupport::delete_notify()) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   504
    // An exiting thread might be waiting in smr_delete(); we need to
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   505
    // check with delete_lock to be sure.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   506
    ThreadsSMRSupport::release_stable_list_wake_up(_has_ref_count);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   507
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   508
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   509
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   510
// Verify that the stable hazard ptr used to safely keep threads
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   511
// alive is scanned by threads_do() which is a key piece of honoring
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   512
// the Thread-SMR protocol.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   513
void SafeThreadsListPtr::verify_hazard_ptr_scanned() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   514
#ifdef ASSERT
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   515
  assert(_list != NULL, "_list must not be NULL");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   516
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   517
  // The closure will attempt to verify that the calling thread can
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   518
  // be found by threads_do() on the specified ThreadsList. If it
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   519
  // is successful, then the specified ThreadsList was acquired as
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   520
  // a stable hazard ptr by the calling thread in a way that honored
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   521
  // the Thread-SMR protocol.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   522
  //
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   523
  // If the calling thread cannot be found by threads_do() and if
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   524
  // it is not the shutdown thread, then the calling thread is not
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   525
  // honoring the Thread-SMR ptotocol. This means that the specified
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   526
  // ThreadsList is not a stable hazard ptr and can be freed by
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   527
  // another thread from the to-be-deleted list at any time.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   528
  //
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   529
  // Note: The shutdown thread has removed itself from the Threads
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   530
  // list and is safe to have a waiver from this check because
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   531
  // VM_Exit::_shutdown_thread is not set until after the VMThread
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   532
  // has started the final safepoint which holds the Threads_lock
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   533
  // for the remainder of the VM's life.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   534
  //
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   535
  VerifyHazardPtrThreadClosure cl(_thread);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   536
  ThreadsSMRSupport::threads_do(&cl, _list);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   537
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   538
  // If the calling thread is not honoring the Thread-SMR protocol,
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   539
  // then we will either crash in threads_do() above because 'threads'
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   540
  // was freed by another thread or we will fail the assert() below.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   541
  // In either case, we won't get past this point with a badly placed
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   542
  // ThreadsListHandle.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   543
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   544
  assert(cl.found() || _thread == VM_Exit::shutdown_thread(), "Acquired a ThreadsList snapshot from a thread not recognized by the Thread-SMR protocol.");
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   545
#endif
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   546
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   547
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   548
// 'entries + 1' so we always have at least one entry.
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   549
ThreadsList::ThreadsList(int entries) :
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   550
  _length(entries),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   551
  _next_list(NULL),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   552
  _threads(NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread)),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   553
  _nested_handle_cnt(0)
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   554
{
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   555
  *(JavaThread**)(_threads + entries) = NULL;  // Make sure the extra entry is NULL.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   556
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   557
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   558
ThreadsList::~ThreadsList() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   559
  FREE_C_HEAP_ARRAY(JavaThread*, _threads);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   560
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   561
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   562
// Add a JavaThread to a ThreadsList. The returned ThreadsList is a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   563
// new copy of the specified ThreadsList with the specified JavaThread
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   564
// appended to the end.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   565
ThreadsList *ThreadsList::add_thread(ThreadsList *list, JavaThread *java_thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   566
  const uint index = list->_length;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   567
  const uint new_length = index + 1;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   568
  const uint head_length = index;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   569
  ThreadsList *const new_list = new ThreadsList(new_length);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   570
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   571
  if (head_length > 0) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   572
    Copy::disjoint_words((HeapWord*)list->_threads, (HeapWord*)new_list->_threads, head_length);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   573
  }
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   574
  *(JavaThread**)(new_list->_threads + index) = java_thread;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   575
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   576
  return new_list;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   577
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   578
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   579
void ThreadsList::dec_nested_handle_cnt() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   580
  // The decrement needs to be MO_ACQ_REL. At the moment, the Atomic::dec
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   581
  // backend on PPC does not yet conform to these requirements. Therefore
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   582
  // the decrement is simulated with an Atomic::sub(1, &addr).
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   583
  // Without this MO_ACQ_REL Atomic::dec simulation, the nested SMR mechanism
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   584
  // is not generally safe to use.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   585
  Atomic::sub(1, &_nested_handle_cnt);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   586
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   587
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   588
int ThreadsList::find_index_of_JavaThread(JavaThread *target) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   589
  if (target == NULL) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   590
    return -1;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   591
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   592
  for (uint i = 0; i < length(); i++) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   593
    if (target == thread_at(i)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   594
      return (int)i;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   595
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   596
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   597
  return -1;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   598
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   599
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   600
JavaThread* ThreadsList::find_JavaThread_from_java_tid(jlong java_tid) const {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   601
  for (uint i = 0; i < length(); i++) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   602
    JavaThread* thread = thread_at(i);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   603
    oop tobj = thread->threadObj();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   604
    // Ignore the thread if it hasn't run yet, has exited
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   605
    // or is starting to exit.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   606
    if (tobj != NULL && !thread->is_exiting() &&
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   607
        java_tid == java_lang_Thread::thread_id(tobj)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   608
      // found a match
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   609
      return thread;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   610
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   611
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   612
  return NULL;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   613
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   614
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   615
void ThreadsList::inc_nested_handle_cnt() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   616
  // The increment needs to be MO_SEQ_CST. At the moment, the Atomic::inc
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   617
  // backend on PPC does not yet conform to these requirements. Therefore
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   618
  // the increment is simulated with a load phi; cas phi + 1; loop.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   619
  // Without this MO_SEQ_CST Atomic::inc simulation, the nested SMR mechanism
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   620
  // is not generally safe to use.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   621
  intx sample = OrderAccess::load_acquire(&_nested_handle_cnt);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   622
  for (;;) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   623
    if (Atomic::cmpxchg(sample + 1, &_nested_handle_cnt, sample) == sample) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   624
      return;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   625
    } else {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   626
      sample = OrderAccess::load_acquire(&_nested_handle_cnt);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   627
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   628
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   629
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   630
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   631
bool ThreadsList::includes(const JavaThread * const p) const {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   632
  if (p == NULL) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   633
    return false;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   634
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   635
  for (uint i = 0; i < length(); i++) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   636
    if (thread_at(i) == p) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   637
      return true;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   638
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   639
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   640
  return false;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   641
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   642
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   643
// Remove a JavaThread from a ThreadsList. The returned ThreadsList is a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   644
// new copy of the specified ThreadsList with the specified JavaThread
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   645
// removed.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   646
ThreadsList *ThreadsList::remove_thread(ThreadsList* list, JavaThread* java_thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   647
  assert(list->_length > 0, "sanity");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   648
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   649
  uint i = (uint)list->find_index_of_JavaThread(java_thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   650
  assert(i < list->_length, "did not find JavaThread on the list");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   651
  const uint index = i;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   652
  const uint new_length = list->_length - 1;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   653
  const uint head_length = index;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   654
  const uint tail_length = (new_length >= index) ? (new_length - index) : 0;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   655
  ThreadsList *const new_list = new ThreadsList(new_length);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   656
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   657
  if (head_length > 0) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   658
    Copy::disjoint_words((HeapWord*)list->_threads, (HeapWord*)new_list->_threads, head_length);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   659
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   660
  if (tail_length > 0) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   661
    Copy::disjoint_words((HeapWord*)list->_threads + index + 1, (HeapWord*)new_list->_threads + index, tail_length);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   662
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   663
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   664
  return new_list;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   665
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   666
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   667
ThreadsListHandle::ThreadsListHandle(Thread *self) : _list_ptr(self, /* acquire */ true) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   668
  assert(self == Thread::current(), "sanity check");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   669
  if (EnableThreadSMRStatistics) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   670
    _timer.start();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   671
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   672
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   673
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   674
ThreadsListHandle::~ThreadsListHandle() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   675
  if (EnableThreadSMRStatistics) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   676
    _timer.stop();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   677
    uint millis = (uint)_timer.milliseconds();
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   678
    ThreadsSMRSupport::update_tlh_stats(millis);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   679
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   680
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   681
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   682
// Convert an internal thread reference to a JavaThread found on the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   683
// associated ThreadsList. This ThreadsListHandle "protects" the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   684
// returned JavaThread *.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   685
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   686
// If thread_oop_p is not NULL, then the caller wants to use the oop
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   687
// after this call so the oop is returned. On success, *jt_pp is set
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   688
// to the converted JavaThread * and true is returned. On error,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   689
// returns false.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   690
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   691
bool ThreadsListHandle::cv_internal_thread_to_JavaThread(jobject jthread,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   692
                                                         JavaThread ** jt_pp,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   693
                                                         oop * thread_oop_p) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   694
  assert(this->list() != NULL, "must have a ThreadsList");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   695
  assert(jt_pp != NULL, "must have a return JavaThread pointer");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   696
  // thread_oop_p is optional so no assert()
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   697
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   698
  // The JVM_* interfaces don't allow a NULL thread parameter; JVM/TI
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   699
  // allows a NULL thread parameter to signify "current thread" which
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   700
  // allows us to avoid calling cv_external_thread_to_JavaThread().
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   701
  // The JVM_* interfaces have no such leeway.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   702
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   703
  oop thread_oop = JNIHandles::resolve_non_null(jthread);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   704
  // Looks like an oop at this point.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   705
  if (thread_oop_p != NULL) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   706
    // Return the oop to the caller; the caller may still want
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   707
    // the oop even if this function returns false.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   708
    *thread_oop_p = thread_oop;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   709
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   710
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   711
  JavaThread *java_thread = java_lang_Thread::thread(thread_oop);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   712
  if (java_thread == NULL) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   713
    // The java.lang.Thread does not contain a JavaThread * so it has
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   714
    // not yet run or it has died.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   715
    return false;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   716
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   717
  // Looks like a live JavaThread at this point.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   718
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   719
  if (java_thread != JavaThread::current()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   720
    // jthread is not for the current JavaThread so have to verify
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   721
    // the JavaThread * against the ThreadsList.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   722
    if (EnableThreadSMRExtraValidityChecks && !includes(java_thread)) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   723
      // Not on the JavaThreads list so it is not alive.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   724
      return false;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   725
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   726
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   727
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   728
  // Return a live JavaThread that is "protected" by the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   729
  // ThreadsListHandle in the caller.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   730
  *jt_pp = java_thread;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   731
  return true;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   732
}
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   733
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   734
void ThreadsSMRSupport::add_thread(JavaThread *thread){
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   735
  ThreadsList *new_list = ThreadsList::add_thread(get_java_thread_list(), thread);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   736
  if (EnableThreadSMRStatistics) {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   737
    inc_java_thread_list_alloc_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   738
    update_java_thread_list_max(new_list->length());
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   739
  }
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   740
  // Initial _java_thread_list will not generate a "Threads::add" mesg.
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   741
  log_debug(thread, smr)("tid=" UINTX_FORMAT ": Threads::add: new ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(new_list));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   742
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   743
  ThreadsList *old_list = xchg_java_thread_list(new_list);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   744
  free_list(old_list);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   745
}
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   746
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   747
// set_delete_notify() and clear_delete_notify() are called
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   748
// under the protection of the delete_lock, but we also use an
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   749
// Atomic operation to ensure the memory update is seen earlier than
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   750
// when the delete_lock is dropped.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   751
//
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   752
void ThreadsSMRSupport::clear_delete_notify() {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   753
  Atomic::dec(&_delete_notify);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   754
}
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   755
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   756
bool ThreadsSMRSupport::delete_notify() {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   757
  // Use load_acquire() in order to see any updates to _delete_notify
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   758
  // earlier than when delete_lock is grabbed.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   759
  return (OrderAccess::load_acquire(&_delete_notify) != 0);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   760
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   761
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   762
// Safely free a ThreadsList after a Threads::add() or Threads::remove().
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   763
// The specified ThreadsList may not get deleted during this call if it
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   764
// is still in-use (referenced by a hazard ptr). Other ThreadsLists
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   765
// in the chain may get deleted by this call if they are no longer in-use.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   766
void ThreadsSMRSupport::free_list(ThreadsList* threads) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   767
  assert_locked_or_safepoint(Threads_lock);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   768
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   769
  threads->set_next_list(_to_delete_list);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   770
  _to_delete_list = threads;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   771
  if (EnableThreadSMRStatistics) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   772
    _to_delete_list_cnt++;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   773
    if (_to_delete_list_cnt > _to_delete_list_max) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   774
      _to_delete_list_max = _to_delete_list_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   775
    }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   776
  }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   777
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   778
  // Hash table size should be first power of two higher than twice the length of the ThreadsList
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   779
  int hash_table_size = MIN2((int)get_java_thread_list()->length(), 32) << 1;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   780
  hash_table_size--;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   781
  hash_table_size |= hash_table_size >> 1;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   782
  hash_table_size |= hash_table_size >> 2;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   783
  hash_table_size |= hash_table_size >> 4;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   784
  hash_table_size |= hash_table_size >> 8;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   785
  hash_table_size |= hash_table_size >> 16;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   786
  hash_table_size++;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   787
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   788
  // Gather a hash table of the current hazard ptrs:
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   789
  ThreadScanHashtable *scan_table = new ThreadScanHashtable(hash_table_size);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   790
  ScanHazardPtrGatherThreadsListClosure scan_cl(scan_table);
49756
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 49636
diff changeset
   791
  threads_do(&scan_cl);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   792
  OrderAccess::acquire(); // Must order reads of hazard ptr before reads of
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   793
                          // nested reference counters
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   794
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   795
  // Walk through the linked list of pending freeable ThreadsLists
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   796
  // and free the ones that are not referenced from hazard ptrs.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   797
  ThreadsList* current = _to_delete_list;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   798
  ThreadsList* prev = NULL;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   799
  ThreadsList* next = NULL;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   800
  bool threads_is_freed = false;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   801
  while (current != NULL) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   802
    next = current->next_list();
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   803
    if (!scan_table->has_entry((void*)current) && current->_nested_handle_cnt == 0) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   804
      // This ThreadsList is not referenced by a hazard ptr.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   805
      if (prev != NULL) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   806
        prev->set_next_list(next);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   807
      }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   808
      if (_to_delete_list == current) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   809
        _to_delete_list = next;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   810
      }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   811
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   812
      log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::free_list: threads=" INTPTR_FORMAT " is freed.", os::current_thread_id(), p2i(current));
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   813
      if (current == threads) threads_is_freed = true;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   814
      delete current;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   815
      if (EnableThreadSMRStatistics) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   816
        _java_thread_list_free_cnt++;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   817
        _to_delete_list_cnt--;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   818
      }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   819
    } else {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   820
      prev = current;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   821
    }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   822
    current = next;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   823
  }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   824
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   825
  if (!threads_is_freed) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   826
    // Only report "is not freed" on the original call to
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   827
    // free_list() for this ThreadsList.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   828
    log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::free_list: threads=" INTPTR_FORMAT " is not freed.", os::current_thread_id(), p2i(threads));
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   829
  }
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   830
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   831
  delete scan_table;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   832
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   833
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   834
// Return true if the specified JavaThread is protected by a hazard
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   835
// pointer (ThreadsList reference). Otherwise, returns false.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   836
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   837
bool ThreadsSMRSupport::is_a_protected_JavaThread(JavaThread *thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   838
  assert_locked_or_safepoint(Threads_lock);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   839
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   840
  // Hash table size should be first power of two higher than twice
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   841
  // the length of the Threads list.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   842
  int hash_table_size = MIN2((int)get_java_thread_list()->length(), 32) << 1;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   843
  hash_table_size--;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   844
  hash_table_size |= hash_table_size >> 1;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   845
  hash_table_size |= hash_table_size >> 2;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   846
  hash_table_size |= hash_table_size >> 4;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   847
  hash_table_size |= hash_table_size >> 8;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   848
  hash_table_size |= hash_table_size >> 16;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   849
  hash_table_size++;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   850
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   851
  // Gather a hash table of the JavaThreads indirectly referenced by
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   852
  // hazard ptrs.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   853
  ThreadScanHashtable *scan_table = new ThreadScanHashtable(hash_table_size);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   854
  ScanHazardPtrGatherProtectedThreadsClosure scan_cl(scan_table);
49756
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 49636
diff changeset
   855
  threads_do(&scan_cl);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   856
  OrderAccess::acquire(); // Must order reads of hazard ptr before reads of
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   857
                          // nested reference counters
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   858
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   859
  // Walk through the linked list of pending freeable ThreadsLists
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   860
  // and include the ones that are currently in use by a nested
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   861
  // ThreadsListHandle in the search set.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   862
  ThreadsList* current = _to_delete_list;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   863
  while (current != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   864
    if (current->_nested_handle_cnt != 0) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   865
      // 'current' is in use by a nested ThreadsListHandle so the hazard
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   866
      // ptr is protecting all the JavaThreads on that ThreadsList.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   867
      AddThreadHazardPointerThreadClosure add_cl(scan_table);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   868
      current->threads_do(&add_cl);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   869
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   870
    current = current->next_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   871
  }
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   872
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   873
  bool thread_is_protected = false;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   874
  if (scan_table->has_entry((void*)thread)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   875
    thread_is_protected = true;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   876
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   877
  delete scan_table;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   878
  return thread_is_protected;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   879
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   880
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   881
// Wake up portion of the release stable ThreadsList protocol;
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   882
// uses the delete_lock().
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   883
//
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   884
void ThreadsSMRSupport::release_stable_list_wake_up(bool is_nested) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   885
  const char* log_str = is_nested ? "nested hazard ptr" : "regular hazard ptr";
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   886
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   887
  // Note: delete_lock is held in smr_delete() for the entire
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   888
  // hazard ptr search so that we do not lose this notify() if
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   889
  // the exiting thread has to wait. That code path also holds
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   890
  // Threads_lock (which was grabbed before delete_lock) so that
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   891
  // threads_do() can be called. This means the system can't start a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   892
  // safepoint which means this thread can't take too long to get to
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   893
  // a safepoint because of being blocked on delete_lock.
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   894
  //
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   895
  MonitorLockerEx ml(ThreadsSMRSupport::delete_lock(), Monitor::_no_safepoint_check_flag);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   896
  if (ThreadsSMRSupport::delete_notify()) {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   897
    // Notify any exiting JavaThreads that are waiting in smr_delete()
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   898
    // that we've released a ThreadsList.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   899
    ml.notify_all();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   900
    log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::release_stable_list notified %s", os::current_thread_id(), log_str);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   901
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   902
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   903
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   904
void ThreadsSMRSupport::remove_thread(JavaThread *thread) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   905
  ThreadsList *new_list = ThreadsList::remove_thread(ThreadsSMRSupport::get_java_thread_list(), thread);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   906
  if (EnableThreadSMRStatistics) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   907
    ThreadsSMRSupport::inc_java_thread_list_alloc_cnt();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   908
    // This list is smaller so no need to check for a "longest" update.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   909
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   910
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   911
  // Final _java_thread_list will not generate a "Threads::remove" mesg.
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   912
  log_debug(thread, smr)("tid=" UINTX_FORMAT ": Threads::remove: new ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(new_list));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   913
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   914
  ThreadsList *old_list = ThreadsSMRSupport::xchg_java_thread_list(new_list);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   915
  ThreadsSMRSupport::free_list(old_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   916
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   917
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   918
// See note for clear_delete_notify().
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   919
//
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   920
void ThreadsSMRSupport::set_delete_notify() {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   921
  Atomic::inc(&_delete_notify);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   922
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   923
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   924
// Safely delete a JavaThread when it is no longer in use by a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   925
// ThreadsListHandle.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   926
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   927
void ThreadsSMRSupport::smr_delete(JavaThread *thread) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   928
  assert(!Threads_lock->owned_by_self(), "sanity");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   929
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   930
  bool has_logged_once = false;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   931
  elapsedTimer timer;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   932
  if (EnableThreadSMRStatistics) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   933
    timer.start();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   934
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   935
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   936
  while (true) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   937
    {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   938
      // No safepoint check because this JavaThread is not on the
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   939
      // Threads list.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   940
      MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   941
      // Cannot use a MonitorLockerEx helper here because we have
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   942
      // to drop the Threads_lock first if we wait.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   943
      ThreadsSMRSupport::delete_lock()->lock_without_safepoint_check();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   944
      // Set the delete_notify flag after we grab delete_lock
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   945
      // and before we scan hazard ptrs because we're doing
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   946
      // double-check locking in release_stable_list().
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   947
      ThreadsSMRSupport::set_delete_notify();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   948
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   949
      if (!is_a_protected_JavaThread(thread)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   950
        // This is the common case.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   951
        ThreadsSMRSupport::clear_delete_notify();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   952
        ThreadsSMRSupport::delete_lock()->unlock();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   953
        break;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   954
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   955
      if (!has_logged_once) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   956
        has_logged_once = true;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   957
        log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::smr_delete: thread=" INTPTR_FORMAT " is not deleted.", os::current_thread_id(), p2i(thread));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   958
        if (log_is_enabled(Debug, os, thread)) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   959
          ScanHazardPtrPrintMatchingThreadsClosure scan_cl(thread);
49756
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 49636
diff changeset
   960
          threads_do(&scan_cl);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   961
          ThreadsList* current = _to_delete_list;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   962
          while (current != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   963
            if (current->_nested_handle_cnt != 0 && current->includes(thread)) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   964
              log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::smr_delete: found nested hazard pointer to thread=" INTPTR_FORMAT, os::current_thread_id(), p2i(thread));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   965
            }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   966
            current = current->next_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   967
          }
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   968
        }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   969
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   970
    } // We have to drop the Threads_lock to wait or delete the thread
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   971
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   972
    if (EnableThreadSMRStatistics) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   973
      _delete_lock_wait_cnt++;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   974
      if (_delete_lock_wait_cnt > _delete_lock_wait_max) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   975
        _delete_lock_wait_max = _delete_lock_wait_cnt;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   976
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   977
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   978
    // Wait for a release_stable_list() call before we check again. No
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   979
    // safepoint check, no timeout, and not as suspend equivalent flag
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   980
    // because this JavaThread is not on the Threads list.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   981
    ThreadsSMRSupport::delete_lock()->wait(Mutex::_no_safepoint_check_flag, 0,
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   982
                                     !Mutex::_as_suspend_equivalent_flag);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   983
    if (EnableThreadSMRStatistics) {
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   984
      _delete_lock_wait_cnt--;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   985
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   986
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   987
    ThreadsSMRSupport::clear_delete_notify();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   988
    ThreadsSMRSupport::delete_lock()->unlock();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   989
    // Retry the whole scenario.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   990
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   991
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   992
  if (ThreadLocalHandshakes) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   993
    // The thread is about to be deleted so cancel any handshake.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   994
    thread->cancel_handshake();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   995
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   996
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   997
  delete thread;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   998
  if (EnableThreadSMRStatistics) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   999
    timer.stop();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1000
    uint millis = (uint)timer.milliseconds();
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1001
    ThreadsSMRSupport::inc_deleted_thread_cnt();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1002
    ThreadsSMRSupport::add_deleted_thread_times(millis);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1003
    ThreadsSMRSupport::update_deleted_thread_time_max(millis);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1004
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1005
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1006
  log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::smr_delete: thread=" INTPTR_FORMAT " is deleted.", os::current_thread_id(), p2i(thread));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1007
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1008
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1009
// Apply the closure to all threads in the system, with a snapshot of
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1010
// all JavaThreads provided by the list parameter.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1011
void ThreadsSMRSupport::threads_do(ThreadClosure *tc, ThreadsList *list) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1012
  list->threads_do(tc);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1013
  Threads::non_java_threads_do(tc);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1014
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1015
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1016
// Apply the closure to all threads in the system.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1017
void ThreadsSMRSupport::threads_do(ThreadClosure *tc) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1018
  threads_do(tc, _java_thread_list);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1019
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1020
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1021
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1022
// Debug, logging, and printing stuff at the end:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1023
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1024
// Print SMR info for a SafeThreadsListPtr to a given output stream.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1025
void SafeThreadsListPtr::print_on(outputStream* st) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1026
  if (this == _thread->_threads_list_ptr) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1027
    // The top level hazard ptr.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1028
    st->print(" _threads_hazard_ptr=" INTPTR_FORMAT, p2i(_list));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1029
  } else {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1030
    // Nested hazard ptrs.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1031
    st->print(", _nested_threads_hazard_ptr=" INTPTR_FORMAT, p2i(_list));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1032
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1033
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1034
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1035
// Log Threads class SMR info.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1036
void ThreadsSMRSupport::log_statistics() {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1037
  LogTarget(Info, thread, smr) log;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1038
  if (log.is_enabled()) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1039
    LogStream out(log);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1040
    print_info_on(&out);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1041
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1042
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1043
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1044
// Print SMR info for a thread to a given output stream.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1045
void ThreadsSMRSupport::print_info_on(const Thread* thread, outputStream* st) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1046
  if (thread->_threads_hazard_ptr != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1047
    st->print(" _threads_hazard_ptr=" INTPTR_FORMAT, p2i(thread->_threads_hazard_ptr));
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1048
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1049
  if (EnableThreadSMRStatistics && thread->_threads_list_ptr != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1050
    // The count is only interesting if we have a _threads_list_ptr.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1051
    st->print(", _nested_threads_hazard_ptr_cnt=%u", thread->_nested_threads_hazard_ptr_cnt);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1052
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1053
  if (SafepointSynchronize::is_at_safepoint() || Thread::current() == thread) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1054
    // It is only safe to walk the list if we're at a safepoint or the
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1055
    // calling thread is walking its own list.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1056
    SafeThreadsListPtr* current = thread->_threads_list_ptr;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1057
    if (current != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1058
      // Skip the top nesting level as it is always printed above.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1059
      current = current->previous();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1060
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1061
    while (current != NULL) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1062
      current->print_on(st);
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1063
      current = current->previous();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1064
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1065
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1066
}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1067
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1068
// Print Threads class SMR info.
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1069
void ThreadsSMRSupport::print_info_on(outputStream* st) {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1070
  // Only grab the Threads_lock if we don't already own it
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1071
  // and if we are not reporting an error.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1072
  MutexLockerEx ml((Threads_lock->owned_by_self() || VMError::is_error_reported()) ? NULL : Threads_lock);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1073
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1074
  st->print_cr("Threads class SMR info:");
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1075
  st->print_cr("_java_thread_list=" INTPTR_FORMAT ", length=%u, "
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1076
               "elements={", p2i(_java_thread_list),
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1077
               _java_thread_list->length());
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1078
  print_info_elements_on(st, _java_thread_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1079
  st->print_cr("}");
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1080
  if (_to_delete_list != NULL) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1081
    st->print_cr("_to_delete_list=" INTPTR_FORMAT ", length=%u, "
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1082
                 "elements={", p2i(_to_delete_list),
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1083
                 _to_delete_list->length());
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1084
    print_info_elements_on(st, _to_delete_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1085
    st->print_cr("}");
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1086
    for (ThreadsList *t_list = _to_delete_list->next_list();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1087
         t_list != NULL; t_list = t_list->next_list()) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1088
      st->print("next-> " INTPTR_FORMAT ", length=%u, "
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1089
                "elements={", p2i(t_list), t_list->length());
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1090
      print_info_elements_on(st, t_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1091
      st->print_cr("}");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1092
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1093
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1094
  if (!EnableThreadSMRStatistics) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1095
    return;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1096
  }
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1097
  st->print_cr("_java_thread_list_alloc_cnt=" UINT64_FORMAT ", "
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
  1098
               "_java_thread_list_free_cnt=" UINT64_FORMAT ", "
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1099
               "_java_thread_list_max=%u, "
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1100
               "_nested_thread_list_max=%u",
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1101
               _java_thread_list_alloc_cnt,
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1102
               _java_thread_list_free_cnt,
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1103
               _java_thread_list_max,
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1104
               _nested_thread_list_max);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1105
  if (_tlh_cnt > 0) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1106
    st->print_cr("_tlh_cnt=%u"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1107
                 ", _tlh_times=%u"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1108
                 ", avg_tlh_time=%0.2f"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1109
                 ", _tlh_time_max=%u",
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1110
                 _tlh_cnt, _tlh_times,
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1111
                 ((double) _tlh_times / _tlh_cnt),
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1112
                 _tlh_time_max);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1113
  }
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1114
  if (_deleted_thread_cnt > 0) {
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1115
    st->print_cr("_deleted_thread_cnt=%u"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1116
                 ", _deleted_thread_times=%u"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1117
                 ", avg_deleted_thread_time=%0.2f"
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1118
                 ", _deleted_thread_time_max=%u",
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1119
                 _deleted_thread_cnt, _deleted_thread_times,
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1120
                 ((double) _deleted_thread_times / _deleted_thread_cnt),
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1121
                 _deleted_thread_time_max);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1122
  }
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1123
  st->print_cr("_delete_lock_wait_cnt=%u, _delete_lock_wait_max=%u",
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1124
               _delete_lock_wait_cnt, _delete_lock_wait_max);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1125
  st->print_cr("_to_delete_list_cnt=%u, _to_delete_list_max=%u",
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1126
               _to_delete_list_cnt, _to_delete_list_max);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1127
}
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1128
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1129
// Print ThreadsList elements (4 per line).
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
  1130
void ThreadsSMRSupport::print_info_elements_on(outputStream* st, ThreadsList* t_list) {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1131
  uint cnt = 0;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1132
  JavaThreadIterator jti(t_list);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1133
  for (JavaThread *jt = jti.first(); jt != NULL; jt = jti.next()) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1134
    st->print(INTPTR_FORMAT, p2i(jt));
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1135
    if (cnt < t_list->length() - 1) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1136
      // Separate with comma or comma-space except for the last one.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1137
      if (((cnt + 1) % 4) == 0) {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1138
        // Four INTPTR_FORMAT fit on an 80 column line so end the
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1139
        // current line with just a comma.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1140
        st->print_cr(",");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1141
      } else {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1142
        // Not the last one on the current line so use comma-space:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1143
        st->print(", ");
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1144
      }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1145
    } else {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1146
      // Last one so just end the current line.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1147
      st->cr();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1148
    }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1149
    cnt++;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1150
  }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
  1151
}