Mercurial > hg > truffle
annotate src/share/vm/memory/gcLocker.hpp @ 7090:05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 29 Nov 2012 13:24:08 +0100 |
parents | ad3b47344802 |
children | f34d701e952e |
rev | line source |
---|---|
0 | 1 /* |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
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:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_MEMORY_GCLOCKER_HPP |
26 #define SHARE_VM_MEMORY_GCLOCKER_HPP | |
27 | |
28 #include "gc_interface/collectedHeap.hpp" | |
29 #include "memory/genCollectedHeap.hpp" | |
30 #include "memory/universe.hpp" | |
31 #include "oops/oop.hpp" | |
32 #ifdef TARGET_OS_FAMILY_linux | |
33 # include "os_linux.inline.hpp" | |
34 # include "thread_linux.inline.hpp" | |
35 #endif | |
36 #ifdef TARGET_OS_FAMILY_solaris | |
37 # include "os_solaris.inline.hpp" | |
38 # include "thread_solaris.inline.hpp" | |
39 #endif | |
40 #ifdef TARGET_OS_FAMILY_windows | |
41 # include "os_windows.inline.hpp" | |
42 # include "thread_windows.inline.hpp" | |
43 #endif | |
3960 | 44 #ifdef TARGET_OS_FAMILY_bsd |
45 # include "os_bsd.inline.hpp" | |
46 # include "thread_bsd.inline.hpp" | |
47 #endif | |
1972 | 48 |
0 | 49 // The direct lock/unlock calls do not force a collection if an unlock |
50 // decrements the count to zero. Avoid calling these if at all possible. | |
51 | |
52 class GC_locker: public AllStatic { | |
53 private: | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
54 // The _jni_lock_count keeps track of the number of threads that are |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
55 // currently in a critical region. It's only kept up to date when |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
56 // _needs_gc is true. The current value is computed during |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
57 // safepointing and decremented during the slow path of GC_locker |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
58 // unlocking. |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
59 static volatile jint _jni_lock_count; // number of jni active instances. |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
60 |
0 | 61 static volatile jint _lock_count; // number of other active instances |
62 static volatile bool _needs_gc; // heap is filling, we need a GC | |
63 // note: bool is typedef'd as jint | |
64 static volatile bool _doing_gc; // unlock_critical() is doing a GC | |
65 | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
66 #ifdef ASSERT |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
67 // This lock count is updated for all operations and is used to |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
68 // validate the jni_lock_count that is computed during safepoints. |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
69 static volatile jint _debug_jni_lock_count; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
70 #endif |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
71 |
0 | 72 // Accessors |
73 static bool is_jni_active() { | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
74 assert(_needs_gc, "only valid when _needs_gc is set"); |
0 | 75 return _jni_lock_count > 0; |
76 } | |
77 | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
78 // At a safepoint, visit all threads and count the number of active |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
79 // critical sections. This is used to ensure that all active |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
80 // critical sections are exited before a new one is started. |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
81 static void verify_critical_count() NOT_DEBUG_RETURN; |
0 | 82 |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
83 static void jni_lock(JavaThread* thread); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
84 static void jni_unlock(JavaThread* thread); |
0 | 85 |
4949
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
86 static bool is_active_internal() { |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
87 verify_critical_count(); |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
88 return _lock_count > 0 || _jni_lock_count > 0; |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
89 } |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
90 |
0 | 91 public: |
92 // Accessors | |
4949
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
93 static bool is_active() { |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
94 assert(_needs_gc || SafepointSynchronize::is_at_safepoint(), "only read at safepoint"); |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
95 return is_active_internal(); |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
96 } |
0 | 97 static bool needs_gc() { return _needs_gc; } |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
98 |
0 | 99 // Shorthand |
4949
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
100 static bool is_active_and_needs_gc() { |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
101 // Use is_active_internal since _needs_gc can change from true to |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
102 // false outside of a safepoint, triggering the assert in |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
103 // is_active. |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
104 return needs_gc() && is_active_internal(); |
ad3b47344802
7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents:
4944
diff
changeset
|
105 } |
0 | 106 |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
107 // In debug mode track the locking state at all times |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
108 static void increment_debug_jni_lock_count() { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
109 #ifdef ASSERT |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
110 assert(_debug_jni_lock_count >= 0, "bad value"); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
111 Atomic::inc(&_debug_jni_lock_count); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
112 #endif |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
113 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
114 static void decrement_debug_jni_lock_count() { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
115 #ifdef ASSERT |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
116 assert(_debug_jni_lock_count > 0, "bad value"); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
117 Atomic::dec(&_debug_jni_lock_count); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
118 #endif |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
119 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
120 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
121 // Set the current lock count |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
122 static void set_jni_lock_count(int count) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
123 _jni_lock_count = count; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
124 verify_critical_count(); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
125 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
126 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
127 // Sets _needs_gc if is_active() is true. Returns is_active(). |
0 | 128 static bool check_active_before_gc(); |
129 | |
130 // Stalls the caller (who should not be in a jni critical section) | |
131 // until needs_gc() clears. Note however that needs_gc() may be | |
132 // set at a subsequent safepoint and/or cleared under the | |
133 // JNICritical_lock, so the caller may not safely assert upon | |
134 // return from this method that "!needs_gc()" since that is | |
135 // not a stable predicate. | |
136 static void stall_until_clear(); | |
137 | |
138 // Non-structured GC locking: currently needed for JNI. Use with care! | |
139 static void lock(); | |
140 static void unlock(); | |
141 | |
142 // The following two methods are used for JNI critical regions. | |
143 // If we find that we failed to perform a GC because the GC_locker | |
144 // was active, arrange for one as soon as possible by allowing | |
145 // all threads in critical regions to complete, but not allowing | |
146 // other critical regions to be entered. The reasons for that are: | |
147 // 1) a GC request won't be starved by overlapping JNI critical | |
148 // region activities, which can cause unnecessary OutOfMemory errors. | |
149 // 2) even if allocation requests can still be satisfied before GC locker | |
150 // becomes inactive, for example, in tenured generation possibly with | |
151 // heap expansion, those allocations can trigger lots of safepointing | |
152 // attempts (ineffective GC attempts) and require Heap_lock which | |
153 // slow down allocations tremendously. | |
154 // | |
155 // Note that critical regions can be nested in a single thread, so | |
156 // we must allow threads already in critical regions to continue. | |
157 // | |
158 // JNI critical regions are the only participants in this scheme | |
159 // because they are, by spec, well bounded while in a critical region. | |
160 // | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
161 // Each of the following two method is split into a fast path and a |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
162 // slow path. JNICritical_lock is only grabbed in the slow path. |
0 | 163 // _needs_gc is initially false and every java thread will go |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
164 // through the fast path, which simply increments or decrements the |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
165 // current thread's critical count. When GC happens at a safepoint, |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
166 // GC_locker::is_active() is checked. Since there is no safepoint in |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
167 // the fast path of lock_critical() and unlock_critical(), there is |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
168 // no race condition between the fast path and GC. After _needs_gc |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
169 // is set at a safepoint, every thread will go through the slow path |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
170 // after the safepoint. Since after a safepoint, each of the |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
171 // following two methods is either entered from the method entry and |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
172 // falls into the slow path, or is resumed from the safepoints in |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
173 // the method, which only exist in the slow path. So when _needs_gc |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
3960
diff
changeset
|
174 // is set, the slow path is always taken, till _needs_gc is cleared. |
0 | 175 static void lock_critical(JavaThread* thread); |
176 static void unlock_critical(JavaThread* thread); | |
4873
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4867
diff
changeset
|
177 |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4867
diff
changeset
|
178 static address needs_gc_address() { return (address) &_needs_gc; } |
0 | 179 }; |
180 | |
181 | |
182 // A No_GC_Verifier object can be placed in methods where one assumes that | |
183 // no garbage collection will occur. The destructor will verify this property | |
184 // unless the constructor is called with argument false (not verifygc). | |
185 // | |
186 // The check will only be done in debug mode and if verifygc true. | |
187 | |
188 class No_GC_Verifier: public StackObj { | |
189 friend class Pause_No_GC_Verifier; | |
190 | |
191 protected: | |
192 bool _verifygc; | |
193 unsigned int _old_invocations; | |
194 | |
195 public: | |
196 #ifdef ASSERT | |
197 No_GC_Verifier(bool verifygc = true); | |
198 ~No_GC_Verifier(); | |
199 #else | |
200 No_GC_Verifier(bool verifygc = true) {} | |
201 ~No_GC_Verifier() {} | |
202 #endif | |
203 }; | |
204 | |
205 // A Pause_No_GC_Verifier is used to temporarily pause the behavior | |
206 // of a No_GC_Verifier object. If we are not in debug mode or if the | |
207 // No_GC_Verifier object has a _verifygc value of false, then there | |
208 // is nothing to do. | |
209 | |
210 class Pause_No_GC_Verifier: public StackObj { | |
211 private: | |
212 No_GC_Verifier * _ngcv; | |
213 | |
214 public: | |
215 #ifdef ASSERT | |
216 Pause_No_GC_Verifier(No_GC_Verifier * ngcv); | |
217 ~Pause_No_GC_Verifier(); | |
218 #else | |
219 Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {} | |
220 ~Pause_No_GC_Verifier() {} | |
221 #endif | |
222 }; | |
223 | |
224 | |
225 // A No_Safepoint_Verifier object will throw an assertion failure if | |
226 // the current thread passes a possible safepoint while this object is | |
227 // instantiated. A safepoint, will either be: an oop allocation, blocking | |
228 // on a Mutex or JavaLock, or executing a VM operation. | |
229 // | |
230 // If StrictSafepointChecks is turned off, it degrades into a No_GC_Verifier | |
231 // | |
232 class No_Safepoint_Verifier : public No_GC_Verifier { | |
233 friend class Pause_No_Safepoint_Verifier; | |
234 | |
235 private: | |
236 bool _activated; | |
237 Thread *_thread; | |
238 public: | |
239 #ifdef ASSERT | |
98
deb97b8ef02b
6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents:
0
diff
changeset
|
240 No_Safepoint_Verifier(bool activated = true, bool verifygc = true ) : |
deb97b8ef02b
6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents:
0
diff
changeset
|
241 No_GC_Verifier(verifygc), |
deb97b8ef02b
6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents:
0
diff
changeset
|
242 _activated(activated) { |
0 | 243 _thread = Thread::current(); |
244 if (_activated) { | |
245 _thread->_allow_allocation_count++; | |
246 _thread->_allow_safepoint_count++; | |
247 } | |
248 } | |
249 | |
250 ~No_Safepoint_Verifier() { | |
251 if (_activated) { | |
252 _thread->_allow_allocation_count--; | |
253 _thread->_allow_safepoint_count--; | |
254 } | |
255 } | |
256 #else | |
257 No_Safepoint_Verifier(bool activated = true, bool verifygc = true) : No_GC_Verifier(verifygc){} | |
258 ~No_Safepoint_Verifier() {} | |
259 #endif | |
260 }; | |
261 | |
262 // A Pause_No_Safepoint_Verifier is used to temporarily pause the | |
263 // behavior of a No_Safepoint_Verifier object. If we are not in debug | |
264 // mode then there is nothing to do. If the No_Safepoint_Verifier | |
265 // object has an _activated value of false, then there is nothing to | |
266 // do for safepoint and allocation checking, but there may still be | |
267 // something to do for the underlying No_GC_Verifier object. | |
268 | |
269 class Pause_No_Safepoint_Verifier : public Pause_No_GC_Verifier { | |
270 private: | |
271 No_Safepoint_Verifier * _nsv; | |
272 | |
273 public: | |
274 #ifdef ASSERT | |
275 Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv) | |
276 : Pause_No_GC_Verifier(nsv) { | |
277 | |
278 _nsv = nsv; | |
279 if (_nsv->_activated) { | |
280 _nsv->_thread->_allow_allocation_count--; | |
281 _nsv->_thread->_allow_safepoint_count--; | |
282 } | |
283 } | |
284 | |
285 ~Pause_No_Safepoint_Verifier() { | |
286 if (_nsv->_activated) { | |
287 _nsv->_thread->_allow_allocation_count++; | |
288 _nsv->_thread->_allow_safepoint_count++; | |
289 } | |
290 } | |
291 #else | |
292 Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv) | |
293 : Pause_No_GC_Verifier(nsv) {} | |
294 ~Pause_No_Safepoint_Verifier() {} | |
295 #endif | |
296 }; | |
297 | |
806
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
298 // A SkipGCALot object is used to elide the usual effect of gc-a-lot |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
299 // over a section of execution by a thread. Currently, it's used only to |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
300 // prevent re-entrant calls to GC. |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
301 class SkipGCALot : public StackObj { |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
302 private: |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
303 bool _saved; |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
304 Thread* _t; |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
305 |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
306 public: |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
307 #ifdef ASSERT |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
308 SkipGCALot(Thread* t) : _t(t) { |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
309 _saved = _t->skip_gcalot(); |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
310 _t->set_skip_gcalot(true); |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
311 } |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
312 |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
313 ~SkipGCALot() { |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
314 assert(_t->skip_gcalot(), "Save-restore protocol invariant"); |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
315 _t->set_skip_gcalot(_saved); |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
316 } |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
317 #else |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
318 SkipGCALot(Thread* t) { } |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
319 ~SkipGCALot() { } |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
320 #endif |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
321 }; |
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
196
diff
changeset
|
322 |
0 | 323 // JRT_LEAF currently can be called from either _thread_in_Java or |
324 // _thread_in_native mode. In _thread_in_native, it is ok | |
325 // for another thread to trigger GC. The rest of the JRT_LEAF | |
326 // rules apply. | |
327 class JRT_Leaf_Verifier : public No_Safepoint_Verifier { | |
328 static bool should_verify_GC(); | |
329 public: | |
330 #ifdef ASSERT | |
331 JRT_Leaf_Verifier(); | |
332 ~JRT_Leaf_Verifier(); | |
333 #else | |
334 JRT_Leaf_Verifier() {} | |
335 ~JRT_Leaf_Verifier() {} | |
336 #endif | |
337 }; | |
338 | |
339 // A No_Alloc_Verifier object can be placed in methods where one assumes that | |
340 // no allocation will occur. The destructor will verify this property | |
341 // unless the constructor is called with argument false (not activated). | |
342 // | |
343 // The check will only be done in debug mode and if activated. | |
344 // Note: this only makes sense at safepoints (otherwise, other threads may | |
345 // allocate concurrently.) | |
346 | |
347 class No_Alloc_Verifier : public StackObj { | |
348 private: | |
349 bool _activated; | |
350 | |
351 public: | |
352 #ifdef ASSERT | |
353 No_Alloc_Verifier(bool activated = true) { | |
354 _activated = activated; | |
355 if (_activated) Thread::current()->_allow_allocation_count++; | |
356 } | |
357 | |
358 ~No_Alloc_Verifier() { | |
359 if (_activated) Thread::current()->_allow_allocation_count--; | |
360 } | |
361 #else | |
362 No_Alloc_Verifier(bool activated = true) {} | |
363 ~No_Alloc_Verifier() {} | |
364 #endif | |
365 }; | |
1972 | 366 |
367 #endif // SHARE_VM_MEMORY_GCLOCKER_HPP |