/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "memory/genCollectedHeap.hpp"
#include "oops/instanceRefKlass.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/vmThread.hpp"
// ======= Concurrent Mark Sweep Thread ========
// The CMS thread is created when Concurrent Mark Sweep is used in the
// older of two generations in a generational memory system.
// When icms is enabled, the icms thread is stopped until explicitly
// started.
: ConcurrentGCThread() {
_cmst = this;
set_name("Concurrent Mark-Sweep GC Thread");
// An old comment here said: "Priority should be just less
// than that of VMThread". Since the VMThread runs at
// NearMaxPriority, the old comment was inaccurate, but
// changing the default priority to NearMaxPriority-1
// could change current behavior, so the default of
// NearMaxPriority stays in place.
//
// Note that there's a possibility of the VMThread
// starving if UseCriticalCMSThreadPriority is on.
// That won't happen on Solaris for various reasons,
// but may well happen on non-Solaris platforms.
int native_prio;
if (UseCriticalCMSThreadPriority) {
} else {
}
if (!DisableStartThread) {
os::start_thread(this);
}
}
}
this->record_stack_base_and_size();
this->initialize_thread_local_storage();
// From this time Thread::current() should be working.
}
// Wait until Universe::is_fully_initialized()
{
"Universe::is_fully_initialized()", 2);
MutexLockerEx x(CGC_lock, true);
// Wait until Universe is initialized and all initialization is completed.
}
// Wait until the surrogate locker thread that will do
// pending list locking on our behalf has been created.
// We cannot start the SLT thread ourselves since we need
// to be a JavaThread to do so.
}
}
while (!_should_terminate) {
if (_should_terminate) break;
}
// Check that the state of any protocol for synchronization
// between background (CMS) and foreground collector is "clean"
// (i.e. will not potentially block the foreground collector,
// requiring action by us).
// Signal that it is terminated
{
}
// Thread destructor usually does this..
}
#ifndef PRODUCT
"Must renounce all worldly possessions and desires for nirvana");
}
#endif
// create and start a new ConcurrentMarkSweep Thread for given CMS generation
if (!_should_terminate) {
return th;
}
return NULL;
}
if (CMSIncrementalMode) {
// Disable incremental mode and wake up the thread so it notices the change.
disable_icms();
start_icms();
}
// it is ok to take late safepoints here, if needed
{
_should_terminate = true;
}
{ // Now post a notify on CGC_lock so as to nudge
// CMS thread(s) that might be slumbering in
// sleepBeforeNextCycle.
CGC_lock->notify_all();
}
{ // Now wait until (all) CMS thread(s) have exited
Terminator_lock->wait();
}
}
}
}
"Called too early, make sure heap is fully initialized");
if (_collector != NULL) {
}
}
}
}
}
if (_collector != NULL) {
}
}
}
if (!is_cms_thread) {
while (CMS_flag_is_set(CMS_cms_has_token)) {
// indicate that we want to get the token
}
// claim the token and proceed
} else {
"Not a CMS thread");
// The following barrier assumes there's only one CMS thread.
// This will need to be modified is there are more CMS threads than one.
}
// claim the token
}
}
if (!is_cms_thread) {
if (CMS_flag_is_set(CMS_cms_wants_token)) {
// wake-up a waiting CMS thread
}
"Should have been cleared");
} else {
"Not a CMS thread");
if (CMS_flag_is_set(CMS_vm_wants_token)) {
// wake-up a waiting VM thread
}
"Should have been cleared");
}
}
// Wait until the next synchronous GC, a concurrent full gc request,
// or a timeout, whichever is earlier.
return;
}
"Should not be set");
}
while (!_should_terminate) {
if (CMSIncrementalMode) {
icms_wait();
return;
} else {
// Wait until the next synchronous GC, a concurrent full gc
// request or a timeout, whichever is earlier.
}
// Check if we should start a CMS collection cycle
if (_collector->shouldConcurrentCollect()) {
return;
}
// .. collection criterion not yet met, let's go back
// and wait some more
}
}
// Incremental CMS
trace_state("start_icms");
_should_run = true;
iCMS_lock->notify_all();
}
if (!_should_stop) {
trace_state("stop_icms");
_should_stop = true;
_should_run = false;
iCMS_lock->notify_all();
}
}
if (_should_stop && icms_is_enabled()) {
trace_state("pause_icms");
while(!_should_run && icms_is_enabled()) {
}
_should_stop = false;
trace_state("pause_icms end");
}
}
// Note: this method, although exported by the ConcurrentMarkSweepThread,
// which is a non-JavaThread, can only be called by a JavaThread.
// Currently this is done at vm creation time (post-vm-init) by the
// main/Primordial (Java)Thread.
// XXX Consider changing this in the future to allow the CMS thread
// itself to create this thread?
}