/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
int compare_methods(Method** a, Method** b) { // compiled_invocation_count() returns int64_t, forcing the entire expression // to be evaluated as int64_t. Overflow is not an issue.
int64_t diff = (((*b)->invocation_count() + (*b)->compiled_invocation_count())
- ((*a)->invocation_count() + (*a)->compiled_invocation_count())); return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
if (PrintNMethodStatistics) {
nmethod::print_statistics();
} if (CountCompiledCalls) {
print_method_invocation_histogram();
}
print_method_profiling_data();
if (TimeOopMap) {
GenerateOopMap::print_time();
} if (PrintSymbolTableSizeHistogram) {
SymbolTable::print_histogram();
} if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
BytecodeCounter::print();
} if (PrintBytecodePairHistogram) {
BytecodePairHistogram::print();
}
if (PrintCodeCache) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeCache::print();
}
// CodeHeap State Analytics. if (PrintCodeHeapAnalytics) {
CompileBroker::print_heapinfo(NULL, "all", 4096); // details
}
if (PrintCodeCache2) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeCache::print_internals();
}
if (VerifyOops && Verbose) {
tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
}
print_bytecode_count();
if (PrintSystemDictionaryAtExit) {
ResourceMark rm;
MutexLocker mcld(ClassLoaderDataGraph_lock);
SystemDictionary::print();
}
if (PrintClassLoaderDataGraphAtExit) {
ResourceMark rm;
MutexLocker mcld(ClassLoaderDataGraph_lock);
ClassLoaderDataGraph::print();
}
// Native memory tracking data if (PrintNMTStatistics) {
MemTracker::final_report(tty);
}
if (PrintMetaspaceStatisticsAtExit) {
MetaspaceUtils::print_basic_report(tty, 0);
}
ThreadsSMRSupport::log_statistics();
}
#else// PRODUCT MODE STATISTICS
void print_statistics() {
if (PrintMethodData) {
print_method_profiling_data();
}
if (CITime) {
CompileBroker::print_times();
}
#ifdef COMPILER2_OR_JVMCI if ((LogVMOutput || LogCompilation) && UseCompiler) { // Only print the statistics to the log file
FlagSetting fs(DisplayVMOutput, false);
Deoptimization::print_statistics();
} #endif/* COMPILER2 || INCLUDE_JVMCI */
if (PrintCodeCache) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeCache::print();
}
// CodeHeap State Analytics. if (PrintCodeHeapAnalytics) {
CompileBroker::print_heapinfo(NULL, "all", 4096); // details
}
#ifdef COMPILER2 if (PrintPreciseRTMLockingStatistics) {
OptoRuntime::print_named_counters();
} #endif
// Native memory tracking data if (PrintNMTStatistics) {
MemTracker::final_report(tty);
}
if (PrintMetaspaceStatisticsAtExit) {
MetaspaceUtils::print_basic_report(tty, 0);
}
ThreadsSMRSupport::log_statistics();
}
#endif
// Note: before_exit() can be executed only once, if more than one threads // are trying to shutdown the VM at the same time, only one thread // can run before_exit() and all other threads must wait. void before_exit(JavaThread* thread, bool halt) { #define BEFORE_EXIT_NOT_RUN 0 #define BEFORE_EXIT_RUNNING 1 #define BEFORE_EXIT_DONE 2 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
// Note: don't use a Mutex to guard the entire before_exit(), as // JVMTI post_thread_end_event and post_vm_death_event will run native code. // A CAS or OSMutex would work just fine but then we need to manipulate // thread state for Safepoint. Here we use Monitor wait() and notify_all() // for synchronization.
{ MonitorLocker ml(BeforeExit_lock); switch (_before_exit_status) { case BEFORE_EXIT_NOT_RUN:
_before_exit_status = BEFORE_EXIT_RUNNING; break; case BEFORE_EXIT_RUNNING: while (_before_exit_status == BEFORE_EXIT_RUNNING) {
ml.wait();
}
assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); return; case BEFORE_EXIT_DONE: // need block to avoid SS compiler bug
{ return;
}
}
}
#if INCLUDE_JVMCI if (EnableJVMCI) {
JVMCI::shutdown(thread);
} #endif
// Hang forever on exit if we're reporting an error. if (ShowMessageBoxOnError && VMError::is_error_reported()) {
os::infinite_sleep();
}
EventThreadEnd event; if (event.should_commit()) {
event.set_thread(JFR_JVM_THREAD_ID(thread));
event.commit();
}
JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
// Stop the WatcherThread. We do this before disenrolling various // PeriodicTasks to reduce the likelihood of races. if (PeriodicTask::num_tasks() > 0) {
WatcherThread::stop();
}
// shut down the StatSampler task
StatSampler::disengage();
StatSampler::destroy();
// Shut down string deduplication if running. if (StringDedup::is_enabled()) {
StringDedup::stop();
}
// Print GC/heap related information.
Log(gc, heap, exit) log; if (log.is_info()) {
ResourceMark rm;
LogStream ls_info(log.info());
Universe::print_on(&ls_info); if (log.is_trace()) {
LogStream ls_trace(log.trace());
MutexLocker mcld(ClassLoaderDataGraph_lock);
ClassLoaderDataGraph::print_on(&ls_trace);
}
}
if (PrintBytecodeHistogram) {
BytecodeHistogram::print();
}
#ifdef LINUX if (DumpPerfMapAtExit) {
CodeCache::write_perf_map();
} #endif
if (JvmtiExport::should_post_thread_life()) {
JvmtiExport::post_thread_end(thread);
}
// Always call even when there are not JVMTI environments yet, since environments // may be attached late and JVMTI must track phases of VM execution
JvmtiExport::post_vm_death();
Threads::shutdown_vm_agents();
// Terminate the signal thread // Note: we don't wait until it actually dies.
os::terminate_signal_thread();
#if INCLUDE_CDS if (DynamicArchive::should_dump_at_vm_exit()) {
assert(ArchiveClassesAtExit != NULL, "Must be already set");
ExceptionMark em(thread);
DynamicArchive::dump(ArchiveClassesAtExit, thread); if (thread->has_pending_exception()) {
ResourceMark rm(thread);
oop pending_exception = thread->pending_exception();
log_error(cds)("ArchiveClassesAtExit has failed %s: %s", pending_exception->klass()->external_name(),
java_lang_String::as_utf8_string(java_lang_Throwable::message(pending_exception)));
thread->clear_pending_exception();
}
} #endif
void vm_exit(int code) {
Thread* thread =
ThreadLocalStorage::is_initialized() ? Thread::current_or_null() : NULL; if (thread == NULL) { // very early initialization failure -- just exit
vm_direct_exit(code);
}
// We'd like to add an entry to the XML log to show that the VM is // terminating, but we can't safely do that here. The logic to make // XML termination logging safe is tied to the termination of the // VMThread, and it doesn't terminate on this exit path. See 8222534.
if (VMThread::vm_thread() != NULL) { if (thread->is_Java_thread()) { // We must be "in_vm" for the code below to work correctly. // Historically there must have been some exit path for which // that was not the case and so we set it explicitly - even // though we no longer know what that path may be.
JavaThread::cast(thread)->set_thread_state(_thread_in_vm);
}
// Fire off a VM_Exit operation to bring VM to a safepoint and exit
VM_Exit op(code);
// 4945125 The vm thread comes to a safepoint during exit. // GC vm_operations can get caught at the safepoint, and the // heap is unparseable if they are caught. Grab the Heap_lock // to prevent this. The GC vm_operations will not be able to // queue until after we release it, but we never do that as we // are terminating the VM process.
MutexLocker ml(Heap_lock);
VMThread::execute(&op); // should never reach here; but in case something wrong with VM Thread.
vm_direct_exit(code);
} else { // VM thread is gone, just exit
vm_direct_exit(code);
}
ShouldNotReachHere();
}
void notify_vm_shutdown() { // For now, just a dtrace probe.
HOTSPOT_VM_SHUTDOWN();
}
void vm_perform_shutdown_actions() { if (is_init_completed()) {
Thread* thread = Thread::current_or_null(); if (thread != NULL && thread->is_Java_thread()) { // We are leaving the VM, set state to native (in case any OS exit // handlers call back to the VM)
JavaThread* jt = JavaThread::cast(thread); // Must always be walkable or have no last_Java_frame when in // thread_in_native
jt->frame_anchor()->make_walkable();
jt->set_thread_state(_thread_in_native);
}
}
notify_vm_shutdown();
}
// Failure during initialization, we don't want to dump core
vm_abort(false);
}
void vm_exit_during_initialization(Handle exception) {
tty->print_cr("Error occurred during initialization of VM"); // If there are exceptions on this thread it must be cleared // first and here. Any future calls to EXCEPTION_MARK requires // that no pending exceptions exist.
JavaThread* THREAD = JavaThread::current(); // can't be NULL if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
}
java_lang_Throwable::print_stack_trace(exception, tty);
tty->cr();
vm_notify_during_shutdown(NULL, NULL);
// Failure during initialization, we don't want to dump core
vm_abort(false);
}
int major = VM_Version::vm_major_version(); int minor = VM_Version::vm_minor_version(); int security = VM_Version::vm_security_version(); int build = VM_Version::vm_build_number(); int patch = VM_Version::vm_patch_version();
_current = JDK_Version(major, minor, security, patch, build);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.