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