author | brutisso |
Fri, 11 Mar 2016 11:34:22 +0100 | |
changeset 37073 | c39d0903390b |
parent 33599 | 69416bbe5e84 |
child 37081 | 7656f5356a5d |
permissions | -rw-r--r-- |
1 | 1 |
/* |
30764 | 2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
30764 | 25 |
#ifndef SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP |
26 |
#define SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP |
|
7397 | 27 |
|
30764 | 28 |
#include "gc/cms/concurrentMarkSweepGeneration.hpp" |
29 |
#include "gc/shared/concurrentGCThread.hpp" |
|
30175 | 30 |
#include "runtime/thread.hpp" |
7397 | 31 |
|
1 | 32 |
class ConcurrentMarkSweepGeneration; |
33 |
class CMSCollector; |
|
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 | 36 |
class ConcurrentMarkSweepThread: public ConcurrentGCThread { |
37 |
friend class VMStructs; |
|
38 |
friend class ConcurrentMarkSweepGeneration; // XXX should remove friendship |
|
39 |
friend class CMSCollector; |
|
40 |
public: |
|
41 |
virtual void run(); |
|
42 |
||
43 |
private: |
|
44 |
static ConcurrentMarkSweepThread* _cmst; |
|
45 |
static CMSCollector* _collector; |
|
46 |
static SurrogateLockerThread* _slt; |
|
47 |
static SurrogateLockerThread::SLT_msg_type _sltBuffer; |
|
48 |
static Monitor* _sltMonitor; |
|
49 |
||
50 |
static bool _should_terminate; |
|
51 |
||
52 |
enum CMS_flag_type { |
|
53 |
CMS_nil = NoBits, |
|
54 |
CMS_cms_wants_token = nth_bit(0), |
|
55 |
CMS_cms_has_token = nth_bit(1), |
|
56 |
CMS_vm_wants_token = nth_bit(2), |
|
57 |
CMS_vm_has_token = nth_bit(3) |
|
58 |
}; |
|
59 |
||
60 |
static int _CMS_flag; |
|
61 |
||
62 |
static bool CMS_flag_is_set(int b) { return (_CMS_flag & b) != 0; } |
|
63 |
static bool set_CMS_flag(int b) { return (_CMS_flag |= b) != 0; } |
|
64 |
static bool clear_CMS_flag(int b) { return (_CMS_flag &= ~b) != 0; } |
|
65 |
void sleepBeforeNextCycle(); |
|
66 |
||
27625 | 67 |
// CMS thread should yield for a young gen collection and direct allocations |
1 | 68 |
static char _pad_1[64 - sizeof(jint)]; // prevent cache-line sharing |
69 |
static volatile jint _pending_yields; |
|
70 |
static char _pad_2[64 - sizeof(jint)]; // prevent cache-line sharing |
|
71 |
||
72 |
// debugging |
|
73 |
void verify_ok_to_terminate() const PRODUCT_RETURN; |
|
74 |
||
75 |
public: |
|
76 |
// Constructor |
|
77 |
ConcurrentMarkSweepThread(CMSCollector* collector); |
|
78 |
||
79 |
static void makeSurrogateLockerThread(TRAPS); |
|
80 |
static SurrogateLockerThread* slt() { return _slt; } |
|
81 |
||
82 |
static void threads_do(ThreadClosure* tc); |
|
83 |
||
84 |
// Printing |
|
85 |
static void print_all_on(outputStream* st); |
|
86 |
static void print_all() { print_all_on(tty); } |
|
87 |
||
88 |
// Returns the CMS Thread |
|
89 |
static ConcurrentMarkSweepThread* cmst() { return _cmst; } |
|
90 |
static CMSCollector* collector() { return _collector; } |
|
91 |
||
92 |
// Create and start the CMS Thread, or stop it on shutdown |
|
93 |
static ConcurrentMarkSweepThread* start(CMSCollector* collector); |
|
94 |
static void stop(); |
|
95 |
static bool should_terminate() { return _should_terminate; } |
|
96 |
||
97 |
// Synchronization using CMS token |
|
98 |
static void synchronize(bool is_cms_thread); |
|
99 |
static void desynchronize(bool is_cms_thread); |
|
100 |
static bool vm_thread_has_cms_token() { |
|
101 |
return CMS_flag_is_set(CMS_vm_has_token); |
|
102 |
} |
|
103 |
static bool cms_thread_has_cms_token() { |
|
104 |
return CMS_flag_is_set(CMS_cms_has_token); |
|
105 |
} |
|
106 |
static bool vm_thread_wants_cms_token() { |
|
107 |
return CMS_flag_is_set(CMS_vm_wants_token); |
|
108 |
} |
|
109 |
static bool cms_thread_wants_cms_token() { |
|
110 |
return CMS_flag_is_set(CMS_cms_wants_token); |
|
111 |
} |
|
112 |
||
113 |
// Wait on CMS lock until the next synchronous GC |
|
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
6763
diff
changeset
|
114 |
// or given timeout, whichever is earlier. A timeout value |
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
6763
diff
changeset
|
115 |
// 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
|
116 |
// A concurrent full gc request terminates the wait. |
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
6763
diff
changeset
|
117 |
void wait_on_cms_lock(long t_millis); |
1 | 118 |
|
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
14583
diff
changeset
|
119 |
// Wait on CMS lock until the next synchronous GC |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
14583
diff
changeset
|
120 |
// or given timeout, whichever is earlier. A timeout value |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
14583
diff
changeset
|
121 |
// 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
|
122 |
// A concurrent full gc request terminates the wait. |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
14583
diff
changeset
|
123 |
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
|
124 |
|
6763
711b8a44c4dd
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
5547
diff
changeset
|
125 |
// The CMS thread will yield during the work portion of its cycle |
27625 | 126 |
// only when requested to. |
127 |
// A synchronous request is used for young gen collections and |
|
128 |
// for direct allocations. The requesting thread increments |
|
129 |
// _pending_yields at the beginning of an operation, and decrements |
|
130 |
// _pending_yields when that operation is completed. |
|
131 |
// In turn, the CMS thread yields when _pending_yields is positive, |
|
132 |
// and continues to yield until the value reverts to 0. |
|
1 | 133 |
|
134 |
static void increment_pending_yields() { |
|
135 |
Atomic::inc(&_pending_yields); |
|
136 |
assert(_pending_yields >= 0, "can't be negative"); |
|
137 |
} |
|
138 |
static void decrement_pending_yields() { |
|
139 |
Atomic::dec(&_pending_yields); |
|
140 |
assert(_pending_yields >= 0, "can't be negative"); |
|
141 |
} |
|
142 |
static bool should_yield() { return _pending_yields > 0; } |
|
143 |
}; |
|
144 |
||
6763
711b8a44c4dd
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
5547
diff
changeset
|
145 |
// For scoped increment/decrement of (synchronous) yield requests |
1 | 146 |
class CMSSynchronousYieldRequest: public StackObj { |
147 |
public: |
|
148 |
CMSSynchronousYieldRequest() { |
|
149 |
ConcurrentMarkSweepThread::increment_pending_yields(); |
|
150 |
} |
|
151 |
~CMSSynchronousYieldRequest() { |
|
152 |
ConcurrentMarkSweepThread::decrement_pending_yields(); |
|
153 |
} |
|
154 |
}; |
|
155 |
||
156 |
// Used to emit a warning in case of unexpectedly excessive |
|
157 |
// looping (in "apparently endless loops") in CMS code. |
|
158 |
class CMSLoopCountWarn: public StackObj { |
|
159 |
private: |
|
160 |
const char* _src; |
|
161 |
const char* _msg; |
|
162 |
const intx _threshold; |
|
163 |
intx _ticks; |
|
164 |
||
165 |
public: |
|
166 |
inline CMSLoopCountWarn(const char* src, const char* msg, |
|
167 |
const intx threshold) : |
|
168 |
_src(src), _msg(msg), _threshold(threshold), _ticks(0) { } |
|
169 |
||
170 |
inline void tick() { |
|
171 |
_ticks++; |
|
172 |
if (CMSLoopWarn && _ticks % _threshold == 0) { |
|
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
33599
diff
changeset
|
173 |
log_warning(gc)("%s has looped " INTX_FORMAT " times %s", _src, _ticks, _msg); |
1 | 174 |
} |
175 |
} |
|
176 |
}; |
|
7397 | 177 |
|
30764 | 178 |
#endif // SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP |