src/hotspot/share/gc/cms/concurrentMarkSweepThread.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    25
#ifndef SHARE_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    26
#define SHARE_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    28
#include "gc/cms/concurrentMarkSweepGeneration.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    29
#include "gc/shared/concurrentGCThread.hpp"
30175
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 27625
diff changeset
    30
#include "runtime/thread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class ConcurrentMarkSweepGeneration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class CMSCollector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
8684
7ebbd0b3e295 6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents: 7397
diff changeset
    35
// The Concurrent Mark Sweep GC Thread
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class ConcurrentMarkSweepThread: public ConcurrentGCThread {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  friend class ConcurrentMarkSweepGeneration;   // XXX should remove friendship
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  friend class CMSCollector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 private:
37129
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents: 37081
diff changeset
    42
  static ConcurrentMarkSweepThread* _cmst;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents: 37081
diff changeset
    43
  static CMSCollector*              _collector;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  enum CMS_flag_type {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    CMS_nil             = NoBits,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    CMS_cms_wants_token = nth_bit(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    CMS_cms_has_token   = nth_bit(1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    CMS_vm_wants_token  = nth_bit(2),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    CMS_vm_has_token    = nth_bit(3)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static int _CMS_flag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static bool CMS_flag_is_set(int b)        { return (_CMS_flag & b) != 0;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static bool set_CMS_flag(int b)           { return (_CMS_flag |= b) != 0;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  static bool clear_CMS_flag(int b)         { return (_CMS_flag &= ~b) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void sleepBeforeNextCycle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
27625
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
    60
  // CMS thread should yield for a young gen collection and direct allocations
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static char _pad_1[64 - sizeof(jint)];    // prevent cache-line sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static volatile jint _pending_yields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  static char _pad_2[64 - sizeof(jint)];    // prevent cache-line sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void verify_ok_to_terminate() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37073
diff changeset
    68
  void run_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37073
diff changeset
    69
  void stop_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37073
diff changeset
    70
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  ConcurrentMarkSweepThread(CMSCollector* collector);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static void threads_do(ThreadClosure* tc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static void print_all_on(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static void print_all()                             { print_all_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Returns the CMS Thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  static ConcurrentMarkSweepThread* cmst()    { return _cmst; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static CMSCollector*         collector()    { return _collector;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Create and start the CMS Thread, or stop it on shutdown
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  static ConcurrentMarkSweepThread* start(CMSCollector* collector);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Synchronization using CMS token
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  static void synchronize(bool is_cms_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static void desynchronize(bool is_cms_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  static bool vm_thread_has_cms_token() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return CMS_flag_is_set(CMS_vm_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  static bool cms_thread_has_cms_token() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return CMS_flag_is_set(CMS_cms_has_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static bool vm_thread_wants_cms_token() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    return CMS_flag_is_set(CMS_vm_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  static bool cms_thread_wants_cms_token() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return CMS_flag_is_set(CMS_cms_wants_token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Wait on CMS lock until the next synchronous GC
6984
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 6763
diff changeset
   105
  // or given timeout, whichever is earlier. A timeout value
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 6763
diff changeset
   106
  // of 0 indicates that there is no upper bound on the wait time.
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 6763
diff changeset
   107
  // A concurrent full gc request terminates the wait.
c6718f921eb6 6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents: 6763
diff changeset
   108
  void wait_on_cms_lock(long t_millis);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
15859
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   110
  // Wait on CMS lock until the next synchronous GC
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   111
  // or given timeout, whichever is earlier. A timeout value
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   112
  // of 0 indicates that there is no upper bound on the wait time.
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   113
  // A concurrent full gc request terminates the wait.
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   114
  void wait_on_cms_lock_for_scavenge(long t_millis);
b8d7620fb179 7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents: 14583
diff changeset
   115
6763
711b8a44c4dd 6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents: 5547
diff changeset
   116
  // The CMS thread will yield during the work portion of its cycle
27625
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   117
  // only when requested to.
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   118
  // A synchronous request is used for young gen collections and
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   119
  // for direct allocations.  The requesting thread increments
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   120
  // _pending_yields at the beginning of an operation, and decrements
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   121
  // _pending_yields when that operation is completed.
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   122
  // In turn, the CMS thread yields when _pending_yields is positive,
07829380b8cd 8061308: Remove iCMS
brutisso
parents: 24424
diff changeset
   123
  // and continues to yield until the value reverts to 0.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static void increment_pending_yields()   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    Atomic::inc(&_pending_yields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(_pending_yields >= 0, "can't be negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static void decrement_pending_yields()   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    Atomic::dec(&_pending_yields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    assert(_pending_yields >= 0, "can't be negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  static bool should_yield()   { return _pending_yields > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
6763
711b8a44c4dd 6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents: 5547
diff changeset
   136
// For scoped increment/decrement of (synchronous) yield requests
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
class CMSSynchronousYieldRequest: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  CMSSynchronousYieldRequest() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    ConcurrentMarkSweepThread::increment_pending_yields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  ~CMSSynchronousYieldRequest() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    ConcurrentMarkSweepThread::decrement_pending_yields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// Used to emit a warning in case of unexpectedly excessive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
// looping (in "apparently endless loops") in CMS code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
class CMSLoopCountWarn: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  const char* _src;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  const char* _msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  const intx  _threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  intx        _ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  inline CMSLoopCountWarn(const char* src, const char* msg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                          const intx threshold) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    _src(src), _msg(msg), _threshold(threshold), _ticks(0) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  inline void tick() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    _ticks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (CMSLoopWarn && _ticks % _threshold == 0) {
37073
c39d0903390b 8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents: 33599
diff changeset
   164
      log_warning(gc)("%s has looped " INTX_FORMAT " times %s", _src, _ticks, _msg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6984
diff changeset
   168
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
   169
#endif // SHARE_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP