< prev index next >

src/hotspot/share/runtime/java.cpp

Print this page

  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 "cds/aotMetaspace.hpp"
 26 #include "cds/cds_globals.hpp"
 27 #include "cds/cdsConfig.hpp"
 28 #include "cds/classListWriter.hpp"
 29 #include "cds/dynamicArchive.hpp"

 30 #include "classfile/classLoader.hpp"
 31 #include "classfile/classLoaderDataGraph.hpp"
 32 #include "classfile/javaClasses.hpp"
 33 #include "classfile/stringTable.hpp"
 34 #include "classfile/symbolTable.hpp"
 35 #include "classfile/systemDictionary.hpp"

 36 #include "code/codeCache.hpp"
 37 #include "compiler/compilationMemoryStatistic.hpp"
 38 #include "compiler/compilationPolicy.hpp"
 39 #include "compiler/compileBroker.hpp"
 40 #include "compiler/compilerOracle.hpp"
 41 #include "gc/shared/collectedHeap.hpp"
 42 #include "gc/shared/stringdedup/stringDedup.hpp"
 43 #include "interpreter/bytecodeHistogram.hpp"

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

 64 #include "prims/jvmtiAgentList.hpp"
 65 #include "prims/jvmtiExport.hpp"

 66 #include "runtime/continuation.hpp"
 67 #include "runtime/deoptimization.hpp"
 68 #include "runtime/flags/flagSetting.hpp"

 69 #include "runtime/handles.inline.hpp"
 70 #include "runtime/init.hpp"
 71 #include "runtime/interfaceSupport.inline.hpp"
 72 #include "runtime/java.hpp"
 73 #include "runtime/javaThread.hpp"
 74 #include "runtime/os.hpp"
 75 #include "runtime/sharedRuntime.hpp"
 76 #include "runtime/stubRoutines.hpp"
 77 #include "runtime/task.hpp"
 78 #include "runtime/threads.hpp"
 79 #include "runtime/timer.hpp"
 80 #include "runtime/trimNativeHeap.hpp"
 81 #include "runtime/vm_version.hpp"
 82 #include "runtime/vmOperations.hpp"
 83 #include "runtime/vmThread.hpp"
 84 #include "sanitizers/leak.hpp"
 85 #include "utilities/dtrace.hpp"
 86 #include "utilities/events.hpp"
 87 #include "utilities/globalDefinitions.hpp"
 88 #include "utilities/macros.hpp"

145         ss.print_cr("------------------------------------------------------------------------");
146         m->print_invocation_count(&ss);
147         ss.print_cr("  mdo size: %d bytes", m->method_data()->size_in_bytes());
148         ss.cr();
149         // Dump data on parameters if any
150         if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
151           ss.fill_to(2);
152           m->method_data()->parameters_type_data()->print_data_on(&ss);
153         }
154         // Buffering to a stringStream, disable internal buffering so it's not done twice.
155         m->print_codes_on(&ss, 0, false);
156         tty->print("%s", ss.as_string()); // print all at once
157         total_size += m->method_data()->size_in_bytes();
158       }
159       tty->print_cr("------------------------------------------------------------------------");
160       tty->print_cr("Total MDO size: %d bytes", total_size);
161     }
162   }
163 }
164 


















































































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

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





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

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






325 #ifndef PRODUCT
326   if (PrintCodeCache2) {
327     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
328     CodeCache::print_internals();
329   }
330 #endif
331 
332   if (VerifyOops && Verbose) {
333     tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
334   }
335 
336   print_bytecode_count();
337 
338   if (PrintVMInfoAtExit) {
339     // Use an intermediate stream to prevent deadlocking on tty_lock
340     stringStream ss;
341     VMError::print_vm_info(&ss);
342     tty->print_raw(ss.base());
343   }
344 

352     ResourceMark rm;
353     MutexLocker mcld(ClassLoaderDataGraph_lock);
354     ClassLoaderDataGraph::print();
355   }
356 
357   // Native memory tracking data
358   if (PrintNMTStatistics) {
359     MemTracker::final_report(tty);
360   }
361 
362   if (PrintMetaspaceStatisticsAtExit) {
363     MetaspaceUtils::print_basic_report(tty, 0);
364   }
365 
366   if (PrintCompilerMemoryStatisticsAtExit) {
367     CompilationMemoryStatistic::print_final_report(tty);
368   }
369 
370   ThreadsSMRSupport::log_statistics();
371 


372   if (log_is_enabled(Info, perf, class, link)) {
373     LogStreamHandle(Info, perf, class, link) log;
374     log.print_cr("At VM exit:");
375     ClassLoader::print_counters(&log);
376   }
377 }
378 
379 // Note: before_exit() can be executed only once, if more than one threads
380 //       are trying to shutdown the VM at the same time, only one thread
381 //       can run before_exit() and all other threads must wait.
382 void before_exit(JavaThread* thread, bool halt) {
383   #define BEFORE_EXIT_NOT_RUN 0
384   #define BEFORE_EXIT_RUNNING 1
385   #define BEFORE_EXIT_DONE    2
386   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
387 
388   Events::log(thread, "Before exit entered");
389 
390   // Note: don't use a Mutex to guard the entire before_exit(), as
391   // JVMTI post_thread_end_event and post_vm_death_event will run native code.

417 
418   // Do not add any additional shutdown logic between the above mutex logic and
419   // leak sanitizer logic below. Any additional shutdown code which performs some
420   // cleanup should be added after the leak sanitizer logic below.
421 
422 #ifdef LEAK_SANITIZER
423   // If we are built with LSan, we need to perform leak checking. If we are
424   // terminating normally, not halting and no VM error, we perform a normal
425   // leak check which terminates if leaks are found. If we are not terminating
426   // normally, halting or VM error, we perform a recoverable leak check which
427   // prints leaks but will not terminate.
428   if (!halt && !VMError::is_error_reported()) {
429     LSAN_DO_LEAK_CHECK();
430   } else {
431     // Ignore the return value.
432     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
433   }
434 #endif
435 
436 #if INCLUDE_CDS

437   // Dynamic CDS dumping must happen whilst we can still reliably
438   // run Java code.
439   DynamicArchive::dump_at_exit(thread);
440   assert(!thread->has_pending_exception(), "must be");
441 #endif
442 
443   // Actual shutdown logic begins here.
444 
445 #if INCLUDE_JVMCI
446   if (EnableJVMCI) {
447     JVMCI::shutdown(thread);
448   }
449 #endif
450 
451 #if INCLUDE_CDS
452   ClassListWriter::write_resolved_constants();
453 
454   if (CDSConfig::is_dumping_preimage_static_archive()) {
455     AOTMetaspace::dump_static_archive(thread);
456   }
457 #endif
458 
459   // Hang forever on exit if we're reporting an error.
460   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
461     os::infinite_sleep();
462   }
463 
464   EventThreadEnd event;
465   if (event.should_commit()) {
466     event.set_thread(JFR_JVM_THREAD_ID(thread));
467     event.commit();
468   }
469 
470   JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
471 
472   // Stop the WatcherThread. We do this before disenrolling various
473   // PeriodicTasks to reduce the likelihood of races.
474   WatcherThread::stop();
475 
476   NativeHeapTrimmer::cleanup();
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   // No user code can be executed in the current thread after this point.
488 
489   // Run before exit and then stop concurrent GC threads.
490   Universe::before_exit();
491 
492   if (PrintBytecodeHistogram) {
493     BytecodeHistogram::print();
494   }
495 
496 #ifdef LINUX
497   if (DumpPerfMapAtExit) {
498     CodeCache::write_perf_map(nullptr, tty);
499   }
500   if (PrintMemoryMapAtExit) {
501     MemMapPrinter::print_all_mappings(tty);
502   }
503 #endif
504 
505   // Terminate the signal thread
506   // Note: we don't wait until it actually dies.
507   os::terminate_signal_thread();
508 
509   #if INCLUDE_CDS
510   if (AOTVerifyTrainingData) {
511     TrainingData::verify();
512   }
513   #endif
514 
515   print_statistics();
516 
517   { MutexLocker ml(BeforeExit_lock);
518     _before_exit_status = BEFORE_EXIT_DONE;
519     BeforeExit_lock->notify_all();
520   }
521 
522   if (VerifyStringTableAtExit) {
523     size_t fail_cnt = StringTable::verify_and_compare_entries();
524     if (fail_cnt != 0) {
525       tty->print_cr("ERROR: fail_cnt=%zu", fail_cnt);
526       guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
527     }
528   }
529 
530   #undef BEFORE_EXIT_NOT_RUN
531   #undef BEFORE_EXIT_RUNNING
532   #undef BEFORE_EXIT_DONE
533 }
534 
535 void vm_exit(int code) {

  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 "cds/aotLinkedClassBulkLoader.hpp"
 26 #include "cds/aotMetaspace.hpp"
 27 #include "cds/cds_globals.hpp"
 28 #include "cds/cdsConfig.hpp"
 29 #include "cds/classListWriter.hpp"
 30 #include "cds/dynamicArchive.hpp"
 31 #include "cds/methodProfiler.hpp"
 32 #include "classfile/classLoader.hpp"
 33 #include "classfile/classLoaderDataGraph.hpp"
 34 #include "classfile/javaClasses.hpp"
 35 #include "classfile/stringTable.hpp"
 36 #include "classfile/symbolTable.hpp"
 37 #include "classfile/systemDictionary.hpp"
 38 #include "code/aotCodeCache.hpp"
 39 #include "code/codeCache.hpp"
 40 #include "compiler/compilationMemoryStatistic.hpp"
 41 #include "compiler/compilationPolicy.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/memMapPrinter.hpp"
 58 #include "nmt/memTracker.hpp"
 59 #include "oops/constantPool.hpp"
 60 #include "oops/generateOopMap.hpp"
 61 #include "oops/instanceKlass.hpp"
 62 #include "oops/instanceOop.hpp"
 63 #include "oops/klassVtable.hpp"
 64 #include "oops/method.inline.hpp"
 65 #include "oops/objArrayOop.hpp"
 66 #include "oops/oop.inline.hpp"
 67 #include "oops/symbol.hpp"
 68 #include "oops/trainingData.hpp"
 69 #include "prims/jvmtiAgentList.hpp"
 70 #include "prims/jvmtiExport.hpp"
 71 #include "prims/methodHandles.hpp"
 72 #include "runtime/continuation.hpp"
 73 #include "runtime/deoptimization.hpp"
 74 #include "runtime/flags/flagSetting.hpp"
 75 #include "runtime/globals_extension.hpp"
 76 #include "runtime/handles.inline.hpp"
 77 #include "runtime/init.hpp"
 78 #include "runtime/interfaceSupport.inline.hpp"
 79 #include "runtime/java.hpp"
 80 #include "runtime/javaThread.hpp"
 81 #include "runtime/os.hpp"
 82 #include "runtime/sharedRuntime.hpp"
 83 #include "runtime/stubRoutines.hpp"
 84 #include "runtime/task.hpp"
 85 #include "runtime/threads.hpp"
 86 #include "runtime/timer.hpp"
 87 #include "runtime/trimNativeHeap.hpp"
 88 #include "runtime/vm_version.hpp"
 89 #include "runtime/vmOperations.hpp"
 90 #include "runtime/vmThread.hpp"
 91 #include "sanitizers/leak.hpp"
 92 #include "utilities/dtrace.hpp"
 93 #include "utilities/events.hpp"
 94 #include "utilities/globalDefinitions.hpp"
 95 #include "utilities/macros.hpp"

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

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

322 




323 }
324 
325 #else
326 
327 static void print_method_invocation_histogram() {}

328 
329 #endif // PRODUCT
330 
331 
332 // General statistics printing (profiling ...)
333 void print_statistics_before_exit() {
334 #if INCLUDE_CDS
335   if (AOTReplayTraining && AOTPrintTrainingInfo) {
336     TrainingData::print_archived_training_data_on(tty);
337   }
338 #endif
339   if (CITime) {
340     CompileBroker::print_times();
341   }
342 
343 #ifdef COMPILER1
344   if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
345     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
346     Runtime1::print_statistics_on(tty);
347     SharedRuntime::print_statistics();
348   }
349 #endif /* COMPILER1 */
350 
351 #ifdef COMPILER2
352   if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
353     FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
354     Compile::print_statistics();
355     Deoptimization::print_statistics();
356 #ifndef COMPILER1
357     SharedRuntime::print_statistics();
358 #endif //COMPILER1
359   }
360 
361   if (PrintLockStatistics) {
362     OptoRuntime::print_named_counters();
363   }
364 #ifdef ASSERT
365   if (CollectIndexSetStatistics) {
366     IndexSet::print_statistics();

393   if (PrintSymbolTableSizeHistogram) {
394     SymbolTable::print_histogram();
395   }
396   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
397     BytecodeCounter::print();
398   }
399   if (PrintBytecodePairHistogram) {
400     BytecodePairHistogram::print();
401   }
402 
403   if (PrintCodeCache) {
404     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
405     CodeCache::print();
406   }
407 
408   // CodeHeap State Analytics.
409   if (PrintCodeHeapAnalytics) {
410     CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
411   }
412 
413   LogStreamHandle(Debug, codecache, nmethod) log;
414   if (log.is_enabled()) {
415     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
416     CodeCache::print_nmethods_on(&log);
417   }
418 
419 #ifndef PRODUCT
420   if (PrintCodeCache2) {
421     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
422     CodeCache::print_internals();
423   }
424 #endif
425 
426   if (VerifyOops && Verbose) {
427     tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
428   }
429 
430   print_bytecode_count();
431 
432   if (PrintVMInfoAtExit) {
433     // Use an intermediate stream to prevent deadlocking on tty_lock
434     stringStream ss;
435     VMError::print_vm_info(&ss);
436     tty->print_raw(ss.base());
437   }
438 

446     ResourceMark rm;
447     MutexLocker mcld(ClassLoaderDataGraph_lock);
448     ClassLoaderDataGraph::print();
449   }
450 
451   // Native memory tracking data
452   if (PrintNMTStatistics) {
453     MemTracker::final_report(tty);
454   }
455 
456   if (PrintMetaspaceStatisticsAtExit) {
457     MetaspaceUtils::print_basic_report(tty, 0);
458   }
459 
460   if (PrintCompilerMemoryStatisticsAtExit) {
461     CompilationMemoryStatistic::print_final_report(tty);
462   }
463 
464   ThreadsSMRSupport::log_statistics();
465 
466   log_vm_init_stats();
467 
468   if (log_is_enabled(Info, perf, class, link)) {
469     LogStreamHandle(Info, perf, class, link) log;
470     log.print_cr("At VM exit:");
471     ClassLoader::print_counters(&log);
472   }
473 }
474 
475 // Note: before_exit() can be executed only once, if more than one threads
476 //       are trying to shutdown the VM at the same time, only one thread
477 //       can run before_exit() and all other threads must wait.
478 void before_exit(JavaThread* thread, bool halt) {
479   #define BEFORE_EXIT_NOT_RUN 0
480   #define BEFORE_EXIT_RUNNING 1
481   #define BEFORE_EXIT_DONE    2
482   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
483 
484   Events::log(thread, "Before exit entered");
485 
486   // Note: don't use a Mutex to guard the entire before_exit(), as
487   // JVMTI post_thread_end_event and post_vm_death_event will run native code.

513 
514   // Do not add any additional shutdown logic between the above mutex logic and
515   // leak sanitizer logic below. Any additional shutdown code which performs some
516   // cleanup should be added after the leak sanitizer logic below.
517 
518 #ifdef LEAK_SANITIZER
519   // If we are built with LSan, we need to perform leak checking. If we are
520   // terminating normally, not halting and no VM error, we perform a normal
521   // leak check which terminates if leaks are found. If we are not terminating
522   // normally, halting or VM error, we perform a recoverable leak check which
523   // prints leaks but will not terminate.
524   if (!halt && !VMError::is_error_reported()) {
525     LSAN_DO_LEAK_CHECK();
526   } else {
527     // Ignore the return value.
528     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
529   }
530 #endif
531 
532 #if INCLUDE_CDS
533   MethodProfiler::process_method_hotness();
534   // Dynamic CDS dumping must happen whilst we can still reliably
535   // run Java code.
536   DynamicArchive::dump_at_exit(thread);
537   assert(!thread->has_pending_exception(), "must be");
538 #endif
539 
540   // Actual shutdown logic begins here.
541 
542 #if INCLUDE_JVMCI
543   if (EnableJVMCI) {
544     JVMCI::shutdown(thread);
545   }
546 #endif
547 
548 #if INCLUDE_CDS
549   ClassListWriter::write_resolved_constants();
550   ClassListWriter::write_loader_negative_lookup_cache();
551   if (CDSConfig::is_dumping_preimage_static_archive()) {
552     AOTMetaspace::dump_static_archive(thread);
553   }
554 #endif
555 
556   // Hang forever on exit if we're reporting an error.
557   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
558     os::infinite_sleep();
559   }
560 
561   EventThreadEnd event;
562   if (event.should_commit()) {
563     event.set_thread(JFR_JVM_THREAD_ID(thread));
564     event.commit();
565   }
566 
567   JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
568 
569   // Stop the WatcherThread. We do this before disenrolling various
570   // PeriodicTasks to reduce the likelihood of races.
571   WatcherThread::stop();
572 
573   NativeHeapTrimmer::cleanup();
574 
575   if (JvmtiExport::should_post_thread_life()) {
576     JvmtiExport::post_thread_end(thread);
577   }
578 
579   // Always call even when there are not JVMTI environments yet, since environments
580   // may be attached late and JVMTI must track phases of VM execution.
581   JvmtiExport::post_vm_death();
582   JvmtiAgentList::unload_agents();
583 
584   // No user code can be executed in the current thread after this point.
585 
586   // Run before exit and then stop concurrent GC threads.
587   Universe::before_exit();
588 
589   if (PrintBytecodeHistogram) {
590     BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
591   }
592 
593 #ifdef LINUX
594   if (DumpPerfMapAtExit) {
595     CodeCache::write_perf_map(nullptr, tty);
596   }
597   if (PrintMemoryMapAtExit) {
598     MemMapPrinter::print_all_mappings(tty);
599   }
600 #endif
601 
602   // Terminate the signal thread
603   // Note: we don't wait until it actually dies.
604   os::terminate_signal_thread();
605 
606   #if INCLUDE_CDS
607   if (AOTVerifyTrainingData) {
608     TrainingData::verify();
609   }
610   #endif
611 
612   print_statistics_before_exit();
613 
614   { MutexLocker ml(BeforeExit_lock);
615     _before_exit_status = BEFORE_EXIT_DONE;
616     BeforeExit_lock->notify_all();
617   }
618 
619   if (VerifyStringTableAtExit) {
620     size_t fail_cnt = StringTable::verify_and_compare_entries();
621     if (fail_cnt != 0) {
622       tty->print_cr("ERROR: fail_cnt=%zu", fail_cnt);
623       guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
624     }
625   }
626 
627   #undef BEFORE_EXIT_NOT_RUN
628   #undef BEFORE_EXIT_RUNNING
629   #undef BEFORE_EXIT_DONE
630 }
631 
632 void vm_exit(int code) {
< prev index next >