author | stefank |
Tue, 26 Nov 2019 10:47:46 +0100 | |
changeset 59290 | 97d13893ec3c |
parent 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, 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:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
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:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/shared/collectedHeap.hpp" |
27 |
#include "gc/shared/collectedHeap.inline.hpp" |
|
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
50429
diff
changeset
|
28 |
#include "logging/log.hpp" |
7397 | 29 |
#include "memory/resourceArea.hpp" |
54786 | 30 |
#include "memory/universe.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
35061
diff
changeset
|
31 |
#include "runtime/atomic.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
32 |
#include "runtime/frame.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
33 |
#include "runtime/handles.inline.hpp" |
7397 | 34 |
#include "runtime/init.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
35 |
#include "runtime/interfaceSupport.inline.hpp" |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
25351
diff
changeset
|
36 |
#include "runtime/os.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
37 |
#include "runtime/thread.inline.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49480
diff
changeset
|
38 |
#include "runtime/safepointVerifiers.hpp" |
7397 | 39 |
#include "runtime/vframe.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
40 |
#include "runtime/vmThread.hpp" |
7397 | 41 |
#include "utilities/preserveException.hpp" |
1 | 42 |
|
43 |
// Implementation of InterfaceSupport |
|
44 |
||
45 |
#ifdef ASSERT |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
46 |
VMEntryWrapper::VMEntryWrapper() { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
47 |
if (VerifyLastFrame) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
48 |
InterfaceSupport::verify_last_frame(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
49 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
50 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
51 |
|
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
52 |
VMEntryWrapper::~VMEntryWrapper() { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
53 |
InterfaceSupport::check_gc_alot(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
54 |
if (WalkStackALot) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
55 |
InterfaceSupport::walk_stack(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
56 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
57 |
if (DeoptimizeALot || DeoptimizeRandom) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
58 |
InterfaceSupport::deoptimizeAll(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
59 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
60 |
if (ZombieALot) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
61 |
InterfaceSupport::zombieAll(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
62 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
63 |
// do verification AFTER potential deoptimization |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
64 |
if (VerifyStack) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
65 |
InterfaceSupport::verify_stack(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
66 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
67 |
} |
1 | 68 |
|
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
69 |
VMNativeEntryWrapper::VMNativeEntryWrapper() { |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
70 |
if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
71 |
} |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
72 |
|
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
73 |
VMNativeEntryWrapper::~VMNativeEntryWrapper() { |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
74 |
if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
75 |
} |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54786
diff
changeset
|
76 |
|
1 | 77 |
long InterfaceSupport::_number_of_calls = 0; |
78 |
long InterfaceSupport::_scavenge_alot_counter = 1; |
|
79 |
long InterfaceSupport::_fullgc_alot_counter = 1; |
|
80 |
long InterfaceSupport::_fullgc_alot_invocation = 0; |
|
81 |
||
82 |
Histogram* RuntimeHistogram; |
|
83 |
||
84 |
RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) { |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
85 |
static volatile int RuntimeHistogram_lock = 0; |
1 | 86 |
_name = elementName; |
87 |
uintx count = 0; |
|
88 |
||
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59247
diff
changeset
|
89 |
while (Atomic::cmpxchg(&RuntimeHistogram_lock, 0, 1) != 0) { |
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58527
diff
changeset
|
90 |
while (Atomic::load_acquire(&RuntimeHistogram_lock) != 0) { |
1 | 91 |
count +=1; |
92 |
if ( (WarnOnStalledSpinLock > 0) |
|
93 |
&& (count % WarnOnStalledSpinLock == 0)) { |
|
94 |
warning("RuntimeHistogram_lock seems to be stalled"); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
if (RuntimeHistogram == NULL) { |
|
100 |
RuntimeHistogram = new Histogram("VM Runtime Call Counts",200); |
|
101 |
} |
|
102 |
||
103 |
RuntimeHistogram->add_element(this); |
|
104 |
Atomic::dec(&RuntimeHistogram_lock); |
|
105 |
} |
|
106 |
||
107 |
void InterfaceSupport::gc_alot() { |
|
108 |
Thread *thread = Thread::current(); |
|
2995
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
109 |
if (!thread->is_Java_thread()) return; // Avoid concurrent calls |
1 | 110 |
// Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC. |
111 |
JavaThread *current_thread = (JavaThread *)thread; |
|
112 |
if (current_thread->active_handles() == NULL) return; |
|
113 |
||
2995
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
114 |
// Short-circuit any possible re-entrant gc-a-lot attempt |
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
115 |
if (thread->skip_gcalot()) return; |
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
116 |
|
27678
d1872bc7dd8d
8062036: ConcurrentMarkThread::slt may be invoked before ConcurrentMarkThread::makeSurrogateLockerThread causing intermittent crashes
kbarrett
parents:
25468
diff
changeset
|
117 |
if (Threads::is_vm_complete()) { |
1 | 118 |
|
119 |
if (++_fullgc_alot_invocation < FullGCALotStart) { |
|
120 |
return; |
|
121 |
} |
|
122 |
||
123 |
// Use this line if you want to block at a specific point, |
|
124 |
// e.g. one number_of_calls/scavenge/gc before you got into problems |
|
125 |
if (FullGCALot) _fullgc_alot_counter--; |
|
126 |
||
127 |
// Check if we should force a full gc |
|
128 |
if (_fullgc_alot_counter == 0) { |
|
129 |
// Release dummy so objects are forced to move |
|
130 |
if (!Universe::release_fullgc_alot_dummy()) { |
|
131 |
warning("FullGCALot: Unable to release more dummies at bottom of heap"); |
|
132 |
} |
|
133 |
HandleMark hm(thread); |
|
134 |
Universe::heap()->collect(GCCause::_full_gc_alot); |
|
135 |
unsigned int invocations = Universe::heap()->total_full_collections(); |
|
136 |
// Compute new interval |
|
137 |
if (FullGCALotInterval > 1) { |
|
138 |
_fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0)); |
|
35061 | 139 |
log_trace(gc)("Full gc no: %u\tInterval: %ld", invocations, _fullgc_alot_counter); |
1 | 140 |
} else { |
141 |
_fullgc_alot_counter = 1; |
|
142 |
} |
|
143 |
// Print progress message |
|
144 |
if (invocations % 100 == 0) { |
|
35061 | 145 |
log_trace(gc)("Full gc no: %u", invocations); |
1 | 146 |
} |
147 |
} else { |
|
148 |
if (ScavengeALot) _scavenge_alot_counter--; |
|
149 |
// Check if we should force a scavenge |
|
150 |
if (_scavenge_alot_counter == 0) { |
|
151 |
HandleMark hm(thread); |
|
152 |
Universe::heap()->collect(GCCause::_scavenge_alot); |
|
153 |
unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections(); |
|
154 |
// Compute new interval |
|
155 |
if (ScavengeALotInterval > 1) { |
|
156 |
_scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0)); |
|
35061 | 157 |
log_trace(gc)("Scavenge no: %u\tInterval: %ld", invocations, _scavenge_alot_counter); |
1 | 158 |
} else { |
159 |
_scavenge_alot_counter = 1; |
|
160 |
} |
|
161 |
// Print progress message |
|
162 |
if (invocations % 1000 == 0) { |
|
35061 | 163 |
log_trace(gc)("Scavenge no: %u", invocations); |
1 | 164 |
} |
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
||
171 |
vframe* vframe_array[50]; |
|
172 |
int walk_stack_counter = 0; |
|
173 |
||
174 |
void InterfaceSupport::walk_stack_from(vframe* start_vf) { |
|
175 |
// walk |
|
176 |
int i = 0; |
|
177 |
for (vframe* f = start_vf; f; f = f->sender() ) { |
|
178 |
if (i < 50) vframe_array[i++] = f; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
183 |
void InterfaceSupport::walk_stack() { |
|
184 |
JavaThread* thread = JavaThread::current(); |
|
185 |
walk_stack_counter++; |
|
186 |
if (!thread->has_last_Java_frame()) return; |
|
187 |
ResourceMark rm(thread); |
|
188 |
RegisterMap reg_map(thread); |
|
189 |
walk_stack_from(thread->last_java_vframe(®_map)); |
|
190 |
} |
|
191 |
||
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
192 |
// invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions |
1 | 193 |
int deoptimizeAllCounter = 0; |
194 |
int zombieAllCounter = 0; |
|
195 |
||
196 |
void InterfaceSupport::zombieAll() { |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
197 |
// This method is called by all threads when a thread make |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
198 |
// transition to VM state (for example, runtime calls). |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
199 |
// Divide number of calls by number of threads to avoid |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
200 |
// dependence of ZombieAll events frequency on number of threads. |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
201 |
int value = zombieAllCounter / Threads::number_of_threads(); |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
202 |
if (is_init_completed() && value > ZombieALotInterval) { |
1 | 203 |
zombieAllCounter = 0; |
204 |
VM_ZombieAll op; |
|
205 |
VMThread::execute(&op); |
|
206 |
} |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
207 |
zombieAllCounter++; |
1 | 208 |
} |
209 |
||
210 |
void InterfaceSupport::deoptimizeAll() { |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
211 |
// This method is called by all threads when a thread make |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
212 |
// transition to VM state (for example, runtime calls). |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
213 |
// Divide number of calls by number of threads to avoid |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
214 |
// dependence of DeoptimizeAll events frequency on number of threads. |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
215 |
int value = deoptimizeAllCounter / Threads::number_of_threads(); |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
216 |
if (is_init_completed()) { |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
217 |
if (DeoptimizeALot && value > DeoptimizeALotInterval) { |
1 | 218 |
deoptimizeAllCounter = 0; |
219 |
VM_DeoptimizeAll op; |
|
220 |
VMThread::execute(&op); |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
221 |
} else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) { |
1 | 222 |
VM_DeoptimizeAll op; |
223 |
VMThread::execute(&op); |
|
224 |
} |
|
225 |
} |
|
226 |
deoptimizeAllCounter++; |
|
227 |
} |
|
228 |
||
229 |
||
230 |
void InterfaceSupport::verify_stack() { |
|
231 |
JavaThread* thread = JavaThread::current(); |
|
232 |
ResourceMark rm(thread); |
|
233 |
// disabled because it throws warnings that oop maps should only be accessed |
|
234 |
// in VM thread or during debugging |
|
235 |
||
236 |
if (!thread->has_pending_exception()) { |
|
237 |
// verification does not work if there are pending exceptions |
|
238 |
StackFrameStream sfs(thread); |
|
239 |
CodeBlob* cb = sfs.current()->cb(); |
|
240 |
// In case of exceptions we might not have a runtime_stub on |
|
241 |
// top of stack, hence, all callee-saved registers are not going |
|
242 |
// to be setup correctly, hence, we cannot do stack verify |
|
243 |
if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return; |
|
244 |
||
245 |
for (; !sfs.is_done(); sfs.next()) { |
|
246 |
sfs.current()->verify(sfs.register_map()); |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
||
252 |
void InterfaceSupport::verify_last_frame() { |
|
253 |
JavaThread* thread = JavaThread::current(); |
|
254 |
ResourceMark rm(thread); |
|
255 |
RegisterMap reg_map(thread); |
|
256 |
frame fr = thread->last_frame(); |
|
257 |
fr.verify(®_map); |
|
258 |
} |
|
259 |
||
260 |
||
261 |
#endif // ASSERT |
|
262 |
||
263 |
||
264 |
void InterfaceSupport_init() { |
|
265 |
#ifdef ASSERT |
|
266 |
if (ScavengeALot || FullGCALot) { |
|
267 |
srand(ScavengeALotInterval * FullGCALotInterval); |
|
268 |
} |
|
269 |
#endif |
|
270 |
} |