annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.cpp @ 10405:f2110083203d

8005849: JEP 167: Event-Based JVM Tracing Reviewed-by: acorn, coleenp, sla Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
author sla
date Mon, 10 Jun 2013 11:30:51 +0200
parents a252e688abcf
children de6a9e811145
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
4854
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
27 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
28 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
29 #include "memory/genCollectedHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
30 #include "oops/instanceRefKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
31 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
32 #include "runtime/init.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
33 #include "runtime/interfaceSupport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
34 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
35 #include "runtime/javaCalls.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
36 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
37 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1887
diff changeset
38 #include "runtime/vmThread.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // ======= Concurrent Mark Sweep Thread ========
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // The CMS thread is created when Concurrent Mark Sweep is used in the
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // older of two generations in a generational memory system.
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 ConcurrentMarkSweepThread*
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ConcurrentMarkSweepThread::_cmst = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 CMSCollector* ConcurrentMarkSweepThread::_collector = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 bool ConcurrentMarkSweepThread::_should_terminate = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 int ConcurrentMarkSweepThread::_CMS_flag = CMS_nil;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 volatile jint ConcurrentMarkSweepThread::_pending_yields = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 volatile jint ConcurrentMarkSweepThread::_pending_decrements = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
2365
a181f3a124dd 6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents: 1972
diff changeset
54 volatile jint ConcurrentMarkSweepThread::_icms_disabled = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 volatile bool ConcurrentMarkSweepThread::_should_run = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // When icms is enabled, the icms thread is stopped until explicitly
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // started.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 volatile bool ConcurrentMarkSweepThread::_should_stop = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 SurrogateLockerThread*
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ConcurrentMarkSweepThread::_slt = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 SurrogateLockerThread::SLT_msg_type
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ConcurrentMarkSweepThread::_sltBuffer = SurrogateLockerThread::empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Monitor*
a61af66fc99e Initial load
duke
parents:
diff changeset
65 ConcurrentMarkSweepThread::_sltMonitor = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector)
a61af66fc99e Initial load
duke
parents:
diff changeset
68 : ConcurrentGCThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 assert(_cmst == NULL, "CMS thread already created");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _cmst = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 assert(_collector == NULL, "Collector already set");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _collector = collector;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 set_name("Concurrent Mark-Sweep GC Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (os::create_thread(this, os::cgc_thread)) {
4854
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
78 // An old comment here said: "Priority should be just less
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
79 // than that of VMThread". Since the VMThread runs at
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
80 // NearMaxPriority, the old comment was inaccurate, but
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
81 // changing the default priority to NearMaxPriority-1
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
82 // could change current behavior, so the default of
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
83 // NearMaxPriority stays in place.
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
84 //
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
85 // Note that there's a possibility of the VMThread
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
86 // starving if UseCriticalCMSThreadPriority is on.
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
87 // That won't happen on Solaris for various reasons,
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
88 // but may well happen on non-Solaris platforms.
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
89 int native_prio;
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
90 if (UseCriticalCMSThreadPriority) {
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
91 native_prio = os::java_to_os_priority[CriticalPriority];
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
92 } else {
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
93 native_prio = os::java_to_os_priority[NearMaxPriority];
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
94 }
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
95 os::set_native_priority(this, native_prio);
de268c8a8075 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 2365
diff changeset
96
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (!DisableStartThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 os::start_thread(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _sltMonitor = SLT_lock;
2365
a181f3a124dd 6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents: 1972
diff changeset
102 assert(!CMSIncrementalMode || icms_is_enabled(), "Error");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void ConcurrentMarkSweepThread::run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(this == cmst(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 this->record_stack_base_and_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 this->initialize_thread_local_storage();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 this->set_active_handles(JNIHandleBlock::allocate_block());
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // From this time Thread::current() should be working.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 assert(this == Thread::current(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 warning("Couldn't bind CMS thread to processor %u", CPUForCMSThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Wait until Universe::is_fully_initialized()
a61af66fc99e Initial load
duke
parents:
diff changeset
117 {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 CMSLoopCountWarn loopX("CMS::run", "waiting for "
a61af66fc99e Initial load
duke
parents:
diff changeset
119 "Universe::is_fully_initialized()", 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 MutexLockerEx x(CGC_lock, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 set_CMS_flag(CMS_cms_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Wait until Universe is initialized and all initialization is completed.
a61af66fc99e Initial load
duke
parents:
diff changeset
123 while (!is_init_completed() && !Universe::is_fully_initialized() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
124 !_should_terminate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 CGC_lock->wait(true, 200);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 loopX.tick();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Wait until the surrogate locker thread that will do
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // pending list locking on our behalf has been created.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // We cannot start the SLT thread ourselves since we need
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // to be a JavaThread to do so.
a61af66fc99e Initial load
duke
parents:
diff changeset
132 CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 while (_slt == NULL && !_should_terminate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 CGC_lock->wait(true, 200);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 loopY.tick();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 clear_CMS_flag(CMS_cms_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 while (!_should_terminate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 sleepBeforeNextCycle();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (_should_terminate) break;
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 8679
diff changeset
143 GCCause::Cause cause = _collector->_full_gc_requested ?
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 8679
diff changeset
144 _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 8679
diff changeset
145 _collector->collect_in_background(false, cause);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 assert(_should_terminate, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Check that the state of any protocol for synchronization
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // between background (CMS) and foreground collector is "clean"
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // (i.e. will not potentially block the foreground collector,
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // requiring action by us).
a61af66fc99e Initial load
duke
parents:
diff changeset
152 verify_ok_to_terminate();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Signal that it is terminated
a61af66fc99e Initial load
duke
parents:
diff changeset
154 {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 MutexLockerEx mu(Terminator_lock,
a61af66fc99e Initial load
duke
parents:
diff changeset
156 Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert(_cmst == this, "Weird!");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 _cmst = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Terminator_lock->notify();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Thread destructor usually does this..
a61af66fc99e Initial load
duke
parents:
diff changeset
163 ThreadLocalStorage::set_thread(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
167 void ConcurrentMarkSweepThread::verify_ok_to_terminate() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 assert(!(CGC_lock->owned_by_self() || cms_thread_has_cms_token() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
169 cms_thread_wants_cms_token()),
a61af66fc99e Initial load
duke
parents:
diff changeset
170 "Must renounce all worldly possessions and desires for nirvana");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _collector->verify_ok_to_terminate();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // create and start a new ConcurrentMarkSweep Thread for given CMS generation
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::start(CMSCollector* collector) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if (!_should_terminate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(cmst() == NULL, "start() called twice?");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 ConcurrentMarkSweepThread* th = new ConcurrentMarkSweepThread(collector);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 assert(cmst() == th, "Where did the just-created CMS thread go?");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return th;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 void ConcurrentMarkSweepThread::stop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (CMSIncrementalMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Disable incremental mode and wake up the thread so it notices the change.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 disable_icms();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 start_icms();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // it is ok to take late safepoints here, if needed
a61af66fc99e Initial load
duke
parents:
diff changeset
193 {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 MutexLockerEx x(Terminator_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 _should_terminate = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 { // Now post a notify on CGC_lock so as to nudge
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // CMS thread(s) that might be slumbering in
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // sleepBeforeNextCycle.
a61af66fc99e Initial load
duke
parents:
diff changeset
200 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 CGC_lock->notify_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 { // Now wait until (all) CMS thread(s) have exited
a61af66fc99e Initial load
duke
parents:
diff changeset
204 MutexLockerEx x(Terminator_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 while(cmst() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 Terminator_lock->wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 assert(tc != NULL, "Null ThreadClosure");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (_cmst != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 tc->do_thread(_cmst);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 assert(Universe::is_fully_initialized(),
a61af66fc99e Initial load
duke
parents:
diff changeset
217 "Called too early, make sure heap is fully initialized");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (_collector != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 AbstractWorkGang* gang = _collector->conc_workers();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if (gang != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 gang->threads_do(tc);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 void ConcurrentMarkSweepThread::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 st->print("\"%s\" ", name());
a61af66fc99e Initial load
duke
parents:
diff changeset
228 Thread::print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 void ConcurrentMarkSweepThread::print_all_on(outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if (_cmst != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 _cmst->print_on(st);
6766
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents: 4854
diff changeset
235 st->cr();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 if (_collector != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 AbstractWorkGang* gang = _collector->conc_workers();
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (gang != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 gang->print_worker_threads_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 void ConcurrentMarkSweepThread::synchronize(bool is_cms_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 assert(UseConcMarkSweepGC, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 MutexLockerEx x(CGC_lock,
a61af66fc99e Initial load
duke
parents:
diff changeset
249 Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (!is_cms_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 assert(Thread::current()->is_VM_thread(), "Not a VM thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 CMSSynchronousYieldRequest yr;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 while (CMS_flag_is_set(CMS_cms_has_token)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // indicate that we want to get the token
a61af66fc99e Initial load
duke
parents:
diff changeset
255 set_CMS_flag(CMS_vm_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 CGC_lock->wait(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // claim the token and proceed
a61af66fc99e Initial load
duke
parents:
diff changeset
259 clear_CMS_flag(CMS_vm_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 set_CMS_flag(CMS_vm_has_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert(Thread::current()->is_ConcurrentGC_thread(),
a61af66fc99e Initial load
duke
parents:
diff changeset
263 "Not a CMS thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // The following barrier assumes there's only one CMS thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // This will need to be modified is there are more CMS threads than one.
a61af66fc99e Initial load
duke
parents:
diff changeset
266 while (CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 set_CMS_flag(CMS_cms_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 CGC_lock->wait(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // claim the token
a61af66fc99e Initial load
duke
parents:
diff changeset
271 clear_CMS_flag(CMS_cms_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 set_CMS_flag(CMS_cms_has_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 void ConcurrentMarkSweepThread::desynchronize(bool is_cms_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 assert(UseConcMarkSweepGC, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 MutexLockerEx x(CGC_lock,
a61af66fc99e Initial load
duke
parents:
diff changeset
280 Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 if (!is_cms_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 assert(Thread::current()->is_VM_thread(), "Not a VM thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
283 assert(CMS_flag_is_set(CMS_vm_has_token), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 clear_CMS_flag(CMS_vm_has_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (CMS_flag_is_set(CMS_cms_wants_token)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // wake-up a waiting CMS thread
a61af66fc99e Initial load
duke
parents:
diff changeset
287 CGC_lock->notify();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 assert(!CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token),
a61af66fc99e Initial load
duke
parents:
diff changeset
290 "Should have been cleared");
a61af66fc99e Initial load
duke
parents:
diff changeset
291 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 assert(Thread::current()->is_ConcurrentGC_thread(),
a61af66fc99e Initial load
duke
parents:
diff changeset
293 "Not a CMS thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
294 assert(CMS_flag_is_set(CMS_cms_has_token), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
295 clear_CMS_flag(CMS_cms_has_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (CMS_flag_is_set(CMS_vm_wants_token)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // wake-up a waiting VM thread
a61af66fc99e Initial load
duke
parents:
diff changeset
298 CGC_lock->notify();
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
a61af66fc99e Initial load
duke
parents:
diff changeset
301 "Should have been cleared");
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304
8679
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
305 // Wait until any cms_lock event
1887
cd3ef3fd20dd 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 1552
diff changeset
306 void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
307 MutexLockerEx x(CGC_lock,
a61af66fc99e Initial load
duke
parents:
diff changeset
308 Mutex::_no_safepoint_check_flag);
1887
cd3ef3fd20dd 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 1552
diff changeset
309 if (_should_terminate || _collector->_full_gc_requested) {
cd3ef3fd20dd 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 1552
diff changeset
310 return;
cd3ef3fd20dd 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 1552
diff changeset
311 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
312 set_CMS_flag(CMS_cms_wants_token); // to provoke notifies
1887
cd3ef3fd20dd 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 1552
diff changeset
313 CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
314 clear_CMS_flag(CMS_cms_wants_token);
a61af66fc99e Initial load
duke
parents:
diff changeset
315 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
a61af66fc99e Initial load
duke
parents:
diff changeset
316 "Should not be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318
8679
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
319 // Wait until the next synchronous GC, a concurrent full gc request,
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
320 // or a timeout, whichever is earlier.
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
321 void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
322 // Wait time in millis or 0 value representing infinite wait for a scavenge
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
323 assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
324
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
325 GenCollectedHeap* gch = GenCollectedHeap::heap();
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
326 double start_time_secs = os::elapsedTime();
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
327 double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
328
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
329 // Total collections count before waiting loop
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
330 unsigned int before_count;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
331 {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
332 MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
333 before_count = gch->total_collections();
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
334 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
335
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
336 unsigned int loop_count = 0;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
337
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
338 while(!_should_terminate) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
339 double now_time = os::elapsedTime();
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
340 long wait_time_millis;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
341
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
342 if(t_millis != 0) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
343 // New wait limit
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
344 wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
345 if(wait_time_millis <= 0) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
346 // Wait time is over
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
347 break;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
348 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
349 } else {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
350 // No wait limit, wait if necessary forever
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
351 wait_time_millis = 0;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
352 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
353
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
354 // Wait until the next event or the remaining timeout
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
355 {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
356 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
357
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
358 if (_should_terminate || _collector->_full_gc_requested) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
359 return;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
360 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
361 set_CMS_flag(CMS_cms_wants_token); // to provoke notifies
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
362 assert(t_millis == 0 || wait_time_millis > 0, "Sanity");
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
363 CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
364 clear_CMS_flag(CMS_cms_wants_token);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
365 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
366 "Should not be set");
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
367 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
368
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
369 // Extra wait time check before entering the heap lock to get the collection count
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
370 if(t_millis != 0 && os::elapsedTime() >= end_time_secs) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
371 // Wait time is over
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
372 break;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
373 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
374
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
375 // Total collections count after the event
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
376 unsigned int after_count;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
377 {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
378 MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
379 after_count = gch->total_collections();
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
380 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
381
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
382 if(before_count != after_count) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
383 // There was a collection - success
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
384 break;
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
385 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
386
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
387 // Too many loops warning
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
388 if(++loop_count == 0) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
389 warning("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
390 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
391 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
392 }
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
393
0
a61af66fc99e Initial load
duke
parents:
diff changeset
394 void ConcurrentMarkSweepThread::sleepBeforeNextCycle() {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 while (!_should_terminate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (CMSIncrementalMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 icms_wait();
8679
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
398 if(CMSWaitDuration >= 0) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
399 // Wait until the next synchronous GC, a concurrent full gc
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
400 // request or a timeout, whichever is earlier.
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
401 wait_on_cms_lock_for_scavenge(CMSWaitDuration);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
402 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
403 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 } else {
8679
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
405 if(CMSWaitDuration >= 0) {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
406 // Wait until the next synchronous GC, a concurrent full gc
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
407 // request or a timeout, whichever is earlier.
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
408 wait_on_cms_lock_for_scavenge(CMSWaitDuration);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
409 } else {
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
410 // Wait until any cms_lock event or check interval not to call shouldConcurrentCollect permanently
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
411 wait_on_cms_lock(CMSCheckInterval);
a252e688abcf 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 6766
diff changeset
412 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // Check if we should start a CMS collection cycle
a61af66fc99e Initial load
duke
parents:
diff changeset
415 if (_collector->shouldConcurrentCollect()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // .. collection criterion not yet met, let's go back
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // and wait some more
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Incremental CMS
a61af66fc99e Initial load
duke
parents:
diff changeset
424 void ConcurrentMarkSweepThread::start_icms() {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
426 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 trace_state("start_icms");
a61af66fc99e Initial load
duke
parents:
diff changeset
428 _should_run = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 iCMS_lock->notify_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 void ConcurrentMarkSweepThread::stop_icms() {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
434 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 if (!_should_stop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 trace_state("stop_icms");
a61af66fc99e Initial load
duke
parents:
diff changeset
437 _should_stop = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
438 _should_run = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 asynchronous_yield_request();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 iCMS_lock->notify_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 void ConcurrentMarkSweepThread::icms_wait() {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
2365
a181f3a124dd 6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents: 1972
diff changeset
446 if (_should_stop && icms_is_enabled()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
447 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 trace_state("pause_icms");
a61af66fc99e Initial load
duke
parents:
diff changeset
449 _collector->stats().stop_cms_timer();
2365
a181f3a124dd 6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents: 1972
diff changeset
450 while(!_should_run && icms_is_enabled()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
451 iCMS_lock->wait(Mutex::_no_safepoint_check_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453 _collector->stats().start_cms_timer();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 _should_stop = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 trace_state("pause_icms end");
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // Note: this method, although exported by the ConcurrentMarkSweepThread,
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // which is a non-JavaThread, can only be called by a JavaThread.
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // Currently this is done at vm creation time (post-vm-init) by the
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // main/Primordial (Java)Thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // XXX Consider changing this in the future to allow the CMS thread
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // itself to create this thread?
a61af66fc99e Initial load
duke
parents:
diff changeset
465 void ConcurrentMarkSweepThread::makeSurrogateLockerThread(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 assert(UseConcMarkSweepGC, "SLT thread needed only for CMS GC");
a61af66fc99e Initial load
duke
parents:
diff changeset
467 assert(_slt == NULL, "SLT already created");
a61af66fc99e Initial load
duke
parents:
diff changeset
468 _slt = SurrogateLockerThread::make(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }