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