1 /* 2 * Copyright (c) 1997, 2015, 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/stringTable.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "code/codeCache.hpp" 30 #include "compiler/compileBroker.hpp" 31 #include "compiler/compilerOracle.hpp" 32 #include "gc/shared/genCollectedHeap.hpp" 33 #include "interpreter/bytecodeHistogram.hpp" 34 #if INCLUDE_JVMCI 35 #include "jvmci/jvmciCompiler.hpp" 36 #include "jvmci/jvmciRuntime.hpp" 37 #endif 38 #include "logging/log.hpp" 39 #include "memory/oopFactory.hpp" 40 #include "memory/universe.hpp" 41 #include "oops/constantPool.hpp" 42 #include "oops/generateOopMap.hpp" 43 #include "oops/instanceKlass.hpp" 44 #include "oops/instanceOop.hpp" 45 #include "oops/method.hpp" 46 #include "oops/objArrayOop.hpp" 47 #include "oops/oop.inline.hpp" 48 #include "oops/symbol.hpp" 49 #include "prims/jvmtiExport.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/sweeper.hpp" 61 #include "runtime/task.hpp" 62 #include "runtime/thread.inline.hpp" 63 #include "runtime/timer.hpp" 64 #include "runtime/vm_operations.hpp" 65 #include "services/memTracker.hpp" 66 #include "trace/tracing.hpp" 67 #include "utilities/dtrace.hpp" 68 #include "utilities/globalDefinitions.hpp" 69 #include "utilities/histogram.hpp" 70 #include "utilities/macros.hpp" 71 #include "utilities/vmError.hpp" 72 #if INCLUDE_ALL_GCS 73 #include "gc/cms/concurrentMarkSweepThread.hpp" 74 #include "gc/parallel/psScavenge.hpp" 75 #endif // INCLUDE_ALL_GCS 76 #ifdef COMPILER1 77 #include "c1/c1_Compiler.hpp" 78 #include "c1/c1_Runtime1.hpp" 79 #endif 80 #ifdef COMPILER2 81 #include "code/compiledIC.hpp" 82 #include "compiler/methodLiveness.hpp" 83 #include "opto/compile.hpp" 84 #include "opto/indexSet.hpp" 85 #include "opto/runtime.hpp" 86 #endif 87 88 GrowableArray<Method*>* collected_profiled_methods; 89 90 int compare_methods(Method** a, Method** b) { 91 // %%% there can be 32-bit overflow here 92 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) 93 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); 94 } 95 96 void collect_profiled_methods(Method* m) { 97 Thread* thread = Thread::current(); 98 // This HandleMark prevents a huge amount of handles from being added 99 // to the metadata_handles() array on the thread. 100 HandleMark hm(thread); 101 methodHandle mh(thread, m); 102 if ((m->method_data() != NULL) && 103 (PrintMethodData || CompilerOracle::should_print(mh))) { 104 collected_profiled_methods->push(m); 105 } 106 } 107 108 void print_method_profiling_data() { 109 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) && 110 (PrintMethodData || CompilerOracle::should_print_methods())) { 111 ResourceMark rm; 112 HandleMark hm; 113 collected_profiled_methods = new GrowableArray<Method*>(1024); 114 ClassLoaderDataGraph::methods_do(collect_profiled_methods); 115 collected_profiled_methods->sort(&compare_methods); 116 117 int count = collected_profiled_methods->length(); 118 int total_size = 0; 119 if (count > 0) { 120 for (int index = 0; index < count; index++) { 121 Method* m = collected_profiled_methods->at(index); 122 ttyLocker ttyl; 123 tty->print_cr("------------------------------------------------------------------------"); 124 m->print_invocation_count(); 125 tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes()); 126 tty->cr(); 127 // Dump data on parameters if any 128 if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) { 129 tty->fill_to(2); 130 m->method_data()->parameters_type_data()->print_data_on(tty); 131 } 132 m->print_codes(); 133 total_size += m->method_data()->size_in_bytes(); 134 } 135 tty->print_cr("------------------------------------------------------------------------"); 136 tty->print_cr("Total MDO size: %d bytes", total_size); 137 } 138 } 139 } 140 141 142 #ifndef PRODUCT 143 144 // Statistics printing (method invocation histogram) 145 146 GrowableArray<Method*>* collected_invoked_methods; 147 148 void collect_invoked_methods(Method* m) { 149 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { 150 collected_invoked_methods->push(m); 151 } 152 } 153 154 155 156 157 void print_method_invocation_histogram() { 158 ResourceMark rm; 159 HandleMark hm; 160 collected_invoked_methods = new GrowableArray<Method*>(1024); 161 SystemDictionary::methods_do(collect_invoked_methods); 162 collected_invoked_methods->sort(&compare_methods); 163 // 164 tty->cr(); 165 tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff); 166 tty->cr(); 167 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); 168 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, 169 synch_total = 0, nativ_total = 0, acces_total = 0; 170 for (int index = 0; index < collected_invoked_methods->length(); index++) { 171 Method* m = collected_invoked_methods->at(index); 172 int c = m->invocation_count() + m->compiled_invocation_count(); 173 if (c >= MethodHistogramCutoff) m->print_invocation_count(); 174 int_total += m->invocation_count(); 175 comp_total += m->compiled_invocation_count(); 176 if (m->is_final()) final_total += c; 177 if (m->is_static()) static_total += c; 178 if (m->is_synchronized()) synch_total += c; 179 if (m->is_native()) nativ_total += c; 180 if (m->is_accessor()) acces_total += c; 181 } 182 tty->cr(); 183 total = int_total + comp_total; 184 tty->print_cr("Invocations summary:"); 185 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); 186 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); 187 tty->print_cr("\t%9d (100%%) total", total); 188 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); 189 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); 190 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); 191 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); 192 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); 193 tty->cr(); 194 SharedRuntime::print_call_statistics(comp_total); 195 } 196 197 void print_bytecode_count() { 198 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 199 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); 200 } 201 } 202 203 AllocStats alloc_stats; 204 205 206 207 // General statistics printing (profiling ...) 208 void print_statistics() { 209 #ifdef ASSERT 210 211 if (CountRuntimeCalls) { 212 extern Histogram *RuntimeHistogram; 213 RuntimeHistogram->print(); 214 } 215 216 if (CountJNICalls) { 217 extern Histogram *JNIHistogram; 218 JNIHistogram->print(); 219 } 220 221 if (CountJVMCalls) { 222 extern Histogram *JVMHistogram; 223 JVMHistogram->print(); 224 } 225 226 #endif 227 228 if (MemProfiling) { 229 MemProfiler::disengage(); 230 } 231 232 if (CITime) { 233 CompileBroker::print_times(); 234 } 235 236 #ifdef COMPILER1 237 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) { 238 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics); 239 Runtime1::print_statistics(); 240 Deoptimization::print_statistics(); 241 SharedRuntime::print_statistics(); 242 } 243 #endif /* COMPILER1 */ 244 245 #ifdef COMPILER2 246 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { 247 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); 248 Compile::print_statistics(); 249 #ifndef COMPILER1 250 Deoptimization::print_statistics(); 251 SharedRuntime::print_statistics(); 252 #endif //COMPILER1 253 os::print_statistics(); 254 } 255 256 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 257 OptoRuntime::print_named_counters(); 258 } 259 260 if (TimeLivenessAnalysis) { 261 MethodLiveness::print_times(); 262 } 263 #ifdef ASSERT 264 if (CollectIndexSetStatistics) { 265 IndexSet::print_statistics(); 266 } 267 #endif // ASSERT 268 #else 269 #ifdef INCLUDE_JVMCI 270 #ifndef COMPILER1 271 if ((TraceDeoptimization || LogVMOutput || LogCompilation) && UseCompiler) { 272 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && TraceDeoptimization); 273 Deoptimization::print_statistics(); 274 SharedRuntime::print_statistics(); 275 } 276 #endif 277 #endif 278 #endif 279 280 if (PrintNMethodStatistics) { 281 nmethod::print_statistics(); 282 } 283 if (CountCompiledCalls) { 284 print_method_invocation_histogram(); 285 } 286 287 print_method_profiling_data(); 288 289 if (TimeCompilationPolicy) { 290 CompilationPolicy::policy()->print_time(); 291 } 292 if (TimeOopMap) { 293 GenerateOopMap::print_time(); 294 } 295 if (ProfilerCheckIntervals) { 296 PeriodicTask::print_intervals(); 297 } 298 if (PrintSymbolTableSizeHistogram) { 299 SymbolTable::print_histogram(); 300 } 301 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 302 BytecodeCounter::print(); 303 } 304 if (PrintBytecodePairHistogram) { 305 BytecodePairHistogram::print(); 306 } 307 308 if (PrintCodeCache) { 309 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 310 CodeCache::print(); 311 } 312 313 if (PrintMethodFlushingStatistics) { 314 NMethodSweeper::print(); 315 } 316 317 if (PrintCodeCache2) { 318 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 319 CodeCache::print_internals(); 320 } 321 322 if (PrintVtableStats) { 323 klassVtable::print_statistics(); 324 klassItable::print_statistics(); 325 } 326 if (VerifyOops) { 327 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); 328 } 329 330 print_bytecode_count(); 331 if (PrintMallocStatistics) { 332 tty->print("allocation stats: "); 333 alloc_stats.print(); 334 tty->cr(); 335 } 336 337 if (PrintSystemDictionaryAtExit) { 338 SystemDictionary::print(); 339 } 340 341 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 342 Method::print_touched_methods(tty); 343 } 344 345 if (PrintBiasedLockingStatistics) { 346 BiasedLocking::print_counters(); 347 } 348 349 // Native memory tracking data 350 if (PrintNMTStatistics) { 351 MemTracker::final_report(tty); 352 } 353 } 354 355 #else // PRODUCT MODE STATISTICS 356 357 void print_statistics() { 358 359 if (PrintMethodData) { 360 print_method_profiling_data(); 361 } 362 363 if (CITime) { 364 CompileBroker::print_times(); 365 } 366 367 if (PrintCodeCache) { 368 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 369 CodeCache::print(); 370 } 371 372 if (PrintMethodFlushingStatistics) { 373 NMethodSweeper::print(); 374 } 375 376 #ifdef COMPILER2 377 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 378 OptoRuntime::print_named_counters(); 379 } 380 #endif 381 if (PrintBiasedLockingStatistics) { 382 BiasedLocking::print_counters(); 383 } 384 385 // Native memory tracking data 386 if (PrintNMTStatistics) { 387 MemTracker::final_report(tty); 388 } 389 390 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 391 Method::print_touched_methods(tty); 392 } 393 } 394 395 #endif 396 397 // Note: before_exit() can be executed only once, if more than one threads 398 // are trying to shutdown the VM at the same time, only one thread 399 // can run before_exit() and all other threads must wait. 400 void before_exit(JavaThread * thread) { 401 #define BEFORE_EXIT_NOT_RUN 0 402 #define BEFORE_EXIT_RUNNING 1 403 #define BEFORE_EXIT_DONE 2 404 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 405 406 // Note: don't use a Mutex to guard the entire before_exit(), as 407 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 408 // A CAS or OSMutex would work just fine but then we need to manipulate 409 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 410 // for synchronization. 411 { MutexLocker ml(BeforeExit_lock); 412 switch (_before_exit_status) { 413 case BEFORE_EXIT_NOT_RUN: 414 _before_exit_status = BEFORE_EXIT_RUNNING; 415 break; 416 case BEFORE_EXIT_RUNNING: 417 while (_before_exit_status == BEFORE_EXIT_RUNNING) { 418 BeforeExit_lock->wait(); 419 } 420 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); 421 return; 422 case BEFORE_EXIT_DONE: 423 return; 424 } 425 } 426 427 #if INCLUDE_JVMCI 428 JVMCIRuntime::shutdown(); 429 #endif 430 431 // Hang forever on exit if we're reporting an error. 432 if (ShowMessageBoxOnError && is_error_reported()) { 433 os::infinite_sleep(); 434 } 435 436 // Stop the WatcherThread. We do this before disenrolling various 437 // PeriodicTasks to reduce the likelihood of races. 438 if (PeriodicTask::num_tasks() > 0) { 439 WatcherThread::stop(); 440 } 441 442 // Print statistics gathered (profiling ...) 443 if (Arguments::has_profile()) { 444 FlatProfiler::disengage(); 445 FlatProfiler::print(10); 446 } 447 448 // shut down the StatSampler task 449 StatSampler::disengage(); 450 StatSampler::destroy(); 451 452 // Stop concurrent GC threads 453 Universe::heap()->stop(); 454 455 // Print GC/heap related information. 456 LogHandle(gc, heap, exit) log; 457 if (log.is_info()) { 458 ResourceMark rm; 459 Universe::print_on(log.info_stream()); 460 if (log.is_trace()) { 461 ClassLoaderDataGraph::dump_on(log.trace_stream()); 462 } 463 } 464 AdaptiveSizePolicyOutput::print(); 465 466 if (PrintBytecodeHistogram) { 467 BytecodeHistogram::print(); 468 } 469 470 if (JvmtiExport::should_post_thread_life()) { 471 JvmtiExport::post_thread_end(thread); 472 } 473 474 475 EventThreadEnd event; 476 if (event.should_commit()) { 477 event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj())); 478 event.commit(); 479 } 480 481 // Always call even when there are not JVMTI environments yet, since environments 482 // may be attached late and JVMTI must track phases of VM execution 483 JvmtiExport::post_vm_death(); 484 Threads::shutdown_vm_agents(); 485 486 // Terminate the signal thread 487 // Note: we don't wait until it actually dies. 488 os::terminate_signal_thread(); 489 490 print_statistics(); 491 Universe::heap()->print_tracing_info(); 492 493 { MutexLocker ml(BeforeExit_lock); 494 _before_exit_status = BEFORE_EXIT_DONE; 495 BeforeExit_lock->notify_all(); 496 } 497 498 if (VerifyStringTableAtExit) { 499 int fail_cnt = 0; 500 { 501 MutexLocker ml(StringTable_lock); 502 fail_cnt = StringTable::verify_and_compare_entries(); 503 } 504 505 if (fail_cnt != 0) { 506 tty->print_cr("ERROR: fail_cnt=%d", fail_cnt); 507 guarantee(fail_cnt == 0, "unexpected StringTable verification failures"); 508 } 509 } 510 511 #undef BEFORE_EXIT_NOT_RUN 512 #undef BEFORE_EXIT_RUNNING 513 #undef BEFORE_EXIT_DONE 514 } 515 516 void vm_exit(int code) { 517 Thread* thread = ThreadLocalStorage::is_initialized() ? 518 ThreadLocalStorage::get_thread_slow() : NULL; 519 if (thread == NULL) { 520 // we have serious problems -- just exit 521 vm_direct_exit(code); 522 } 523 524 if (VMThread::vm_thread() != NULL) { 525 // Fire off a VM_Exit operation to bring VM to a safepoint and exit 526 VM_Exit op(code); 527 if (thread->is_Java_thread()) 528 ((JavaThread*)thread)->set_thread_state(_thread_in_vm); 529 VMThread::execute(&op); 530 // should never reach here; but in case something wrong with VM Thread. 531 vm_direct_exit(code); 532 } else { 533 // VM thread is gone, just exit 534 vm_direct_exit(code); 535 } 536 ShouldNotReachHere(); 537 } 538 539 void notify_vm_shutdown() { 540 // For now, just a dtrace probe. 541 HOTSPOT_VM_SHUTDOWN(); 542 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 543 } 544 545 void vm_direct_exit(int code) { 546 notify_vm_shutdown(); 547 os::wait_for_keypress_at_exit(); 548 os::exit(code); 549 } 550 551 void vm_perform_shutdown_actions() { 552 // Warning: do not call 'exit_globals()' here. All threads are still running. 553 // Calling 'exit_globals()' will disable thread-local-storage and cause all 554 // kinds of assertions to trigger in debug mode. 555 if (is_init_completed()) { 556 Thread* thread = ThreadLocalStorage::is_initialized() ? 557 ThreadLocalStorage::get_thread_slow() : NULL; 558 if (thread != NULL && thread->is_Java_thread()) { 559 // We are leaving the VM, set state to native (in case any OS exit 560 // handlers call back to the VM) 561 JavaThread* jt = (JavaThread*)thread; 562 // Must always be walkable or have no last_Java_frame when in 563 // thread_in_native 564 jt->frame_anchor()->make_walkable(jt); 565 jt->set_thread_state(_thread_in_native); 566 } 567 } 568 notify_vm_shutdown(); 569 } 570 571 void vm_shutdown() 572 { 573 vm_perform_shutdown_actions(); 574 os::wait_for_keypress_at_exit(); 575 os::shutdown(); 576 } 577 578 void vm_abort(bool dump_core) { 579 vm_perform_shutdown_actions(); 580 os::wait_for_keypress_at_exit(); 581 582 // Flush stdout and stderr before abort. 583 fflush(stdout); 584 fflush(stderr); 585 586 os::abort(dump_core); 587 ShouldNotReachHere(); 588 } 589 590 void vm_notify_during_shutdown(const char* error, const char* message) { 591 if (error != NULL) { 592 tty->print_cr("Error occurred during initialization of VM"); 593 tty->print("%s", error); 594 if (message != NULL) { 595 tty->print_cr(": %s", message); 596 } 597 else { 598 tty->cr(); 599 } 600 } 601 if (ShowMessageBoxOnError && WizardMode) { 602 fatal("Error occurred during initialization of VM"); 603 } 604 } 605 606 void vm_exit_during_initialization(Handle exception) { 607 tty->print_cr("Error occurred during initialization of VM"); 608 // If there are exceptions on this thread it must be cleared 609 // first and here. Any future calls to EXCEPTION_MARK requires 610 // that no pending exceptions exist. 611 Thread *THREAD = Thread::current(); 612 if (HAS_PENDING_EXCEPTION) { 613 CLEAR_PENDING_EXCEPTION; 614 } 615 java_lang_Throwable::print(exception, tty); 616 tty->cr(); 617 java_lang_Throwable::print_stack_trace(exception(), tty); 618 tty->cr(); 619 vm_notify_during_shutdown(NULL, NULL); 620 621 // Failure during initialization, we don't want to dump core 622 vm_abort(false); 623 } 624 625 void vm_exit_during_initialization(Symbol* ex, const char* message) { 626 ResourceMark rm; 627 vm_notify_during_shutdown(ex->as_C_string(), message); 628 629 // Failure during initialization, we don't want to dump core 630 vm_abort(false); 631 } 632 633 void vm_exit_during_initialization(const char* error, const char* message) { 634 vm_notify_during_shutdown(error, message); 635 636 // Failure during initialization, we don't want to dump core 637 vm_abort(false); 638 } 639 640 void vm_shutdown_during_initialization(const char* error, const char* message) { 641 vm_notify_during_shutdown(error, message); 642 vm_shutdown(); 643 } 644 645 JDK_Version JDK_Version::_current; 646 const char* JDK_Version::_runtime_name; 647 const char* JDK_Version::_runtime_version; 648 649 void JDK_Version::initialize() { 650 jdk_version_info info; 651 assert(!_current.is_valid(), "Don't initialize twice"); 652 653 void *lib_handle = os::native_java_library(); 654 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, 655 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); 656 657 if (func == NULL) { 658 // JDK older than 1.6 659 _current._partially_initialized = true; 660 } else { 661 (*func)(&info, sizeof(info)); 662 663 int major = JDK_VERSION_MAJOR(info.jdk_version); 664 int minor = JDK_VERSION_MINOR(info.jdk_version); 665 int micro = JDK_VERSION_MICRO(info.jdk_version); 666 int build = JDK_VERSION_BUILD(info.jdk_version); 667 if (major == 1 && minor > 4) { 668 // We represent "1.5.0" as "5.0", but 1.4.2 as itself. 669 major = minor; 670 minor = micro; 671 micro = 0; 672 } 673 // Incompatible with pre-4243978 JDK. 674 if (info.pending_list_uses_discovered_field == 0) { 675 vm_exit_during_initialization( 676 "Incompatible JDK is not using Reference.discovered field for pending list"); 677 } 678 _current = JDK_Version(major, minor, micro, info.update_version, 679 info.special_update_version, build, 680 info.thread_park_blocker == 1, 681 info.post_vm_init_hook_enabled == 1); 682 } 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; 696 } 697 _current = JDK_Version(major, minor, micro, update); 698 } 699 700 void JDK_Version_init() { 701 JDK_Version::initialize(); 702 } 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 assert(buffer && buflen > 0, "call with useful buffer"); 733 size_t index = 0; 734 735 if (!is_valid()) { 736 jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); 737 } else if (is_partially_initialized()) { 738 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); 739 } else { 740 int rc = jio_snprintf( 741 &buffer[index], buflen - index, "%d.%d", _major, _minor); 742 if (rc == -1) return; 743 index += rc; 744 if (_micro > 0) { 745 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); 746 } 747 if (_update > 0) { 748 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); 749 if (rc == -1) return; 750 index += rc; 751 } 752 if (_special > 0) { 753 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special); 754 if (rc == -1) return; 755 index += rc; 756 } 757 if (_build > 0) { 758 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); 759 if (rc == -1) return; 760 index += rc; 761 } 762 } 763 }