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

Thu, 20 Sep 2012 09:52:56 -0700

author
johnc
date
Thu, 20 Sep 2012 09:52:56 -0700
changeset 4067
b2ef234911c9
parent 2964
2a241e764894
child 4542
db9981fd3124
permissions
-rw-r--r--

7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
Summary: Reset the fields in ParGCAllocBuffer, that are used for accumulating values for the ResizePLAB sensors in PLABStats, to zero after flushing the values to the PLABStats fields. Flush PLABStats values only when retiring the final allocation buffers prior to disposing of a G1ParScanThreadState object, rather than when retiring every allocation buffer.
Reviewed-by: jwilhelm, jmasa, ysr

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

mercurial