src/hotspot/share/runtime/threadSMR.hpp
author iklam
Fri, 29 Nov 2019 14:11:50 -0800
changeset 59328 f280911d3427
parent 54955 46409371a691
permissions -rw-r--r--
8230385: [cds] No message is logged when shared image cannot be used due to mismatched configuration Reviewed-by: stuefe, dholmes, ccheung
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
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52452
diff changeset
     2
 * Copyright (c) 2017, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52452
diff changeset
    25
#ifndef SHARE_RUNTIME_THREADSMR_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52452
diff changeset
    26
#define SHARE_RUNTIME_THREADSMR_HPP
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    27
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    28
#include "memory/allocation.hpp"
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    29
#include "runtime/timer.hpp"
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    30
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    31
class JavaThread;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    32
class Monitor;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    33
class outputStream;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    34
class Thread;
49756
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 48382
diff changeset
    35
class ThreadClosure;
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 48382
diff changeset
    36
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    37
// Thread Safe Memory Reclamation (Thread-SMR) support.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    38
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    39
// ThreadsListHandles are used to safely perform operations on one or more
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    40
// threads without the risk of the thread or threads exiting during the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    41
// operation. It is no longer necessary to hold the Threads_lock to safely
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    42
// perform an operation on a target thread.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    43
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    44
// There are several different ways to refer to java.lang.Thread objects
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    45
// so we have a few ways to get a protected JavaThread *:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    46
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    47
// JNI jobject example:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    48
//   jobject jthread = ...;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    49
//   :
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    50
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    51
//   JavaThread* jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    52
//   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &jt, NULL);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    53
//   if (is_alive) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    54
//     :  // do stuff with 'jt'...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    55
//   }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    56
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    57
// JVM/TI jthread example:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    58
//   jthread thread = ...;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    59
//   :
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    60
//   JavaThread* jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    61
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    62
//   jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &jt, NULL);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    63
//   if (err != JVMTI_ERROR_NONE) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    64
//     return err;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    65
//   }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    66
//   :  // do stuff with 'jt'...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    67
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    68
// JVM/TI oop example (this one should be very rare):
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    69
//   oop thread_obj = ...;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    70
//   :
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    71
//   JavaThread *jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    72
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    73
//   jvmtiError err = JvmtiExport::cv_oop_to_JavaThread(tlh.list(), thread_obj, &jt);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    74
//   if (err != JVMTI_ERROR_NONE) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    75
//     return err;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    76
//   }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    77
//   :  // do stuff with 'jt'...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    78
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    79
// A JavaThread * that is included in the ThreadsList that is held by
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    80
// a ThreadsListHandle is protected as long as the ThreadsListHandle
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    81
// remains in scope. The target JavaThread * may have logically exited,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    82
// but that target JavaThread * will not be deleted until it is no
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    83
// longer protected by a ThreadsListHandle.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    84
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    85
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    86
// SMR Support for the Threads class.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    87
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    88
class ThreadsSMRSupport : AllStatic {
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 53244
diff changeset
    89
  friend class VMStructs;
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    90
  friend class SafeThreadsListPtr;  // for _nested_thread_list_max, delete_notify(), release_stable_list_wake_up() access
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
    91
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    92
  // The coordination between ThreadsSMRSupport::release_stable_list() and
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
    93
  // ThreadsSMRSupport::smr_delete() uses the delete_lock in order to
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    94
  // reduce the traffic on the Threads_lock.
52448
bc5c7f63dbae 8213137: Remove static initialization of monitor/mutex instances
dholmes
parents: 49956
diff changeset
    95
  static Monitor* delete_lock() { return ThreadsSMRDelete_lock; }
bc5c7f63dbae 8213137: Remove static initialization of monitor/mutex instances
dholmes
parents: 49956
diff changeset
    96
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    97
  // 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
    98
  // -XX:+EnableThreadSMRStatistics (see thread.cpp for a
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    99
  // description about each field):
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   100
  static uint                  _delete_lock_wait_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   101
  static uint                  _delete_lock_wait_max;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   102
  // The delete_notify flag is used for proper double-check
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   103
  // locking in order to reduce the traffic on the system wide
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   104
  // Thread-SMR delete_lock.
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   105
  static volatile uint         _delete_notify;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   106
  static volatile uint         _deleted_thread_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   107
  static volatile uint         _deleted_thread_time_max;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   108
  static volatile uint         _deleted_thread_times;
52452
3315e47741c7 8209139: globalCounter bootstrap issue
rehn
parents: 52448
diff changeset
   109
  static ThreadsList           _bootstrap_list;
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   110
  static ThreadsList* volatile _java_thread_list;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   111
  static uint64_t              _java_thread_list_alloc_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   112
  static uint64_t              _java_thread_list_free_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   113
  static uint                  _java_thread_list_max;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   114
  static uint                  _nested_thread_list_max;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   115
  static volatile uint         _tlh_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   116
  static volatile uint         _tlh_time_max;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   117
  static volatile uint         _tlh_times;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   118
  static ThreadsList*          _to_delete_list;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   119
  static uint                  _to_delete_list_cnt;
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   120
  static uint                  _to_delete_list_max;
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   121
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   122
  static ThreadsList *acquire_stable_list_fast_path(Thread *self);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   123
  static ThreadsList *acquire_stable_list_nested_path(Thread *self);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   124
  static void add_deleted_thread_times(uint add_value);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   125
  static void add_tlh_times(uint add_value);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   126
  static void clear_delete_notify();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   127
  static bool delete_notify();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   128
  static void free_list(ThreadsList* threads);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   129
  static void inc_deleted_thread_cnt();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   130
  static void inc_java_thread_list_alloc_cnt();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   131
  static void inc_tlh_cnt();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   132
  static bool is_a_protected_JavaThread(JavaThread *thread);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   133
  static void release_stable_list_wake_up(bool is_nested);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   134
  static void set_delete_notify();
49756
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 48382
diff changeset
   135
  static void threads_do(ThreadClosure *tc);
129d60b5dac7 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().
dcubed
parents: 48382
diff changeset
   136
  static void threads_do(ThreadClosure *tc, ThreadsList *list);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   137
  static void update_deleted_thread_time_max(uint new_value);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   138
  static void 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
   139
  static void update_tlh_time_max(uint new_value);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   140
  static void verify_hazard_ptr_scanned(Thread *self, ThreadsList *threads);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   141
  static ThreadsList* xchg_java_thread_list(ThreadsList* new_list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   142
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   143
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   144
  static void add_thread(JavaThread *thread);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   145
  static ThreadsList* get_java_thread_list();
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   146
  static bool is_a_protected_JavaThread_with_lock(JavaThread *thread);
52452
3315e47741c7 8209139: globalCounter bootstrap issue
rehn
parents: 52448
diff changeset
   147
  static bool is_bootstrap_list(ThreadsList* list);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   148
  static void remove_thread(JavaThread *thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   149
  static void smr_delete(JavaThread *thread);
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   150
  static void update_tlh_stats(uint millis);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   151
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   152
  // Logging and printing support:
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   153
  static void log_statistics();
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   154
  static void print_info_elements_on(outputStream* st, ThreadsList* t_list);
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48312
diff changeset
   155
  static void print_info_on(outputStream* st);
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   156
  static void print_info_on(const Thread* thread, outputStream* st);
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   157
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   158
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   159
// A fast list of JavaThreads.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   160
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   161
class ThreadsList : public CHeapObj<mtThread> {
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 53244
diff changeset
   162
  friend class VMStructs;
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   163
  friend class SafeThreadsListPtr;  // for {dec,inc}_nested_handle_cnt() access
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   164
  friend class ThreadsSMRSupport;  // for _nested_handle_cnt, {add,remove}_thread(), {,set_}next_list() access
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   165
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   166
  const uint _length;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   167
  ThreadsList* _next_list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   168
  JavaThread *const *const _threads;
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   169
  volatile intx _nested_handle_cnt;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   170
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   171
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   172
  void threads_do_dispatch(T *cl, JavaThread *const thread) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   173
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   174
  ThreadsList *next_list() const        { return _next_list; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   175
  void set_next_list(ThreadsList *list) { _next_list = list; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   176
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   177
  void inc_nested_handle_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   178
  void dec_nested_handle_cnt();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   179
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   180
  static 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
   181
  static 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
   182
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   183
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   184
  ThreadsList(int entries);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   185
  ~ThreadsList();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   186
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   187
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   188
  void threads_do(T *cl) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   189
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   190
  uint length() const                       { return _length; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   191
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   192
  JavaThread *const thread_at(uint i) const { return _threads[i]; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   193
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   194
  JavaThread *const *threads() const        { return _threads; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   195
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   196
  // Returns -1 if target is not found.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   197
  int find_index_of_JavaThread(JavaThread* target);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   198
  JavaThread* find_JavaThread_from_java_tid(jlong java_tid) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   199
  bool includes(const JavaThread * const p) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   200
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   201
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   202
// An abstract safe ptr to a ThreadsList comprising either a stable hazard ptr
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   203
// for leaves, or a retained reference count for nested uses. The user of this
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   204
// API does not need to know which mechanism is providing the safety.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   205
class SafeThreadsListPtr {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   206
  friend class ThreadsListSetter;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   207
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   208
  SafeThreadsListPtr* _previous;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   209
  Thread*                 _thread;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   210
  ThreadsList*            _list;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   211
  bool                    _has_ref_count;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   212
  bool                    _needs_release;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   213
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   214
  void acquire_stable_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   215
  void acquire_stable_list_fast_path();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   216
  void acquire_stable_list_nested_path();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   217
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   218
  void release_stable_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   219
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   220
  void verify_hazard_ptr_scanned();
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   221
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   222
public:
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   223
  // Constructor that attaches the list onto a thread.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   224
  SafeThreadsListPtr(Thread *thread, bool acquire) :
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   225
    _previous(NULL),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   226
    _thread(thread),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   227
    _list(NULL),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   228
    _has_ref_count(false),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   229
    _needs_release(false)
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   230
  {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   231
    if (acquire) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   232
      acquire_stable_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   233
    }
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   234
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   235
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   236
  // Constructor that transfers ownership of the pointer.
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   237
  SafeThreadsListPtr(SafeThreadsListPtr& other) :
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   238
    _previous(other._previous),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   239
    _thread(other._thread),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   240
    _list(other._list),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   241
    _has_ref_count(other._has_ref_count),
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   242
    _needs_release(other._needs_release)
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   243
  {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   244
    other._needs_release = false;
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   245
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   246
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   247
  ~SafeThreadsListPtr() {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   248
    if (_needs_release) {
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   249
      release_stable_list();
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   250
    }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   251
  }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   252
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   253
  ThreadsList* list() const { return _list; }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   254
  SafeThreadsListPtr* previous() const { return _previous; }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   255
  void print_on(outputStream* st);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   256
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   257
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   258
// A helper to optionally set the hazard ptr in ourself. This helper can
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   259
// be used by ourself or by another thread. If the hazard ptr is set(),
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   260
// then the destructor will release it.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   261
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   262
class ThreadsListSetter : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   263
private:
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   264
  SafeThreadsListPtr _list_ptr;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   265
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   266
public:
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   267
  ThreadsListSetter() : _list_ptr(Thread::current(), /* acquire */ false) {}
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   268
  ThreadsList* list() { return _list_ptr.list(); }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   269
  void set() { _list_ptr.acquire_stable_list(); }
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   270
  bool is_set() { return _list_ptr._needs_release; }
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   271
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   272
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   273
// This stack allocated ThreadsListHandle keeps all JavaThreads in the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   274
// ThreadsList from being deleted until it is safe.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   275
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   276
class ThreadsListHandle : public StackObj {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   277
  SafeThreadsListPtr _list_ptr;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   278
  elapsedTimer _timer;  // Enabled via -XX:+EnableThreadSMRStatistics.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   279
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   280
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   281
  ThreadsListHandle(Thread *self = Thread::current());
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   282
  ~ThreadsListHandle();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   283
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   284
  ThreadsList *list() const {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   285
    return _list_ptr.list();
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   286
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   287
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   288
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   289
  void threads_do(T *cl) const {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   290
    return list()->threads_do(cl);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   291
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   292
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   293
  bool cv_internal_thread_to_JavaThread(jobject jthread, JavaThread ** jt_pp, oop * thread_oop_p);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   294
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   295
  bool includes(JavaThread* p) {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   296
    return list()->includes(p);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   297
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   298
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   299
  uint length() const {
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 49756
diff changeset
   300
    return list()->length();
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   301
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   302
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   303
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   304
// This stack allocated JavaThreadIterator is used to walk the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   305
// specified ThreadsList using the following style:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   306
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   307
//   JavaThreadIterator jti(t_list);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   308
//   for (JavaThread *jt = jti.first(); jt != NULL; jt = jti.next()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   309
//     ...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   310
//   }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   311
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   312
class JavaThreadIterator : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   313
  ThreadsList * _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   314
  uint _index;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   315
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   316
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   317
  JavaThreadIterator(ThreadsList *list) : _list(list), _index(0) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   318
    assert(list != NULL, "ThreadsList must not be NULL.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   319
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   320
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   321
  JavaThread *first() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   322
    _index = 0;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   323
    return _list->thread_at(_index);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   324
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   325
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   326
  uint length() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   327
    return _list->length();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   328
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   329
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   330
  ThreadsList *list() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   331
    return _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   332
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   333
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   334
  JavaThread *next() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   335
    if (++_index >= length()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   336
      return NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   337
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   338
    return _list->thread_at(_index);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   339
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   340
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   341
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   342
// This stack allocated ThreadsListHandle and JavaThreadIterator combo
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   343
// is used to walk the ThreadsList in the included ThreadsListHandle
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   344
// using the following style:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   345
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   346
//   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   347
//     ...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   348
//   }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   349
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   350
class JavaThreadIteratorWithHandle : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   351
  ThreadsListHandle _tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   352
  uint _index;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   353
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   354
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   355
  JavaThreadIteratorWithHandle() : _index(0) {}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   356
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   357
  uint length() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   358
    return _tlh.length();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   359
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   360
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   361
  ThreadsList *list() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   362
    return _tlh.list();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   363
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   364
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   365
  JavaThread *next() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   366
    if (_index >= length()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   367
      return NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   368
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   369
    return _tlh.list()->thread_at(_index++);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   370
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   371
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   372
  void rewind() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   373
    _index = 0;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   374
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   375
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   376
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52452
diff changeset
   377
#endif // SHARE_RUNTIME_THREADSMR_HPP