< prev index next >

src/hotspot/share/runtime/java.cpp

Print this page

  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 "cds/cds_globals.hpp"



 27 #include "cds/dynamicArchive.hpp"



 28 #include "classfile/classLoaderDataGraph.hpp"
 29 #include "classfile/javaClasses.hpp"
 30 #include "classfile/stringTable.hpp"
 31 #include "classfile/symbolTable.hpp"
 32 #include "classfile/systemDictionary.hpp"
 33 #include "code/codeCache.hpp"

 34 #include "compiler/compilationMemoryStatistic.hpp"
 35 #include "compiler/compileBroker.hpp"
 36 #include "compiler/compilerOracle.hpp"
 37 #include "gc/shared/collectedHeap.hpp"
 38 #include "gc/shared/stringdedup/stringDedup.hpp"
 39 #include "interpreter/bytecodeHistogram.hpp"

 40 #include "jfr/jfrEvents.hpp"
 41 #include "jfr/support/jfrThreadId.hpp"
 42 #include "jvm.h"
 43 #include "logging/log.hpp"
 44 #include "logging/logStream.hpp"
 45 #include "memory/metaspaceUtils.hpp"
 46 #include "memory/oopFactory.hpp"
 47 #include "memory/resourceArea.hpp"
 48 #include "memory/universe.hpp"
 49 #include "nmt/memTracker.hpp"
 50 #include "oops/constantPool.hpp"
 51 #include "oops/generateOopMap.hpp"
 52 #include "oops/instanceKlass.hpp"
 53 #include "oops/instanceOop.hpp"
 54 #include "oops/klassVtable.hpp"
 55 #include "oops/method.hpp"
 56 #include "oops/objArrayOop.hpp"
 57 #include "oops/oop.inline.hpp"
 58 #include "oops/symbol.hpp"

 59 #include "prims/jvmtiAgentList.hpp"
 60 #include "prims/jvmtiExport.hpp"

 61 #include "runtime/continuation.hpp"
 62 #include "runtime/deoptimization.hpp"
 63 #include "runtime/flags/flagSetting.hpp"

 64 #include "runtime/handles.inline.hpp"
 65 #include "runtime/init.hpp"
 66 #include "runtime/interfaceSupport.inline.hpp"
 67 #include "runtime/java.hpp"
 68 #include "runtime/javaThread.hpp"
 69 #include "runtime/sharedRuntime.hpp"
 70 #include "runtime/statSampler.hpp"
 71 #include "runtime/stubRoutines.hpp"
 72 #include "runtime/task.hpp"
 73 #include "runtime/threads.hpp"
 74 #include "runtime/timer.hpp"
 75 #include "runtime/trimNativeHeap.hpp"
 76 #include "runtime/vmOperations.hpp"
 77 #include "runtime/vmThread.hpp"
 78 #include "runtime/vm_version.hpp"
 79 #include "sanitizers/leak.hpp"
 80 #include "utilities/dtrace.hpp"
 81 #include "utilities/globalDefinitions.hpp"
 82 #include "utilities/macros.hpp"
 83 #include "utilities/vmError.hpp"

138 
139         ss.print_cr("------------------------------------------------------------------------");
140         m->print_invocation_count(&ss);
141         ss.print_cr("  mdo size: %d bytes", m->method_data()->size_in_bytes());
142         ss.cr();
143         // Dump data on parameters if any
144         if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
145           ss.fill_to(2);
146           m->method_data()->parameters_type_data()->print_data_on(&ss);
147         }
148         m->print_codes_on(&ss);
149         tty->print("%s", ss.as_string()); // print all at once
150         total_size += m->method_data()->size_in_bytes();
151       }
152       tty->print_cr("------------------------------------------------------------------------");
153       tty->print_cr("Total MDO size: %d bytes", total_size);
154     }
155   }
156 }
157 













































































158 
159 #ifndef PRODUCT
160 
161 // Statistics printing (method invocation histogram)
162 
163 GrowableArray<Method*>* collected_invoked_methods;
164 
165 void collect_invoked_methods(Method* m) {
166   if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
167     collected_invoked_methods->push(m);
168   }
169 }
170 
171 
172 // Invocation count accumulators should be unsigned long to shift the
173 // overflow border. Longer-running workloads tend to create invocation
174 // counts which already overflow 32-bit counters for individual methods.
175 void print_method_invocation_histogram() {
176   ResourceMark rm;
177   collected_invoked_methods = new GrowableArray<Method*>(1024);

206     if (m->is_synchronized()) synch_total  += iic + cic;
207     if (m->is_native())       native_total += iic + cic;
208     if (m->is_accessor())     access_total += iic + cic;
209   }
210   tty->cr();
211   total = int_total + comp_total;
212   special_total = final_total + static_total +synch_total + native_total + access_total;
213   tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
214   double total_div = (double)total;
215   tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%)  total",           total);
216   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total,     100.0 * (double)int_total    / total_div);
217   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled",    comp_total,    100.0 * (double)comp_total   / total_div);
218   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
219                                                                          special_total, 100.0 * (double)special_total/ total_div);
220   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- synchronized",synch_total,   100.0 * (double)synch_total  / total_div);
221   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- final",       final_total,   100.0 * (double)final_total  / total_div);
222   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- static",      static_total,  100.0 * (double)static_total / total_div);
223   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- native",      native_total,  100.0 * (double)native_total / total_div);
224   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- accessor",    access_total,  100.0 * (double)access_total / total_div);
225   tty->cr();
226   SharedRuntime::print_call_statistics(comp_total);
227 }
228 
229 void print_bytecode_count() {
230   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
231     tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
232   }
233 }
234 
235 #else
236 
237 void print_method_invocation_histogram() {}
238 void print_bytecode_count() {}
239 
240 #endif // PRODUCT
241 
242 
243 // General statistics printing (profiling ...)
244 void print_statistics() {



245   if (CITime) {
246     CompileBroker::print_times();
247   }
248 
249 #ifdef COMPILER1
250   if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
251     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
252     Runtime1::print_statistics();
253     SharedRuntime::print_statistics();
254   }
255 #endif /* COMPILER1 */
256 
257 #ifdef COMPILER2
258   if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
259     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
260     Compile::print_statistics();
261     Deoptimization::print_statistics();
262 #ifndef COMPILER1
263     SharedRuntime::print_statistics();
264 #endif //COMPILER1
265   }
266 
267   if (PrintLockStatistics || PrintPreciseRTMLockingStatistics) {
268     OptoRuntime::print_named_counters();
269   }
270 #ifdef ASSERT
271   if (CollectIndexSetStatistics) {
272     IndexSet::print_statistics();

299   if (PrintSymbolTableSizeHistogram) {
300     SymbolTable::print_histogram();
301   }
302   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
303     BytecodeCounter::print();
304   }
305   if (PrintBytecodePairHistogram) {
306     BytecodePairHistogram::print();
307   }
308 
309   if (PrintCodeCache) {
310     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
311     CodeCache::print();
312   }
313 
314   // CodeHeap State Analytics.
315   if (PrintCodeHeapAnalytics) {
316     CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
317   }
318 






319   if (PrintCodeCache2) {
320     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
321     CodeCache::print_internals();
322   }
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   }
335 
336   if (PrintClassLoaderDataGraphAtExit) {
337     ResourceMark rm;
338     MutexLocker mcld(ClassLoaderDataGraph_lock);
339     ClassLoaderDataGraph::print();
340   }
341 
342   // Native memory tracking data
343   if (PrintNMTStatistics) {
344     MemTracker::final_report(tty);
345   }
346 
347   if (PrintMetaspaceStatisticsAtExit) {
348     MetaspaceUtils::print_basic_report(tty, 0);
349   }
350 
351   if (CompilerOracle::should_print_final_memstat_report()) {
352     CompilationMemoryStatistic::print_all_by_size(tty, false, 0);
353   }
354 
355   ThreadsSMRSupport::log_statistics();


356 }
357 
358 // Note: before_exit() can be executed only once, if more than one threads
359 //       are trying to shutdown the VM at the same time, only one thread
360 //       can run before_exit() and all other threads must wait.
361 void before_exit(JavaThread* thread, bool halt) {
362   #define BEFORE_EXIT_NOT_RUN 0
363   #define BEFORE_EXIT_RUNNING 1
364   #define BEFORE_EXIT_DONE    2
365   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
366 
367   // Note: don't use a Mutex to guard the entire before_exit(), as
368   // JVMTI post_thread_end_event and post_vm_death_event will run native code.
369   // A CAS or OSMutex would work just fine but then we need to manipulate
370   // thread state for Safepoint. Here we use Monitor wait() and notify_all()
371   // for synchronization.
372   { MonitorLocker ml(BeforeExit_lock);
373     switch (_before_exit_status) {
374     case BEFORE_EXIT_NOT_RUN:
375       _before_exit_status = BEFORE_EXIT_RUNNING;

393   // this thread finishes before_exit().
394 
395   // Do not add any additional shutdown logic between the above mutex logic and
396   // leak sanitizer logic below. Any additional shutdown code which performs some
397   // cleanup should be added after the leak sanitizer logic below.
398 
399 #ifdef LEAK_SANITIZER
400   // If we are built with LSan, we need to perform leak checking. If we are
401   // terminating normally, not halting and no VM error, we perform a normal
402   // leak check which terminates if leaks are found. If we are not terminating
403   // normally, halting or VM error, we perform a recoverable leak check which
404   // prints leaks but will not terminate.
405   if (!halt && !VMError::is_error_reported()) {
406     LSAN_DO_LEAK_CHECK();
407   } else {
408     // Ignore the return value.
409     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
410   }
411 #endif
412 


413 #if INCLUDE_CDS



414   // Dynamic CDS dumping must happen whilst we can still reliably
415   // run Java code.
416   DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);





417   assert(!thread->has_pending_exception(), "must be");
418 #endif
419 
420 
421   // Actual shutdown logic begins here.
422 
423 #if INCLUDE_JVMCI
424   if (EnableJVMCI) {
425     JVMCI::shutdown(thread);
426   }
427 #endif
428 


429   // Hang forever on exit if we're reporting an error.
430   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
431     os::infinite_sleep();
432   }
433 
434   EventThreadEnd event;
435   if (event.should_commit()) {
436     event.set_thread(JFR_JVM_THREAD_ID(thread));
437     event.commit();
438   }
439 
440   JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
441 
442   // Stop the WatcherThread. We do this before disenrolling various
443   // PeriodicTasks to reduce the likelihood of races.
444   WatcherThread::stop();
445 
446   // shut down the StatSampler task
447   StatSampler::disengage();
448   StatSampler::destroy();
449 
450   NativeHeapTrimmer::cleanup();
451 
452   // Stop concurrent GC threads
453   Universe::heap()->stop();
454 
455   // Print GC/heap related information.
456   Log(gc, heap, exit) log;
457   if (log.is_info()) {
458     ResourceMark rm;
459     LogStream ls_info(log.info());
460     Universe::print_on(&ls_info);
461     if (log.is_trace()) {
462       LogStream ls_trace(log.trace());
463       MutexLocker mcld(ClassLoaderDataGraph_lock);
464       ClassLoaderDataGraph::print_on(&ls_trace);
465     }
466   }
467 
468   if (PrintBytecodeHistogram) {
469     BytecodeHistogram::print();
470   }
471 
472 #ifdef LINUX
473   if (DumpPerfMapAtExit) {
474     CodeCache::write_perf_map();
475   }
476 #endif
477 
478   if (JvmtiExport::should_post_thread_life()) {
479     JvmtiExport::post_thread_end(thread);
480   }
481 
482   // Always call even when there are not JVMTI environments yet, since environments
483   // may be attached late and JVMTI must track phases of VM execution
484   JvmtiExport::post_vm_death();
485   JvmtiAgentList::unload_agents();
486 
487   // Terminate the signal thread
488   // Note: we don't wait until it actually dies.
489   os::terminate_signal_thread();

  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 "cds/cds_globals.hpp"
 27 #include "cds/cdsConfig.hpp"
 28 #include "cds/classListWriter.hpp"
 29 #include "cds/classPrelinker.hpp"
 30 #include "cds/dynamicArchive.hpp"
 31 #include "cds/methodProfiler.hpp"
 32 #include "cds/metaspaceShared.hpp"
 33 #include "classfile/classLoader.hpp"
 34 #include "classfile/classLoaderDataGraph.hpp"
 35 #include "classfile/javaClasses.hpp"
 36 #include "classfile/stringTable.hpp"
 37 #include "classfile/symbolTable.hpp"
 38 #include "classfile/systemDictionary.hpp"
 39 #include "code/codeCache.hpp"
 40 #include "code/SCCache.hpp"
 41 #include "compiler/compilationMemoryStatistic.hpp"
 42 #include "compiler/compileBroker.hpp"
 43 #include "compiler/compilerOracle.hpp"
 44 #include "gc/shared/collectedHeap.hpp"
 45 #include "gc/shared/stringdedup/stringDedup.hpp"
 46 #include "interpreter/bytecodeHistogram.hpp"
 47 #include "interpreter/interpreterRuntime.hpp"
 48 #include "jfr/jfrEvents.hpp"
 49 #include "jfr/support/jfrThreadId.hpp"
 50 #include "jvm.h"
 51 #include "logging/log.hpp"
 52 #include "logging/logStream.hpp"
 53 #include "memory/metaspaceUtils.hpp"
 54 #include "memory/oopFactory.hpp"
 55 #include "memory/resourceArea.hpp"
 56 #include "memory/universe.hpp"
 57 #include "nmt/memTracker.hpp"
 58 #include "oops/constantPool.hpp"
 59 #include "oops/generateOopMap.hpp"
 60 #include "oops/instanceKlass.hpp"
 61 #include "oops/instanceOop.hpp"
 62 #include "oops/klassVtable.hpp"
 63 #include "oops/method.hpp"
 64 #include "oops/objArrayOop.hpp"
 65 #include "oops/oop.inline.hpp"
 66 #include "oops/symbol.hpp"
 67 #include "oops/trainingData.hpp"
 68 #include "prims/jvmtiAgentList.hpp"
 69 #include "prims/jvmtiExport.hpp"
 70 #include "prims/methodHandles.hpp"
 71 #include "runtime/continuation.hpp"
 72 #include "runtime/deoptimization.hpp"
 73 #include "runtime/flags/flagSetting.hpp"
 74 #include "runtime/globals_extension.hpp"
 75 #include "runtime/handles.inline.hpp"
 76 #include "runtime/init.hpp"
 77 #include "runtime/interfaceSupport.inline.hpp"
 78 #include "runtime/java.hpp"
 79 #include "runtime/javaThread.hpp"
 80 #include "runtime/sharedRuntime.hpp"
 81 #include "runtime/statSampler.hpp"
 82 #include "runtime/stubRoutines.hpp"
 83 #include "runtime/task.hpp"
 84 #include "runtime/threads.hpp"
 85 #include "runtime/timer.hpp"
 86 #include "runtime/trimNativeHeap.hpp"
 87 #include "runtime/vmOperations.hpp"
 88 #include "runtime/vmThread.hpp"
 89 #include "runtime/vm_version.hpp"
 90 #include "sanitizers/leak.hpp"
 91 #include "utilities/dtrace.hpp"
 92 #include "utilities/globalDefinitions.hpp"
 93 #include "utilities/macros.hpp"
 94 #include "utilities/vmError.hpp"

149 
150         ss.print_cr("------------------------------------------------------------------------");
151         m->print_invocation_count(&ss);
152         ss.print_cr("  mdo size: %d bytes", m->method_data()->size_in_bytes());
153         ss.cr();
154         // Dump data on parameters if any
155         if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
156           ss.fill_to(2);
157           m->method_data()->parameters_type_data()->print_data_on(&ss);
158         }
159         m->print_codes_on(&ss);
160         tty->print("%s", ss.as_string()); // print all at once
161         total_size += m->method_data()->size_in_bytes();
162       }
163       tty->print_cr("------------------------------------------------------------------------");
164       tty->print_cr("Total MDO size: %d bytes", total_size);
165     }
166   }
167 }
168 
169 void perf_jvm_print_on(outputStream* st);
170 
171 void log_vm_init_stats() {
172   LogStreamHandle(Info, init) log;
173   if (log.is_enabled()) {
174     SharedRuntime::print_counters_on(&log);
175     ClassLoader::print_counters();
176     ClassPrelinker::print_counters();
177     log.cr();
178     // FIXME: intermittent crashes
179 //    if (CountBytecodesPerThread) {
180 //      log.print_cr("Thread info:");
181 //      class PrintThreadInfo : public ThreadClosure {
182 //        outputStream* _st;
183 //      public:
184 //        PrintThreadInfo(outputStream* st) : ThreadClosure(), _st(st) {}
185 //        void do_thread(Thread* thread) {
186 //          JavaThread* jt = JavaThread::cast(thread);
187 //          if (jt->bc_counter_value() > 0) {
188 //            _st->print_cr("  Thread " INTPTR_FORMAT ": %ld bytecodes executed (clinit: %ld)",
189 //                          p2i(jt), /*jt->name(),*/ jt->bc_counter_value(), jt->clinit_bc_counter_value());
190 //          }
191 //        }
192 //      };
193 //      PrintThreadInfo cl(&log);
194 //      Threads::java_threads_do(&cl);
195 //    }
196 //    log.cr();
197     log.print("Deoptimization events: ");
198     Deoptimization::print_statistics_on(&log);
199     log.cr();
200 
201     log.print("Compilation statistics: ");
202     CompileBroker::print_statistics_on(&log);
203     log.cr();
204 
205     {
206       MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
207       log.print("Code cache statistics: ");
208       CodeCache::print_nmethod_statistics_on(&log);
209       log.cr();
210     }
211 
212     if (SCCache::is_on_for_read()) {
213       log.print_cr("Startup Code Cache: ");
214       SCCache::print_statistics_on(&log);
215       log.cr();
216       SCCache::print_timers_on(&log);
217     }
218 
219     VMThread::print_counters_on(&log);
220     log.cr();
221     MutexLockerImpl::print_counters_on(&log);
222     log.cr();
223     log.print("Runtime events for thread \"main\"");
224     if (ProfileRuntimeCalls) {
225       log.print_cr(" (%d nested events):", ProfileVMCallContext::nested_runtime_calls_count());
226 
227       Runtime1::print_counters_on(&log);
228       OptoRuntime::print_counters_on(&log);
229       InterpreterRuntime::print_counters_on(&log);
230       Deoptimization::print_counters_on(&log);
231     } else {
232       log.print_cr(": no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
233     }
234     log.cr();
235     perf_jvm_print_on(&log);
236     log.cr();
237     MethodHandles::print_counters_on(&log);
238   }
239 }
240 
241 void print_bytecode_count() {
242   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
243     tty->print_cr("[BytecodeCounter::counter_value = %ld]", BytecodeCounter::counter_value());
244   }
245 }
246 
247 #ifndef PRODUCT
248 
249 // Statistics printing (method invocation histogram)
250 
251 GrowableArray<Method*>* collected_invoked_methods;
252 
253 void collect_invoked_methods(Method* m) {
254   if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
255     collected_invoked_methods->push(m);
256   }
257 }
258 
259 
260 // Invocation count accumulators should be unsigned long to shift the
261 // overflow border. Longer-running workloads tend to create invocation
262 // counts which already overflow 32-bit counters for individual methods.
263 void print_method_invocation_histogram() {
264   ResourceMark rm;
265   collected_invoked_methods = new GrowableArray<Method*>(1024);

294     if (m->is_synchronized()) synch_total  += iic + cic;
295     if (m->is_native())       native_total += iic + cic;
296     if (m->is_accessor())     access_total += iic + cic;
297   }
298   tty->cr();
299   total = int_total + comp_total;
300   special_total = final_total + static_total +synch_total + native_total + access_total;
301   tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
302   double total_div = (double)total;
303   tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%)  total",           total);
304   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total,     100.0 * (double)int_total    / total_div);
305   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled",    comp_total,    100.0 * (double)comp_total   / total_div);
306   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
307                                                                          special_total, 100.0 * (double)special_total/ total_div);
308   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- synchronized",synch_total,   100.0 * (double)synch_total  / total_div);
309   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- final",       final_total,   100.0 * (double)final_total  / total_div);
310   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- static",      static_total,  100.0 * (double)static_total / total_div);
311   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- native",      native_total,  100.0 * (double)native_total / total_div);
312   tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%)    |- accessor",    access_total,  100.0 * (double)access_total / total_div);
313   tty->cr();
314   SharedRuntime::print_call_statistics_on(tty);






315 }
316 
317 #else
318 
319 void print_method_invocation_histogram() {}

320 
321 #endif // PRODUCT
322 
323 
324 // General statistics printing (profiling ...)
325 void print_statistics() {
326   if (ReplayTraining && PrintTrainingInfo) {
327     TrainingData::print_archived_training_data_on(tty);
328   }
329   if (CITime) {
330     CompileBroker::print_times();
331   }
332 
333 #ifdef COMPILER1
334   if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
335     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
336     Runtime1::print_statistics_on(tty);
337     SharedRuntime::print_statistics();
338   }
339 #endif /* COMPILER1 */
340 
341 #ifdef COMPILER2
342   if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
343     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
344     Compile::print_statistics();
345     Deoptimization::print_statistics();
346 #ifndef COMPILER1
347     SharedRuntime::print_statistics();
348 #endif //COMPILER1
349   }
350 
351   if (PrintLockStatistics || PrintPreciseRTMLockingStatistics) {
352     OptoRuntime::print_named_counters();
353   }
354 #ifdef ASSERT
355   if (CollectIndexSetStatistics) {
356     IndexSet::print_statistics();

383   if (PrintSymbolTableSizeHistogram) {
384     SymbolTable::print_histogram();
385   }
386   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
387     BytecodeCounter::print();
388   }
389   if (PrintBytecodePairHistogram) {
390     BytecodePairHistogram::print();
391   }
392 
393   if (PrintCodeCache) {
394     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
395     CodeCache::print();
396   }
397 
398   // CodeHeap State Analytics.
399   if (PrintCodeHeapAnalytics) {
400     CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
401   }
402 
403   LogStreamHandle(Debug, codecache, nmethod) log;
404   if (log.is_enabled()) {
405     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
406     CodeCache::print_nmethods_on(&log);
407   }
408 
409   if (PrintCodeCache2) {
410     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
411     CodeCache::print_internals();
412   }
413 
414   if (VerifyOops && Verbose) {
415     tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
416   }
417 
418   print_bytecode_count();
419 
420   if (PrintSystemDictionaryAtExit) {
421     ResourceMark rm;
422     MutexLocker mcld(ClassLoaderDataGraph_lock);
423     SystemDictionary::print();
424   }
425 
426   if (PrintClassLoaderDataGraphAtExit) {
427     ResourceMark rm;
428     MutexLocker mcld(ClassLoaderDataGraph_lock);
429     ClassLoaderDataGraph::print();
430   }
431 
432   // Native memory tracking data
433   if (PrintNMTStatistics) {
434     MemTracker::final_report(tty);
435   }
436 
437   if (PrintMetaspaceStatisticsAtExit) {
438     MetaspaceUtils::print_basic_report(tty, 0);
439   }
440 
441   if (CompilerOracle::should_print_final_memstat_report()) {
442     CompilationMemoryStatistic::print_all_by_size(tty, false, 0);
443   }
444 
445   ThreadsSMRSupport::log_statistics();
446 
447   log_vm_init_stats();
448 }
449 
450 // Note: before_exit() can be executed only once, if more than one threads
451 //       are trying to shutdown the VM at the same time, only one thread
452 //       can run before_exit() and all other threads must wait.
453 void before_exit(JavaThread* thread, bool halt) {
454   #define BEFORE_EXIT_NOT_RUN 0
455   #define BEFORE_EXIT_RUNNING 1
456   #define BEFORE_EXIT_DONE    2
457   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
458 
459   // Note: don't use a Mutex to guard the entire before_exit(), as
460   // JVMTI post_thread_end_event and post_vm_death_event will run native code.
461   // A CAS or OSMutex would work just fine but then we need to manipulate
462   // thread state for Safepoint. Here we use Monitor wait() and notify_all()
463   // for synchronization.
464   { MonitorLocker ml(BeforeExit_lock);
465     switch (_before_exit_status) {
466     case BEFORE_EXIT_NOT_RUN:
467       _before_exit_status = BEFORE_EXIT_RUNNING;

485   // this thread finishes before_exit().
486 
487   // Do not add any additional shutdown logic between the above mutex logic and
488   // leak sanitizer logic below. Any additional shutdown code which performs some
489   // cleanup should be added after the leak sanitizer logic below.
490 
491 #ifdef LEAK_SANITIZER
492   // If we are built with LSan, we need to perform leak checking. If we are
493   // terminating normally, not halting and no VM error, we perform a normal
494   // leak check which terminates if leaks are found. If we are not terminating
495   // normally, halting or VM error, we perform a recoverable leak check which
496   // prints leaks but will not terminate.
497   if (!halt && !VMError::is_error_reported()) {
498     LSAN_DO_LEAK_CHECK();
499   } else {
500     // Ignore the return value.
501     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
502   }
503 #endif
504 
505   MethodProfiler::process_method_hotness();
506 
507 #if INCLUDE_CDS
508   ClassListWriter::write_resolved_constants();
509   ClassListWriter::write_reflection_data();
510   ClassListWriter::write_loader_negative_lookup_cache();
511   // Dynamic CDS dumping must happen whilst we can still reliably
512   // run Java code.
513   if (CDSConfig::is_dumping_preimage_static_archive()) {
514     // Creating the hotspot.cds.preimage file
515     MetaspaceShared::preload_and_dump();
516   } else {
517     DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);
518   }
519   assert(!thread->has_pending_exception(), "must be");
520 #endif
521 

522   // Actual shutdown logic begins here.
523 
524 #if INCLUDE_JVMCI
525   if (EnableJVMCI) {
526     JVMCI::shutdown(thread);
527   }
528 #endif
529 
530   SCCache::close(); // Write final data and close archive
531 
532   // Hang forever on exit if we're reporting an error.
533   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
534     os::infinite_sleep();
535   }
536 
537   EventThreadEnd event;
538   if (event.should_commit()) {
539     event.set_thread(JFR_JVM_THREAD_ID(thread));
540     event.commit();
541   }
542 
543   JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
544 
545   // Stop the WatcherThread. We do this before disenrolling various
546   // PeriodicTasks to reduce the likelihood of races.
547   WatcherThread::stop();
548 
549   // shut down the StatSampler task
550   StatSampler::disengage();
551   StatSampler::destroy();
552 
553   NativeHeapTrimmer::cleanup();
554 
555   // Stop concurrent GC threads
556   Universe::heap()->stop();
557 
558   // Print GC/heap related information.
559   Log(gc, heap, exit) log;
560   if (log.is_info()) {
561     ResourceMark rm;
562     LogStream ls_info(log.info());
563     Universe::print_on(&ls_info);
564     if (log.is_trace()) {
565       LogStream ls_trace(log.trace());
566       MutexLocker mcld(ClassLoaderDataGraph_lock);
567       ClassLoaderDataGraph::print_on(&ls_trace);
568     }
569   }
570 
571   if (PrintBytecodeHistogram) {
572     BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
573   }
574 
575 #ifdef LINUX
576   if (DumpPerfMapAtExit) {
577     CodeCache::write_perf_map();
578   }
579 #endif
580 
581   if (JvmtiExport::should_post_thread_life()) {
582     JvmtiExport::post_thread_end(thread);
583   }
584 
585   // Always call even when there are not JVMTI environments yet, since environments
586   // may be attached late and JVMTI must track phases of VM execution
587   JvmtiExport::post_vm_death();
588   JvmtiAgentList::unload_agents();
589 
590   // Terminate the signal thread
591   // Note: we don't wait until it actually dies.
592   os::terminate_signal_thread();
< prev index next >