< prev index next >

src/hotspot/share/runtime/threadSMR.hpp

Print this page
rev 47862 : imported patch 10.07.open.rebase_20171110.dcubed
rev 47867 : coleenp CR: Change ThreadsList::_threads from 'mtGC' -> 'mtThread', add header comment to threadSMR.hpp file, cleanup JavaThreadIteratorWithHandle ctr, make ErrorHandling more efficient.


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREADSMR_HPP
  26 #define SHARE_VM_RUNTIME_THREADSMR_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/timer.hpp"
  30 

















































  31 // A fast list of JavaThreads.
  32 //
  33 class ThreadsList : public CHeapObj<mtThread> {
  34   friend class ScanHazardPtrGatherProtectedThreadsClosure;
  35   friend class Threads;
  36 
  37   const uint _length;
  38   ThreadsList* _next_list;
  39   JavaThread *const *const _threads;
  40 
  41   template <class T>
  42   void threads_do_dispatch(T *cl, JavaThread *const thread) const;
  43 
  44   ThreadsList *next_list() const        { return _next_list; }
  45   void set_next_list(ThreadsList *list) { _next_list = list; }
  46 
  47 public:
  48   ThreadsList(int entries);
  49   ~ThreadsList();
  50 


 166     if (++_index >= length()) {
 167       return NULL;
 168     }
 169     return _list->thread_at(_index);
 170   }
 171 };
 172 
 173 // This stack allocated ThreadsListHandle and JavaThreadIterator combo
 174 // is used to walk the ThreadsList in the included ThreadsListHandle
 175 // using the following style:
 176 //
 177 //   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
 178 //     ...
 179 //   }
 180 //
 181 class JavaThreadIteratorWithHandle : public StackObj {
 182   ThreadsListHandle _tlh;
 183   uint _index;
 184 
 185 public:
 186   JavaThreadIteratorWithHandle() : _tlh(), _index(0) {}
 187 
 188   uint length() const {
 189     return _tlh.length();
 190   }
 191 
 192   ThreadsList *list() const {
 193     return _tlh.list();
 194   }
 195 
 196   JavaThread *next() {
 197     if (_index >= length()) {
 198       return NULL;
 199     }
 200     return _tlh.list()->thread_at(_index++);
 201   }
 202 
 203   void rewind() {
 204     _index = 0;
 205   }
 206 };


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREADSMR_HPP
  26 #define SHARE_VM_RUNTIME_THREADSMR_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/timer.hpp"
  30 
  31 // Thread Safe Memory Reclaimation (Thread-SMR) support.
  32 //
  33 // ThreadsListHandles are used to safely perform operations on one or more
  34 // threads without the risk of the thread or threads exiting during the
  35 // operation. It is no longer necessary to hold the Threads_lock to safely
  36 // perform an operation on a target thread.
  37 //
  38 // There are several different ways to refer to java.lang.Thread objects
  39 // so we have a few ways to get a protected JavaThread *:
  40 //
  41 // JNI jobject example:
  42 //   jobject jthread = ...;
  43 //   :
  44 //   ThreadsListHandle tlh;
  45 //   JavaThread* jt = NULL;
  46 //   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &jt, NULL);
  47 //   if (is_alive) {
  48 //     :  // do stuff with 'jt'...
  49 //   }
  50 //
  51 // JVM/TI jthread example:
  52 //   jthread thread = ...;
  53 //   :
  54 //   JavaThread* jt = NULL;
  55 //   ThreadsListHandle tlh;
  56 //   jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &jt, NULL);
  57 //   if (err != JVMTI_ERROR_NONE) {
  58 //     return err;
  59 //   }
  60 //   :  // do stuff with 'jt'...
  61 //
  62 // JVM/TI oop example (this one should be very rare):
  63 //   oop thread_obj = ...;
  64 //   :
  65 //   JavaThread *jt = NULL;
  66 //   ThreadsListHandle tlh;
  67 //   jvmtiError err = JvmtiExport::cv_oop_to_JavaThread(tlh.list(), thread_obj, &jt);
  68 //   if (err != JVMTI_ERROR_NONE) {
  69 //     return err;
  70 //   }
  71 //   :  // do stuff with 'jt'...
  72 //
  73 // A JavaThread * that is included in the ThreadsList that is held by
  74 // a ThreadsListHandle is protected as long as the ThreadsListHandle
  75 // remains in scope. The target JavaThread * may have logically exited,
  76 // but that target JavaThread * will not be deleted until it is no
  77 // longer protected by a ThreadsListHandle.
  78 
  79 
  80 // A fast list of JavaThreads.
  81 //
  82 class ThreadsList : public CHeapObj<mtThread> {
  83   friend class ScanHazardPtrGatherProtectedThreadsClosure;
  84   friend class Threads;
  85 
  86   const uint _length;
  87   ThreadsList* _next_list;
  88   JavaThread *const *const _threads;
  89 
  90   template <class T>
  91   void threads_do_dispatch(T *cl, JavaThread *const thread) const;
  92 
  93   ThreadsList *next_list() const        { return _next_list; }
  94   void set_next_list(ThreadsList *list) { _next_list = list; }
  95 
  96 public:
  97   ThreadsList(int entries);
  98   ~ThreadsList();
  99 


 215     if (++_index >= length()) {
 216       return NULL;
 217     }
 218     return _list->thread_at(_index);
 219   }
 220 };
 221 
 222 // This stack allocated ThreadsListHandle and JavaThreadIterator combo
 223 // is used to walk the ThreadsList in the included ThreadsListHandle
 224 // using the following style:
 225 //
 226 //   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
 227 //     ...
 228 //   }
 229 //
 230 class JavaThreadIteratorWithHandle : public StackObj {
 231   ThreadsListHandle _tlh;
 232   uint _index;
 233 
 234 public:
 235   JavaThreadIteratorWithHandle() : _index(0) {}
 236 
 237   uint length() const {
 238     return _tlh.length();
 239   }
 240 
 241   ThreadsList *list() const {
 242     return _tlh.list();
 243   }
 244 
 245   JavaThread *next() {
 246     if (_index >= length()) {
 247       return NULL;
 248     }
 249     return _tlh.list()->thread_at(_index++);
 250   }
 251 
 252   void rewind() {
 253     _index = 0;
 254   }
 255 };
< prev index next >