aoqi@0: /* shshahma@8584: * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/classLoader.hpp" aoqi@0: #include "classfile/symbolTable.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "code/codeCache.hpp" aoqi@0: #include "compiler/compileBroker.hpp" aoqi@0: #include "compiler/compilerOracle.hpp" aoqi@0: #include "interpreter/bytecodeHistogram.hpp" aoqi@0: #include "memory/genCollectedHeap.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "memory/universe.hpp" aoqi@0: #include "oops/constantPool.hpp" aoqi@0: #include "oops/generateOopMap.hpp" aoqi@0: #include "oops/instanceKlass.hpp" aoqi@0: #include "oops/instanceOop.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/objArrayOop.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/symbol.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "runtime/arguments.hpp" aoqi@0: #include "runtime/biasedLocking.hpp" aoqi@0: #include "runtime/compilationPolicy.hpp" aoqi@0: #include "runtime/fprofiler.hpp" aoqi@0: #include "runtime/init.hpp" aoqi@0: #include "runtime/interfaceSupport.hpp" aoqi@0: #include "runtime/java.hpp" aoqi@0: #include "runtime/memprofiler.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/statSampler.hpp" aoqi@0: #include "runtime/sweeper.hpp" aoqi@0: #include "runtime/task.hpp" aoqi@0: #include "runtime/thread.inline.hpp" aoqi@0: #include "runtime/timer.hpp" aoqi@0: #include "runtime/vm_operations.hpp" aoqi@0: #include "services/memTracker.hpp" aoqi@0: #include "trace/tracing.hpp" aoqi@0: #include "utilities/dtrace.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: #include "utilities/histogram.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: #include "utilities/vmError.hpp" aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "vm_version_x86.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "vm_version_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "vm_version_zero.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "vm_version_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "vm_version_ppc.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "vm_version_mips.hpp" aoqi@1: #endif aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" aoqi@0: #include "gc_implementation/parallelScavenge/psScavenge.hpp" aoqi@0: #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: #ifdef COMPILER1 aoqi@0: #include "c1/c1_Compiler.hpp" aoqi@0: #include "c1/c1_Runtime1.hpp" aoqi@0: #endif aoqi@0: #ifdef COMPILER2 aoqi@0: #include "code/compiledIC.hpp" aoqi@0: #include "compiler/methodLiveness.hpp" aoqi@0: #include "opto/compile.hpp" aoqi@0: #include "opto/indexSet.hpp" aoqi@0: #include "opto/runtime.hpp" aoqi@0: #endif aoqi@0: aoqi@0: #ifndef USDT2 aoqi@0: HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown); aoqi@0: #endif /* !USDT2 */ aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: // Statistics printing (method invocation histogram) aoqi@0: aoqi@0: GrowableArray* collected_invoked_methods; aoqi@0: aoqi@0: void collect_invoked_methods(Method* m) { aoqi@0: if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { aoqi@0: collected_invoked_methods->push(m); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: GrowableArray* collected_profiled_methods; aoqi@0: aoqi@0: void collect_profiled_methods(Method* m) { aoqi@0: Thread* thread = Thread::current(); aoqi@0: // This HandleMark prevents a huge amount of handles from being added aoqi@0: // to the metadata_handles() array on the thread. aoqi@0: HandleMark hm(thread); aoqi@0: methodHandle mh(thread, m); aoqi@0: if ((m->method_data() != NULL) && aoqi@0: (PrintMethodData || CompilerOracle::should_print(mh))) { aoqi@0: collected_profiled_methods->push(m); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int compare_methods(Method** a, Method** b) { aoqi@0: // %%% there can be 32-bit overflow here aoqi@0: return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) aoqi@0: - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void print_method_invocation_histogram() { aoqi@0: ResourceMark rm; aoqi@0: HandleMark hm; aoqi@0: collected_invoked_methods = new GrowableArray(1024); aoqi@0: SystemDictionary::methods_do(collect_invoked_methods); aoqi@0: collected_invoked_methods->sort(&compare_methods); aoqi@0: // aoqi@0: tty->cr(); aoqi@0: tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff); aoqi@0: tty->cr(); aoqi@0: tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); aoqi@0: unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, aoqi@0: synch_total = 0, nativ_total = 0, acces_total = 0; aoqi@0: for (int index = 0; index < collected_invoked_methods->length(); index++) { aoqi@0: Method* m = collected_invoked_methods->at(index); aoqi@0: int c = m->invocation_count() + m->compiled_invocation_count(); aoqi@0: if (c >= MethodHistogramCutoff) m->print_invocation_count(); aoqi@0: int_total += m->invocation_count(); aoqi@0: comp_total += m->compiled_invocation_count(); aoqi@0: if (m->is_final()) final_total += c; aoqi@0: if (m->is_static()) static_total += c; aoqi@0: if (m->is_synchronized()) synch_total += c; aoqi@0: if (m->is_native()) nativ_total += c; aoqi@0: if (m->is_accessor()) acces_total += c; aoqi@0: } aoqi@0: tty->cr(); aoqi@0: total = int_total + comp_total; aoqi@0: tty->print_cr("Invocations summary:"); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); aoqi@0: tty->print_cr("\t%9d (100%%) total", total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); aoqi@0: tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); aoqi@0: tty->cr(); aoqi@0: SharedRuntime::print_call_statistics(comp_total); aoqi@0: } aoqi@0: aoqi@0: void print_method_profiling_data() { aoqi@0: ResourceMark rm; aoqi@0: HandleMark hm; aoqi@0: collected_profiled_methods = new GrowableArray(1024); aoqi@0: SystemDictionary::methods_do(collect_profiled_methods); aoqi@0: collected_profiled_methods->sort(&compare_methods); aoqi@0: aoqi@0: int count = collected_profiled_methods->length(); aoqi@0: int total_size = 0; aoqi@0: if (count > 0) { aoqi@0: for (int index = 0; index < count; index++) { aoqi@0: Method* m = collected_profiled_methods->at(index); aoqi@0: ttyLocker ttyl; aoqi@0: tty->print_cr("------------------------------------------------------------------------"); aoqi@0: //m->print_name(tty); aoqi@0: m->print_invocation_count(); aoqi@0: tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes()); aoqi@0: tty->cr(); aoqi@0: // Dump data on parameters if any aoqi@0: if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) { aoqi@0: tty->fill_to(2); aoqi@0: m->method_data()->parameters_type_data()->print_data_on(tty); aoqi@0: } aoqi@0: m->print_codes(); aoqi@0: total_size += m->method_data()->size_in_bytes(); aoqi@0: } aoqi@0: tty->print_cr("------------------------------------------------------------------------"); aoqi@0: tty->print_cr("Total MDO size: %d bytes", total_size); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void print_bytecode_count() { aoqi@0: if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { aoqi@0: tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: AllocStats alloc_stats; aoqi@0: aoqi@0: aoqi@0: aoqi@0: // General statistics printing (profiling ...) aoqi@0: void print_statistics() { aoqi@0: #ifdef ASSERT aoqi@0: aoqi@0: if (CountRuntimeCalls) { aoqi@0: extern Histogram *RuntimeHistogram; aoqi@0: RuntimeHistogram->print(); aoqi@0: } aoqi@0: aoqi@0: if (CountJNICalls) { aoqi@0: extern Histogram *JNIHistogram; aoqi@0: JNIHistogram->print(); aoqi@0: } aoqi@0: aoqi@0: if (CountJVMCalls) { aoqi@0: extern Histogram *JVMHistogram; aoqi@0: JVMHistogram->print(); aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: if (MemProfiling) { aoqi@0: MemProfiler::disengage(); aoqi@0: } aoqi@0: aoqi@0: if (CITime) { aoqi@0: CompileBroker::print_times(); aoqi@0: } aoqi@0: aoqi@0: #ifdef COMPILER1 aoqi@0: if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) { aoqi@0: FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics); aoqi@0: Runtime1::print_statistics(); aoqi@0: Deoptimization::print_statistics(); aoqi@0: SharedRuntime::print_statistics(); aoqi@0: nmethod::print_statistics(); aoqi@0: } aoqi@0: #endif /* COMPILER1 */ aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { aoqi@0: FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); aoqi@0: Compile::print_statistics(); aoqi@0: #ifndef COMPILER1 aoqi@0: Deoptimization::print_statistics(); aoqi@0: nmethod::print_statistics(); aoqi@0: SharedRuntime::print_statistics(); aoqi@0: #endif //COMPILER1 aoqi@0: os::print_statistics(); aoqi@0: } aoqi@0: aoqi@0: if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { aoqi@0: OptoRuntime::print_named_counters(); aoqi@0: } aoqi@0: aoqi@0: if (TimeLivenessAnalysis) { aoqi@0: MethodLiveness::print_times(); aoqi@0: } aoqi@0: #ifdef ASSERT aoqi@0: if (CollectIndexSetStatistics) { aoqi@0: IndexSet::print_statistics(); aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: #endif // COMPILER2 aoqi@0: if (CountCompiledCalls) { aoqi@0: print_method_invocation_histogram(); aoqi@0: } aoqi@0: if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) { aoqi@0: print_method_profiling_data(); aoqi@0: } aoqi@0: if (TimeCompiler) { aoqi@0: COMPILER2_PRESENT(Compile::print_timers();) aoqi@0: } aoqi@0: if (TimeCompilationPolicy) { aoqi@0: CompilationPolicy::policy()->print_time(); aoqi@0: } aoqi@0: if (TimeOopMap) { aoqi@0: GenerateOopMap::print_time(); aoqi@0: } aoqi@0: if (ProfilerCheckIntervals) { aoqi@0: PeriodicTask::print_intervals(); aoqi@0: } aoqi@0: if (PrintSymbolTableSizeHistogram) { aoqi@0: SymbolTable::print_histogram(); aoqi@0: } aoqi@0: if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { aoqi@0: BytecodeCounter::print(); aoqi@0: } aoqi@0: if (PrintBytecodePairHistogram) { aoqi@0: BytecodePairHistogram::print(); aoqi@0: } aoqi@0: aoqi@0: if (PrintCodeCache) { aoqi@0: MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); aoqi@0: CodeCache::print(); aoqi@0: } aoqi@0: aoqi@0: if (PrintMethodFlushingStatistics) { aoqi@0: NMethodSweeper::print(); aoqi@0: } aoqi@0: aoqi@0: if (PrintCodeCache2) { aoqi@0: MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); aoqi@0: CodeCache::print_internals(); aoqi@0: } aoqi@0: aoqi@0: if (PrintClassStatistics) { aoqi@0: SystemDictionary::print_class_statistics(); aoqi@0: } aoqi@0: if (PrintMethodStatistics) { aoqi@0: SystemDictionary::print_method_statistics(); aoqi@0: } aoqi@0: aoqi@0: if (PrintVtableStats) { aoqi@0: klassVtable::print_statistics(); aoqi@0: klassItable::print_statistics(); aoqi@0: } aoqi@0: if (VerifyOops) { aoqi@0: tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); aoqi@0: } aoqi@0: aoqi@0: print_bytecode_count(); aoqi@0: if (PrintMallocStatistics) { aoqi@0: tty->print("allocation stats: "); aoqi@0: alloc_stats.print(); aoqi@0: tty->cr(); aoqi@0: } aoqi@0: aoqi@0: if (PrintSystemDictionaryAtExit) { aoqi@0: SystemDictionary::print(); aoqi@0: } aoqi@0: aoqi@0: if (PrintBiasedLockingStatistics) { aoqi@0: BiasedLocking::print_counters(); aoqi@0: } aoqi@0: aoqi@0: #ifdef ENABLE_ZAP_DEAD_LOCALS aoqi@0: #ifdef COMPILER2 aoqi@0: if (ZapDeadCompiledLocals) { aoqi@0: tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count); aoqi@0: tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count); aoqi@0: } aoqi@0: #endif // COMPILER2 aoqi@0: #endif // ENABLE_ZAP_DEAD_LOCALS aoqi@0: // Native memory tracking data aoqi@0: if (PrintNMTStatistics) { zgu@7074: MemTracker::final_report(tty); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #else // PRODUCT MODE STATISTICS aoqi@0: aoqi@0: void print_statistics() { aoqi@0: aoqi@0: if (CITime) { aoqi@0: CompileBroker::print_times(); aoqi@0: } aoqi@0: aoqi@0: if (PrintCodeCache) { aoqi@0: MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); aoqi@0: CodeCache::print(); aoqi@0: } aoqi@0: aoqi@0: if (PrintMethodFlushingStatistics) { aoqi@0: NMethodSweeper::print(); aoqi@0: } aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { aoqi@0: OptoRuntime::print_named_counters(); aoqi@0: } aoqi@0: #endif aoqi@0: if (PrintBiasedLockingStatistics) { aoqi@0: BiasedLocking::print_counters(); aoqi@0: } aoqi@0: aoqi@0: // Native memory tracking data aoqi@0: if (PrintNMTStatistics) { zgu@7074: MemTracker::final_report(tty); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: // Helper class for registering on_exit calls through JVM_OnExit aoqi@0: aoqi@0: extern "C" { aoqi@0: typedef void (*__exit_proc)(void); aoqi@0: } aoqi@0: aoqi@0: class ExitProc : public CHeapObj { aoqi@0: private: aoqi@0: __exit_proc _proc; aoqi@0: // void (*_proc)(void); aoqi@0: ExitProc* _next; aoqi@0: public: aoqi@0: // ExitProc(void (*proc)(void)) { aoqi@0: ExitProc(__exit_proc proc) { aoqi@0: _proc = proc; aoqi@0: _next = NULL; aoqi@0: } aoqi@0: void evaluate() { _proc(); } aoqi@0: ExitProc* next() const { return _next; } aoqi@0: void set_next(ExitProc* next) { _next = next; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Linked list of registered on_exit procedures aoqi@0: aoqi@0: static ExitProc* exit_procs = NULL; aoqi@0: aoqi@0: aoqi@0: extern "C" { aoqi@0: void register_on_exit_function(void (*func)(void)) { aoqi@0: ExitProc *entry = new ExitProc(func); aoqi@0: // Classic vm does not throw an exception in case the allocation failed, aoqi@0: if (entry != NULL) { aoqi@0: entry->set_next(exit_procs); aoqi@0: exit_procs = entry; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Note: before_exit() can be executed only once, if more than one threads aoqi@0: // are trying to shutdown the VM at the same time, only one thread aoqi@0: // can run before_exit() and all other threads must wait. aoqi@0: void before_exit(JavaThread * thread) { aoqi@0: #define BEFORE_EXIT_NOT_RUN 0 aoqi@0: #define BEFORE_EXIT_RUNNING 1 aoqi@0: #define BEFORE_EXIT_DONE 2 aoqi@0: static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; aoqi@0: aoqi@0: // Note: don't use a Mutex to guard the entire before_exit(), as aoqi@0: // JVMTI post_thread_end_event and post_vm_death_event will run native code. aoqi@0: // A CAS or OSMutex would work just fine but then we need to manipulate aoqi@0: // thread state for Safepoint. Here we use Monitor wait() and notify_all() aoqi@0: // for synchronization. aoqi@0: { MutexLocker ml(BeforeExit_lock); aoqi@0: switch (_before_exit_status) { aoqi@0: case BEFORE_EXIT_NOT_RUN: aoqi@0: _before_exit_status = BEFORE_EXIT_RUNNING; aoqi@0: break; aoqi@0: case BEFORE_EXIT_RUNNING: aoqi@0: while (_before_exit_status == BEFORE_EXIT_RUNNING) { aoqi@0: BeforeExit_lock->wait(); aoqi@0: } aoqi@0: assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); aoqi@0: return; aoqi@0: case BEFORE_EXIT_DONE: aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // The only difference between this and Win32's _onexit procs is that aoqi@0: // this version is invoked before any threads get killed. aoqi@0: ExitProc* current = exit_procs; aoqi@0: while (current != NULL) { aoqi@0: ExitProc* next = current->next(); aoqi@0: current->evaluate(); aoqi@0: delete current; aoqi@0: current = next; aoqi@0: } aoqi@0: aoqi@0: // Hang forever on exit if we're reporting an error. aoqi@0: if (ShowMessageBoxOnError && is_error_reported()) { aoqi@0: os::infinite_sleep(); aoqi@0: } aoqi@0: aoqi@0: // Terminate watcher thread - must before disenrolling any periodic task aoqi@0: if (PeriodicTask::num_tasks() > 0) aoqi@0: WatcherThread::stop(); aoqi@0: aoqi@0: // Print statistics gathered (profiling ...) aoqi@0: if (Arguments::has_profile()) { aoqi@0: FlatProfiler::disengage(); aoqi@0: FlatProfiler::print(10); aoqi@0: } aoqi@0: aoqi@0: // shut down the StatSampler task aoqi@0: StatSampler::disengage(); aoqi@0: StatSampler::destroy(); aoqi@0: aoqi@0: // Stop concurrent GC threads aoqi@0: Universe::heap()->stop(); aoqi@0: aoqi@0: // Print GC/heap related information. aoqi@0: if (PrintGCDetails) { aoqi@0: Universe::print(); aoqi@0: AdaptiveSizePolicyOutput(0); aoqi@0: if (Verbose) { aoqi@0: ClassLoaderDataGraph::dump_on(gclog_or_tty); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (PrintBytecodeHistogram) { aoqi@0: BytecodeHistogram::print(); aoqi@0: } aoqi@0: aoqi@0: if (JvmtiExport::should_post_thread_life()) { aoqi@0: JvmtiExport::post_thread_end(thread); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: EventThreadEnd event; aoqi@0: if (event.should_commit()) { aoqi@0: event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj())); aoqi@0: event.commit(); aoqi@0: } aoqi@0: aoqi@0: // Always call even when there are not JVMTI environments yet, since environments aoqi@0: // may be attached late and JVMTI must track phases of VM execution aoqi@0: JvmtiExport::post_vm_death(); aoqi@0: Threads::shutdown_vm_agents(); aoqi@0: aoqi@0: // Terminate the signal thread aoqi@0: // Note: we don't wait until it actually dies. aoqi@0: os::terminate_signal_thread(); aoqi@0: aoqi@0: print_statistics(); aoqi@0: Universe::heap()->print_tracing_info(); aoqi@0: aoqi@0: { MutexLocker ml(BeforeExit_lock); aoqi@0: _before_exit_status = BEFORE_EXIT_DONE; aoqi@0: BeforeExit_lock->notify_all(); aoqi@0: } aoqi@0: aoqi@0: if (VerifyStringTableAtExit) { aoqi@0: int fail_cnt = 0; aoqi@0: { aoqi@0: MutexLocker ml(StringTable_lock); aoqi@0: fail_cnt = StringTable::verify_and_compare_entries(); aoqi@0: } aoqi@0: aoqi@0: if (fail_cnt != 0) { aoqi@0: tty->print_cr("ERROR: fail_cnt=%d", fail_cnt); aoqi@0: guarantee(fail_cnt == 0, "unexpected StringTable verification failures"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #undef BEFORE_EXIT_NOT_RUN aoqi@0: #undef BEFORE_EXIT_RUNNING aoqi@0: #undef BEFORE_EXIT_DONE aoqi@0: } aoqi@0: aoqi@0: void vm_exit(int code) { aoqi@0: Thread* thread = ThreadLocalStorage::is_initialized() ? aoqi@0: ThreadLocalStorage::get_thread_slow() : NULL; aoqi@0: if (thread == NULL) { aoqi@0: // we have serious problems -- just exit aoqi@0: vm_direct_exit(code); aoqi@0: } aoqi@0: aoqi@0: if (VMThread::vm_thread() != NULL) { aoqi@0: // Fire off a VM_Exit operation to bring VM to a safepoint and exit aoqi@0: VM_Exit op(code); aoqi@0: if (thread->is_Java_thread()) aoqi@0: ((JavaThread*)thread)->set_thread_state(_thread_in_vm); aoqi@0: VMThread::execute(&op); aoqi@0: // should never reach here; but in case something wrong with VM Thread. aoqi@0: vm_direct_exit(code); aoqi@0: } else { aoqi@0: // VM thread is gone, just exit aoqi@0: vm_direct_exit(code); aoqi@0: } aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: void notify_vm_shutdown() { aoqi@0: // For now, just a dtrace probe. aoqi@0: #ifndef USDT2 aoqi@0: HS_DTRACE_PROBE(hotspot, vm__shutdown); aoqi@0: HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); aoqi@0: #else /* USDT2 */ aoqi@0: HOTSPOT_VM_SHUTDOWN(); aoqi@0: #endif /* USDT2 */ aoqi@0: } aoqi@0: aoqi@0: void vm_direct_exit(int code) { aoqi@0: notify_vm_shutdown(); aoqi@0: os::wait_for_keypress_at_exit(); aoqi@0: ::exit(code); aoqi@0: } aoqi@0: aoqi@0: void vm_perform_shutdown_actions() { aoqi@0: // Warning: do not call 'exit_globals()' here. All threads are still running. aoqi@0: // Calling 'exit_globals()' will disable thread-local-storage and cause all aoqi@0: // kinds of assertions to trigger in debug mode. aoqi@0: if (is_init_completed()) { aoqi@0: Thread* thread = ThreadLocalStorage::is_initialized() ? aoqi@0: ThreadLocalStorage::get_thread_slow() : NULL; aoqi@0: if (thread != NULL && thread->is_Java_thread()) { aoqi@0: // We are leaving the VM, set state to native (in case any OS exit aoqi@0: // handlers call back to the VM) aoqi@0: JavaThread* jt = (JavaThread*)thread; aoqi@0: // Must always be walkable or have no last_Java_frame when in aoqi@0: // thread_in_native aoqi@0: jt->frame_anchor()->make_walkable(jt); aoqi@0: jt->set_thread_state(_thread_in_native); aoqi@0: } aoqi@0: } aoqi@0: notify_vm_shutdown(); aoqi@0: } aoqi@0: aoqi@0: void vm_shutdown() aoqi@0: { aoqi@0: vm_perform_shutdown_actions(); aoqi@0: os::wait_for_keypress_at_exit(); aoqi@0: os::shutdown(); aoqi@0: } aoqi@0: aoqi@0: void vm_abort(bool dump_core) { aoqi@0: vm_perform_shutdown_actions(); aoqi@0: os::wait_for_keypress_at_exit(); aoqi@0: os::abort(dump_core); aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: void vm_notify_during_shutdown(const char* error, const char* message) { aoqi@0: if (error != NULL) { aoqi@0: tty->print_cr("Error occurred during initialization of VM"); aoqi@0: tty->print("%s", error); aoqi@0: if (message != NULL) { aoqi@0: tty->print_cr(": %s", message); aoqi@0: } aoqi@0: else { aoqi@0: tty->cr(); aoqi@0: } aoqi@0: } aoqi@0: if (ShowMessageBoxOnError && WizardMode) { aoqi@0: fatal("Error occurred during initialization of VM"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void vm_exit_during_initialization(Handle exception) { aoqi@0: tty->print_cr("Error occurred during initialization of VM"); aoqi@0: // If there are exceptions on this thread it must be cleared aoqi@0: // first and here. Any future calls to EXCEPTION_MARK requires aoqi@0: // that no pending exceptions exist. aoqi@0: Thread *THREAD = Thread::current(); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } aoqi@0: java_lang_Throwable::print(exception, tty); aoqi@0: tty->cr(); aoqi@0: java_lang_Throwable::print_stack_trace(exception(), tty); aoqi@0: tty->cr(); aoqi@0: vm_notify_during_shutdown(NULL, NULL); aoqi@0: aoqi@0: // Failure during initialization, we don't want to dump core aoqi@0: vm_abort(false); aoqi@0: } aoqi@0: aoqi@0: void vm_exit_during_initialization(Symbol* ex, const char* message) { aoqi@0: ResourceMark rm; aoqi@0: vm_notify_during_shutdown(ex->as_C_string(), message); aoqi@0: aoqi@0: // Failure during initialization, we don't want to dump core aoqi@0: vm_abort(false); aoqi@0: } aoqi@0: aoqi@0: void vm_exit_during_initialization(const char* error, const char* message) { aoqi@0: vm_notify_during_shutdown(error, message); aoqi@0: aoqi@0: // Failure during initialization, we don't want to dump core aoqi@0: vm_abort(false); aoqi@0: } aoqi@0: aoqi@0: void vm_shutdown_during_initialization(const char* error, const char* message) { aoqi@0: vm_notify_during_shutdown(error, message); aoqi@0: vm_shutdown(); aoqi@0: } aoqi@0: aoqi@0: JDK_Version JDK_Version::_current; aoqi@0: const char* JDK_Version::_runtime_name; aoqi@0: const char* JDK_Version::_runtime_version; aoqi@0: aoqi@0: void JDK_Version::initialize() { aoqi@0: jdk_version_info info; aoqi@0: assert(!_current.is_valid(), "Don't initialize twice"); aoqi@0: aoqi@0: void *lib_handle = os::native_java_library(); aoqi@0: jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, aoqi@0: os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); aoqi@0: aoqi@0: if (func == NULL) { aoqi@0: // JDK older than 1.6 aoqi@0: _current._partially_initialized = true; aoqi@0: } else { aoqi@0: (*func)(&info, sizeof(info)); aoqi@0: aoqi@0: int major = JDK_VERSION_MAJOR(info.jdk_version); aoqi@0: int minor = JDK_VERSION_MINOR(info.jdk_version); aoqi@0: int micro = JDK_VERSION_MICRO(info.jdk_version); aoqi@0: int build = JDK_VERSION_BUILD(info.jdk_version); aoqi@0: if (major == 1 && minor > 4) { aoqi@0: // We represent "1.5.0" as "5.0", but 1.4.2 as itself. aoqi@0: major = minor; aoqi@0: minor = micro; aoqi@0: micro = 0; aoqi@0: } aoqi@0: _current = JDK_Version(major, minor, micro, info.update_version, aoqi@0: info.special_update_version, build, aoqi@0: info.thread_park_blocker == 1, aoqi@0: info.post_vm_init_hook_enabled == 1, aoqi@0: info.pending_list_uses_discovered_field == 1); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void JDK_Version::fully_initialize( aoqi@0: uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) { aoqi@0: // This is only called when current is less than 1.6 and we've gotten aoqi@0: // far enough in the initialization to determine the exact version. aoqi@0: assert(major < 6, "not needed for JDK version >= 6"); aoqi@0: assert(is_partially_initialized(), "must not initialize"); aoqi@0: if (major < 5) { aoqi@0: // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc. aoqi@0: micro = minor; aoqi@0: minor = major; aoqi@0: major = 1; aoqi@0: } aoqi@0: _current = JDK_Version(major, minor, micro, update); aoqi@0: } aoqi@0: aoqi@0: void JDK_Version_init() { aoqi@0: JDK_Version::initialize(); aoqi@0: } aoqi@0: aoqi@0: static int64_t encode_jdk_version(const JDK_Version& v) { aoqi@0: return aoqi@0: ((int64_t)v.major_version() << (BitsPerByte * 5)) | aoqi@0: ((int64_t)v.minor_version() << (BitsPerByte * 4)) | aoqi@0: ((int64_t)v.micro_version() << (BitsPerByte * 3)) | aoqi@0: ((int64_t)v.update_version() << (BitsPerByte * 2)) | aoqi@0: ((int64_t)v.special_update_version() << (BitsPerByte * 1)) | aoqi@0: ((int64_t)v.build_number() << (BitsPerByte * 0)); aoqi@0: } aoqi@0: aoqi@0: int JDK_Version::compare(const JDK_Version& other) const { aoqi@0: assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); aoqi@0: if (!is_partially_initialized() && other.is_partially_initialized()) { aoqi@0: return -(other.compare(*this)); // flip the comparators aoqi@0: } aoqi@0: assert(!other.is_partially_initialized(), "Not initialized yet"); aoqi@0: if (is_partially_initialized()) { aoqi@0: assert(other.major_version() >= 6, aoqi@0: "Invalid JDK version comparison during initialization"); aoqi@0: return -1; aoqi@0: } else { aoqi@0: uint64_t e = encode_jdk_version(*this); aoqi@0: uint64_t o = encode_jdk_version(other); aoqi@0: return (e > o) ? 1 : ((e == o) ? 0 : -1); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void JDK_Version::to_string(char* buffer, size_t buflen) const { shshahma@8584: assert(buffer && buflen > 0, "call with useful buffer"); aoqi@0: size_t index = 0; aoqi@0: if (!is_valid()) { aoqi@0: jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); aoqi@0: } else if (is_partially_initialized()) { aoqi@0: jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); aoqi@0: } else { shshahma@8584: int rc = jio_snprintf( aoqi@0: &buffer[index], buflen - index, "%d.%d", _major, _minor); shshahma@8584: if (rc == -1) return; shshahma@8584: index += rc; aoqi@0: if (_micro > 0) { shshahma@8584: rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); shshahma@8584: if (rc == -1) return; shshahma@8584: index += rc; aoqi@0: } aoqi@0: if (_update > 0) { shshahma@8584: rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); shshahma@8584: if (rc == -1) return; shshahma@8584: index += rc; aoqi@0: } aoqi@0: if (_special > 0) { shshahma@8584: rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special); shshahma@8584: if (rc == -1) return; shshahma@8584: index += rc; aoqi@0: } aoqi@0: if (_build > 0) { shshahma@8584: rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); shshahma@8584: if (rc == -1) return; shshahma@8584: index += rc; aoqi@0: } aoqi@0: } aoqi@0: }