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

Mon, 11 May 2009 16:30:56 -0700

author
iveresov
date
Mon, 11 May 2009 16:30:56 -0700
changeset 1229
315a5d70b295
parent 777
37f87013dfd8
child 1279
bd02caa94611
permissions
-rw-r--r--

6484957: G1: parallel concurrent refinement
6826318: G1: remove traversal-based refinement code
Summary: Removed traversal-based refinement code as it's no longer used. Made the concurrent refinement (queue-based) parallel.
Reviewed-by: tonyp

ysr@777 1 /*
ysr@777 2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 class VoidClosure;
ysr@777 26
ysr@777 27 // A SuspendibleThreadSet is (obviously) a set of threads that can be
ysr@777 28 // suspended. A thread can join and later leave the set, and periodically
ysr@777 29 // yield. If some thread (not in the set) requests, via suspend_all, that
ysr@777 30 // the threads be suspended, then the requesting thread is blocked until
ysr@777 31 // all the threads in the set have yielded or left the set. (Threads may
ysr@777 32 // not enter the set when an attempted suspension is in progress.) The
ysr@777 33 // suspending thread later calls resume_all, allowing the suspended threads
ysr@777 34 // to continue.
ysr@777 35
ysr@777 36 class SuspendibleThreadSet {
ysr@777 37 Monitor* _m;
ysr@777 38 int _async;
ysr@777 39 bool _async_stop;
ysr@777 40 int _async_stopped;
ysr@777 41 bool _initialized;
ysr@777 42 double _suspend_all_start;
ysr@777 43
ysr@777 44 void initialize_work();
ysr@777 45
ysr@777 46 public:
ysr@777 47 SuspendibleThreadSet() : _initialized(false) {}
ysr@777 48
ysr@777 49 // Add the current thread to the set. May block if a suspension
ysr@777 50 // is in progress.
ysr@777 51 void join();
ysr@777 52 // Removes the current thread from the set.
ysr@777 53 void leave();
ysr@777 54 // Returns "true" iff an suspension is in progress.
ysr@777 55 bool should_yield() { return _async_stop; }
ysr@777 56 // Suspends the current thread if a suspension is in progress (for
ysr@777 57 // the duration of the suspension.)
ysr@777 58 void yield(const char* id);
ysr@777 59 // Return when all threads in the set are suspended.
ysr@777 60 void suspend_all();
ysr@777 61 // Allow suspended threads to resume.
ysr@777 62 void resume_all();
ysr@777 63 // Redundant initializations okay.
ysr@777 64 void initialize() {
ysr@777 65 // Double-check dirty read idiom.
ysr@777 66 if (!_initialized) initialize_work();
ysr@777 67 }
ysr@777 68 };
ysr@777 69
ysr@777 70
ysr@777 71 class ConcurrentGCThread: public NamedThread {
ysr@777 72 friend class VMStructs;
ysr@777 73
ysr@777 74 protected:
iveresov@1229 75 bool _should_terminate;
iveresov@1229 76 bool _has_terminated;
ysr@777 77
ysr@777 78 enum CGC_flag_type {
ysr@777 79 CGC_nil = 0x0,
ysr@777 80 CGC_dont_suspend = 0x1,
ysr@777 81 CGC_CGC_safepoint = 0x2,
ysr@777 82 CGC_VM_safepoint = 0x4
ysr@777 83 };
ysr@777 84
ysr@777 85 static int _CGC_flag;
ysr@777 86
ysr@777 87 static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; }
ysr@777 88 static int set_CGC_flag(int b) { return _CGC_flag |= b; }
ysr@777 89 static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; }
ysr@777 90
ysr@777 91 void stopWorldAndDo(VoidClosure* op);
ysr@777 92
ysr@777 93 // All instances share this one set.
ysr@777 94 static SuspendibleThreadSet _sts;
ysr@777 95
ysr@777 96 // Create and start the thread (setting it's priority high.)
ysr@777 97 void create_and_start();
ysr@777 98
ysr@777 99 // Do initialization steps in the thread: record stack base and size,
ysr@777 100 // init thread local storage, set JNI handle block.
ysr@777 101 void initialize_in_thread();
ysr@777 102
ysr@777 103 // Wait until Universe::is_fully_initialized();
ysr@777 104 void wait_for_universe_init();
ysr@777 105
ysr@777 106 // Record that the current thread is terminating, and will do more
ysr@777 107 // concurrent work.
ysr@777 108 void terminate();
ysr@777 109
ysr@777 110 public:
ysr@777 111 // Constructor
ysr@777 112
ysr@777 113 ConcurrentGCThread();
ysr@777 114 ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
ysr@777 115
ysr@777 116 // Tester
ysr@777 117 bool is_ConcurrentGC_thread() const { return true; }
ysr@777 118
ysr@777 119 static void safepoint_synchronize();
ysr@777 120 static void safepoint_desynchronize();
ysr@777 121
ysr@777 122 // All overridings should probably do _sts::yield, but we allow
ysr@777 123 // overriding for distinguished debugging messages. Default is to do
ysr@777 124 // nothing.
ysr@777 125 virtual void yield() {}
ysr@777 126
ysr@777 127 bool should_yield() { return _sts.should_yield(); }
ysr@777 128
ysr@777 129 // they are prefixed by sts since there are already yield() and
ysr@777 130 // should_yield() (non-static) methods in this class and it was an
ysr@777 131 // easy way to differentiate them.
ysr@777 132 static void stsYield(const char* id);
ysr@777 133 static bool stsShouldYield();
ysr@777 134 static void stsJoin();
ysr@777 135 static void stsLeave();
ysr@777 136
ysr@777 137 };
ysr@777 138
ysr@777 139 // The SurrogateLockerThread is used by concurrent GC threads for
ysr@777 140 // manipulating Java monitors, in particular, currently for
ysr@777 141 // manipulating the pending_list_lock. XXX
ysr@777 142 class SurrogateLockerThread: public JavaThread {
ysr@777 143 friend class VMStructs;
ysr@777 144 public:
ysr@777 145 enum SLT_msg_type {
ysr@777 146 empty = 0, // no message
ysr@777 147 acquirePLL, // acquire pending list lock
ysr@777 148 releaseAndNotifyPLL // notify and release pending list lock
ysr@777 149 };
ysr@777 150 private:
ysr@777 151 // the following are shared with the CMSThread
ysr@777 152 SLT_msg_type _buffer; // communication buffer
ysr@777 153 Monitor _monitor; // monitor controlling buffer
ysr@777 154 BasicLock _basicLock; // used for PLL locking
ysr@777 155
ysr@777 156 public:
ysr@777 157 static SurrogateLockerThread* make(TRAPS);
ysr@777 158
ysr@777 159 SurrogateLockerThread();
ysr@777 160
ysr@777 161 bool is_hidden_from_external_view() const { return true; }
ysr@777 162
ysr@777 163 void loop(); // main method
ysr@777 164
ysr@777 165 void manipulatePLL(SLT_msg_type msg);
ysr@777 166
ysr@777 167 };

mercurial