Mercurial > hg > truffle
annotate src/share/vm/runtime/java.cpp @ 4237:30b6720604d2
Undid expected failure for EscapeAnalysisTest.testMonitor2().
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 06 Jan 2012 15:35:52 +0100 |
parents | 04b9a2566eec |
children | 3c21eee8ab4d |
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(); |
0 | 253 nmethod::print_statistics(); |
254 } | |
255 #endif /* COMPILER1 */ | |
256 | |
257 #ifdef COMPILER2 | |
258 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { | |
259 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); | |
260 Compile::print_statistics(); | |
261 #ifndef COMPILER1 | |
262 Deoptimization::print_statistics(); | |
263 nmethod::print_statistics(); | |
3841
0f34fdee809e
7071427: AdapterFingerPrint can hold 8 entries per int
never
parents:
3769
diff
changeset
|
264 SharedRuntime::print_statistics(); |
0 | 265 #endif //COMPILER1 |
266 os::print_statistics(); | |
267 } | |
268 | |
269 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics) { | |
270 OptoRuntime::print_named_counters(); | |
271 } | |
272 | |
273 if (TimeLivenessAnalysis) { | |
274 MethodLiveness::print_times(); | |
275 } | |
276 #ifdef ASSERT | |
277 if (CollectIndexSetStatistics) { | |
278 IndexSet::print_statistics(); | |
279 } | |
280 #endif // ASSERT | |
281 #endif // COMPILER2 | |
282 if (CountCompiledCalls) { | |
283 print_method_invocation_histogram(); | |
284 } | |
1918 | 285 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) { |
0 | 286 print_method_profiling_data(); |
287 } | |
288 if (TimeCompiler) { | |
289 COMPILER2_PRESENT(Compile::print_timers();) | |
290 } | |
291 if (TimeCompilationPolicy) { | |
292 CompilationPolicy::policy()->print_time(); | |
293 } | |
294 if (TimeOopMap) { | |
295 GenerateOopMap::print_time(); | |
296 } | |
297 if (ProfilerCheckIntervals) { | |
298 PeriodicTask::print_intervals(); | |
299 } | |
300 if (PrintSymbolTableSizeHistogram) { | |
301 SymbolTable::print_histogram(); | |
302 } | |
303 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
304 BytecodeCounter::print(); | |
305 } | |
306 if (PrintBytecodePairHistogram) { | |
307 BytecodePairHistogram::print(); | |
308 } | |
309 | |
310 if (PrintCodeCache) { | |
311 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
312 CodeCache::print(); | |
313 } | |
314 | |
315 if (PrintCodeCache2) { | |
316 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
317 CodeCache::print_internals(); | |
318 } | |
319 | |
320 if (PrintClassStatistics) { | |
321 SystemDictionary::print_class_statistics(); | |
322 } | |
323 if (PrintMethodStatistics) { | |
324 SystemDictionary::print_method_statistics(); | |
325 } | |
326 | |
327 if (PrintVtableStats) { | |
328 klassVtable::print_statistics(); | |
329 klassItable::print_statistics(); | |
330 } | |
331 if (VerifyOops) { | |
332 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); | |
333 } | |
334 | |
335 print_bytecode_count(); | |
2250 | 336 if (PrintMallocStatistics) { |
0 | 337 tty->print("allocation stats: "); |
338 alloc_stats.print(); | |
339 tty->cr(); | |
340 } | |
341 | |
342 if (PrintSystemDictionaryAtExit) { | |
343 SystemDictionary::print(); | |
344 } | |
345 | |
346 if (PrintBiasedLockingStatistics) { | |
347 BiasedLocking::print_counters(); | |
348 } | |
349 | |
350 #ifdef ENABLE_ZAP_DEAD_LOCALS | |
351 #ifdef COMPILER2 | |
352 if (ZapDeadCompiledLocals) { | |
353 tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count); | |
354 tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count); | |
355 } | |
356 #endif // COMPILER2 | |
357 #endif // ENABLE_ZAP_DEAD_LOCALS | |
358 } | |
359 | |
360 #else // PRODUCT MODE STATISTICS | |
361 | |
362 void print_statistics() { | |
363 | |
364 if (CITime) { | |
365 CompileBroker::print_times(); | |
366 } | |
367 #ifdef COMPILER2 | |
368 if (PrintPreciseBiasedLockingStatistics) { | |
369 OptoRuntime::print_named_counters(); | |
370 } | |
371 #endif | |
372 if (PrintBiasedLockingStatistics) { | |
373 BiasedLocking::print_counters(); | |
374 } | |
375 } | |
376 | |
377 #endif | |
378 | |
379 | |
380 // Helper class for registering on_exit calls through JVM_OnExit | |
381 | |
382 extern "C" { | |
383 typedef void (*__exit_proc)(void); | |
384 } | |
385 | |
386 class ExitProc : public CHeapObj { | |
387 private: | |
388 __exit_proc _proc; | |
389 // void (*_proc)(void); | |
390 ExitProc* _next; | |
391 public: | |
392 // ExitProc(void (*proc)(void)) { | |
393 ExitProc(__exit_proc proc) { | |
394 _proc = proc; | |
395 _next = NULL; | |
396 } | |
397 void evaluate() { _proc(); } | |
398 ExitProc* next() const { return _next; } | |
399 void set_next(ExitProc* next) { _next = next; } | |
400 }; | |
401 | |
402 | |
403 // Linked list of registered on_exit procedures | |
404 | |
405 static ExitProc* exit_procs = NULL; | |
406 | |
407 | |
408 extern "C" { | |
409 void register_on_exit_function(void (*func)(void)) { | |
410 ExitProc *entry = new ExitProc(func); | |
411 // Classic vm does not throw an exception in case the allocation failed, | |
412 if (entry != NULL) { | |
413 entry->set_next(exit_procs); | |
414 exit_procs = entry; | |
415 } | |
416 } | |
417 } | |
418 | |
419 // Note: before_exit() can be executed only once, if more than one threads | |
420 // are trying to shutdown the VM at the same time, only one thread | |
421 // can run before_exit() and all other threads must wait. | |
422 void before_exit(JavaThread * thread) { | |
423 #define BEFORE_EXIT_NOT_RUN 0 | |
424 #define BEFORE_EXIT_RUNNING 1 | |
425 #define BEFORE_EXIT_DONE 2 | |
426 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; | |
427 | |
2937
2823897b2da2
Fix for NodeWorkList
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2928
diff
changeset
|
428 if (UseGraal) { |
2823897b2da2
Fix for NodeWorkList
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2928
diff
changeset
|
429 GraalCompiler::instance()->exit(); |
2823897b2da2
Fix for NodeWorkList
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2928
diff
changeset
|
430 } |
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
|
431 |
0 | 432 // Note: don't use a Mutex to guard the entire before_exit(), as |
433 // JVMTI post_thread_end_event and post_vm_death_event will run native code. | |
434 // A CAS or OSMutex would work just fine but then we need to manipulate | |
435 // thread state for Safepoint. Here we use Monitor wait() and notify_all() | |
436 // for synchronization. | |
437 { MutexLocker ml(BeforeExit_lock); | |
438 switch (_before_exit_status) { | |
439 case BEFORE_EXIT_NOT_RUN: | |
440 _before_exit_status = BEFORE_EXIT_RUNNING; | |
441 break; | |
442 case BEFORE_EXIT_RUNNING: | |
443 while (_before_exit_status == BEFORE_EXIT_RUNNING) { | |
444 BeforeExit_lock->wait(); | |
445 } | |
446 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); | |
447 return; | |
448 case BEFORE_EXIT_DONE: | |
449 return; | |
450 } | |
451 } | |
452 | |
453 // The only difference between this and Win32's _onexit procs is that | |
454 // this version is invoked before any threads get killed. | |
455 ExitProc* current = exit_procs; | |
456 while (current != NULL) { | |
457 ExitProc* next = current->next(); | |
458 current->evaluate(); | |
459 delete current; | |
460 current = next; | |
461 } | |
462 | |
463 // Hang forever on exit if we're reporting an error. | |
464 if (ShowMessageBoxOnError && is_error_reported()) { | |
465 os::infinite_sleep(); | |
466 } | |
467 | |
468 // Terminate watcher thread - must before disenrolling any periodic task | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
469 if (PeriodicTask::num_tasks() > 0) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
470 WatcherThread::stop(); |
0 | 471 |
472 // Print statistics gathered (profiling ...) | |
473 if (Arguments::has_profile()) { | |
474 FlatProfiler::disengage(); | |
475 FlatProfiler::print(10); | |
476 } | |
477 | |
478 // shut down the StatSampler task | |
479 StatSampler::disengage(); | |
480 StatSampler::destroy(); | |
481 | |
3769
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
2304
diff
changeset
|
482 // 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
|
483 // 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
|
484 // 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
|
485 // Threads::destroy_vm(). |
0 | 486 |
487 // Print GC/heap related information. | |
488 if (PrintGCDetails) { | |
489 Universe::print(); | |
490 AdaptiveSizePolicyOutput(0); | |
491 } | |
492 | |
493 | |
494 if (Arguments::has_alloc_profile()) { | |
495 HandleMark hm; | |
496 // Do one last collection to enumerate all the objects | |
497 // allocated since the last one. | |
498 Universe::heap()->collect(GCCause::_allocation_profiler); | |
499 AllocationProfiler::disengage(); | |
500 AllocationProfiler::print(0); | |
501 } | |
502 | |
503 if (PrintBytecodeHistogram) { | |
504 BytecodeHistogram::print(); | |
505 } | |
506 | |
507 if (JvmtiExport::should_post_thread_life()) { | |
508 JvmtiExport::post_thread_end(thread); | |
509 } | |
510 // Always call even when there are not JVMTI environments yet, since environments | |
511 // may be attached late and JVMTI must track phases of VM execution | |
512 JvmtiExport::post_vm_death(); | |
513 Threads::shutdown_vm_agents(); | |
514 | |
515 // Terminate the signal thread | |
516 // Note: we don't wait until it actually dies. | |
517 os::terminate_signal_thread(); | |
518 | |
519 print_statistics(); | |
520 Universe::heap()->print_tracing_info(); | |
521 | |
522 { MutexLocker ml(BeforeExit_lock); | |
523 _before_exit_status = BEFORE_EXIT_DONE; | |
524 BeforeExit_lock->notify_all(); | |
525 } | |
526 | |
527 #undef BEFORE_EXIT_NOT_RUN | |
528 #undef BEFORE_EXIT_RUNNING | |
529 #undef BEFORE_EXIT_DONE | |
530 } | |
531 | |
532 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
|
533 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
|
534 ThreadLocalStorage::get_thread_slow() : NULL; |
0 | 535 if (thread == NULL) { |
536 // we have serious problems -- just exit | |
537 vm_direct_exit(code); | |
538 } | |
539 | |
540 if (VMThread::vm_thread() != NULL) { | |
541 // Fire off a VM_Exit operation to bring VM to a safepoint and exit | |
542 VM_Exit op(code); | |
543 if (thread->is_Java_thread()) | |
544 ((JavaThread*)thread)->set_thread_state(_thread_in_vm); | |
545 VMThread::execute(&op); | |
546 // should never reach here; but in case something wrong with VM Thread. | |
547 vm_direct_exit(code); | |
548 } else { | |
549 // VM thread is gone, just exit | |
550 vm_direct_exit(code); | |
551 } | |
552 ShouldNotReachHere(); | |
553 } | |
554 | |
555 void notify_vm_shutdown() { | |
556 // For now, just a dtrace probe. | |
4006 | 557 #ifndef USDT2 |
0 | 558 HS_DTRACE_PROBE(hotspot, vm__shutdown); |
1547
fb1a39993f69
6951319: enable solaris builds using Sun Studio 12 update 1
jcoomes
parents:
242
diff
changeset
|
559 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); |
4006 | 560 #else /* USDT2 */ |
561 HOTSPOT_VM_SHUTDOWN(); | |
562 #endif /* USDT2 */ | |
0 | 563 } |
564 | |
565 void vm_direct_exit(int code) { | |
566 notify_vm_shutdown(); | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
567 os::wait_for_keypress_at_exit(); |
0 | 568 ::exit(code); |
569 } | |
570 | |
571 void vm_perform_shutdown_actions() { | |
572 // Warning: do not call 'exit_globals()' here. All threads are still running. | |
573 // Calling 'exit_globals()' will disable thread-local-storage and cause all | |
574 // kinds of assertions to trigger in debug mode. | |
575 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
|
576 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
|
577 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
|
578 if (thread != NULL && thread->is_Java_thread()) { |
0 | 579 // We are leaving the VM, set state to native (in case any OS exit |
580 // handlers call back to the VM) | |
581 JavaThread* jt = (JavaThread*)thread; | |
582 // Must always be walkable or have no last_Java_frame when in | |
583 // thread_in_native | |
584 jt->frame_anchor()->make_walkable(jt); | |
585 jt->set_thread_state(_thread_in_native); | |
586 } | |
587 } | |
588 notify_vm_shutdown(); | |
589 } | |
590 | |
591 void vm_shutdown() | |
592 { | |
593 vm_perform_shutdown_actions(); | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
594 os::wait_for_keypress_at_exit(); |
0 | 595 os::shutdown(); |
596 } | |
597 | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
598 void vm_abort(bool dump_core) { |
0 | 599 vm_perform_shutdown_actions(); |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2192
diff
changeset
|
600 os::wait_for_keypress_at_exit(); |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
601 os::abort(dump_core); |
0 | 602 ShouldNotReachHere(); |
603 } | |
604 | |
605 void vm_notify_during_shutdown(const char* error, const char* message) { | |
606 if (error != NULL) { | |
607 tty->print_cr("Error occurred during initialization of VM"); | |
608 tty->print("%s", error); | |
609 if (message != NULL) { | |
610 tty->print_cr(": %s", message); | |
611 } | |
612 else { | |
613 tty->cr(); | |
614 } | |
615 } | |
616 if (ShowMessageBoxOnError && WizardMode) { | |
617 fatal("Error occurred during initialization of VM"); | |
618 } | |
619 } | |
620 | |
621 void vm_exit_during_initialization(Handle exception) { | |
622 tty->print_cr("Error occurred during initialization of VM"); | |
623 // If there are exceptions on this thread it must be cleared | |
624 // first and here. Any future calls to EXCEPTION_MARK requires | |
625 // that no pending exceptions exist. | |
626 Thread *THREAD = Thread::current(); | |
627 if (HAS_PENDING_EXCEPTION) { | |
628 CLEAR_PENDING_EXCEPTION; | |
629 } | |
630 java_lang_Throwable::print(exception, tty); | |
631 tty->cr(); | |
632 java_lang_Throwable::print_stack_trace(exception(), tty); | |
633 tty->cr(); | |
634 vm_notify_during_shutdown(NULL, NULL); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
635 |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
636 // 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
|
637 vm_abort(false); |
0 | 638 } |
639 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2129
diff
changeset
|
640 void vm_exit_during_initialization(Symbol* ex, const char* message) { |
0 | 641 ResourceMark rm; |
642 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
|
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 | |
648 void vm_exit_during_initialization(const char* error, const char* message) { | |
649 vm_notify_during_shutdown(error, message); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
650 |
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
61
diff
changeset
|
651 // 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
|
652 vm_abort(false); |
0 | 653 } |
654 | |
655 void vm_shutdown_during_initialization(const char* error, const char* message) { | |
656 vm_notify_during_shutdown(error, message); | |
657 vm_shutdown(); | |
658 } | |
659 | |
242 | 660 JDK_Version JDK_Version::_current; |
0 | 661 |
662 void JDK_Version::initialize() { | |
242 | 663 jdk_version_info info; |
664 assert(!_current.is_valid(), "Don't initialize twice"); | |
665 | |
0 | 666 void *lib_handle = os::native_java_library(); |
242 | 667 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, |
668 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); | |
0 | 669 |
670 if (func == NULL) { | |
671 // JDK older than 1.6 | |
242 | 672 _current._partially_initialized = true; |
673 } else { | |
674 (*func)(&info, sizeof(info)); | |
0 | 675 |
242 | 676 int major = JDK_VERSION_MAJOR(info.jdk_version); |
677 int minor = JDK_VERSION_MINOR(info.jdk_version); | |
678 int micro = JDK_VERSION_MICRO(info.jdk_version); | |
679 int build = JDK_VERSION_BUILD(info.jdk_version); | |
680 if (major == 1 && minor > 4) { | |
681 // We represent "1.5.0" as "5.0", but 1.4.2 as itself. | |
682 major = minor; | |
683 minor = micro; | |
684 micro = 0; | |
685 } | |
686 _current = JDK_Version(major, minor, micro, info.update_version, | |
687 info.special_update_version, build, | |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2096
diff
changeset
|
688 info.thread_park_blocker == 1, |
3917
eca1193ca245
4965777: GC changes to support use of discovered field for pending references
ysr
parents:
3841
diff
changeset
|
689 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
|
690 info.pending_list_uses_discovered_field == 1); |
0 | 691 } |
242 | 692 } |
693 | |
694 void JDK_Version::fully_initialize( | |
695 uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) { | |
696 // This is only called when current is less than 1.6 and we've gotten | |
697 // far enough in the initialization to determine the exact version. | |
698 assert(major < 6, "not needed for JDK version >= 6"); | |
699 assert(is_partially_initialized(), "must not initialize"); | |
700 if (major < 5) { | |
701 // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc. | |
702 micro = minor; | |
703 minor = major; | |
704 major = 1; | |
0 | 705 } |
242 | 706 _current = JDK_Version(major, minor, micro, update); |
0 | 707 } |
708 | |
709 void JDK_Version_init() { | |
710 JDK_Version::initialize(); | |
711 } | |
242 | 712 |
713 static int64_t encode_jdk_version(const JDK_Version& v) { | |
714 return | |
715 ((int64_t)v.major_version() << (BitsPerByte * 5)) | | |
716 ((int64_t)v.minor_version() << (BitsPerByte * 4)) | | |
717 ((int64_t)v.micro_version() << (BitsPerByte * 3)) | | |
718 ((int64_t)v.update_version() << (BitsPerByte * 2)) | | |
719 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) | | |
720 ((int64_t)v.build_number() << (BitsPerByte * 0)); | |
721 } | |
722 | |
723 int JDK_Version::compare(const JDK_Version& other) const { | |
724 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); | |
725 if (!is_partially_initialized() && other.is_partially_initialized()) { | |
726 return -(other.compare(*this)); // flip the comparators | |
727 } | |
728 assert(!other.is_partially_initialized(), "Not initialized yet"); | |
729 if (is_partially_initialized()) { | |
730 assert(other.major_version() >= 6, | |
731 "Invalid JDK version comparison during initialization"); | |
732 return -1; | |
733 } else { | |
734 uint64_t e = encode_jdk_version(*this); | |
735 uint64_t o = encode_jdk_version(other); | |
736 return (e > o) ? 1 : ((e == o) ? 0 : -1); | |
737 } | |
738 } | |
739 | |
740 void JDK_Version::to_string(char* buffer, size_t buflen) const { | |
741 size_t index = 0; | |
742 if (!is_valid()) { | |
743 jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); | |
744 } else if (is_partially_initialized()) { | |
745 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); | |
746 } else { | |
747 index += jio_snprintf( | |
748 &buffer[index], buflen - index, "%d.%d", _major, _minor); | |
749 if (_micro > 0) { | |
750 index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); | |
751 } | |
752 if (_update > 0) { | |
753 index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); | |
754 } | |
755 if (_special > 0) { | |
756 index += jio_snprintf(&buffer[index], buflen - index, "%c", _special); | |
757 } | |
758 if (_build > 0) { | |
759 index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); | |
760 } | |
761 } | |
762 } |