Mercurial > hg > graal-compiler
annotate src/share/vm/runtime/java.cpp @ 4665:f9811bcf3402
fixed fastdebug crash (deoptimization requires that no exception is pending)
author | Christian Haeubl <christian.haeubl@oracle.com> |
---|---|
date | Tue, 21 Feb 2012 10:48:32 -0800 |
parents | ef00461e29af |
children | 33df1aeaebbf |
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" | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4319
diff
changeset
|
33 #ifdef GRAAL |
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
|
34 #include "graal/graalCompiler.hpp" |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4319
diff
changeset
|
35 #endif |
1972 | 36 #include "memory/genCollectedHeap.hpp" |
37 #include "memory/oopFactory.hpp" | |
38 #include "memory/universe.hpp" | |
39 #include "oops/constantPoolOop.hpp" | |
40 #include "oops/generateOopMap.hpp" | |
41 #include "oops/instanceKlass.hpp" | |
42 #include "oops/instanceKlassKlass.hpp" | |
43 #include "oops/instanceOop.hpp" | |
44 #include "oops/methodOop.hpp" | |
45 #include "oops/objArrayOop.hpp" | |
46 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2129
diff
changeset
|
47 #include "oops/symbol.hpp" |
1972 | 48 #include "prims/jvmtiExport.hpp" |
49 #include "runtime/aprofiler.hpp" | |
50 #include "runtime/arguments.hpp" | |
51 #include "runtime/biasedLocking.hpp" | |
52 #include "runtime/compilationPolicy.hpp" | |
53 #include "runtime/fprofiler.hpp" | |
54 #include "runtime/init.hpp" | |
55 #include "runtime/interfaceSupport.hpp" | |
56 #include "runtime/java.hpp" | |
57 #include "runtime/memprofiler.hpp" | |
58 #include "runtime/sharedRuntime.hpp" | |
59 #include "runtime/statSampler.hpp" | |
60 #include "runtime/task.hpp" | |
61 #include "runtime/timer.hpp" | |
62 #include "runtime/vm_operations.hpp" | |
63 #include "utilities/dtrace.hpp" | |
64 #include "utilities/globalDefinitions.hpp" | |
65 #include "utilities/histogram.hpp" | |
66 #include "utilities/vmError.hpp" | |
67 #ifdef TARGET_ARCH_x86 | |
68 # include "vm_version_x86.hpp" | |
69 #endif | |
70 #ifdef TARGET_ARCH_sparc | |
71 # include "vm_version_sparc.hpp" | |
72 #endif | |
73 #ifdef TARGET_ARCH_zero | |
74 # include "vm_version_zero.hpp" | |
75 #endif | |
2192
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
76 #ifdef TARGET_ARCH_arm |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
77 # include "vm_version_arm.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
78 #endif |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
79 #ifdef TARGET_ARCH_ppc |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
80 # include "vm_version_ppc.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
81 #endif |
1972 | 82 #ifdef TARGET_OS_FAMILY_linux |
83 # include "thread_linux.inline.hpp" | |
84 #endif | |
85 #ifdef TARGET_OS_FAMILY_solaris | |
86 # include "thread_solaris.inline.hpp" | |
87 #endif | |
88 #ifdef TARGET_OS_FAMILY_windows | |
89 # include "thread_windows.inline.hpp" | |
90 #endif | |
3960 | 91 #ifdef TARGET_OS_FAMILY_bsd |
92 # include "thread_bsd.inline.hpp" | |
93 #endif | |
1972 | 94 #ifndef SERIALGC |
95 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" | |
96 #include "gc_implementation/parallelScavenge/psScavenge.hpp" | |
97 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" | |
98 #endif | |
99 #ifdef COMPILER1 | |
100 #include "c1/c1_Compiler.hpp" | |
101 #include "c1/c1_Runtime1.hpp" | |
102 #endif | |
103 #ifdef COMPILER2 | |
104 #include "code/compiledIC.hpp" | |
105 #include "compiler/methodLiveness.hpp" | |
106 #include "opto/compile.hpp" | |
107 #include "opto/indexSet.hpp" | |
108 #include "opto/runtime.hpp" | |
109 #endif | |
0 | 110 |
4006 | 111 #ifndef USDT2 |
0 | 112 HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown); |
4006 | 113 #endif /* !USDT2 */ |
0 | 114 |
115 #ifndef PRODUCT | |
116 | |
117 // Statistics printing (method invocation histogram) | |
118 | |
119 GrowableArray<methodOop>* collected_invoked_methods; | |
120 | |
121 void collect_invoked_methods(methodOop m) { | |
122 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { | |
123 collected_invoked_methods->push(m); | |
124 } | |
125 } | |
126 | |
127 | |
128 GrowableArray<methodOop>* collected_profiled_methods; | |
129 | |
130 void collect_profiled_methods(methodOop m) { | |
131 methodHandle mh(Thread::current(), m); | |
132 if ((m->method_data() != NULL) && | |
133 (PrintMethodData || CompilerOracle::should_print(mh))) { | |
134 collected_profiled_methods->push(m); | |
135 } | |
136 } | |
137 | |
138 | |
139 int compare_methods(methodOop* a, methodOop* b) { | |
140 // %%% there can be 32-bit overflow here | |
141 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) | |
142 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); | |
143 } | |
144 | |
145 | |
146 void print_method_invocation_histogram() { | |
147 ResourceMark rm; | |
148 HandleMark hm; | |
149 collected_invoked_methods = new GrowableArray<methodOop>(1024); | |
150 SystemDictionary::methods_do(collect_invoked_methods); | |
151 collected_invoked_methods->sort(&compare_methods); | |
152 // | |
153 tty->cr(); | |
154 tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff); | |
155 tty->cr(); | |
156 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); | |
157 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, | |
158 synch_total = 0, nativ_total = 0, acces_total = 0; | |
159 for (int index = 0; index < collected_invoked_methods->length(); index++) { | |
160 methodOop m = collected_invoked_methods->at(index); | |
161 int c = m->invocation_count() + m->compiled_invocation_count(); | |
162 if (c >= MethodHistogramCutoff) m->print_invocation_count(); | |
163 int_total += m->invocation_count(); | |
164 comp_total += m->compiled_invocation_count(); | |
165 if (m->is_final()) final_total += c; | |
166 if (m->is_static()) static_total += c; | |
167 if (m->is_synchronized()) synch_total += c; | |
168 if (m->is_native()) nativ_total += c; | |
169 if (m->is_accessor()) acces_total += c; | |
170 } | |
171 tty->cr(); | |
172 total = int_total + comp_total; | |
173 tty->print_cr("Invocations summary:"); | |
174 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); | |
175 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); | |
176 tty->print_cr("\t%9d (100%%) total", total); | |
177 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); | |
178 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); | |
179 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); | |
180 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); | |
181 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); | |
182 tty->cr(); | |
183 SharedRuntime::print_call_statistics(comp_total); | |
184 } | |
185 | |
186 void print_method_profiling_data() { | |
187 ResourceMark rm; | |
188 HandleMark hm; | |
189 collected_profiled_methods = new GrowableArray<methodOop>(1024); | |
190 SystemDictionary::methods_do(collect_profiled_methods); | |
191 collected_profiled_methods->sort(&compare_methods); | |
192 | |
193 int count = collected_profiled_methods->length(); | |
194 if (count > 0) { | |
195 for (int index = 0; index < count; index++) { | |
196 methodOop m = collected_profiled_methods->at(index); | |
197 ttyLocker ttyl; | |
198 tty->print_cr("------------------------------------------------------------------------"); | |
199 //m->print_name(tty); | |
200 m->print_invocation_count(); | |
201 tty->cr(); | |
202 m->print_codes(); | |
203 } | |
204 tty->print_cr("------------------------------------------------------------------------"); | |
205 } | |
206 } | |
207 | |
208 void print_bytecode_count() { | |
209 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
210 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); | |
211 } | |
212 } | |
213 | |
214 AllocStats alloc_stats; | |
215 | |
216 | |
217 | |
218 // General statistics printing (profiling ...) | |
219 | |
220 void print_statistics() { | |
221 | |
222 #ifdef ASSERT | |
223 | |
224 if (CountRuntimeCalls) { | |
225 extern Histogram *RuntimeHistogram; | |
226 RuntimeHistogram->print(); | |
227 } | |
228 | |
229 if (CountJNICalls) { | |
230 extern Histogram *JNIHistogram; | |
231 JNIHistogram->print(); | |
232 } | |
233 | |
234 if (CountJVMCalls) { | |
235 extern Histogram *JVMHistogram; | |
236 JVMHistogram->print(); | |
237 } | |
238 | |
239 #endif | |
240 | |
241 if (MemProfiling) { | |
242 MemProfiler::disengage(); | |
243 } | |
244 | |
245 if (CITime) { | |
246 CompileBroker::print_times(); | |
247 } | |
248 | |
249 #ifdef COMPILER1 | |
250 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) { | |
251 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics); | |
252 Runtime1::print_statistics(); | |
253 Deoptimization::print_statistics(); | |
3841
0f34fdee809e
7071427: AdapterFingerPrint can hold 8 entries per int
never
parents:
3769
diff
changeset
|
254 SharedRuntime::print_statistics(); |
4561
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 #endif /* COMPILER1 */ |
35ca3ade314d
enabled nmethod statistics for product build
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4319
diff
changeset
|
257 |
35ca3ade314d
enabled nmethod statistics for product build
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4319
diff
changeset
|
258 if(PrintNMethodStatistics) { |
0 | 259 nmethod::print_statistics(); |
260 } | |
261 | |
262 #ifdef COMPILER2 | |
263 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { | |
264 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); | |
265 Compile::print_statistics(); | |
266 #ifndef COMPILER1 | |
267 Deoptimization::print_statistics(); | |
268 nmethod::print_statistics(); | |
3841
0f34fdee809e
7071427: AdapterFingerPrint can hold 8 entries per int
never
parents:
3769
diff
changeset
|
269 SharedRuntime::print_statistics(); |
0 | 270 #endif //COMPILER1 |
271 os::print_statistics(); | |
272 } | |
273 | |
274 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics) { | |
275 OptoRuntime::print_named_counters(); | |
276 } | |
277 | |
278 if (TimeLivenessAnalysis) { | |
279 MethodLiveness::print_times(); | |
280 } | |
281 #ifdef ASSERT | |
282 if (CollectIndexSetStatistics) { | |
283 IndexSet::print_statistics(); | |
284 } | |
285 #endif // ASSERT | |
286 #endif // COMPILER2 | |
287 if (CountCompiledCalls) { | |
288 print_method_invocation_histogram(); | |
289 } | |
1918 | 290 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) { |
0 | 291 print_method_profiling_data(); |
292 } | |
293 if (TimeCompiler) { | |
294 COMPILER2_PRESENT(Compile::print_timers();) | |
295 } | |
296 if (TimeCompilationPolicy) { | |
297 CompilationPolicy::policy()->print_time(); | |
298 } | |
299 if (TimeOopMap) { | |
300 GenerateOopMap::print_time(); | |
301 } | |
302 if (ProfilerCheckIntervals) { | |
303 PeriodicTask::print_intervals(); | |
304 } | |
305 if (PrintSymbolTableSizeHistogram) { | |
306 SymbolTable::print_histogram(); | |
307 } | |
308 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
309 BytecodeCounter::print(); | |
310 } | |
311 if (PrintBytecodePairHistogram) { | |
312 BytecodePairHistogram::print(); | |
313 } | |
314 | |
315 if (PrintCodeCache) { | |
316 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
317 CodeCache::print(); | |
318 } | |
319 | |
320 if (PrintCodeCache2) { | |
321 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
322 CodeCache::print_internals(); | |
323 } | |
324 | |
325 if (PrintClassStatistics) { | |
326 SystemDictionary::print_class_statistics(); | |
327 } | |
328 if (PrintMethodStatistics) { | |
329 SystemDictionary::print_method_statistics(); | |
330 } | |
331 | |
332 if (PrintVtableStats) { | |
333 klassVtable::print_statistics(); | |
334 klassItable::print_statistics(); | |
335 } | |
336 if (VerifyOops) { | |
337 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); | |
338 } | |
339 | |
340 print_bytecode_count(); | |
2250 | 341 if (PrintMallocStatistics) { |
0 | 342 tty->print("allocation stats: "); |
343 alloc_stats.print(); | |
344 tty->cr(); | |
345 } | |
346 | |
347 if (PrintSystemDictionaryAtExit) { | |
348 SystemDictionary::print(); | |
349 } | |
350 | |
351 if (PrintBiasedLockingStatistics) { | |
352 BiasedLocking::print_counters(); | |
353 } | |
354 | |
355 #ifdef ENABLE_ZAP_DEAD_LOCALS | |
356 #ifdef COMPILER2 | |
357 if (ZapDeadCompiledLocals) { | |
358 tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count); | |
359 tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count); | |
360 } | |
361 #endif // COMPILER2 | |
362 #endif // ENABLE_ZAP_DEAD_LOCALS | |
363 } | |
364 | |
365 #else // PRODUCT MODE STATISTICS | |
366 | |
367 void print_statistics() { | |
368 | |
369 if (CITime) { | |
370 CompileBroker::print_times(); | |
371 } | |
4561
35ca3ade314d
enabled nmethod statistics for product build
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4319
diff
changeset
|
372 if(PrintNMethodStatistics) { |
35ca3ade314d
enabled nmethod statistics for product build
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4319
diff
changeset
|
373 nmethod::print_statistics(); |
35ca3ade314d
enabled nmethod statistics for product build
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4319
diff
changeset
|
374 } |
0 | 375 #ifdef COMPILER2 |
376 if (PrintPreciseBiasedLockingStatistics) { | |
377 OptoRuntime::print_named_counters(); | |
378 } | |
379 #endif | |
380 if (PrintBiasedLockingStatistics) { | |
381 BiasedLocking::print_counters(); | |
382 } | |
383 } | |
384 | |
385 #endif | |
386 | |
387 | |
388 // Helper class for registering on_exit calls through JVM_OnExit | |
389 | |
390 extern "C" { | |
391 typedef void (*__exit_proc)(void); | |
392 } | |
393 | |
394 class ExitProc : public CHeapObj { | |
395 private: | |
396 __exit_proc _proc; | |
397 // void (*_proc)(void); | |
398 ExitProc* _next; | |
399 public: | |
400 // ExitProc(void (*proc)(void)) { | |
401 ExitProc(__exit_proc proc) { | |
402 _proc = proc; | |
403 _next = NULL; | |
404 } | |
405 void evaluate() { _proc(); } | |
406 ExitProc* next() const { return _next; } | |
407 void set_next(ExitProc* next) { _next = next; } | |
408 }; | |
409 | |
410 | |
411 // Linked list of registered on_exit procedures | |
412 | |
413 static ExitProc* exit_procs = NULL; | |
414 | |
415 | |
416 extern "C" { | |
417 void register_on_exit_function(void (*func)(void)) { | |
418 ExitProc *entry = new ExitProc(func); | |
419 // Classic vm does not throw an exception in case the allocation failed, | |
420 if (entry != NULL) { | |
421 entry->set_next(exit_procs); | |
422 exit_procs = entry; | |
423 } | |
424 } | |
425 } | |
426 | |
427 // Note: before_exit() can be executed only once, if more than one threads | |
428 // are trying to shutdown the VM at the same time, only one thread | |
429 // can run before_exit() and all other threads must wait. | |
430 void before_exit(JavaThread * thread) { | |
431 #define BEFORE_EXIT_NOT_RUN 0 | |
432 #define BEFORE_EXIT_RUNNING 1 | |
433 #define BEFORE_EXIT_DONE 2 | |
434 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; | |
435 | |
4319
3c21eee8ab4d
Add installMethodCallback() to HotSpotRuntime.
Andreas Woess <andreas.woess@jku.at>
parents:
4137
diff
changeset
|
436 #ifdef GRAAL |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4319
diff
changeset
|
437 GraalCompiler::instance()->exit(); |
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 } |