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