Mercurial > hg > truffle
annotate src/share/vm/memory/gcLocker.cpp @ 18712:37a5c6b8b930
Log deopt before deoptimizing the frame
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Wed, 17 Dec 2014 13:39:48 -0800 |
parents | 52b4284cb496 |
children | 7848fc12602b |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17876
diff
changeset
|
2 * Copyright (c) 1997, 2014, 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:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
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:
196
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/gcLocker.inline.hpp" | |
27 #include "memory/resourceArea.hpp" | |
28 #include "memory/sharedHeap.hpp" | |
0 | 29 |
30 volatile jint GC_locker::_jni_lock_count = 0; | |
31 volatile bool GC_locker::_needs_gc = false; | |
32 volatile bool GC_locker::_doing_gc = false; | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
33 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
34 #ifdef ASSERT |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
35 volatile jint GC_locker::_debug_jni_lock_count = 0; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
36 #endif |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
37 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
38 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
39 #ifdef ASSERT |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
40 void GC_locker::verify_critical_count() { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
41 if (SafepointSynchronize::is_at_safepoint()) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
42 assert(!needs_gc() || _debug_jni_lock_count == _jni_lock_count, "must agree"); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
43 int count = 0; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
44 // Count the number of threads with critical operations in progress |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
45 for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
46 if (thr->in_critical()) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
47 count++; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
48 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
49 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
50 if (_jni_lock_count != count) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
51 tty->print_cr("critical counts don't match: %d != %d", _jni_lock_count, count); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
52 for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
53 if (thr->in_critical()) { |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17876
diff
changeset
|
54 tty->print_cr(INTPTR_FORMAT " in_critical %d", p2i(thr), thr->in_critical()); |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
55 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
56 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
57 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
58 assert(_jni_lock_count == count, "must be equal"); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
59 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
60 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
61 #endif |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
62 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
63 bool GC_locker::check_active_before_gc() { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
64 assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint"); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
65 if (is_active() && !_needs_gc) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
66 verify_critical_count(); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
67 _needs_gc = true; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
68 if (PrintJNIGCStalls && PrintGCDetails) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
69 ResourceMark rm; // JavaThread::name() allocates to convert to UTF8 |
4944 | 70 gclog_or_tty->print_cr("%.3f: Setting _needs_gc. Thread \"%s\" %d locked.", |
71 gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count); | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
72 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
73 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
74 } |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
75 return is_active(); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
76 } |
0 | 77 |
78 void GC_locker::stall_until_clear() { | |
79 assert(!JavaThread::current()->in_critical(), "Would deadlock"); | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
80 MutexLocker ml(JNICritical_lock); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
81 |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
82 if (needs_gc()) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
83 if (PrintJNIGCStalls && PrintGCDetails) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
84 ResourceMark rm; // JavaThread::name() allocates to convert to UTF8 |
4944 | 85 gclog_or_tty->print_cr("%.3f: Allocation failed. Thread \"%s\" is stalled by JNI critical section, %d locked.", |
86 gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count); | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
87 } |
139
c0492d52d55b
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
0
diff
changeset
|
88 } |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
89 |
0 | 90 // Wait for _needs_gc to be cleared |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
91 while (needs_gc()) { |
0 | 92 JNICritical_lock->wait(); |
93 } | |
94 } | |
95 | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
96 void GC_locker::jni_lock(JavaThread* thread) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
97 assert(!thread->in_critical(), "shouldn't currently be in a critical region"); |
0 | 98 MutexLocker mu(JNICritical_lock); |
99 // Block entering threads if we know at least one thread is in a | |
100 // JNI critical region and we need a GC. | |
101 // We check that at least one thread is in a critical region before | |
102 // blocking because blocked threads are woken up by a thread exiting | |
103 // a JNI critical region. | |
17876
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
104 while (is_active_and_needs_gc() || _doing_gc) { |
0 | 105 JNICritical_lock->wait(); |
106 } | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
107 thread->enter_critical(); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
108 _jni_lock_count++; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
109 increment_debug_jni_lock_count(); |
0 | 110 } |
111 | |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
112 void GC_locker::jni_unlock(JavaThread* thread) { |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
113 assert(thread->in_last_critical(), "should be exiting critical region"); |
0 | 114 MutexLocker mu(JNICritical_lock); |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
115 _jni_lock_count--; |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
116 decrement_debug_jni_lock_count(); |
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
117 thread->exit_critical(); |
17876
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
118 if (needs_gc() && !is_active_internal()) { |
0 | 119 // We're the last thread out. Cause a GC to occur. |
17876
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
120 _doing_gc = true; |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
121 { |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
122 // Must give up the lock while at a safepoint |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
123 MutexUnlocker munlock(JNICritical_lock); |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
124 if (PrintJNIGCStalls && PrintGCDetails) { |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
125 ResourceMark rm; // JavaThread::name() allocates to convert to UTF8 |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
126 gclog_or_tty->print_cr("%.3f: Thread \"%s\" is performing GC after exiting critical section, %d locked", |
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
127 gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count); |
0 | 128 } |
17876
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
129 Universe::heap()->collect(GCCause::_gc_locker); |
0 | 130 } |
17876
9c3dc501b5eb
8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents:
14223
diff
changeset
|
131 _doing_gc = false; |
4867
1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
1972
diff
changeset
|
132 _needs_gc = false; |
0 | 133 JNICritical_lock->notify_all(); |
134 } | |
135 } | |
136 | |
137 // Implementation of No_GC_Verifier | |
138 | |
139 #ifdef ASSERT | |
140 | |
141 No_GC_Verifier::No_GC_Verifier(bool verifygc) { | |
142 _verifygc = verifygc; | |
143 if (_verifygc) { | |
144 CollectedHeap* h = Universe::heap(); | |
145 assert(!h->is_gc_active(), "GC active during No_GC_Verifier"); | |
146 _old_invocations = h->total_collections(); | |
147 } | |
148 } | |
149 | |
150 | |
151 No_GC_Verifier::~No_GC_Verifier() { | |
152 if (_verifygc) { | |
153 CollectedHeap* h = Universe::heap(); | |
154 assert(!h->is_gc_active(), "GC active during No_GC_Verifier"); | |
155 if (_old_invocations != h->total_collections()) { | |
156 fatal("collection in a No_GC_Verifier secured function"); | |
157 } | |
158 } | |
159 } | |
160 | |
161 Pause_No_GC_Verifier::Pause_No_GC_Verifier(No_GC_Verifier * ngcv) { | |
162 _ngcv = ngcv; | |
163 if (_ngcv->_verifygc) { | |
164 // if we were verifying, then make sure that nothing is | |
165 // wrong before we "pause" verification | |
166 CollectedHeap* h = Universe::heap(); | |
167 assert(!h->is_gc_active(), "GC active during No_GC_Verifier"); | |
168 if (_ngcv->_old_invocations != h->total_collections()) { | |
169 fatal("collection in a No_GC_Verifier secured function"); | |
170 } | |
171 } | |
172 } | |
173 | |
174 | |
175 Pause_No_GC_Verifier::~Pause_No_GC_Verifier() { | |
176 if (_ngcv->_verifygc) { | |
177 // if we were verifying before, then reenable verification | |
178 CollectedHeap* h = Universe::heap(); | |
179 assert(!h->is_gc_active(), "GC active during No_GC_Verifier"); | |
180 _ngcv->_old_invocations = h->total_collections(); | |
181 } | |
182 } | |
183 | |
184 | |
185 // JRT_LEAF rules: | |
186 // A JRT_LEAF method may not interfere with safepointing by | |
187 // 1) acquiring or blocking on a Mutex or JavaLock - checked | |
188 // 2) allocating heap memory - checked | |
189 // 3) executing a VM operation - checked | |
190 // 4) executing a system call (including malloc) that could block or grab a lock | |
191 // 5) invoking GC | |
192 // 6) reaching a safepoint | |
193 // 7) running too long | |
194 // Nor may any method it calls. | |
195 JRT_Leaf_Verifier::JRT_Leaf_Verifier() | |
196 : No_Safepoint_Verifier(true, JRT_Leaf_Verifier::should_verify_GC()) | |
197 { | |
198 } | |
199 | |
200 JRT_Leaf_Verifier::~JRT_Leaf_Verifier() | |
201 { | |
202 } | |
203 | |
204 bool JRT_Leaf_Verifier::should_verify_GC() { | |
205 switch (JavaThread::current()->thread_state()) { | |
206 case _thread_in_Java: | |
207 // is in a leaf routine, there must be no safepoint. | |
208 return true; | |
209 case _thread_in_native: | |
210 // A native thread is not subject to safepoints. | |
211 // Even while it is in a leaf routine, GC is ok | |
212 return false; | |
213 default: | |
214 // Leaf routines cannot be called from other contexts. | |
215 ShouldNotReachHere(); | |
216 return false; | |
217 } | |
218 } | |
219 #endif |