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

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 2964
2a241e764894
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

ysr@777 1 /*
stefank@2314 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
stefank@2314 27
jprovino@4542 28 #include "utilities/macros.hpp"
jprovino@4542 29 #if INCLUDE_ALL_GCS
stefank@2314 30 #include "runtime/thread.hpp"
jprovino@4542 31 #endif // INCLUDE_ALL_GCS
stefank@2314 32
ysr@777 33 class VoidClosure;
ysr@777 34
ysr@777 35 // A SuspendibleThreadSet is (obviously) a set of threads that can be
ysr@777 36 // suspended. A thread can join and later leave the set, and periodically
ysr@777 37 // yield. If some thread (not in the set) requests, via suspend_all, that
ysr@777 38 // the threads be suspended, then the requesting thread is blocked until
ysr@777 39 // all the threads in the set have yielded or left the set. (Threads may
ysr@777 40 // not enter the set when an attempted suspension is in progress.) The
ysr@777 41 // suspending thread later calls resume_all, allowing the suspended threads
ysr@777 42 // to continue.
ysr@777 43
ysr@777 44 class SuspendibleThreadSet {
ysr@777 45 Monitor* _m;
ysr@777 46 int _async;
ysr@777 47 bool _async_stop;
ysr@777 48 int _async_stopped;
ysr@777 49 bool _initialized;
ysr@777 50 double _suspend_all_start;
ysr@777 51
ysr@777 52 void initialize_work();
ysr@777 53
ysr@777 54 public:
ysr@777 55 SuspendibleThreadSet() : _initialized(false) {}
ysr@777 56
ysr@777 57 // Add the current thread to the set. May block if a suspension
ysr@777 58 // is in progress.
ysr@777 59 void join();
ysr@777 60 // Removes the current thread from the set.
ysr@777 61 void leave();
ysr@777 62 // Returns "true" iff an suspension is in progress.
ysr@777 63 bool should_yield() { return _async_stop; }
ysr@777 64 // Suspends the current thread if a suspension is in progress (for
ysr@777 65 // the duration of the suspension.)
ysr@777 66 void yield(const char* id);
ysr@777 67 // Return when all threads in the set are suspended.
ysr@777 68 void suspend_all();
ysr@777 69 // Allow suspended threads to resume.
ysr@777 70 void resume_all();
ysr@777 71 // Redundant initializations okay.
ysr@777 72 void initialize() {
ysr@777 73 // Double-check dirty read idiom.
ysr@777 74 if (!_initialized) initialize_work();
ysr@777 75 }
ysr@777 76 };
ysr@777 77
ysr@777 78
ysr@777 79 class ConcurrentGCThread: public NamedThread {
ysr@777 80 friend class VMStructs;
ysr@777 81
ysr@777 82 protected:
iveresov@1229 83 bool _should_terminate;
iveresov@1229 84 bool _has_terminated;
ysr@777 85
ysr@777 86 enum CGC_flag_type {
ysr@777 87 CGC_nil = 0x0,
ysr@777 88 CGC_dont_suspend = 0x1,
ysr@777 89 CGC_CGC_safepoint = 0x2,
ysr@777 90 CGC_VM_safepoint = 0x4
ysr@777 91 };
ysr@777 92
ysr@777 93 static int _CGC_flag;
ysr@777 94
ysr@777 95 static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; }
ysr@777 96 static int set_CGC_flag(int b) { return _CGC_flag |= b; }
ysr@777 97 static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; }
ysr@777 98
ysr@777 99 // All instances share this one set.
ysr@777 100 static SuspendibleThreadSet _sts;
ysr@777 101
ysr@777 102 // Create and start the thread (setting it's priority high.)
ysr@777 103 void create_and_start();
ysr@777 104
ysr@777 105 // Do initialization steps in the thread: record stack base and size,
ysr@777 106 // init thread local storage, set JNI handle block.
ysr@777 107 void initialize_in_thread();
ysr@777 108
ysr@777 109 // Wait until Universe::is_fully_initialized();
ysr@777 110 void wait_for_universe_init();
ysr@777 111
ysr@777 112 // Record that the current thread is terminating, and will do more
ysr@777 113 // concurrent work.
ysr@777 114 void terminate();
ysr@777 115
ysr@777 116 public:
ysr@777 117 // Constructor
ysr@777 118
ysr@777 119 ConcurrentGCThread();
ysr@777 120 ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
ysr@777 121
ysr@777 122 // Tester
ysr@777 123 bool is_ConcurrentGC_thread() const { return true; }
ysr@777 124
ysr@777 125 static void safepoint_synchronize();
ysr@777 126 static void safepoint_desynchronize();
ysr@777 127
ysr@777 128 // All overridings should probably do _sts::yield, but we allow
ysr@777 129 // overriding for distinguished debugging messages. Default is to do
ysr@777 130 // nothing.
ysr@777 131 virtual void yield() {}
ysr@777 132
ysr@777 133 bool should_yield() { return _sts.should_yield(); }
ysr@777 134
ysr@777 135 // they are prefixed by sts since there are already yield() and
ysr@777 136 // should_yield() (non-static) methods in this class and it was an
ysr@777 137 // easy way to differentiate them.
ysr@777 138 static void stsYield(const char* id);
ysr@777 139 static bool stsShouldYield();
ysr@777 140 static void stsJoin();
ysr@777 141 static void stsLeave();
ysr@777 142
ysr@777 143 };
ysr@777 144
ysr@777 145 // The SurrogateLockerThread is used by concurrent GC threads for
ysr@777 146 // manipulating Java monitors, in particular, currently for
ysr@777 147 // manipulating the pending_list_lock. XXX
ysr@777 148 class SurrogateLockerThread: public JavaThread {
ysr@777 149 friend class VMStructs;
ysr@777 150 public:
ysr@777 151 enum SLT_msg_type {
ysr@777 152 empty = 0, // no message
ysr@777 153 acquirePLL, // acquire pending list lock
ysr@777 154 releaseAndNotifyPLL // notify and release pending list lock
ysr@777 155 };
ysr@777 156 private:
ysr@777 157 // the following are shared with the CMSThread
ysr@777 158 SLT_msg_type _buffer; // communication buffer
ysr@777 159 Monitor _monitor; // monitor controlling buffer
ysr@777 160 BasicLock _basicLock; // used for PLL locking
ysr@777 161
ysr@777 162 public:
ysr@777 163 static SurrogateLockerThread* make(TRAPS);
ysr@777 164
ysr@777 165 SurrogateLockerThread();
ysr@777 166
ysr@777 167 bool is_hidden_from_external_view() const { return true; }
ysr@777 168
ysr@777 169 void loop(); // main method
ysr@777 170
ysr@777 171 void manipulatePLL(SLT_msg_type msg);
ysr@777 172
ysr@777 173 };
stefank@2314 174
stefank@2314 175 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP

mercurial