src/share/vm/gc_implementation/shared/concurrentGCThread.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/concurrentGCThread.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,175 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
    1.30 +
    1.31 +#include "utilities/macros.hpp"
    1.32 +#if INCLUDE_ALL_GCS
    1.33 +#include "runtime/thread.hpp"
    1.34 +#endif // INCLUDE_ALL_GCS
    1.35 +
    1.36 +class VoidClosure;
    1.37 +
    1.38 +// A SuspendibleThreadSet is (obviously) a set of threads that can be
    1.39 +// suspended.  A thread can join and later leave the set, and periodically
    1.40 +// yield.  If some thread (not in the set) requests, via suspend_all, that
    1.41 +// the threads be suspended, then the requesting thread is blocked until
    1.42 +// all the threads in the set have yielded or left the set.  (Threads may
    1.43 +// not enter the set when an attempted suspension is in progress.)  The
    1.44 +// suspending thread later calls resume_all, allowing the suspended threads
    1.45 +// to continue.
    1.46 +
    1.47 +class SuspendibleThreadSet {
    1.48 +  Monitor* _m;
    1.49 +  int      _async;
    1.50 +  bool     _async_stop;
    1.51 +  int      _async_stopped;
    1.52 +  bool     _initialized;
    1.53 +  double   _suspend_all_start;
    1.54 +
    1.55 +  void initialize_work();
    1.56 +
    1.57 + public:
    1.58 +  SuspendibleThreadSet() : _initialized(false) {}
    1.59 +
    1.60 +  // Add the current thread to the set.  May block if a suspension
    1.61 +  // is in progress.
    1.62 +  void join();
    1.63 +  // Removes the current thread from the set.
    1.64 +  void leave();
    1.65 +  // Returns "true" iff an suspension is in progress.
    1.66 +  bool should_yield() { return _async_stop; }
    1.67 +  // Suspends the current thread if a suspension is in progress (for
    1.68 +  // the duration of the suspension.)
    1.69 +  void yield(const char* id);
    1.70 +  // Return when all threads in the set are suspended.
    1.71 +  void suspend_all();
    1.72 +  // Allow suspended threads to resume.
    1.73 +  void resume_all();
    1.74 +  // Redundant initializations okay.
    1.75 +  void initialize() {
    1.76 +    // Double-check dirty read idiom.
    1.77 +    if (!_initialized) initialize_work();
    1.78 +  }
    1.79 +};
    1.80 +
    1.81 +
    1.82 +class ConcurrentGCThread: public NamedThread {
    1.83 +  friend class VMStructs;
    1.84 +
    1.85 +protected:
    1.86 +  bool _should_terminate;
    1.87 +  bool _has_terminated;
    1.88 +
    1.89 +  enum CGC_flag_type {
    1.90 +    CGC_nil           = 0x0,
    1.91 +    CGC_dont_suspend  = 0x1,
    1.92 +    CGC_CGC_safepoint = 0x2,
    1.93 +    CGC_VM_safepoint  = 0x4
    1.94 +  };
    1.95 +
    1.96 +  static int _CGC_flag;
    1.97 +
    1.98 +  static bool CGC_flag_is_set(int b)       { return (_CGC_flag & b) != 0; }
    1.99 +  static int set_CGC_flag(int b)           { return _CGC_flag |= b; }
   1.100 +  static int reset_CGC_flag(int b)         { return _CGC_flag &= ~b; }
   1.101 +
   1.102 +  // All instances share this one set.
   1.103 +  static SuspendibleThreadSet _sts;
   1.104 +
   1.105 +  // Create and start the thread (setting it's priority high.)
   1.106 +  void create_and_start();
   1.107 +
   1.108 +  // Do initialization steps in the thread: record stack base and size,
   1.109 +  // init thread local storage, set JNI handle block.
   1.110 +  void initialize_in_thread();
   1.111 +
   1.112 +  // Wait until Universe::is_fully_initialized();
   1.113 +  void wait_for_universe_init();
   1.114 +
   1.115 +  // Record that the current thread is terminating, and will do more
   1.116 +  // concurrent work.
   1.117 +  void terminate();
   1.118 +
   1.119 +public:
   1.120 +  // Constructor
   1.121 +
   1.122 +  ConcurrentGCThread();
   1.123 +  ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
   1.124 +
   1.125 +  // Tester
   1.126 +  bool is_ConcurrentGC_thread() const          { return true;       }
   1.127 +
   1.128 +  static void safepoint_synchronize();
   1.129 +  static void safepoint_desynchronize();
   1.130 +
   1.131 +  // All overridings should probably do _sts::yield, but we allow
   1.132 +  // overriding for distinguished debugging messages.  Default is to do
   1.133 +  // nothing.
   1.134 +  virtual void yield() {}
   1.135 +
   1.136 +  bool should_yield() { return _sts.should_yield(); }
   1.137 +
   1.138 +  // they are prefixed by sts since there are already yield() and
   1.139 +  // should_yield() (non-static) methods in this class and it was an
   1.140 +  // easy way to differentiate them.
   1.141 +  static void stsYield(const char* id);
   1.142 +  static bool stsShouldYield();
   1.143 +  static void stsJoin();
   1.144 +  static void stsLeave();
   1.145 +
   1.146 +};
   1.147 +
   1.148 +// The SurrogateLockerThread is used by concurrent GC threads for
   1.149 +// manipulating Java monitors, in particular, currently for
   1.150 +// manipulating the pending_list_lock. XXX
   1.151 +class SurrogateLockerThread: public JavaThread {
   1.152 +  friend class VMStructs;
   1.153 + public:
   1.154 +  enum SLT_msg_type {
   1.155 +    empty = 0,           // no message
   1.156 +    acquirePLL,          // acquire pending list lock
   1.157 +    releaseAndNotifyPLL  // notify and release pending list lock
   1.158 +  };
   1.159 + private:
   1.160 +  // the following are shared with the CMSThread
   1.161 +  SLT_msg_type  _buffer;  // communication buffer
   1.162 +  Monitor       _monitor; // monitor controlling buffer
   1.163 +  BasicLock     _basicLock; // used for PLL locking
   1.164 +
   1.165 + public:
   1.166 +  static SurrogateLockerThread* make(TRAPS);
   1.167 +
   1.168 +  SurrogateLockerThread();
   1.169 +
   1.170 +  bool is_hidden_from_external_view() const     { return true; }
   1.171 +
   1.172 +  void loop(); // main method
   1.173 +
   1.174 +  void manipulatePLL(SLT_msg_type msg);
   1.175 +
   1.176 +};
   1.177 +
   1.178 +#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP

mercurial