1 /* 2 * Copyright (c) 1997, 2019, 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 "jvm.h" 27 #include "aot/aotLoader.hpp" 28 #include "classfile/classLoader.hpp" 29 #include "classfile/classLoaderDataGraph.hpp" 30 #include "classfile/stringTable.hpp" 31 #include "classfile/symbolTable.hpp" 32 #include "classfile/systemDictionary.hpp" 33 #include "code/codeCache.hpp" 34 #include "compiler/compileBroker.hpp" 35 #include "compiler/compilerOracle.hpp" 36 #include "interpreter/bytecodeHistogram.hpp" 37 #include "jfr/jfrEvents.hpp" 38 #include "jfr/support/jfrThreadId.hpp" 39 #if INCLUDE_JVMCI 40 #include "jvmci/jvmci.hpp" 41 #endif 42 #include "logging/log.hpp" 43 #include "logging/logStream.hpp" 44 #include "memory/oopFactory.hpp" 45 #include "memory/resourceArea.hpp" 46 #include "memory/dynamicArchive.hpp" 47 #include "memory/universe.hpp" 48 #include "oops/constantPool.hpp" 49 #include "oops/generateOopMap.hpp" 50 #include "oops/instanceKlass.hpp" 51 #include "oops/instanceOop.hpp" 52 #include "oops/method.hpp" 53 #include "oops/objArrayOop.hpp" 54 #include "oops/oop.inline.hpp" 55 #include "oops/symbol.hpp" 56 #include "prims/jvmtiExport.hpp" 57 #include "runtime/arguments.hpp" 58 #include "runtime/biasedLocking.hpp" 59 #include "runtime/compilationPolicy.hpp" 60 #include "runtime/deoptimization.hpp" 61 #include "runtime/flags/flagSetting.hpp" 62 #include "runtime/handles.inline.hpp" 63 #include "runtime/init.hpp" 64 #include "runtime/interfaceSupport.inline.hpp" 65 #include "runtime/java.hpp" 66 #include "runtime/memprofiler.hpp" 67 #include "runtime/sharedRuntime.hpp" 68 #include "runtime/statSampler.hpp" 69 #include "runtime/sweeper.hpp" 70 #include "runtime/task.hpp" 71 #include "runtime/thread.inline.hpp" 72 #include "runtime/timer.hpp" 73 #include "runtime/vmOperations.hpp" 74 #include "services/memTracker.hpp" 75 #include "utilities/dtrace.hpp" 76 #include "utilities/globalDefinitions.hpp" 77 #include "utilities/histogram.hpp" 78 #include "utilities/macros.hpp" 79 #include "utilities/vmError.hpp" 80 #ifdef COMPILER1 81 #include "c1/c1_Compiler.hpp" 82 #include "c1/c1_Runtime1.hpp" 83 #endif 84 #ifdef COMPILER2 85 #include "code/compiledIC.hpp" 86 #include "opto/compile.hpp" 87 #include "opto/indexSet.hpp" 88 #include "opto/runtime.hpp" 89 #endif 90 #if INCLUDE_JFR 91 #include "jfr/jfr.hpp" 92 #endif 93 94 GrowableArray<Method*>* collected_profiled_methods; 95 96 int compare_methods(Method** a, Method** b) { 97 // %%% there can be 32-bit overflow here 98 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) 99 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); 100 } 101 102 void collect_profiled_methods(Method* m) { 103 Thread* thread = Thread::current(); 104 methodHandle mh(thread, m); 105 if ((m->method_data() != NULL) && 106 (PrintMethodData || CompilerOracle::should_print(mh))) { 107 collected_profiled_methods->push(m); 108 } 109 } 110 111 void print_method_profiling_data() { 112 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) && 113 (PrintMethodData || CompilerOracle::should_print_methods())) { 114 ResourceMark rm; 115 HandleMark hm; 116 collected_profiled_methods = new GrowableArray<Method*>(1024); 117 SystemDictionary::methods_do(collect_profiled_methods); 118 collected_profiled_methods->sort(&compare_methods); 119 120 int count = collected_profiled_methods->length(); 121 int total_size = 0; 122 if (count > 0) { 123 for (int index = 0; index < count; index++) { 124 Method* m = collected_profiled_methods->at(index); 125 ttyLocker ttyl; 126 tty->print_cr("------------------------------------------------------------------------"); 127 m->print_invocation_count(); 128 tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes()); 129 tty->cr(); 130 // Dump data on parameters if any 131 if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) { 132 tty->fill_to(2); 133 m->method_data()->parameters_type_data()->print_data_on(tty); 134 } 135 m->print_codes(); 136 total_size += m->method_data()->size_in_bytes(); 137 } 138 tty->print_cr("------------------------------------------------------------------------"); 139 tty->print_cr("Total MDO size: %d bytes", total_size); 140 } 141 } 142 } 143 144 145 #ifndef PRODUCT 146 147 // Statistics printing (method invocation histogram) 148 149 GrowableArray<Method*>* collected_invoked_methods; 150 151 void collect_invoked_methods(Method* m) { 152 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { 153 collected_invoked_methods->push(m); 154 } 155 } 156 157 158 159 160 void print_method_invocation_histogram() { 161 ResourceMark rm; 162 HandleMark hm; 163 collected_invoked_methods = new GrowableArray<Method*>(1024); 164 SystemDictionary::methods_do(collect_invoked_methods); 165 collected_invoked_methods->sort(&compare_methods); 166 // 167 tty->cr(); 168 tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff); 169 tty->cr(); 170 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); 171 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, 172 synch_total = 0, nativ_total = 0, acces_total = 0; 173 for (int index = 0; index < collected_invoked_methods->length(); index++) { 174 Method* m = collected_invoked_methods->at(index); 175 int c = m->invocation_count() + m->compiled_invocation_count(); 176 if (c >= MethodHistogramCutoff) m->print_invocation_count(); 177 int_total += m->invocation_count(); 178 comp_total += m->compiled_invocation_count(); 179 if (m->is_final()) final_total += c; 180 if (m->is_static()) static_total += c; 181 if (m->is_synchronized()) synch_total += c; 182 if (m->is_native()) nativ_total += c; 183 if (m->is_accessor()) acces_total += c; 184 } 185 tty->cr(); 186 total = int_total + comp_total; 187 tty->print_cr("Invocations summary:"); 188 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); 189 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); 190 tty->print_cr("\t%9d (100%%) total", total); 191 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); 192 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); 193 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); 194 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); 195 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); 196 tty->cr(); 197 SharedRuntime::print_call_statistics(comp_total); 198 } 199 200 void print_bytecode_count() { 201 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 202 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); 203 } 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 #ifdef ASSERT 260 if (CollectIndexSetStatistics) { 261 IndexSet::print_statistics(); 262 } 263 #endif // ASSERT 264 #else // COMPILER2 265 #if INCLUDE_JVMCI 266 #ifndef COMPILER1 267 if ((TraceDeoptimization || LogVMOutput || LogCompilation) && UseCompiler) { 268 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && TraceDeoptimization); 269 Deoptimization::print_statistics(); 270 SharedRuntime::print_statistics(); 271 } 272 #endif // COMPILER1 273 #endif // INCLUDE_JVMCI 274 #endif // COMPILER2 275 276 if (PrintAOTStatistics) { 277 AOTLoader::print_statistics(); 278 } 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 (TimeOopMap) { 290 GenerateOopMap::print_time(); 291 } 292 if (PrintSymbolTableSizeHistogram) { 293 SymbolTable::print_histogram(); 294 } 295 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 296 BytecodeCounter::print(); 297 } 298 if (PrintBytecodePairHistogram) { 299 BytecodePairHistogram::print(); 300 } 301 302 if (PrintCodeCache) { 303 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 304 CodeCache::print(); 305 } 306 307 // CodeHeap State Analytics. 308 // Does also call NMethodSweeper::print(tty) 309 if (PrintCodeHeapAnalytics) { 310 CompileBroker::print_heapinfo(NULL, "all", 4096); // details 311 } else if (PrintMethodFlushingStatistics) { 312 NMethodSweeper::print(tty); 313 } 314 315 if (PrintCodeCache2) { 316 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 317 CodeCache::print_internals(); 318 } 319 320 if (PrintVtableStats) { 321 klassVtable::print_statistics(); 322 klassItable::print_statistics(); 323 } 324 if (VerifyOops && Verbose) { 325 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); 326 } 327 328 print_bytecode_count(); 329 330 if (PrintSystemDictionaryAtExit) { 331 ResourceMark rm; 332 MutexLocker mcld(ClassLoaderDataGraph_lock); 333 SystemDictionary::print(); 334 ClassLoaderDataGraph::print(); 335 } 336 337 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 338 Method::print_touched_methods(tty); 339 } 340 341 if (PrintBiasedLockingStatistics) { 342 BiasedLocking::print_counters(); 343 } 344 345 // Native memory tracking data 346 if (PrintNMTStatistics) { 347 MemTracker::final_report(tty); 348 } 349 350 ThreadsSMRSupport::log_statistics(); 351 } 352 353 #else // PRODUCT MODE STATISTICS 354 355 void print_statistics() { 356 357 if (PrintMethodData) { 358 print_method_profiling_data(); 359 } 360 361 if (CITime) { 362 CompileBroker::print_times(); 363 } 364 365 if (PrintCodeCache) { 366 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 367 CodeCache::print(); 368 } 369 370 // CodeHeap State Analytics. 371 // Does also call NMethodSweeper::print(tty) 372 if (PrintCodeHeapAnalytics) { 373 CompileBroker::print_heapinfo(NULL, "all", 4096); // details 374 } else if (PrintMethodFlushingStatistics) { 375 NMethodSweeper::print(tty); 376 } 377 378 #ifdef COMPILER2 379 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 380 OptoRuntime::print_named_counters(); 381 } 382 #endif 383 if (PrintBiasedLockingStatistics) { 384 BiasedLocking::print_counters(); 385 } 386 387 // Native memory tracking data 388 if (PrintNMTStatistics) { 389 MemTracker::final_report(tty); 390 } 391 392 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 393 Method::print_touched_methods(tty); 394 } 395 396 ThreadsSMRSupport::log_statistics(); 397 } 398 399 #endif 400 401 // Note: before_exit() can be executed only once, if more than one threads 402 // are trying to shutdown the VM at the same time, only one thread 403 // can run before_exit() and all other threads must wait. 404 void before_exit(JavaThread* thread) { 405 #define BEFORE_EXIT_NOT_RUN 0 406 #define BEFORE_EXIT_RUNNING 1 407 #define BEFORE_EXIT_DONE 2 408 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 409 410 // Note: don't use a Mutex to guard the entire before_exit(), as 411 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 412 // A CAS or OSMutex would work just fine but then we need to manipulate 413 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 414 // for synchronization. 415 { MonitorLocker ml(BeforeExit_lock); 416 switch (_before_exit_status) { 417 case BEFORE_EXIT_NOT_RUN: 418 _before_exit_status = BEFORE_EXIT_RUNNING; 419 break; 420 case BEFORE_EXIT_RUNNING: 421 while (_before_exit_status == BEFORE_EXIT_RUNNING) { 422 ml.wait(); 423 } 424 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); 425 return; 426 case BEFORE_EXIT_DONE: 427 // need block to avoid SS compiler bug 428 { 429 return; 430 } 431 } 432 } 433 434 #if INCLUDE_JVMCI 435 JVMCI::shutdown(); 436 #endif 437 438 // Hang forever on exit if we're reporting an error. 439 if (ShowMessageBoxOnError && VMError::is_error_reported()) { 440 os::infinite_sleep(); 441 } 442 443 EventThreadEnd event; 444 if (event.should_commit()) { 445 event.set_thread(JFR_THREAD_ID(thread)); 446 event.commit(); 447 } 448 449 JFR_ONLY(Jfr::on_vm_shutdown();) 450 451 // Stop the WatcherThread. We do this before disenrolling various 452 // PeriodicTasks to reduce the likelihood of races. 453 if (PeriodicTask::num_tasks() > 0) { 454 WatcherThread::stop(); 455 } 456 457 // shut down the StatSampler task 458 StatSampler::disengage(); 459 StatSampler::destroy(); 460 461 // Stop concurrent GC threads 462 Universe::heap()->stop(); 463 464 // Print GC/heap related information. 465 Log(gc, heap, exit) log; 466 if (log.is_info()) { 467 ResourceMark rm; 468 LogStream ls_info(log.info()); 469 Universe::print_on(&ls_info); 470 if (log.is_trace()) { 471 LogStream ls_trace(log.trace()); 472 MutexLocker mcld(ClassLoaderDataGraph_lock); 473 ClassLoaderDataGraph::print_on(&ls_trace); 474 } 475 } 476 477 if (PrintBytecodeHistogram) { 478 BytecodeHistogram::print(); 479 } 480 481 if (JvmtiExport::should_post_thread_life()) { 482 JvmtiExport::post_thread_end(thread); 483 } 484 485 // Always call even when there are not JVMTI environments yet, since environments 486 // may be attached late and JVMTI must track phases of VM execution 487 JvmtiExport::post_vm_death(); 488 Threads::shutdown_vm_agents(); 489 490 // Terminate the signal thread 491 // Note: we don't wait until it actually dies. 492 os::terminate_signal_thread(); 493 494 #if INCLUDE_CDS 495 if (DynamicDumpSharedSpaces) { 496 DynamicArchive::dump(); 497 } 498 #endif 499 500 print_statistics(); 501 Universe::heap()->print_tracing_info(); 502 503 { MutexLocker ml(BeforeExit_lock); 504 _before_exit_status = BEFORE_EXIT_DONE; 505 BeforeExit_lock->notify_all(); 506 } 507 508 if (VerifyStringTableAtExit) { 509 size_t fail_cnt = StringTable::verify_and_compare_entries(); 510 if (fail_cnt != 0) { 511 tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt); 512 guarantee(fail_cnt == 0, "unexpected StringTable verification failures"); 513 } 514 } 515 516 #undef BEFORE_EXIT_NOT_RUN 517 #undef BEFORE_EXIT_RUNNING 518 #undef BEFORE_EXIT_DONE 519 } 520 521 void vm_exit(int code) { 522 Thread* thread = 523 ThreadLocalStorage::is_initialized() ? Thread::current_or_null() : NULL; 524 if (thread == NULL) { 525 // very early initialization failure -- just exit 526 vm_direct_exit(code); 527 } 528 529 // We'd like to add an entry to the XML log to show that the VM is 530 // terminating, but we can't safely do that here. The logic to make 531 // XML termination logging safe is tied to the termination of the 532 // VMThread, and it doesn't terminate on this exit path. See 8222534. 533 534 if (VMThread::vm_thread() != NULL) { 535 if (thread->is_Java_thread()) { 536 // We must be "in_vm" for the code below to work correctly. 537 // Historically there must have been some exit path for which 538 // that was not the case and so we set it explicitly - even 539 // though we no longer know what that path may be. 540 ((JavaThread*)thread)->set_thread_state(_thread_in_vm); 541 } 542 543 // Fire off a VM_Exit operation to bring VM to a safepoint and exit 544 VM_Exit op(code); 545 546 // 4945125 The vm thread comes to a safepoint during exit. 547 // GC vm_operations can get caught at the safepoint, and the 548 // heap is unparseable if they are caught. Grab the Heap_lock 549 // to prevent this. The GC vm_operations will not be able to 550 // queue until after we release it, but we never do that as we 551 // are terminating the VM process. 552 MutexLocker ml(Heap_lock); 553 554 VMThread::execute(&op); 555 // should never reach here; but in case something wrong with VM Thread. 556 vm_direct_exit(code); 557 } else { 558 // VM thread is gone, just exit 559 vm_direct_exit(code); 560 } 561 ShouldNotReachHere(); 562 } 563 564 void notify_vm_shutdown() { 565 // For now, just a dtrace probe. 566 HOTSPOT_VM_SHUTDOWN(); 567 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 568 } 569 570 void vm_direct_exit(int code) { 571 notify_vm_shutdown(); 572 os::wait_for_keypress_at_exit(); 573 os::exit(code); 574 } 575 576 void vm_perform_shutdown_actions() { 577 if (is_init_completed()) { 578 Thread* thread = Thread::current_or_null(); 579 if (thread != NULL && thread->is_Java_thread()) { 580 // We are leaving the VM, set state to native (in case any OS exit 581 // handlers call back to the VM) 582 JavaThread* jt = (JavaThread*)thread; 583 // Must always be walkable or have no last_Java_frame when in 584 // thread_in_native 585 jt->frame_anchor()->make_walkable(jt); 586 jt->set_thread_state(_thread_in_native); 587 } 588 } 589 notify_vm_shutdown(); 590 } 591 592 void vm_shutdown() 593 { 594 vm_perform_shutdown_actions(); 595 os::wait_for_keypress_at_exit(); 596 os::shutdown(); 597 } 598 599 void vm_abort(bool dump_core) { 600 vm_perform_shutdown_actions(); 601 os::wait_for_keypress_at_exit(); 602 603 // Flush stdout and stderr before abort. 604 fflush(stdout); 605 fflush(stderr); 606 607 os::abort(dump_core); 608 ShouldNotReachHere(); 609 } 610 611 void vm_notify_during_cds_dumping(const char* error, const char* message) { 612 if (error != NULL) { 613 tty->print_cr("Error occurred during CDS dumping"); 614 tty->print("%s", error); 615 if (message != NULL) { 616 tty->print_cr(": %s", message); 617 } 618 else { 619 tty->cr(); 620 } 621 } 622 } 623 624 void vm_exit_during_cds_dumping(const char* error, const char* message) { 625 vm_notify_during_cds_dumping(error, message); 626 627 // Failure during CDS dumping, we don't want to dump core 628 vm_abort(false); 629 } 630 631 void vm_notify_during_shutdown(const char* error, const char* message) { 632 if (error != NULL) { 633 tty->print_cr("Error occurred during initialization of VM"); 634 tty->print("%s", error); 635 if (message != NULL) { 636 tty->print_cr(": %s", message); 637 } 638 else { 639 tty->cr(); 640 } 641 } 642 if (ShowMessageBoxOnError && WizardMode) { 643 fatal("Error occurred during initialization of VM"); 644 } 645 } 646 647 void vm_exit_during_initialization() { 648 vm_notify_during_shutdown(NULL, NULL); 649 650 // Failure during initialization, we don't want to dump core 651 vm_abort(false); 652 } 653 654 void vm_exit_during_initialization(Handle exception) { 655 tty->print_cr("Error occurred during initialization of VM"); 656 // If there are exceptions on this thread it must be cleared 657 // first and here. Any future calls to EXCEPTION_MARK requires 658 // that no pending exceptions exist. 659 Thread *THREAD = Thread::current(); // can't be NULL 660 if (HAS_PENDING_EXCEPTION) { 661 CLEAR_PENDING_EXCEPTION; 662 } 663 java_lang_Throwable::print_stack_trace(exception, tty); 664 tty->cr(); 665 vm_notify_during_shutdown(NULL, NULL); 666 667 // Failure during initialization, we don't want to dump core 668 vm_abort(false); 669 } 670 671 void vm_exit_during_initialization(Symbol* ex, const char* message) { 672 ResourceMark rm; 673 vm_notify_during_shutdown(ex->as_C_string(), message); 674 675 // Failure during initialization, we don't want to dump core 676 vm_abort(false); 677 } 678 679 void vm_exit_during_initialization(const char* error, const char* message) { 680 vm_notify_during_shutdown(error, message); 681 682 // Failure during initialization, we don't want to dump core 683 vm_abort(false); 684 } 685 686 void vm_shutdown_during_initialization(const char* error, const char* message) { 687 vm_notify_during_shutdown(error, message); 688 vm_shutdown(); 689 } 690 691 JDK_Version JDK_Version::_current; 692 const char* JDK_Version::_runtime_name; 693 const char* JDK_Version::_runtime_version; 694 695 void JDK_Version::initialize() { 696 jdk_version_info info; 697 assert(!_current.is_valid(), "Don't initialize twice"); 698 699 void *lib_handle = os::native_java_library(); 700 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, 701 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); 702 703 assert(func != NULL, "Support for JDK 1.5 or older has been removed after JEP-223"); 704 705 (*func)(&info, sizeof(info)); 706 707 int major = JDK_VERSION_MAJOR(info.jdk_version); 708 int minor = JDK_VERSION_MINOR(info.jdk_version); 709 int security = JDK_VERSION_SECURITY(info.jdk_version); 710 int build = JDK_VERSION_BUILD(info.jdk_version); 711 712 _current = JDK_Version(major, minor, security, info.patch_version, build); 713 } 714 715 void JDK_Version_init() { 716 JDK_Version::initialize(); 717 } 718 719 static int64_t encode_jdk_version(const JDK_Version& v) { 720 return 721 ((int64_t)v.major_version() << (BitsPerByte * 4)) | 722 ((int64_t)v.minor_version() << (BitsPerByte * 3)) | 723 ((int64_t)v.security_version() << (BitsPerByte * 2)) | 724 ((int64_t)v.patch_version() << (BitsPerByte * 1)) | 725 ((int64_t)v.build_number() << (BitsPerByte * 0)); 726 } 727 728 int JDK_Version::compare(const JDK_Version& other) const { 729 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); 730 uint64_t e = encode_jdk_version(*this); 731 uint64_t o = encode_jdk_version(other); 732 return (e > o) ? 1 : ((e == o) ? 0 : -1); 733 } 734 735 void JDK_Version::to_string(char* buffer, size_t buflen) const { 736 assert(buffer && buflen > 0, "call with useful buffer"); 737 size_t index = 0; 738 739 if (!is_valid()) { 740 jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); 741 } else { 742 int rc = jio_snprintf( 743 &buffer[index], buflen - index, "%d.%d", _major, _minor); 744 if (rc == -1) return; 745 index += rc; 746 if (_security > 0) { 747 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security); 748 if (rc == -1) return; 749 index += rc; 750 } 751 if (_patch > 0) { 752 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch); 753 if (rc == -1) return; 754 index += rc; 755 } 756 if (_build > 0) { 757 rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build); 758 if (rc == -1) return; 759 index += rc; 760 } 761 } 762 }