Mercurial > hg > graal-jvmci-8
annotate src/share/vm/runtime/java.cpp @ 11006:b88209cf98c0
Merge
author | kvn |
---|---|
date | Thu, 20 Jun 2013 16:08:11 -0700 |
parents | f2110083203d |
children | 836a62f43af9 71180a6e5080 |
rev | line source |
---|---|
0 | 1 /* |
10405 | 2 * Copyright (c) 1997, 2013, 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:
1547
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1547
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:
1547
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
27 #include "classfile/symbolTable.hpp" | |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "code/codeCache.hpp" | |
30 #include "compiler/compileBroker.hpp" | |
31 #include "compiler/compilerOracle.hpp" | |
32 #include "interpreter/bytecodeHistogram.hpp" | |
33 #include "memory/genCollectedHeap.hpp" | |
34 #include "memory/oopFactory.hpp" | |
35 #include "memory/universe.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
36 #include "oops/constantPool.hpp" |
1972 | 37 #include "oops/generateOopMap.hpp" |
38 #include "oops/instanceKlass.hpp" | |
39 #include "oops/instanceOop.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
40 #include "oops/method.hpp" |
1972 | 41 #include "oops/objArrayOop.hpp" |
42 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2129
diff
changeset
|
43 #include "oops/symbol.hpp" |
1972 | 44 #include "prims/jvmtiExport.hpp" |
45 #include "runtime/aprofiler.hpp" | |
46 #include "runtime/arguments.hpp" | |
47 #include "runtime/biasedLocking.hpp" | |
48 #include "runtime/compilationPolicy.hpp" | |
49 #include "runtime/fprofiler.hpp" | |
50 #include "runtime/init.hpp" | |
51 #include "runtime/interfaceSupport.hpp" | |
52 #include "runtime/java.hpp" | |
53 #include "runtime/memprofiler.hpp" | |
54 #include "runtime/sharedRuntime.hpp" | |
55 #include "runtime/statSampler.hpp" | |
56 #include "runtime/task.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
6921
diff
changeset
|
57 #include "runtime/thread.inline.hpp" |
1972 | 58 #include "runtime/timer.hpp" |
59 #include "runtime/vm_operations.hpp" | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
60 #include "services/memReporter.hpp" |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
61 #include "services/memTracker.hpp" |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4006
diff
changeset
|
62 #include "trace/tracing.hpp" |
1972 | 63 #include "utilities/dtrace.hpp" |
64 #include "utilities/globalDefinitions.hpp" | |
65 #include "utilities/histogram.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7596
diff
changeset
|
66 #include "utilities/macros.hpp" |
1972 | 67 #include "utilities/vmError.hpp" |
68 #ifdef TARGET_ARCH_x86 | |
69 # include "vm_version_x86.hpp" | |
70 #endif | |
71 #ifdef TARGET_ARCH_sparc | |
72 # include "vm_version_sparc.hpp" | |
73 #endif | |
74 #ifdef TARGET_ARCH_zero | |
75 # include "vm_version_zero.hpp" | |
76 #endif | |
2192
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
77 #ifdef TARGET_ARCH_arm |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
78 # include "vm_version_arm.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
79 #endif |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
80 #ifdef TARGET_ARCH_ppc |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
81 # include "vm_version_ppc.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
82 #endif |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7596
diff
changeset
|
83 #if INCLUDE_ALL_GCS |
1972 | 84 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" |
85 #include "gc_implementation/parallelScavenge/psScavenge.hpp" | |
86 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7596
diff
changeset
|
87 #endif // INCLUDE_ALL_GCS |
1972 | 88 #ifdef COMPILER1 |
89 #include "c1/c1_Compiler.hpp" | |
90 #include "c1/c1_Runtime1.hpp" | |
91 #endif | |
92 #ifdef COMPILER2 | |
93 #include "code/compiledIC.hpp" | |
94 #include "compiler/methodLiveness.hpp" | |
95 #include "opto/compile.hpp" | |
96 #include "opto/indexSet.hpp" | |
97 #include "opto/runtime.hpp" | |
98 #endif | |
0 | 99 |
4006 | 100 #ifndef USDT2 |
0 | 101 HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown); |
4006 | 102 #endif /* !USDT2 */ |
0 | 103 |
104 #ifndef PRODUCT | |
105 | |
106 // Statistics printing (method invocation histogram) | |
107 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
108 GrowableArray<Method*>* collected_invoked_methods; |
0 | 109 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
110 void collect_invoked_methods(Method* m) { |
0 | 111 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { |
112 collected_invoked_methods->push(m); | |
113 } | |
114 } | |
115 | |
116 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
117 GrowableArray<Method*>* collected_profiled_methods; |
0 | 118 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
119 void collect_profiled_methods(Method* m) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
120 Thread* thread = Thread::current(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
121 // This HandleMark prevents a huge amount of handles from being added |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
122 // to the metadata_handles() array on the thread. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
123 HandleMark hm(thread); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
124 methodHandle mh(thread, m); |
0 | 125 if ((m->method_data() != NULL) && |
126 (PrintMethodData || CompilerOracle::should_print(mh))) { | |
127 collected_profiled_methods->push(m); | |
128 } | |
129 } | |
130 | |
131 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
132 int compare_methods(Method** a, Method** b) { |
0 | 133 // %%% there can be 32-bit overflow here |
134 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) | |
135 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); | |
136 } | |
137 | |
138 | |
139 void print_method_invocation_histogram() { | |
140 ResourceMark rm; | |
141 HandleMark hm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
142 collected_invoked_methods = new GrowableArray<Method*>(1024); |
0 | 143 SystemDictionary::methods_do(collect_invoked_methods); |
144 collected_invoked_methods->sort(&compare_methods); | |
145 // | |
146 tty->cr(); | |
147 tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff); | |
148 tty->cr(); | |
149 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); | |
150 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, | |
151 synch_total = 0, nativ_total = 0, acces_total = 0; | |
152 for (int index = 0; index < collected_invoked_methods->length(); index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
153 Method* m = collected_invoked_methods->at(index); |
0 | 154 int c = m->invocation_count() + m->compiled_invocation_count(); |
155 if (c >= MethodHistogramCutoff) m->print_invocation_count(); | |
156 int_total += m->invocation_count(); | |
157 comp_total += m->compiled_invocation_count(); | |
158 if (m->is_final()) final_total += c; | |
159 if (m->is_static()) static_total += c; | |
160 if (m->is_synchronized()) synch_total += c; | |
161 if (m->is_native()) nativ_total += c; | |
162 if (m->is_accessor()) acces_total += c; | |
163 } | |
164 tty->cr(); | |
165 total = int_total + comp_total; | |
166 tty->print_cr("Invocations summary:"); | |
167 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); | |
168 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); | |
169 tty->print_cr("\t%9d (100%%) total", total); | |
170 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); | |
171 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); | |
172 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); | |
173 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); | |
174 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); | |
175 tty->cr(); | |
176 SharedRuntime::print_call_statistics(comp_total); | |
177 } | |
178 | |
179 void print_method_profiling_data() { | |
180 ResourceMark rm; | |
181 HandleMark hm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
182 collected_profiled_methods = new GrowableArray<Method*>(1024); |
0 | 183 SystemDictionary::methods_do(collect_profiled_methods); |
184 collected_profiled_methods->sort(&compare_methods); | |
185 | |
186 int count = collected_profiled_methods->length(); | |
187 if (count > 0) { | |
188 for (int index = 0; index < count; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
189 Method* m = collected_profiled_methods->at(index); |
0 | 190 ttyLocker ttyl; |
191 tty->print_cr("------------------------------------------------------------------------"); | |
192 //m->print_name(tty); | |
193 m->print_invocation_count(); | |
194 tty->cr(); | |
195 m->print_codes(); | |
196 } | |
197 tty->print_cr("------------------------------------------------------------------------"); | |
198 } | |
199 } | |
200 | |
201 void print_bytecode_count() { | |
202 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
203 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); | |
204 } | |
205 } | |
206 | |
207 AllocStats alloc_stats; | |
208 | |
209 | |
210 | |
211 // General statistics printing (profiling ...) | |
212 | |
213 void print_statistics() { | |
214 | |
215 #ifdef ASSERT | |
216 | |
217 if (CountRuntimeCalls) { | |
218 extern Histogram *RuntimeHistogram; | |
219 RuntimeHistogram->print(); | |
220 } | |
221 | |
222 if (CountJNICalls) { | |
223 extern Histogram *JNIHistogram; | |
224 JNIHistogram->print(); | |
225 } | |
226 | |
227 if (CountJVMCalls) { | |
228 extern Histogram *JVMHistogram; | |
229 JVMHistogram->print(); | |
230 } | |
231 | |
232 #endif | |
233 | |
234 if (MemProfiling) { | |
235 MemProfiler::disengage(); | |
236 } | |
237 | |
238 if (CITime) { | |
239 CompileBroker::print_times(); | |
240 } | |
241 | |
242 #ifdef COMPILER1 | |
243 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) { | |
244 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics); | |
245 Runtime1::print_statistics(); | |
246 Deoptimization::print_statistics(); | |
3841
0f34fdee809e
7071427: AdapterFingerPrint can hold 8 entries per int
never
parents:
3769
diff
changeset
|
247 SharedRuntime::print_statistics(); |
0 | 248 nmethod::print_statistics(); |
249 } | |
250 #endif /* COMPILER1 */ | |
251 | |
252 #ifdef COMPILER2 | |
253 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { | |
254 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); | |
255 Compile::print_statistics(); | |
256 #ifndef COMPILER1 | |
257 Deoptimization::print_statistics(); | |
258 nmethod::print_statistics(); | |
3841
0f34fdee809e
7071427: AdapterFingerPrint can hold 8 entries per int
never
parents:
3769
diff
changeset
|
259 SharedRuntime::print_statistics(); |
0 | 260 #endif //COMPILER1 |
261 os::print_statistics(); | |
262 } | |
263 | |
264 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics) { | |
265 OptoRuntime::print_named_counters(); | |
266 } | |
267 | |
268 if (TimeLivenessAnalysis) { | |
269 MethodLiveness::print_times(); | |
270 } | |
271 #ifdef ASSERT | |
272 if (CollectIndexSetStatistics) { | |
273 IndexSet::print_statistics(); | |
274 } | |
275 #endif // ASSERT | |
276 #endif // COMPILER2 | |
277 if (CountCompiledCalls) { | |
278 print_method_invocation_histogram(); | |
279 } | |
1918 | 280 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) { |
0 | 281 print_method_profiling_data(); |
282 } | |
283 if (TimeCompiler) { | |
284 COMPILER2_PRESENT(Compile::print_timers();) | |
285 } | |
286 if (TimeCompilationPolicy) { | |
287 CompilationPolicy::policy()->print_time(); | |
288 } | |
289 if (TimeOopMap) { | |
290 GenerateOopMap::print_time(); | |
291 } | |
292 if (ProfilerCheckIntervals) { | |
293 PeriodicTask::print_intervals(); | |
294 } | |
295 if (PrintSymbolTableSizeHistogram) { | |
296 SymbolTable::print_histogram(); | |
297 } | |
298 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
299 BytecodeCounter::print(); | |
300 } | |
301 if (PrintBytecodePairHistogram) { | |
302 BytecodePairHistogram::print(); | |
303 } | |
304 | |
305 if (PrintCodeCache) { | |
306 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
307 CodeCache::print(); | |
308 } | |
309 | |
310 if (PrintCodeCache2) { | |
311 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
312 CodeCache::print_internals(); | |
313 } | |
314 | |
315 if (PrintClassStatistics) { | |
316 SystemDictionary::print_class_statistics(); | |
317 } | |
318 if (PrintMethodStatistics) { | |
319 SystemDictionary::print_method_statistics(); | |
320 } | |
321 | |
322 if (PrintVtableStats) { | |
323 klassVtable::print_statistics(); | |
324 klassItable::print_statistics(); | |
325 } | |
326 if (VerifyOops) { | |
327 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); | |
328 } | |
329 | |
330 print_bytecode_count(); | |
2250 | 331 if (PrintMallocStatistics) { |
0 | 332 tty->print("allocation stats: "); |
333 alloc_stats.print(); | |
334 tty->cr(); | |
335 } | |
336 | |
337 if (PrintSystemDictionaryAtExit) { | |
338 SystemDictionary::print(); | |
339 } | |
340 | |
341 if (PrintBiasedLockingStatistics) { | |
342 BiasedLocking::print_counters(); | |
343 } | |
344 | |
345 #ifdef ENABLE_ZAP_DEAD_LOCALS | |
346 #ifdef COMPILER2 | |
347 if (ZapDeadCompiledLocals) { | |
348 tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count); | |
349 tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count); | |
350 } | |
351 #endif // COMPILER2 | |
352 #endif // ENABLE_ZAP_DEAD_LOCALS | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
353 // Native memory tracking data |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
354 if (PrintNMTStatistics) { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
355 if (MemTracker::is_on()) { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
356 BaselineTTYOutputer outputer(tty); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
357 MemTracker::print_memory_usage(outputer, K, false); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
358 } else { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
359 tty->print_cr(MemTracker::reason()); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
360 } |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
361 } |
0 | 362 } |
363 | |
364 #else // PRODUCT MODE STATISTICS | |
365 | |
366 void print_statistics() { | |
367 | |
368 if (CITime) { | |
369 CompileBroker::print_times(); | |
370 } | |
7595
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
371 |
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
372 if (PrintCodeCache) { |
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
373 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
374 CodeCache::print(); |
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
375 } |
9deda4d8e126
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
7180
diff
changeset
|
376 |
0 | 377 #ifdef COMPILER2 |
378 if (PrintPreciseBiasedLockingStatistics) { | |
379 OptoRuntime::print_named_counters(); | |
380 } | |
381 #endif | |
382 if (PrintBiasedLockingStatistics) { | |
383 BiasedLocking::print_counters(); | |
384 } | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
385 |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
386 // Native memory tracking data |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
387 if (PrintNMTStatistics) { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
388 if (MemTracker::is_on()) { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
389 BaselineTTYOutputer outputer(tty); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
390 MemTracker::print_memory_usage(outputer, K, false); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
391 } else { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
392 tty->print_cr(MemTracker::reason()); |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
393 } |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6725
diff
changeset
|
394 } |
0 | 395 } |
396 | |
397 #endif | |
398 | |
399 | |
400 // Helper class for registering on_exit calls through JVM_OnExit | |
401 | |
402 extern "C" { | |
403 typedef void (*__exit_proc)(void); | |
404 } | |
405 | |
6197 | 406 class ExitProc : public CHeapObj<mtInternal> { |
0 | 407 private: |
408 __exit_proc _proc; | |
409 // void (*_proc)(void); | |
410 ExitProc* _next; | |
411 public: | |
412 // ExitProc(void (*proc)(void)) { | |
413 ExitProc(__exit_proc proc) { | |
414 _proc = proc; | |
415 _next = NULL; | |
416 } | |
417 void evaluate() { _proc(); } | |
418 ExitProc* next() const { return _next; } | |
419 void set_next(ExitProc* next) { _next = next; } | |
420 }; | |
421 | |
422 | |
423 // Linked list of registered on_exit procedures | |
424 | |
425 static ExitProc* exit_procs = NULL; | |
426 | |
427 | |
428 extern "C" { | |
429 void register_on_exit_function(void (*func)(void)) { | |
430 ExitProc *entry = new ExitProc(func); | |
431 // Classic vm does not throw an exception in case the allocation failed, | |
432 if (entry != NULL) { | |
433 entry->set_next(exit_procs); | |
434 exit_procs = entry; | |
435 } | |
436 } | |
437 } | |
438 | |
439 // Note: before_exit() can be executed only once, if more than one threads | |
440 // are trying to shutdown the VM at the same time, only one thread | |
441 // can run before_exit() and all other threads must wait. | |
442 void before_exit(JavaThread * thread) { | |
443 #define BEFORE_EXIT_NOT_RUN 0 | |
444 #define BEFORE_EXIT_RUNNING 1 | |
445 #define BEFORE_EXIT_DONE 2 | |
446 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; | |
447 | |
448 // Note: don't use a Mutex to guard the entire before_exit(), as | |
449 // JVMTI post_thread_end_event and post_vm_death_event will run native code. | |
450 // A CAS or OSMutex would work just fine but then we need to manipulate | |
451 // thread state for Safepoint. Here we use Monitor wait() and notify_all() | |
452 // for synchronization. | |
453 { MutexLocker ml(BeforeExit_lock); | |
454 switch (_before_exit_status) { | |
455 case BEFORE_EXIT_NOT_RUN: | |
456 _before_exit_status = BEFORE_EXIT_RUNNING; | |
457 break; | |
458 case BEFORE_EXIT_RUNNING: | |
459 while (_before_exit_status == BEFORE_EXIT_RUNNING) { | |
460 BeforeExit_lock->wait(); | |
461 } | |
462 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); | |
463 return; | |
464 case BEFORE_EXIT_DONE: | |
465 return; | |
466 } | |
467 } | |
468 | |
469 // The only difference between this and Win32's _onexit procs is that | |
470 // this version is invoked before any threads get killed. | |
471 ExitProc* current = exit_procs; | |
472 while (current != NULL) { | |
473 ExitProc* next = current->next(); | |
474 current->evaluate(); | |
475 delete current; | |
476 current = next; | |
477 } | |
478 | |
479 // Hang forever on exit if we're reporting an error. | |
480 if (ShowMessageBoxOnError && is_error_reported()) { | |
481 os::infinite_sleep(); | |
482 } | |
483 | |
484 // Terminate watcher thread - must before disenrolling any periodic task | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
485 if (PeriodicTask::num_tasks() > 0) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
486 WatcherThread::stop(); |
0 | 487 |
488 // Print statistics gathered (profiling ...) | |
489 if (Arguments::has_profile()) { | |
490 FlatProfiler::disengage(); | |
491 FlatProfiler::print(10); | |
492 } | |
493 | |
494 // shut down the StatSampler task | |
495 StatSampler::disengage(); | |
496 StatSampler::destroy(); | |
497 | |
3769
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
2304
diff
changeset
|
498 // We do not need to explicitly stop concurrent GC threads because the |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
2304
diff
changeset
|
499 // JVM will be taken down at a safepoint when such threads are inactive -- |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
2304
diff
changeset
|
500 // except for some concurrent G1 threads, see (comment in) |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
2304
diff
changeset
|
501 // Threads::destroy_vm(). |
0 | 502 |
503 // Print GC/heap related information. | |
504 if (PrintGCDetails) { | |
505 Universe::print(); | |
506 AdaptiveSizePolicyOutput(0); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
507 if (Verbose) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
508 ClassLoaderDataGraph::dump_on(gclog_or_tty); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
509 } |
0 | 510 } |
511 | |
512 | |
513 if (Arguments::has_alloc_profile()) { | |
514 HandleMark hm; | |
515 // Do one last collection to enumerate all the objects | |
516 // allocated since the last one. | |
517 Universe::heap()->collect(GCCause::_allocation_profiler); | |
518 AllocationProfiler::disengage(); | |
519 AllocationProfiler::print(0); | |
520 } | |
521 | |
522 if (PrintBytecodeHistogram) { | |
523 BytecodeHistogram::print(); | |
524 } | |
525 | |
526 if (JvmtiExport::should_post_thread_life()) { | |
527 JvmtiExport::post_thread_end(thread); | |
528 } | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4006
diff
changeset
|
529 |
10405 | 530 |
531 EventThreadEnd event; | |
532 if (event.should_commit()) { | |
533 event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj())); | |
534 event.commit(); | |
535 } | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4006
diff
changeset
|
536 |
0 | 537 // Always call even when there are not JVMTI environments yet, since environments |
538 // may be attached late and JVMTI must track phases of VM execution | |
539 JvmtiExport::post_vm_death(); | |
540 Threads::shutdown_vm_agents(); | |
541 | |
542 // Terminate the signal thread | |
543 // Note: we don't wait until it actually dies. | |
544 os::terminate_signal_thread(); | |
545 | |
546 print_statistics(); | |
547 Universe::heap()->print_tracing_info(); | |
548 | |
549 { MutexLocker ml(BeforeExit_lock); | |
550 _before_exit_status = BEFORE_EXIT_DONE; | |
551 BeforeExit_lock->notify_all(); | |
552 } | |
553 | |
7585
e0cf9af8978e
8005936: PrintNMTStatistics doesn't work for normal JVM exit
zgu
parents:
7180
diff
changeset
|
554 // Shutdown NMT before exit. Otherwise, |
e0cf9af8978e
8005936: PrintNMTStatistics doesn't work for normal JVM exit
zgu
parents:
7180
diff
changeset
|
555 // it will run into trouble when system destroys static variables. |
e0cf9af8978e
8005936: PrintNMTStatistics doesn't work for normal JVM exit
zgu
parents:
7180
diff
changeset
|
556 MemTracker::shutdown(MemTracker::NMT_normal); |
e0cf9af8978e
8005936: PrintNMTStatistics doesn't work for normal JVM exit
zgu
parents:
7180
diff
changeset
|
557 |
0 | 558 #undef BEFORE_EXIT_NOT_RUN |
559 #undef BEFORE_EXIT_RUNNING | |
560 #undef BEFORE_EXIT_DONE | |
561 } | |
562 | |
563 void vm_exit(int code) { | |
2096
0eb90baf1b69
6583275: Hotspot crash in vm_perform_shutdown_actions due to uninitialized TLS during out of memory handling
coleenp
parents:
1972
diff
changeset
|
564 Thread* thread = ThreadLocalStorage::is_initialized() ? |
0eb90baf1b69
6583275: Hotspot crash in vm_perform_shutdown_actions due to uninitialized TLS during out of memory handling
coleenp
parents:
1972
diff
changeset
|
565 ThreadLocalStorage::get_thread_slow() : NULL; |
0 | 566 if (thread == NULL) { |
567 // we have serious problems -- just exit | |
568 vm_direct_exit(code); | |
569 } | |
570 | |
571 if (VMThread::vm_thread() != NULL) { | |
572 // Fire off a VM_Exit operation to bring VM to a safepoint and exit | |
573 VM_Exit op(code); | |
574 if (thread->is_Java_thread()) | |
575 ((JavaThread*)thread)->set_thread_state(_thread_in_vm); | |
576 VMThread::execute(&op); | |
577 // should never reach here; but in case something wrong with VM Thread. | |
578 vm_direct_exit(code); | |
579 } else { | |
580 // VM thread is gone, just exit | |
581 vm_direct_exit(code); | |
582 } | |
583 ShouldNotReachHere(); | |
584 } | |
585 | |
586 void notify_vm_shutdown() { | |
587 // For now, just a dtrace probe. | |
4006 | 588 #ifndef USDT2 |
0 | 589 HS_DTRACE_PROBE(hotspot, vm__shutdown); |
1547
fb1a39993f69
6951319: enable solaris builds using Sun Studio 12 update 1
jcoomes
parents:
242
diff
changeset
|
590 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); |
4006 | 591 #else /* USDT2 */ |
592 HOTSPOT_VM_SHUTDOWN(); | |
593 #endif /* USDT2 */ | |
0 | 594 } |
595 | |
596 void vm_direct_exit(int code) { | |
597 notify_vm_shutdown(); | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
598 os::wait_for_keypress_at_exit(); |
0 | 599 ::exit(code); |
600 } | |
601 | |
602 void vm_perform_shutdown_actions() { | |
603 // Warning: do not call 'exit_globals()' here. All threads are still running. | |
604 // Calling 'exit_globals()' will disable thread-local-storage and cause all | |
605 // kinds of assertions to trigger in debug mode. | |
606 if (is_init_completed()) { | |
2096
0eb90baf1b69
6583275: Hotspot crash in vm_perform_shutdown_actions due to uninitialized TLS during out of memory handling
coleenp
parents:
1972
diff
changeset
|
607 Thread* thread = ThreadLocalStorage::is_initialized() ? |
0eb90baf1b69
6583275: Hotspot crash in vm_perform_shutdown_actions due to uninitialized TLS during out of memory handling
coleenp
parents:
1972
diff
changeset
|
608 ThreadLocalStorage::get_thread_slow() : NULL; |
0eb90baf1b69
6583275: Hotspot crash in vm_perform_shutdown_actions due to uninitialized TLS during out of memory handling
coleenp
parents:
1972
diff
changeset
|
609 if (thread != NULL && thread->is_Java_thread()) { |
0 | 610 // We are leaving the VM, set state to native (in case any OS exit |
611 // handlers call back to the VM) | |
612 JavaThread* jt = (JavaThread*)thread; | |
613 // Must always be walkable or have no last_Java_frame when in | |
614 // thread_in_native | |
615 jt->frame_anchor()->make_walkable(jt); | |
616 jt->set_thread_state(_thread_in_native); | |
617 } | |
618 } | |
619 notify_vm_shutdown(); | |
620 } | |
621 | |
622 void vm_shutdown() | |
623 { | |
624 vm_perform_shutdown_actions(); | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
625 os::wait_for_keypress_at_exit(); |
0 | 626 os::shutdown(); |
627 } | |
628 | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
629 void vm_abort(bool dump_core) { |
0 | 630 vm_perform_shutdown_actions(); |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
631 os::wait_for_keypress_at_exit(); |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
632 os::abort(dump_core); |
0 | 633 ShouldNotReachHere(); |
634 } | |
635 | |
636 void vm_notify_during_shutdown(const char* error, const char* message) { | |
637 if (error != NULL) { | |
638 tty->print_cr("Error occurred during initialization of VM"); | |
639 tty->print("%s", error); | |
640 if (message != NULL) { | |
641 tty->print_cr(": %s", message); | |
642 } | |
643 else { | |
644 tty->cr(); | |
645 } | |
646 } | |
647 if (ShowMessageBoxOnError && WizardMode) { | |
648 fatal("Error occurred during initialization of VM"); | |
649 } | |
650 } | |
651 | |
652 void vm_exit_during_initialization(Handle exception) { | |
653 tty->print_cr("Error occurred during initialization of VM"); | |
654 // If there are exceptions on this thread it must be cleared | |
655 // first and here. Any future calls to EXCEPTION_MARK requires | |
656 // that no pending exceptions exist. | |
657 Thread *THREAD = Thread::current(); | |
658 if (HAS_PENDING_EXCEPTION) { | |
659 CLEAR_PENDING_EXCEPTION; | |
660 } | |
661 java_lang_Throwable::print(exception, tty); | |
662 tty->cr(); | |
663 java_lang_Throwable::print_stack_trace(exception(), tty); | |
664 tty->cr(); | |
665 vm_notify_during_shutdown(NULL, NULL); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
666 |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
667 // Failure during initialization, we don't want to dump core |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
668 vm_abort(false); |
0 | 669 } |
670 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2129
diff
changeset
|
671 void vm_exit_during_initialization(Symbol* ex, const char* message) { |
0 | 672 ResourceMark rm; |
673 vm_notify_during_shutdown(ex->as_C_string(), message); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
674 |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
675 // Failure during initialization, we don't want to dump core |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
676 vm_abort(false); |
0 | 677 } |
678 | |
679 void vm_exit_during_initialization(const char* error, const char* message) { | |
680 vm_notify_during_shutdown(error, message); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
681 |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
682 // Failure during initialization, we don't want to dump core |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
683 vm_abort(false); |
0 | 684 } |
685 | |
686 void vm_shutdown_during_initialization(const char* error, const char* message) { | |
687 vm_notify_during_shutdown(error, message); | |
688 vm_shutdown(); | |
689 } | |
690 | |
242 | 691 JDK_Version JDK_Version::_current; |
6181 | 692 const char* JDK_Version::_runtime_name; |
6921
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6770
diff
changeset
|
693 const char* JDK_Version::_runtime_version; |
0 | 694 |
695 void JDK_Version::initialize() { | |
242 | 696 jdk_version_info info; |
697 assert(!_current.is_valid(), "Don't initialize twice"); | |
698 | |
0 | 699 void *lib_handle = os::native_java_library(); |
242 | 700 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, |
701 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); | |
0 | 702 |
703 if (func == NULL) { | |
704 // JDK older than 1.6 | |
242 | 705 _current._partially_initialized = true; |
706 } else { | |
707 (*func)(&info, sizeof(info)); | |
0 | 708 |
242 | 709 int major = JDK_VERSION_MAJOR(info.jdk_version); |
710 int minor = JDK_VERSION_MINOR(info.jdk_version); | |
711 int micro = JDK_VERSION_MICRO(info.jdk_version); | |
712 int build = JDK_VERSION_BUILD(info.jdk_version); | |
713 if (major == 1 && minor > 4) { | |
714 // We represent "1.5.0" as "5.0", but 1.4.2 as itself. | |
715 major = minor; | |
716 minor = micro; | |
717 micro = 0; | |
718 } | |
719 _current = JDK_Version(major, minor, micro, info.update_version, | |
720 info.special_update_version, build, | |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2096
diff
changeset
|
721 info.thread_park_blocker == 1, |
3917
eca1193ca245
4965777: GC changes to support use of discovered field for pending references
ysr
parents:
3841
diff
changeset
|
722 info.post_vm_init_hook_enabled == 1, |
eca1193ca245
4965777: GC changes to support use of discovered field for pending references
ysr
parents:
3841
diff
changeset
|
723 info.pending_list_uses_discovered_field == 1); |
0 | 724 } |
242 | 725 } |
726 | |
727 void JDK_Version::fully_initialize( | |
728 uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) { | |
729 // This is only called when current is less than 1.6 and we've gotten | |
730 // far enough in the initialization to determine the exact version. | |
731 assert(major < 6, "not needed for JDK version >= 6"); | |
732 assert(is_partially_initialized(), "must not initialize"); | |
733 if (major < 5) { | |
734 // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc. | |
735 micro = minor; | |
736 minor = major; | |
737 major = 1; | |
0 | 738 } |
242 | 739 _current = JDK_Version(major, minor, micro, update); |
0 | 740 } |
741 | |
742 void JDK_Version_init() { | |
743 JDK_Version::initialize(); | |
744 } | |
242 | 745 |
746 static int64_t encode_jdk_version(const JDK_Version& v) { | |
747 return | |
748 ((int64_t)v.major_version() << (BitsPerByte * 5)) | | |
749 ((int64_t)v.minor_version() << (BitsPerByte * 4)) | | |
750 ((int64_t)v.micro_version() << (BitsPerByte * 3)) | | |
751 ((int64_t)v.update_version() << (BitsPerByte * 2)) | | |
752 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) | | |
753 ((int64_t)v.build_number() << (BitsPerByte * 0)); | |
754 } | |
755 | |
756 int JDK_Version::compare(const JDK_Version& other) const { | |
757 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); | |
758 if (!is_partially_initialized() && other.is_partially_initialized()) { | |
759 return -(other.compare(*this)); // flip the comparators | |
760 } | |
761 assert(!other.is_partially_initialized(), "Not initialized yet"); | |
762 if (is_partially_initialized()) { | |
763 assert(other.major_version() >= 6, | |
764 "Invalid JDK version comparison during initialization"); | |
765 return -1; | |
766 } else { | |
767 uint64_t e = encode_jdk_version(*this); | |
768 uint64_t o = encode_jdk_version(other); | |
769 return (e > o) ? 1 : ((e == o) ? 0 : -1); | |
770 } | |
771 } | |
772 | |
773 void JDK_Version::to_string(char* buffer, size_t buflen) const { | |
774 size_t index = 0; | |
775 if (!is_valid()) { | |
776 jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); | |
777 } else if (is_partially_initialized()) { | |
778 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); | |
779 } else { | |
780 index += jio_snprintf( | |
781 &buffer[index], buflen - index, "%d.%d", _major, _minor); | |
782 if (_micro > 0) { | |
783 index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); | |
784 } | |
785 if (_update > 0) { | |
786 index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); | |
787 } | |
788 if (_special > 0) { | |
789 index += jio_snprintf(&buffer[index], buflen - index, "%c", _special); | |
790 } | |
791 if (_build > 0) { | |
792 index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); | |
793 } | |
794 } | |
795 } |