author | coleenp |
Wed, 28 Oct 2015 09:47:23 -0400 | |
changeset 33611 | 9abd65805e19 |
parent 33148 | 68fa8b6c4340 |
child 34285 | 0b07014c15e9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
30764 | 2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
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" |
|
28 |
#include "gc/shared/genCollectedHeap.hpp" |
|
7397 | 29 |
#include "memory/resourceArea.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
24424
diff
changeset
|
30 |
#include "runtime/atomic.inline.hpp" |
7397 | 31 |
#include "runtime/init.hpp" |
32 |
#include "runtime/interfaceSupport.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
8921
diff
changeset
|
33 |
#include "runtime/orderAccess.inline.hpp" |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
25351
diff
changeset
|
34 |
#include "runtime/os.inline.hpp" |
7397 | 35 |
#include "runtime/threadLocalStorage.hpp" |
36 |
#include "runtime/vframe.hpp" |
|
37 |
#include "utilities/preserveException.hpp" |
|
1 | 38 |
|
39 |
// Implementation of InterfaceSupport |
|
40 |
||
41 |
#ifdef ASSERT |
|
42 |
||
43 |
long InterfaceSupport::_number_of_calls = 0; |
|
44 |
long InterfaceSupport::_scavenge_alot_counter = 1; |
|
45 |
long InterfaceSupport::_fullgc_alot_counter = 1; |
|
46 |
long InterfaceSupport::_fullgc_alot_invocation = 0; |
|
47 |
||
48 |
Histogram* RuntimeHistogram; |
|
49 |
||
50 |
RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) { |
|
51 |
static volatile jint RuntimeHistogram_lock = 0; |
|
52 |
_name = elementName; |
|
53 |
uintx count = 0; |
|
54 |
||
55 |
while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) { |
|
56 |
while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) { |
|
57 |
count +=1; |
|
58 |
if ( (WarnOnStalledSpinLock > 0) |
|
59 |
&& (count % WarnOnStalledSpinLock == 0)) { |
|
60 |
warning("RuntimeHistogram_lock seems to be stalled"); |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
if (RuntimeHistogram == NULL) { |
|
66 |
RuntimeHistogram = new Histogram("VM Runtime Call Counts",200); |
|
67 |
} |
|
68 |
||
69 |
RuntimeHistogram->add_element(this); |
|
70 |
Atomic::dec(&RuntimeHistogram_lock); |
|
71 |
} |
|
72 |
||
73 |
void InterfaceSupport::trace(const char* result_type, const char* header) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33063
diff
changeset
|
74 |
tty->print_cr("%6ld %s", _number_of_calls, header); |
1 | 75 |
} |
76 |
||
77 |
void InterfaceSupport::gc_alot() { |
|
78 |
Thread *thread = Thread::current(); |
|
2995
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
79 |
if (!thread->is_Java_thread()) return; // Avoid concurrent calls |
1 | 80 |
// Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC. |
81 |
JavaThread *current_thread = (JavaThread *)thread; |
|
82 |
if (current_thread->active_handles() == NULL) return; |
|
83 |
||
2995
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
84 |
// Short-circuit any possible re-entrant gc-a-lot attempt |
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
85 |
if (thread->skip_gcalot()) return; |
d8283445992a
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
1
diff
changeset
|
86 |
|
27678
d1872bc7dd8d
8062036: ConcurrentMarkThread::slt may be invoked before ConcurrentMarkThread::makeSurrogateLockerThread causing intermittent crashes
kbarrett
parents:
25468
diff
changeset
|
87 |
if (Threads::is_vm_complete()) { |
1 | 88 |
|
89 |
if (++_fullgc_alot_invocation < FullGCALotStart) { |
|
90 |
return; |
|
91 |
} |
|
92 |
||
93 |
// Use this line if you want to block at a specific point, |
|
94 |
// e.g. one number_of_calls/scavenge/gc before you got into problems |
|
95 |
if (FullGCALot) _fullgc_alot_counter--; |
|
96 |
||
97 |
// Check if we should force a full gc |
|
98 |
if (_fullgc_alot_counter == 0) { |
|
99 |
// Release dummy so objects are forced to move |
|
100 |
if (!Universe::release_fullgc_alot_dummy()) { |
|
101 |
warning("FullGCALot: Unable to release more dummies at bottom of heap"); |
|
102 |
} |
|
103 |
HandleMark hm(thread); |
|
104 |
Universe::heap()->collect(GCCause::_full_gc_alot); |
|
105 |
unsigned int invocations = Universe::heap()->total_full_collections(); |
|
106 |
// Compute new interval |
|
107 |
if (FullGCALotInterval > 1) { |
|
108 |
_fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0)); |
|
109 |
if (PrintGCDetails && Verbose) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33063
diff
changeset
|
110 |
tty->print_cr("Full gc no: %u\tInterval: %ld", invocations, _fullgc_alot_counter); |
1 | 111 |
} |
112 |
} else { |
|
113 |
_fullgc_alot_counter = 1; |
|
114 |
} |
|
115 |
// Print progress message |
|
116 |
if (invocations % 100 == 0) { |
|
117 |
if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations); |
|
118 |
} |
|
119 |
} else { |
|
120 |
if (ScavengeALot) _scavenge_alot_counter--; |
|
121 |
// Check if we should force a scavenge |
|
122 |
if (_scavenge_alot_counter == 0) { |
|
123 |
HandleMark hm(thread); |
|
124 |
Universe::heap()->collect(GCCause::_scavenge_alot); |
|
125 |
unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections(); |
|
126 |
// Compute new interval |
|
127 |
if (ScavengeALotInterval > 1) { |
|
128 |
_scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0)); |
|
129 |
if (PrintGCDetails && Verbose) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33063
diff
changeset
|
130 |
tty->print_cr("Scavenge no: %u\tInterval: %ld", invocations, _scavenge_alot_counter); |
1 | 131 |
} |
132 |
} else { |
|
133 |
_scavenge_alot_counter = 1; |
|
134 |
} |
|
135 |
// Print progress message |
|
136 |
if (invocations % 1000 == 0) { |
|
137 |
if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations); |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
||
145 |
vframe* vframe_array[50]; |
|
146 |
int walk_stack_counter = 0; |
|
147 |
||
148 |
void InterfaceSupport::walk_stack_from(vframe* start_vf) { |
|
149 |
// walk |
|
150 |
int i = 0; |
|
151 |
for (vframe* f = start_vf; f; f = f->sender() ) { |
|
152 |
if (i < 50) vframe_array[i++] = f; |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
||
157 |
void InterfaceSupport::walk_stack() { |
|
158 |
JavaThread* thread = JavaThread::current(); |
|
159 |
walk_stack_counter++; |
|
160 |
if (!thread->has_last_Java_frame()) return; |
|
161 |
ResourceMark rm(thread); |
|
162 |
RegisterMap reg_map(thread); |
|
163 |
walk_stack_from(thread->last_java_vframe(®_map)); |
|
164 |
} |
|
165 |
||
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
166 |
// invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions |
1 | 167 |
int deoptimizeAllCounter = 0; |
168 |
int zombieAllCounter = 0; |
|
169 |
||
170 |
void InterfaceSupport::zombieAll() { |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
171 |
// 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
|
172 |
// transition to VM state (for example, runtime calls). |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
173 |
// Divide number of calls by number of threads to avoid |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
174 |
// dependence of ZombieAll events frequency on number of threads. |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
175 |
int value = zombieAllCounter / Threads::number_of_threads(); |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
176 |
if (is_init_completed() && value > ZombieALotInterval) { |
1 | 177 |
zombieAllCounter = 0; |
178 |
VM_ZombieAll op; |
|
179 |
VMThread::execute(&op); |
|
180 |
} |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
181 |
zombieAllCounter++; |
1 | 182 |
} |
183 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
184 |
void InterfaceSupport::unlinkSymbols() { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
185 |
VM_UnlinkSymbols op; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
186 |
VMThread::execute(&op); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
187 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
188 |
|
1 | 189 |
void InterfaceSupport::deoptimizeAll() { |
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
190 |
// 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
|
191 |
// transition to VM state (for example, runtime calls). |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
192 |
// Divide number of calls by number of threads to avoid |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
193 |
// dependence of DeoptimizeAll events frequency on number of threads. |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
194 |
int value = deoptimizeAllCounter / Threads::number_of_threads(); |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
195 |
if (is_init_completed()) { |
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
196 |
if (DeoptimizeALot && value > DeoptimizeALotInterval) { |
1 | 197 |
deoptimizeAllCounter = 0; |
198 |
VM_DeoptimizeAll op; |
|
199 |
VMThread::execute(&op); |
|
27451
7e2e2b955d15
8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents:
25468
diff
changeset
|
200 |
} else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) { |
1 | 201 |
VM_DeoptimizeAll op; |
202 |
VMThread::execute(&op); |
|
203 |
} |
|
204 |
} |
|
205 |
deoptimizeAllCounter++; |
|
206 |
} |
|
207 |
||
208 |
||
209 |
void InterfaceSupport::stress_derived_pointers() { |
|
210 |
#ifdef COMPILER2 |
|
211 |
JavaThread *thread = JavaThread::current(); |
|
212 |
if (!is_init_completed()) return; |
|
213 |
ResourceMark rm(thread); |
|
214 |
bool found = false; |
|
215 |
for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) { |
|
216 |
CodeBlob* cb = sfs.current()->cb(); |
|
217 |
if (cb != NULL && cb->oop_maps() ) { |
|
218 |
// Find oopmap for current method |
|
30590 | 219 |
const ImmutableOopMap* map = cb->oop_map_for_return_address(sfs.current()->pc()); |
1 | 220 |
assert(map != NULL, "no oopmap found for pc"); |
221 |
found = map->has_derived_pointer(); |
|
222 |
} |
|
223 |
} |
|
224 |
if (found) { |
|
225 |
// $$$ Not sure what to do here. |
|
226 |
/* |
|
227 |
Scavenge::invoke(0); |
|
228 |
*/ |
|
229 |
} |
|
230 |
#endif |
|
231 |
} |
|
232 |
||
233 |
||
234 |
void InterfaceSupport::verify_stack() { |
|
235 |
JavaThread* thread = JavaThread::current(); |
|
236 |
ResourceMark rm(thread); |
|
237 |
// disabled because it throws warnings that oop maps should only be accessed |
|
238 |
// in VM thread or during debugging |
|
239 |
||
240 |
if (!thread->has_pending_exception()) { |
|
241 |
// verification does not work if there are pending exceptions |
|
242 |
StackFrameStream sfs(thread); |
|
243 |
CodeBlob* cb = sfs.current()->cb(); |
|
244 |
// In case of exceptions we might not have a runtime_stub on |
|
245 |
// top of stack, hence, all callee-saved registers are not going |
|
246 |
// to be setup correctly, hence, we cannot do stack verify |
|
247 |
if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return; |
|
248 |
||
249 |
for (; !sfs.is_done(); sfs.next()) { |
|
250 |
sfs.current()->verify(sfs.register_map()); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
||
255 |
||
256 |
void InterfaceSupport::verify_last_frame() { |
|
257 |
JavaThread* thread = JavaThread::current(); |
|
258 |
ResourceMark rm(thread); |
|
259 |
RegisterMap reg_map(thread); |
|
260 |
frame fr = thread->last_frame(); |
|
261 |
fr.verify(®_map); |
|
262 |
} |
|
263 |
||
264 |
||
265 |
#endif // ASSERT |
|
266 |
||
267 |
||
268 |
void InterfaceSupport_init() { |
|
269 |
#ifdef ASSERT |
|
270 |
if (ScavengeALot || FullGCALot) { |
|
271 |
srand(ScavengeALotInterval * FullGCALotInterval); |
|
272 |
} |
|
273 |
#endif |
|
274 |
} |