annotate src/share/vm/memory/gcLocker.hpp @ 20543:e7d0505c8a30

8059758: Footprint regressions with JDK-8038423 Summary: Changes in JDK-8038423 always initialize (zero out) virtual memory used for auxiliary data structures. This causes a footprint regression for G1 in startup benchmarks. This is because they do not touch that memory at all, so the operating system does not actually commit these pages. The fix is to, if the initialization value of the data structures matches the default value of just committed memory (=0), do not do anything. Reviewed-by: jwilhelm, brutisso
author tschatzl
date Fri, 10 Oct 2014 15:51:58 +0200
parents 9c3dc501b5eb
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12301
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_MEMORY_GCLOCKER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_MEMORY_GCLOCKER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_interface/collectedHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/genCollectedHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/universe.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "oops/oop.hpp"
7180
f34d701e952e 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 4949
diff changeset
32 #include "runtime/thread.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #ifdef TARGET_OS_FAMILY_linux
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 # include "os_linux.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #ifdef TARGET_OS_FAMILY_solaris
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 # include "os_solaris.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 #ifdef TARGET_OS_FAMILY_windows
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
40 # include "os_windows.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
41 #endif
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
42 #ifdef TARGET_OS_FAMILY_bsd
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
43 # include "os_bsd.inline.hpp"
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
44 #endif
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
45
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // The direct lock/unlock calls do not force a collection if an unlock
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // decrements the count to zero. Avoid calling these if at all possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 class GC_locker: public AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private:
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
51 // 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
52 // 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
53 // _needs_gc is true. The current value is computed during
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
54 // safepointing and decremented during the slow path of GC_locker
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
55 // unlocking.
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
56 static volatile jint _jni_lock_count; // number of jni active instances.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static volatile bool _needs_gc; // heap is filling, we need a GC
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // note: bool is typedef'd as jint
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static volatile bool _doing_gc; // unlock_critical() is doing a GC
a61af66fc99e Initial load
duke
parents:
diff changeset
60
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
61 #ifdef ASSERT
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
62 // 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
63 // validate the jni_lock_count that is computed during safepoints.
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
64 static volatile jint _debug_jni_lock_count;
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
65 #endif
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
66
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
67 // 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
68 // critical sections. This is used to ensure that all active
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
69 // critical sections are exited before a new one is started.
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
70 static void verify_critical_count() NOT_DEBUG_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
71
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
72 static void jni_lock(JavaThread* thread);
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
73 static void jni_unlock(JavaThread* thread);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74
4949
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
75 static bool is_active_internal() {
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
76 verify_critical_count();
17876
9c3dc501b5eb 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 17467
diff changeset
77 return _jni_lock_count > 0;
4949
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
78 }
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
79
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Accessors
4949
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
82 static bool is_active() {
12301
2c022e432e10 8024974: Incorrect use of GC_locker::is_active()
stefank
parents: 7180
diff changeset
83 assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
4949
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
84 return is_active_internal();
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
85 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
86 static bool needs_gc() { return _needs_gc; }
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
87
0
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Shorthand
4949
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
89 static bool is_active_and_needs_gc() {
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
90 // 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
91 // 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
92 // is_active.
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
93 return needs_gc() && is_active_internal();
ad3b47344802 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 4944
diff changeset
94 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
95
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
96 // In debug mode track the locking state at all times
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
97 static void increment_debug_jni_lock_count() {
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
98 #ifdef ASSERT
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
99 assert(_debug_jni_lock_count >= 0, "bad value");
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
100 Atomic::inc(&_debug_jni_lock_count);
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
101 #endif
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
102 }
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
103 static void decrement_debug_jni_lock_count() {
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
104 #ifdef ASSERT
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
105 assert(_debug_jni_lock_count > 0, "bad value");
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
106 Atomic::dec(&_debug_jni_lock_count);
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
107 #endif
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
108 }
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
109
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
110 // Set the current lock count
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
111 static void set_jni_lock_count(int count) {
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
112 _jni_lock_count = count;
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
113 verify_critical_count();
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
114 }
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
115
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
116 // Sets _needs_gc if is_active() is true. Returns is_active().
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 static bool check_active_before_gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Stalls the caller (who should not be in a jni critical section)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // until needs_gc() clears. Note however that needs_gc() may be
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // set at a subsequent safepoint and/or cleared under the
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // JNICritical_lock, so the caller may not safely assert upon
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // return from this method that "!needs_gc()" since that is
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // not a stable predicate.
a61af66fc99e Initial load
duke
parents:
diff changeset
125 static void stall_until_clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // The following two methods are used for JNI critical regions.
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // If we find that we failed to perform a GC because the GC_locker
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // was active, arrange for one as soon as possible by allowing
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // all threads in critical regions to complete, but not allowing
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // other critical regions to be entered. The reasons for that are:
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // 1) a GC request won't be starved by overlapping JNI critical
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // region activities, which can cause unnecessary OutOfMemory errors.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // 2) even if allocation requests can still be satisfied before GC locker
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // becomes inactive, for example, in tenured generation possibly with
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // heap expansion, those allocations can trigger lots of safepointing
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // attempts (ineffective GC attempts) and require Heap_lock which
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // slow down allocations tremendously.
a61af66fc99e Initial load
duke
parents:
diff changeset
139 //
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // Note that critical regions can be nested in a single thread, so
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // we must allow threads already in critical regions to continue.
a61af66fc99e Initial load
duke
parents:
diff changeset
142 //
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // JNI critical regions are the only participants in this scheme
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // because they are, by spec, well bounded while in a critical region.
a61af66fc99e Initial load
duke
parents:
diff changeset
145 //
4867
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
146 // 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
147 // slow path. JNICritical_lock is only grabbed in the slow path.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // _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
149 // through the fast path, which simply increments or decrements the
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
150 // current thread's critical count. When GC happens at a safepoint,
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
151 // 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
152 // the fast path of lock_critical() and unlock_critical(), there is
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
153 // 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
154 // 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
155 // after the safepoint. Since after a safepoint, each of the
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
156 // following two methods is either entered from the method entry and
1a2723f7ad8e 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 3960
diff changeset
157 // 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
158 // 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
159 // is set, the slow path is always taken, till _needs_gc is cleared.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 static void lock_critical(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 static void unlock_critical(JavaThread* thread);
4873
0382d2b469b2 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 4867
diff changeset
162
0382d2b469b2 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 4867
diff changeset
163 static address needs_gc_address() { return (address) &_needs_gc; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
164 };
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // A No_GC_Verifier object can be placed in methods where one assumes that
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // no garbage collection will occur. The destructor will verify this property
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // unless the constructor is called with argument false (not verifygc).
a61af66fc99e Initial load
duke
parents:
diff changeset
170 //
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // The check will only be done in debug mode and if verifygc true.
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 class No_GC_Verifier: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 friend class Pause_No_GC_Verifier;
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
177 bool _verifygc;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 unsigned int _old_invocations;
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
181 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
182 No_GC_Verifier(bool verifygc = true);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 ~No_GC_Verifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
185 No_GC_Verifier(bool verifygc = true) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
186 ~No_GC_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
187 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
188 };
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // A Pause_No_GC_Verifier is used to temporarily pause the behavior
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // of a No_GC_Verifier object. If we are not in debug mode or if the
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // No_GC_Verifier object has a _verifygc value of false, then there
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // is nothing to do.
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 class Pause_No_GC_Verifier: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
197 No_GC_Verifier * _ngcv;
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
200 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Pause_No_GC_Verifier(No_GC_Verifier * ngcv);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 ~Pause_No_GC_Verifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
205 ~Pause_No_GC_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
206 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
207 };
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // A No_Safepoint_Verifier object will throw an assertion failure if
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // the current thread passes a possible safepoint while this object is
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // instantiated. A safepoint, will either be: an oop allocation, blocking
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // on a Mutex or JavaLock, or executing a VM operation.
a61af66fc99e Initial load
duke
parents:
diff changeset
214 //
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // If StrictSafepointChecks is turned off, it degrades into a No_GC_Verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
216 //
a61af66fc99e Initial load
duke
parents:
diff changeset
217 class No_Safepoint_Verifier : public No_GC_Verifier {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 friend class Pause_No_Safepoint_Verifier;
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
221 bool _activated;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 Thread *_thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
224 #ifdef ASSERT
98
deb97b8ef02b 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 0
diff changeset
225 No_Safepoint_Verifier(bool activated = true, bool verifygc = true ) :
deb97b8ef02b 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 0
diff changeset
226 No_GC_Verifier(verifygc),
deb97b8ef02b 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 0
diff changeset
227 _activated(activated) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (_activated) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 _thread->_allow_allocation_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 _thread->_allow_safepoint_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 ~No_Safepoint_Verifier() {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (_activated) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 _thread->_allow_allocation_count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 _thread->_allow_safepoint_count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
242 No_Safepoint_Verifier(bool activated = true, bool verifygc = true) : No_GC_Verifier(verifygc){}
a61af66fc99e Initial load
duke
parents:
diff changeset
243 ~No_Safepoint_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
244 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
245 };
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // A Pause_No_Safepoint_Verifier is used to temporarily pause the
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // behavior of a No_Safepoint_Verifier object. If we are not in debug
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // mode then there is nothing to do. If the No_Safepoint_Verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // object has an _activated value of false, then there is nothing to
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // do for safepoint and allocation checking, but there may still be
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // something to do for the underlying No_GC_Verifier object.
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 class Pause_No_Safepoint_Verifier : public Pause_No_GC_Verifier {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
256 No_Safepoint_Verifier * _nsv;
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
259 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
260 Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
a61af66fc99e Initial load
duke
parents:
diff changeset
261 : Pause_No_GC_Verifier(nsv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 _nsv = nsv;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 if (_nsv->_activated) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 _nsv->_thread->_allow_allocation_count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 _nsv->_thread->_allow_safepoint_count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 ~Pause_No_Safepoint_Verifier() {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if (_nsv->_activated) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 _nsv->_thread->_allow_allocation_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 _nsv->_thread->_allow_safepoint_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
277 Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
a61af66fc99e Initial load
duke
parents:
diff changeset
278 : Pause_No_GC_Verifier(nsv) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
279 ~Pause_No_Safepoint_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
280 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
281 };
a61af66fc99e Initial load
duke
parents:
diff changeset
282
806
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
283 // 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
284 // 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
285 // prevent re-entrant calls to GC.
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
286 class SkipGCALot : public StackObj {
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
287 private:
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
288 bool _saved;
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
289 Thread* _t;
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
290
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
291 public:
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
292 #ifdef ASSERT
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
293 SkipGCALot(Thread* t) : _t(t) {
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
294 _saved = _t->skip_gcalot();
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
295 _t->set_skip_gcalot(true);
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
296 }
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
297
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
298 ~SkipGCALot() {
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
299 assert(_t->skip_gcalot(), "Save-restore protocol invariant");
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
300 _t->set_skip_gcalot(_saved);
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
301 }
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
302 #else
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
303 SkipGCALot(Thread* t) { }
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
304 ~SkipGCALot() { }
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
305 #endif
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
306 };
821269eca479 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 196
diff changeset
307
0
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // JRT_LEAF currently can be called from either _thread_in_Java or
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // _thread_in_native mode. In _thread_in_native, it is ok
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // for another thread to trigger GC. The rest of the JRT_LEAF
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // rules apply.
a61af66fc99e Initial load
duke
parents:
diff changeset
312 class JRT_Leaf_Verifier : public No_Safepoint_Verifier {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 static bool should_verify_GC();
a61af66fc99e Initial load
duke
parents:
diff changeset
314 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
315 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
316 JRT_Leaf_Verifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 ~JRT_Leaf_Verifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
319 JRT_Leaf_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
320 ~JRT_Leaf_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
321 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
322 };
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // A No_Alloc_Verifier object can be placed in methods where one assumes that
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // no allocation will occur. The destructor will verify this property
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // unless the constructor is called with argument false (not activated).
a61af66fc99e Initial load
duke
parents:
diff changeset
327 //
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // The check will only be done in debug mode and if activated.
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // Note: this only makes sense at safepoints (otherwise, other threads may
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // allocate concurrently.)
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 class No_Alloc_Verifier : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
334 bool _activated;
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
337 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
338 No_Alloc_Verifier(bool activated = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _activated = activated;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (_activated) Thread::current()->_allow_allocation_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 ~No_Alloc_Verifier() {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (_activated) Thread::current()->_allow_allocation_count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
347 No_Alloc_Verifier(bool activated = true) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
348 ~No_Alloc_Verifier() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
349 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
350 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
351
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
352 #endif // SHARE_VM_MEMORY_GCLOCKER_HPP