Tue, 03 Mar 2020 12:57:23 +0000
Merge
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
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"
33 #include "jfr/jfrEvents.hpp"
34 #include "jfr/support/jfrThreadId.hpp"
35 #include "memory/genCollectedHeap.hpp"
36 #include "memory/oopFactory.hpp"
37 #include "memory/universe.hpp"
38 #include "oops/constantPool.hpp"
39 #include "oops/generateOopMap.hpp"
40 #include "oops/instanceKlass.hpp"
41 #include "oops/instanceOop.hpp"
42 #include "oops/method.hpp"
43 #include "oops/objArrayOop.hpp"
44 #include "oops/oop.inline.hpp"
45 #include "oops/symbol.hpp"
46 #include "prims/jvmtiExport.hpp"
47 #include "runtime/arguments.hpp"
48 #include "runtime/biasedLocking.hpp"
49 #include "runtime/compilationPolicy.hpp"
50 #include "runtime/deoptimization.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/sweeper.hpp"
59 #include "runtime/task.hpp"
60 #include "runtime/thread.inline.hpp"
61 #include "runtime/timer.hpp"
62 #include "runtime/vm_operations.hpp"
63 #include "services/memTracker.hpp"
64 #include "utilities/dtrace.hpp"
65 #include "utilities/globalDefinitions.hpp"
66 #include "utilities/histogram.hpp"
67 #include "utilities/macros.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
78 #ifdef TARGET_ARCH_arm
79 # include "vm_version_arm.hpp"
80 #endif
81 #ifdef TARGET_ARCH_ppc
82 # include "vm_version_ppc.hpp"
83 #endif
84 #if INCLUDE_ALL_GCS
85 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
86 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
87 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
88 #endif // INCLUDE_ALL_GCS
89 #ifdef COMPILER1
90 #include "c1/c1_Compiler.hpp"
91 #include "c1/c1_Runtime1.hpp"
92 #endif
93 #ifdef COMPILER2
94 #include "code/compiledIC.hpp"
95 #include "compiler/methodLiveness.hpp"
96 #include "opto/compile.hpp"
97 #include "opto/indexSet.hpp"
98 #include "opto/runtime.hpp"
99 #endif
100 #if INCLUDE_JFR
101 #include "jfr/jfr.hpp"
102 #endif
104 #ifndef USDT2
105 HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown);
106 #endif /* !USDT2 */
108 #ifndef PRODUCT
110 // Statistics printing (method invocation histogram)
112 GrowableArray<Method*>* collected_invoked_methods;
114 void collect_invoked_methods(Method* m) {
115 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) {
116 collected_invoked_methods->push(m);
117 }
118 }
120 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
122 GrowableArray<Method*>* collected_profiled_methods;
124 void collect_profiled_methods(Method* m) {
125 Thread* thread = Thread::current();
126 // This HandleMark prevents a huge amount of handles from being added
127 // to the metadata_handles() array on the thread.
128 HandleMark hm(thread);
129 methodHandle mh(thread, m);
130 if ((m->method_data() != NULL) &&
131 (PrintMethodData || CompilerOracle::should_print(mh))) {
132 collected_profiled_methods->push(m);
133 }
134 }
137 int compare_methods(Method** a, Method** b) {
138 // %%% there can be 32-bit overflow here
139 return ((*b)->invocation_count() + (*b)->compiled_invocation_count())
140 - ((*a)->invocation_count() + (*a)->compiled_invocation_count());
141 }
144 void print_method_invocation_histogram() {
145 ResourceMark rm;
146 HandleMark hm;
147 collected_invoked_methods = new GrowableArray<Method*>(1024);
148 SystemDictionary::methods_do(collect_invoked_methods);
149 collected_invoked_methods->sort(&compare_methods);
150 //
151 tty->cr();
152 tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff);
153 tty->cr();
154 tty->print_cr("____Count_(I+C)____Method________________________Module_________________");
155 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,
156 synch_total = 0, nativ_total = 0, acces_total = 0;
157 for (int index = 0; index < collected_invoked_methods->length(); index++) {
158 Method* m = collected_invoked_methods->at(index);
159 int c = m->invocation_count() + m->compiled_invocation_count();
160 if (c >= MethodHistogramCutoff) m->print_invocation_count();
161 int_total += m->invocation_count();
162 comp_total += m->compiled_invocation_count();
163 if (m->is_final()) final_total += c;
164 if (m->is_static()) static_total += c;
165 if (m->is_synchronized()) synch_total += c;
166 if (m->is_native()) nativ_total += c;
167 if (m->is_accessor()) acces_total += c;
168 }
169 tty->cr();
170 total = int_total + comp_total;
171 tty->print_cr("Invocations summary:");
172 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total);
173 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total);
174 tty->print_cr("\t%9d (100%%) total", total);
175 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total);
176 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total);
177 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total);
178 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total);
179 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total);
180 tty->cr();
181 SharedRuntime::print_call_statistics(comp_total);
182 }
184 void print_method_profiling_data() {
185 ResourceMark rm;
186 HandleMark hm;
187 collected_profiled_methods = new GrowableArray<Method*>(1024);
188 SystemDictionary::methods_do(collect_profiled_methods);
189 collected_profiled_methods->sort(&compare_methods);
191 int count = collected_profiled_methods->length();
192 int total_size = 0;
193 if (count > 0) {
194 for (int index = 0; index < count; index++) {
195 Method* m = collected_profiled_methods->at(index);
196 ttyLocker ttyl;
197 tty->print_cr("------------------------------------------------------------------------");
198 //m->print_name(tty);
199 m->print_invocation_count();
200 tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
201 tty->cr();
202 // Dump data on parameters if any
203 if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) {
204 tty->fill_to(2);
205 m->method_data()->parameters_type_data()->print_data_on(tty);
206 }
207 m->print_codes();
208 total_size += m->method_data()->size_in_bytes();
209 }
210 tty->print_cr("------------------------------------------------------------------------");
211 tty->print_cr("Total MDO size: %d bytes", total_size);
212 }
213 }
215 void print_bytecode_count() {
216 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
217 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
218 }
219 }
221 AllocStats alloc_stats;
225 // General statistics printing (profiling ...)
226 void print_statistics() {
227 #ifdef ASSERT
229 if (CountRuntimeCalls) {
230 extern Histogram *RuntimeHistogram;
231 RuntimeHistogram->print();
232 }
234 if (CountJNICalls) {
235 extern Histogram *JNIHistogram;
236 JNIHistogram->print();
237 }
239 if (CountJVMCalls) {
240 extern Histogram *JVMHistogram;
241 JVMHistogram->print();
242 }
244 #endif
246 if (MemProfiling) {
247 MemProfiler::disengage();
248 }
250 if (CITime) {
251 CompileBroker::print_times();
252 }
254 #ifdef COMPILER1
255 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
256 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
257 Runtime1::print_statistics();
258 Deoptimization::print_statistics();
259 SharedRuntime::print_statistics();
260 nmethod::print_statistics();
261 }
262 #endif /* COMPILER1 */
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();
271 SharedRuntime::print_statistics();
272 #endif //COMPILER1
273 os::print_statistics();
274 }
276 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
277 OptoRuntime::print_named_counters();
278 }
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 }
292 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) {
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 }
317 if (PrintCodeCache) {
318 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
319 CodeCache::print();
320 }
322 if (PrintMethodFlushingStatistics) {
323 NMethodSweeper::print();
324 }
326 if (PrintCodeCache2) {
327 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
328 CodeCache::print_internals();
329 }
331 if (PrintClassStatistics) {
332 SystemDictionary::print_class_statistics();
333 }
334 if (PrintMethodStatistics) {
335 SystemDictionary::print_method_statistics();
336 }
338 if (PrintVtableStats) {
339 klassVtable::print_statistics();
340 klassItable::print_statistics();
341 }
342 if (VerifyOops && Verbose) {
343 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
344 }
346 print_bytecode_count();
347 if (PrintMallocStatistics) {
348 tty->print("allocation stats: ");
349 alloc_stats.print();
350 tty->cr();
351 }
353 if (PrintSystemDictionaryAtExit) {
354 SystemDictionary::print();
355 }
357 if (PrintBiasedLockingStatistics) {
358 BiasedLocking::print_counters();
359 }
361 #ifdef ENABLE_ZAP_DEAD_LOCALS
362 #ifdef COMPILER2
363 if (ZapDeadCompiledLocals) {
364 tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count);
365 tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count);
366 }
367 #endif // COMPILER2
368 #endif // ENABLE_ZAP_DEAD_LOCALS
369 // Native memory tracking data
370 if (PrintNMTStatistics) {
371 MemTracker::final_report(tty);
372 }
373 }
375 #else // PRODUCT MODE STATISTICS
377 void print_statistics() {
379 if (CITime) {
380 CompileBroker::print_times();
381 }
383 if (PrintCodeCache) {
384 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
385 CodeCache::print();
386 }
388 if (PrintMethodFlushingStatistics) {
389 NMethodSweeper::print();
390 }
392 #ifdef COMPILER2
393 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
394 OptoRuntime::print_named_counters();
395 }
396 #endif
397 if (PrintBiasedLockingStatistics) {
398 BiasedLocking::print_counters();
399 }
401 // Native memory tracking data
402 if (PrintNMTStatistics) {
403 MemTracker::final_report(tty);
404 }
405 }
407 #endif
410 // Helper class for registering on_exit calls through JVM_OnExit
412 extern "C" {
413 typedef void (*__exit_proc)(void);
414 }
416 class ExitProc : public CHeapObj<mtInternal> {
417 private:
418 __exit_proc _proc;
419 // void (*_proc)(void);
420 ExitProc* _next;
421 public:
422 // ExitProc(void (*proc)(void)) {
423 ExitProc(__exit_proc proc) {
424 _proc = proc;
425 _next = NULL;
426 }
427 void evaluate() { _proc(); }
428 ExitProc* next() const { return _next; }
429 void set_next(ExitProc* next) { _next = next; }
430 };
433 // Linked list of registered on_exit procedures
435 static ExitProc* exit_procs = NULL;
438 extern "C" {
439 void register_on_exit_function(void (*func)(void)) {
440 ExitProc *entry = new ExitProc(func);
441 // Classic vm does not throw an exception in case the allocation failed,
442 if (entry != NULL) {
443 entry->set_next(exit_procs);
444 exit_procs = entry;
445 }
446 }
447 }
449 // Note: before_exit() can be executed only once, if more than one threads
450 // are trying to shutdown the VM at the same time, only one thread
451 // can run before_exit() and all other threads must wait.
452 void before_exit(JavaThread * thread) {
453 #define BEFORE_EXIT_NOT_RUN 0
454 #define BEFORE_EXIT_RUNNING 1
455 #define BEFORE_EXIT_DONE 2
456 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
458 // Note: don't use a Mutex to guard the entire before_exit(), as
459 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
460 // A CAS or OSMutex would work just fine but then we need to manipulate
461 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
462 // for synchronization.
463 { MutexLocker ml(BeforeExit_lock);
464 switch (_before_exit_status) {
465 case BEFORE_EXIT_NOT_RUN:
466 _before_exit_status = BEFORE_EXIT_RUNNING;
467 break;
468 case BEFORE_EXIT_RUNNING:
469 while (_before_exit_status == BEFORE_EXIT_RUNNING) {
470 BeforeExit_lock->wait();
471 }
472 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
473 return;
474 case BEFORE_EXIT_DONE:
475 return;
476 }
477 }
479 // The only difference between this and Win32's _onexit procs is that
480 // this version is invoked before any threads get killed.
481 ExitProc* current = exit_procs;
482 while (current != NULL) {
483 ExitProc* next = current->next();
484 current->evaluate();
485 delete current;
486 current = next;
487 }
489 // Hang forever on exit if we're reporting an error.
490 if (ShowMessageBoxOnError && is_error_reported()) {
491 os::infinite_sleep();
492 }
494 // Terminate watcher thread - must before disenrolling any periodic task
495 if (PeriodicTask::num_tasks() > 0)
496 WatcherThread::stop();
498 // Print statistics gathered (profiling ...)
499 if (Arguments::has_profile()) {
500 FlatProfiler::disengage();
501 FlatProfiler::print(10);
502 }
504 // shut down the StatSampler task
505 StatSampler::disengage();
506 StatSampler::destroy();
508 // Stop concurrent GC threads
509 Universe::heap()->stop();
511 // Print GC/heap related information.
512 if (PrintGCDetails) {
513 Universe::print();
514 AdaptiveSizePolicyOutput(0);
515 if (Verbose) {
516 ClassLoaderDataGraph::dump_on(gclog_or_tty);
517 }
518 }
520 if (PrintBytecodeHistogram) {
521 BytecodeHistogram::print();
522 }
524 if (JvmtiExport::should_post_thread_life()) {
525 JvmtiExport::post_thread_end(thread);
526 }
529 EventThreadEnd event;
530 if (event.should_commit()) {
531 event.set_thread(JFR_THREAD_ID(thread));
532 event.commit();
533 }
535 JFR_ONLY(Jfr::on_vm_shutdown();)
537 // Always call even when there are not JVMTI environments yet, since environments
538 // may be attached late and JVMTI must track phases of VM execution
539 JvmtiExport::post_vm_death();
540 Threads::shutdown_vm_agents();
542 // Terminate the signal thread
543 // Note: we don't wait until it actually dies.
544 os::terminate_signal_thread();
546 print_statistics();
547 Universe::heap()->print_tracing_info();
549 { MutexLocker ml(BeforeExit_lock);
550 _before_exit_status = BEFORE_EXIT_DONE;
551 BeforeExit_lock->notify_all();
552 }
554 if (VerifyStringTableAtExit) {
555 int fail_cnt = 0;
556 {
557 MutexLocker ml(StringTable_lock);
558 fail_cnt = StringTable::verify_and_compare_entries();
559 }
561 if (fail_cnt != 0) {
562 tty->print_cr("ERROR: fail_cnt=%d", fail_cnt);
563 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
564 }
565 }
567 #undef BEFORE_EXIT_NOT_RUN
568 #undef BEFORE_EXIT_RUNNING
569 #undef BEFORE_EXIT_DONE
570 }
572 void vm_exit(int code) {
573 Thread* thread = ThreadLocalStorage::is_initialized() ?
574 ThreadLocalStorage::get_thread_slow() : NULL;
575 if (thread == NULL) {
576 // we have serious problems -- just exit
577 vm_direct_exit(code);
578 }
580 if (VMThread::vm_thread() != NULL) {
581 // Fire off a VM_Exit operation to bring VM to a safepoint and exit
582 VM_Exit op(code);
583 if (thread->is_Java_thread())
584 ((JavaThread*)thread)->set_thread_state(_thread_in_vm);
585 VMThread::execute(&op);
586 // should never reach here; but in case something wrong with VM Thread.
587 vm_direct_exit(code);
588 } else {
589 // VM thread is gone, just exit
590 vm_direct_exit(code);
591 }
592 ShouldNotReachHere();
593 }
595 void notify_vm_shutdown() {
596 // For now, just a dtrace probe.
597 #ifndef USDT2
598 HS_DTRACE_PROBE(hotspot, vm__shutdown);
599 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
600 #else /* USDT2 */
601 HOTSPOT_VM_SHUTDOWN();
602 #endif /* USDT2 */
603 }
605 void vm_direct_exit(int code) {
606 notify_vm_shutdown();
607 os::wait_for_keypress_at_exit();
608 ::exit(code);
609 }
611 void vm_perform_shutdown_actions() {
612 // Warning: do not call 'exit_globals()' here. All threads are still running.
613 // Calling 'exit_globals()' will disable thread-local-storage and cause all
614 // kinds of assertions to trigger in debug mode.
615 if (is_init_completed()) {
616 Thread* thread = ThreadLocalStorage::is_initialized() ?
617 ThreadLocalStorage::get_thread_slow() : NULL;
618 if (thread != NULL && thread->is_Java_thread()) {
619 // We are leaving the VM, set state to native (in case any OS exit
620 // handlers call back to the VM)
621 JavaThread* jt = (JavaThread*)thread;
622 // Must always be walkable or have no last_Java_frame when in
623 // thread_in_native
624 jt->frame_anchor()->make_walkable(jt);
625 jt->set_thread_state(_thread_in_native);
626 }
627 }
628 notify_vm_shutdown();
629 }
631 void vm_shutdown()
632 {
633 vm_perform_shutdown_actions();
634 os::wait_for_keypress_at_exit();
635 os::shutdown();
636 }
638 void vm_abort(bool dump_core) {
639 vm_perform_shutdown_actions();
640 os::wait_for_keypress_at_exit();
641 os::abort(dump_core);
642 ShouldNotReachHere();
643 }
645 void vm_notify_during_shutdown(const char* error, const char* message) {
646 if (error != NULL) {
647 tty->print_cr("Error occurred during initialization of VM");
648 tty->print("%s", error);
649 if (message != NULL) {
650 tty->print_cr(": %s", message);
651 }
652 else {
653 tty->cr();
654 }
655 }
656 if (ShowMessageBoxOnError && WizardMode) {
657 fatal("Error occurred during initialization of VM");
658 }
659 }
661 void vm_exit_during_initialization(Handle exception) {
662 tty->print_cr("Error occurred during initialization of VM");
663 // If there are exceptions on this thread it must be cleared
664 // first and here. Any future calls to EXCEPTION_MARK requires
665 // that no pending exceptions exist.
666 Thread *THREAD = Thread::current();
667 if (HAS_PENDING_EXCEPTION) {
668 CLEAR_PENDING_EXCEPTION;
669 }
670 java_lang_Throwable::print(exception, tty);
671 tty->cr();
672 java_lang_Throwable::print_stack_trace(exception(), tty);
673 tty->cr();
674 vm_notify_during_shutdown(NULL, NULL);
676 // Failure during initialization, we don't want to dump core
677 vm_abort(false);
678 }
680 void vm_exit_during_initialization(Symbol* ex, const char* message) {
681 ResourceMark rm;
682 vm_notify_during_shutdown(ex->as_C_string(), message);
684 // Failure during initialization, we don't want to dump core
685 vm_abort(false);
686 }
688 void vm_exit_during_initialization(const char* error, const char* message) {
689 vm_notify_during_shutdown(error, message);
691 // Failure during initialization, we don't want to dump core
692 vm_abort(false);
693 }
695 void vm_shutdown_during_initialization(const char* error, const char* message) {
696 vm_notify_during_shutdown(error, message);
697 vm_shutdown();
698 }
700 JDK_Version JDK_Version::_current;
701 const char* JDK_Version::_runtime_name;
702 const char* JDK_Version::_runtime_version;
704 void JDK_Version::initialize() {
705 jdk_version_info info;
706 assert(!_current.is_valid(), "Don't initialize twice");
708 void *lib_handle = os::native_java_library();
709 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
710 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
712 if (func == NULL) {
713 // JDK older than 1.6
714 _current._partially_initialized = true;
715 } else {
716 (*func)(&info, sizeof(info));
718 int major = JDK_VERSION_MAJOR(info.jdk_version);
719 int minor = JDK_VERSION_MINOR(info.jdk_version);
720 int micro = JDK_VERSION_MICRO(info.jdk_version);
721 int build = JDK_VERSION_BUILD(info.jdk_version);
722 if (major == 1 && minor > 4) {
723 // We represent "1.5.0" as "5.0", but 1.4.2 as itself.
724 major = minor;
725 minor = micro;
726 micro = 0;
727 }
728 _current = JDK_Version(major, minor, micro, info.update_version,
729 info.special_update_version, build,
730 info.thread_park_blocker == 1,
731 info.post_vm_init_hook_enabled == 1,
732 info.pending_list_uses_discovered_field == 1);
733 }
734 }
736 void JDK_Version::fully_initialize(
737 uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {
738 // This is only called when current is less than 1.6 and we've gotten
739 // far enough in the initialization to determine the exact version.
740 assert(major < 6, "not needed for JDK version >= 6");
741 assert(is_partially_initialized(), "must not initialize");
742 if (major < 5) {
743 // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.
744 micro = minor;
745 minor = major;
746 major = 1;
747 }
748 _current = JDK_Version(major, minor, micro, update);
749 }
751 void JDK_Version_init() {
752 JDK_Version::initialize();
753 }
755 static int64_t encode_jdk_version(const JDK_Version& v) {
756 return
757 ((int64_t)v.major_version() << (BitsPerByte * 5)) |
758 ((int64_t)v.minor_version() << (BitsPerByte * 4)) |
759 ((int64_t)v.micro_version() << (BitsPerByte * 3)) |
760 ((int64_t)v.update_version() << (BitsPerByte * 2)) |
761 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) |
762 ((int64_t)v.build_number() << (BitsPerByte * 0));
763 }
765 int JDK_Version::compare(const JDK_Version& other) const {
766 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
767 if (!is_partially_initialized() && other.is_partially_initialized()) {
768 return -(other.compare(*this)); // flip the comparators
769 }
770 assert(!other.is_partially_initialized(), "Not initialized yet");
771 if (is_partially_initialized()) {
772 assert(other.major_version() >= 6,
773 "Invalid JDK version comparison during initialization");
774 return -1;
775 } else {
776 uint64_t e = encode_jdk_version(*this);
777 uint64_t o = encode_jdk_version(other);
778 return (e > o) ? 1 : ((e == o) ? 0 : -1);
779 }
780 }
782 void JDK_Version::to_string(char* buffer, size_t buflen) const {
783 assert(buffer && buflen > 0, "call with useful buffer");
784 size_t index = 0;
785 if (!is_valid()) {
786 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
787 } else if (is_partially_initialized()) {
788 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
789 } else {
790 int rc = jio_snprintf(
791 &buffer[index], buflen - index, "%d.%d", _major, _minor);
792 if (rc == -1) return;
793 index += rc;
794 if (_micro > 0) {
795 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
796 if (rc == -1) return;
797 index += rc;
798 }
799 if (_update > 0) {
800 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
801 if (rc == -1) return;
802 index += rc;
803 }
804 if (_special > 0) {
805 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
806 if (rc == -1) return;
807 index += rc;
808 }
809 if (_build > 0) {
810 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
811 if (rc == -1) return;
812 index += rc;
813 }
814 }
815 }