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