src/hotspot/share/runtime/threadSMR.hpp
author dcubed
Wed, 06 Dec 2017 15:19:30 -0500
changeset 48312 2a1413298af0
parent 48105 8d15b1369c7a
child 48382 0997d6959851
permissions -rw-r--r--
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp Reviewed-by: stefank, coleenp, dholmes, gthornbr
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
/*
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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
#ifndef SHARE_VM_RUNTIME_THREADSMR_HPP
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    26
#define SHARE_VM_RUNTIME_THREADSMR_HPP
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
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    31
// Thread Safe Memory Reclamation (Thread-SMR) support.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    32
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    33
// 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
    34
// 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
    35
// 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
    36
// perform an operation on a target thread.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    37
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    38
// 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
    39
// 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
    40
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    41
// JNI jobject example:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    42
//   jobject jthread = ...;
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
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    45
//   JavaThread* jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    46
//   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
    47
//   if (is_alive) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    48
//     :  // do stuff with 'jt'...
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
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    51
// JVM/TI jthread example:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    52
//   jthread thread = ...;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    53
//   :
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    54
//   JavaThread* jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    55
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    56
//   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
    57
//   if (err != JVMTI_ERROR_NONE) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    58
//     return err;
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
//   :  // do stuff with 'jt'...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    61
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    62
// 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
    63
//   oop thread_obj = ...;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    64
//   :
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    65
//   JavaThread *jt = NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    66
//   ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    67
//   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
    68
//   if (err != JVMTI_ERROR_NONE) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    69
//     return err;
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
//   :  // do stuff with 'jt'...
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    72
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    73
// 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
    74
// a ThreadsListHandle is protected as long as the ThreadsListHandle
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    75
// 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
    76
// 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
    77
// longer protected by a ThreadsListHandle.
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
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    80
// 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
    81
//
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    82
class ThreadsSMRSupport : AllStatic {
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    83
  // The coordination between ThreadsSMRSupport::release_stable_list() and
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    84
  // ThreadsSMRSupport::smr_delete() uses the smr_delete_lock in order to
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    85
  // reduce the traffic on the Threads_lock.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    86
  static Monitor*              _smr_delete_lock;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    87
  // 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
    88
  // -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
    89
  // description about each field):
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    90
  static uint                  _smr_delete_lock_wait_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    91
  static uint                  _smr_delete_lock_wait_max;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    92
  // The smr_delete_notify flag is used for proper double-check
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    93
  // locking in order to reduce the traffic on the smr_delete_lock.
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    94
  static volatile uint         _smr_delete_notify;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    95
  static volatile uint         _smr_deleted_thread_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    96
  static volatile uint         _smr_deleted_thread_time_max;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    97
  static volatile uint         _smr_deleted_thread_times;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    98
  static ThreadsList* volatile _smr_java_thread_list;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
    99
  static uint64_t              _smr_java_thread_list_alloc_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   100
  static uint64_t              _smr_java_thread_list_free_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   101
  static uint                  _smr_java_thread_list_max;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   102
  static uint                  _smr_nested_thread_list_max;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   103
  static volatile uint         _smr_tlh_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   104
  static volatile uint         _smr_tlh_time_max;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   105
  static volatile uint         _smr_tlh_times;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   106
  static ThreadsList*          _smr_to_delete_list;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   107
  static uint                  _smr_to_delete_list_cnt;
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   108
  static uint                  _smr_to_delete_list_max;
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
  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
   111
  static ThreadsList *acquire_stable_list_nested_path(Thread *self);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   112
  static void add_smr_deleted_thread_times(uint add_value);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   113
  static void add_smr_tlh_times(uint add_value);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   114
  static void clear_smr_delete_notify();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   115
  static void inc_smr_deleted_thread_cnt();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   116
  static void inc_smr_java_thread_list_alloc_cnt();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   117
  static void inc_smr_tlh_cnt();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   118
  static bool 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
   119
  static void release_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
   120
  static void release_stable_list_nested_path(Thread *self);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   121
  static void release_stable_list_wake_up(char *log_str);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   122
  static void set_smr_delete_notify();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   123
  static Monitor* smr_delete_lock() { return _smr_delete_lock; }
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   124
  static bool smr_delete_notify();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   125
  static void smr_free_list(ThreadsList* threads);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   126
  static void update_smr_deleted_thread_time_max(uint new_value);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   127
  static void update_smr_java_thread_list_max(uint new_value);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   128
  static void update_smr_tlh_time_max(uint new_value);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   129
  static ThreadsList* xchg_smr_java_thread_list(ThreadsList* new_list);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   130
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   131
 public:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   132
  static ThreadsList *acquire_stable_list(Thread *self, bool is_ThreadsListSetter);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   133
  static void add_thread(JavaThread *thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   134
  static ThreadsList* get_smr_java_thread_list();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   135
  static bool is_a_protected_JavaThread_with_lock(JavaThread *thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   136
  static void release_stable_list(Thread *self);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   137
  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
   138
  static void smr_delete(JavaThread *thread);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   139
  static void update_smr_tlh_stats(uint millis);
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
  // Logging and printing support:
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   142
  static void log_smr_statistics();
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   143
  static void print_smr_info_elements_on(outputStream* st, ThreadsList* t_list);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   144
  static void print_smr_info_on(outputStream* st);
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   145
};
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   146
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   147
// A fast list of JavaThreads.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   148
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   149
class ThreadsList : public CHeapObj<mtThread> {
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   150
  friend class ThreadsSMRSupport;  // for next_list(), set_next_list() access
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   151
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   152
  const uint _length;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   153
  ThreadsList* _next_list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   154
  JavaThread *const *const _threads;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   155
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   156
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   157
  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
   158
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   159
  ThreadsList *next_list() const        { return _next_list; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   160
  void set_next_list(ThreadsList *list) { _next_list = list; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   161
48312
2a1413298af0 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents: 48105
diff changeset
   162
  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
   163
  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
   164
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   165
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   166
  ThreadsList(int entries);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   167
  ~ThreadsList();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   168
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   169
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   170
  void threads_do(T *cl) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   171
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   172
  uint length() const                       { return _length; }
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
  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
   175
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   176
  JavaThread *const *threads() const        { return _threads; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   177
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   178
  // Returns -1 if target is not found.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   179
  int find_index_of_JavaThread(JavaThread* target);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   180
  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
   181
  bool includes(const JavaThread * const p) const;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   182
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   183
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   184
// Linked list of ThreadsLists to support nested ThreadsListHandles.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   185
class NestedThreadsList : public CHeapObj<mtThread> {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   186
  ThreadsList*const _t_list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   187
  NestedThreadsList* _next;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   188
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   189
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   190
  NestedThreadsList(ThreadsList* t_list) : _t_list(t_list) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   191
    assert(Threads_lock->owned_by_self(),
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   192
           "must own Threads_lock for saved t_list to be valid.");
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
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   195
  ThreadsList* t_list() { return _t_list; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   196
  NestedThreadsList* next() { return _next; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   197
  void set_next(NestedThreadsList* value) { _next = value; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   198
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   199
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   200
// 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
   201
// 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
   202
// then the destructor will release it.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   203
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   204
class ThreadsListSetter : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   205
private:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   206
  bool _target_needs_release;  // needs release only when set()
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   207
  Thread * _target;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   208
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   209
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   210
  ThreadsListSetter() : _target_needs_release(false), _target(Thread::current()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   211
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   212
  ~ThreadsListSetter();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   213
  ThreadsList* list();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   214
  void set();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   215
  bool target_needs_release() { return _target_needs_release; }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   216
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   217
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   218
// This stack allocated ThreadsListHandle keeps all JavaThreads in the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   219
// ThreadsList from being deleted until it is safe.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   220
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   221
class ThreadsListHandle : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   222
  ThreadsList * _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   223
  Thread *const _self;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   224
  elapsedTimer _timer;  // Enabled via -XX:+EnableThreadSMRStatistics.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   225
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   226
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   227
  ThreadsListHandle(Thread *self = Thread::current());
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   228
  ~ThreadsListHandle();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   229
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   230
  ThreadsList *list() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   231
    return _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   232
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   233
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   234
  template <class T>
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   235
  void threads_do(T *cl) const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   236
    return _list->threads_do(cl);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   237
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   238
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   239
  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
   240
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   241
  bool includes(JavaThread* p) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   242
    return _list->includes(p);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   243
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   244
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   245
  uint length() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   246
    return _list->length();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   247
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   248
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   249
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   250
// This stack allocated JavaThreadIterator is used to walk the
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   251
// specified ThreadsList using the following style:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   252
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   253
//   JavaThreadIterator jti(t_list);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   254
//   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
   255
//     ...
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
class JavaThreadIterator : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   259
  ThreadsList * _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   260
  uint _index;
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
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   263
  JavaThreadIterator(ThreadsList *list) : _list(list), _index(0) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   264
    assert(list != NULL, "ThreadsList must not be NULL.");
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
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   267
  JavaThread *first() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   268
    _index = 0;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   269
    return _list->thread_at(_index);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   270
  }
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
  uint length() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   273
    return _list->length();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   274
  }
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
  ThreadsList *list() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   277
    return _list;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   278
  }
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
  JavaThread *next() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   281
    if (++_index >= length()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   282
      return NULL;
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
    return _list->thread_at(_index);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   285
  }
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
// This stack allocated ThreadsListHandle and JavaThreadIterator combo
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   289
// 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
   290
// using the following style:
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
//   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   293
//     ...
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
//
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   296
class JavaThreadIteratorWithHandle : public StackObj {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   297
  ThreadsListHandle _tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   298
  uint _index;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   299
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   300
public:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   301
  JavaThreadIteratorWithHandle() : _index(0) {}
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
  uint length() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   304
    return _tlh.length();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   305
  }
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
  ThreadsList *list() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   308
    return _tlh.list();
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
  JavaThread *next() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   312
    if (_index >= length()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   313
      return NULL;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   314
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   315
    return _tlh.list()->thread_at(_index++);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   316
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   317
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   318
  void rewind() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   319
    _index = 0;
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
};
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   322
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   323
#endif // SHARE_VM_RUNTIME_THREADSMR_HPP