hotspot/src/share/vm/gc/cms/concurrentMarkSweepThread.cpp
author brutisso
Wed, 30 Sep 2015 09:07:21 +0200
changeset 33107 77bf0d2069a3
parent 32623 390a27af5657
child 34633 2a6c7c7b30a7
permissions -rw-r--r--
8134953: Make the GC ID available in a central place Reviewed-by: pliden, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29326
ebaa169c6dc3 8073464: GC workers do not have thread names
david
parents: 27686
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    26
#include "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29464
diff changeset
    27
#include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29464
diff changeset
    28
#include "gc/cms/concurrentMarkSweepThread.hpp"
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 32623
diff changeset
    29
#include "gc/shared/gcId.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29464
diff changeset
    30
#include "gc/shared/genCollectedHeap.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    31
#include "oops/instanceRefKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    32
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    33
#include "runtime/init.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    34
#include "runtime/interfaceSupport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    35
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    36
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    37
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    38
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    39
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// ======= Concurrent Mark Sweep Thread ========
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    43
ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::_cmst = NULL;
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    44
CMSCollector* ConcurrentMarkSweepThread::_collector         = NULL;
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    45
bool ConcurrentMarkSweepThread::_should_terminate           = false;
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    46
int  ConcurrentMarkSweepThread::_CMS_flag                   = CMS_nil;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    48
volatile jint ConcurrentMarkSweepThread::_pending_yields    = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    50
SurrogateLockerThread* ConcurrentMarkSweepThread::_slt      = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
SurrogateLockerThread::SLT_msg_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
     ConcurrentMarkSweepThread::_sltBuffer = SurrogateLockerThread::empty;
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 30764
diff changeset
    53
Monitor* ConcurrentMarkSweepThread::_sltMonitor             = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  : ConcurrentGCThread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  assert(UseConcMarkSweepGC,  "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  assert(_cmst == NULL, "CMS thread already created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _cmst = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  assert(_collector == NULL, "Collector already set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _collector = collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 29326
diff changeset
    63
  set_name("CMS Main Thread");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (os::create_thread(this, os::cgc_thread)) {
11601
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    66
    // An old comment here said: "Priority should be just less
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    67
    // than that of VMThread".  Since the VMThread runs at
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    68
    // NearMaxPriority, the old comment was inaccurate, but
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    69
    // changing the default priority to NearMaxPriority-1
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    70
    // could change current behavior, so the default of
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    71
    // NearMaxPriority stays in place.
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    72
    //
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    73
    // Note that there's a possibility of the VMThread
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    74
    // starving if UseCriticalCMSThreadPriority is on.
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    75
    // That won't happen on Solaris for various reasons,
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    76
    // but may well happen on non-Solaris platforms.
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    77
    int native_prio;
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    78
    if (UseCriticalCMSThreadPriority) {
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    79
      native_prio = os::java_to_os_priority[CriticalPriority];
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    80
    } else {
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    81
      native_prio = os::java_to_os_priority[NearMaxPriority];
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    82
    }
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    83
    os::set_native_priority(this, native_prio);
f359304c1856 7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents: 8684
diff changeset
    84
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (!DisableStartThread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      os::start_thread(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  _sltMonitor = SLT_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
void ConcurrentMarkSweepThread::run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  assert(this == cmst(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
29326
ebaa169c6dc3 8073464: GC workers do not have thread names
david
parents: 27686
diff changeset
    95
  initialize_in_thread();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // From this time Thread::current() should be working.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  assert(this == Thread::current(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24331
diff changeset
    99
    warning("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // Wait until Universe::is_fully_initialized()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    CMSLoopCountWarn loopX("CMS::run", "waiting for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                           "Universe::is_fully_initialized()", 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    MutexLockerEx x(CGC_lock, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    set_CMS_flag(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    // Wait until Universe is initialized and all initialization is completed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    while (!is_init_completed() && !Universe::is_fully_initialized() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
           !_should_terminate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      CGC_lock->wait(true, 200);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      loopX.tick();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // Wait until the surrogate locker thread that will do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // pending list locking on our behalf has been created.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // We cannot start the SLT thread ourselves since we need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // to be a JavaThread to do so.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    while (_slt == NULL && !_should_terminate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      CGC_lock->wait(true, 200);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      loopY.tick();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    clear_CMS_flag(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  while (!_should_terminate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    sleepBeforeNextCycle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (_should_terminate) break;
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 32623
diff changeset
   128
    GCIdMark gc_id_mark;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15859
diff changeset
   129
    GCCause::Cause cause = _collector->_full_gc_requested ?
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15859
diff changeset
   130
      _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
27686
f91c482793e6 8064702: Remove the CMS foreground collector
brutisso
parents: 27625
diff changeset
   131
    _collector->collect_in_background(cause);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(_should_terminate, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Check that the state of any protocol for synchronization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // between background (CMS) and foreground collector is "clean"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // (i.e. will not potentially block the foreground collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // requiring action by us).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  verify_ok_to_terminate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Signal that it is terminated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    MutexLockerEx mu(Terminator_lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                     Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    assert(_cmst == this, "Weird!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    _cmst = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    Terminator_lock->notify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Thread destructor usually does this..
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  ThreadLocalStorage::set_thread(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
void ConcurrentMarkSweepThread::verify_ok_to_terminate() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  assert(!(CGC_lock->owned_by_self() || cms_thread_has_cms_token() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
           cms_thread_wants_cms_token()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
         "Must renounce all worldly possessions and desires for nirvana");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _collector->verify_ok_to_terminate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// create and start a new ConcurrentMarkSweep Thread for given CMS generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::start(CMSCollector* collector) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  if (!_should_terminate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    assert(cmst() == NULL, "start() called twice?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    ConcurrentMarkSweepThread* th = new ConcurrentMarkSweepThread(collector);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    assert(cmst() == th, "Where did the just-created CMS thread go?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    return th;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
void ConcurrentMarkSweepThread::stop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // it is ok to take late safepoints here, if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    MutexLockerEx x(Terminator_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    _should_terminate = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  { // Now post a notify on CGC_lock so as to nudge
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // CMS thread(s) that might be slumbering in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // sleepBeforeNextCycle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    CGC_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  { // Now wait until (all) CMS thread(s) have exited
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    MutexLockerEx x(Terminator_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    while(cmst() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      Terminator_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert(tc != NULL, "Null ThreadClosure");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if (_cmst != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    tc->do_thread(_cmst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(Universe::is_fully_initialized(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
         "Called too early, make sure heap is fully initialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  if (_collector != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    AbstractWorkGang* gang = _collector->conc_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if (gang != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      gang->threads_do(tc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
void ConcurrentMarkSweepThread::print_all_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (_cmst != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    _cmst->print_on(st);
13857
93015306affa 7194254: jstack reports wrong thread priorities
dholmes
parents: 11601
diff changeset
   210
    st->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if (_collector != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    AbstractWorkGang* gang = _collector->conc_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    if (gang != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      gang->print_worker_threads_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
void ConcurrentMarkSweepThread::synchronize(bool is_cms_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(UseConcMarkSweepGC, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  MutexLockerEx x(CGC_lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                  Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  if (!is_cms_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    assert(Thread::current()->is_VM_thread(), "Not a VM thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    CMSSynchronousYieldRequest yr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    while (CMS_flag_is_set(CMS_cms_has_token)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      // indicate that we want to get the token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      set_CMS_flag(CMS_vm_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      CGC_lock->wait(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    // claim the token and proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    clear_CMS_flag(CMS_vm_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    set_CMS_flag(CMS_vm_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    assert(Thread::current()->is_ConcurrentGC_thread(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
           "Not a CMS thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    // The following barrier assumes there's only one CMS thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    // This will need to be modified is there are more CMS threads than one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    while (CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      set_CMS_flag(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      CGC_lock->wait(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // claim the token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    clear_CMS_flag(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    set_CMS_flag(CMS_cms_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
void ConcurrentMarkSweepThread::desynchronize(bool is_cms_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  assert(UseConcMarkSweepGC, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  MutexLockerEx x(CGC_lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
                  Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  if (!is_cms_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    assert(Thread::current()->is_VM_thread(), "Not a VM thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    assert(CMS_flag_is_set(CMS_vm_has_token), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    clear_CMS_flag(CMS_vm_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    if (CMS_flag_is_set(CMS_cms_wants_token)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      // wake-up a waiting CMS thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      CGC_lock->notify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    assert(!CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
           "Should have been cleared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    assert(Thread::current()->is_ConcurrentGC_thread(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
           "Not a CMS thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    assert(CMS_flag_is_set(CMS_cms_has_token), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    clear_CMS_flag(CMS_cms_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    if (CMS_flag_is_set(CMS_vm_wants_token)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      // wake-up a waiting VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      CGC_lock->notify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
           "Should have been cleared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
15859
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   280
// Wait until any cms_lock event
6984
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 5547
diff changeset
   281
void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  MutexLockerEx x(CGC_lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                  Mutex::_no_safepoint_check_flag);
6984
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 5547
diff changeset
   284
  if (_should_terminate || _collector->_full_gc_requested) {
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 5547
diff changeset
   285
    return;
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 5547
diff changeset
   286
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
6984
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 5547
diff changeset
   288
  CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  clear_CMS_flag(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
         "Should not be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
15859
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   294
// Wait until the next synchronous GC, a concurrent full gc request,
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   295
// or a timeout, whichever is earlier.
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   296
void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   297
  // Wait time in millis or 0 value representing infinite wait for a scavenge
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   298
  assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   299
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   300
  GenCollectedHeap* gch = GenCollectedHeap::heap();
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   301
  double start_time_secs = os::elapsedTime();
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   302
  double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   303
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   304
  // Total collections count before waiting loop
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   305
  unsigned int before_count;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   306
  {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   307
    MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   308
    before_count = gch->total_collections();
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   309
  }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   310
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   311
  unsigned int loop_count = 0;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   312
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   313
  while(!_should_terminate) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   314
    double now_time = os::elapsedTime();
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   315
    long wait_time_millis;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   316
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   317
    if(t_millis != 0) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   318
      // New wait limit
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   319
      wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   320
      if(wait_time_millis <= 0) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   321
        // Wait time is over
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   322
        break;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   323
      }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   324
    } else {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   325
      // No wait limit, wait if necessary forever
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   326
      wait_time_millis = 0;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   327
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   328
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   329
    // Wait until the next event or the remaining timeout
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   330
    {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   331
      MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   332
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   333
      if (_should_terminate || _collector->_full_gc_requested) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   334
        return;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   335
      }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   336
      set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   337
      assert(t_millis == 0 || wait_time_millis > 0, "Sanity");
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   338
      CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   339
      clear_CMS_flag(CMS_cms_wants_token);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   340
      assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   341
             "Should not be set");
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   342
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   343
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   344
    // Extra wait time check before entering the heap lock to get the collection count
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   345
    if(t_millis != 0 && os::elapsedTime() >= end_time_secs) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   346
      // Wait time is over
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   347
      break;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   348
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   349
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   350
    // Total collections count after the event
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   351
    unsigned int after_count;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   352
    {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   353
      MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   354
      after_count = gch->total_collections();
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   355
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   356
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   357
    if(before_count != after_count) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   358
      // There was a collection - success
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   359
      break;
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   360
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   361
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   362
    // Too many loops warning
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   363
    if(++loop_count == 0) {
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   364
      warning("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   365
    }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   366
  }
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   367
}
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 13857
diff changeset
   368
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
void ConcurrentMarkSweepThread::sleepBeforeNextCycle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  while (!_should_terminate) {
27625
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   371
    if(CMSWaitDuration >= 0) {
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   372
      // Wait until the next synchronous GC, a concurrent full gc
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   373
      // request or a timeout, whichever is earlier.
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   374
      wait_on_cms_lock_for_scavenge(CMSWaitDuration);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    } else {
27625
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   376
      // Wait until any cms_lock event or check interval not to call shouldConcurrentCollect permanently
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   377
      wait_on_cms_lock(CMSCheckInterval);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    // Check if we should start a CMS collection cycle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    if (_collector->shouldConcurrentCollect()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    // .. collection criterion not yet met, let's go back
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    // and wait some more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
// Note: this method, although exported by the ConcurrentMarkSweepThread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
// which is a non-JavaThread, can only be called by a JavaThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
// Currently this is done at vm creation time (post-vm-init) by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// main/Primordial (Java)Thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// XXX Consider changing this in the future to allow the CMS thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
// itself to create this thread?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
void ConcurrentMarkSweepThread::makeSurrogateLockerThread(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  assert(UseConcMarkSweepGC, "SLT thread needed only for CMS GC");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  assert(_slt == NULL, "SLT already created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  _slt = SurrogateLockerThread::make(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
}