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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial