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

 28 #include "cds/dynamicArchive.hpp"


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

 36 #include "compiler/compilationMemoryStatistic.hpp"

 37 #include "compiler/compileBroker.hpp"
 38 #include "compiler/compilerOracle.hpp"
 39 #include "gc/shared/collectedHeap.hpp"
 40 #include "gc/shared/stringdedup/stringDedup.hpp"
 41 #include "interpreter/bytecodeHistogram.hpp"

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

 62 #include "prims/jvmtiAgentList.hpp"
 63 #include "prims/jvmtiExport.hpp"

 64 #include "runtime/continuation.hpp"
 65 #include "runtime/deoptimization.hpp"
 66 #include "runtime/flags/flagSetting.hpp"

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

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

















































































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

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



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

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






322 #ifndef PRODUCT
323   if (PrintCodeCache2) {
324     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
325     CodeCache::print_internals();
326   }
327 #endif
328 
329   if (VerifyOops && Verbose) {
330     tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
331   }
332 
333   print_bytecode_count();
334 
335   if (PrintSystemDictionaryAtExit) {
336     ResourceMark rm;
337     MutexLocker mcld(ClassLoaderDataGraph_lock);
338     SystemDictionary::print();
339   }
340 
341   if (PrintClassLoaderDataGraphAtExit) {
342     ResourceMark rm;
343     MutexLocker mcld(ClassLoaderDataGraph_lock);
344     ClassLoaderDataGraph::print();
345   }
346 
347   // Native memory tracking data
348   if (PrintNMTStatistics) {
349     MemTracker::final_report(tty);
350   }
351 
352   if (PrintMetaspaceStatisticsAtExit) {
353     MetaspaceUtils::print_basic_report(tty, 0);
354   }
355 
356   if (CompilerOracle::should_print_final_memstat_report()) {
357     CompilationMemoryStatistic::print_all_by_size(tty, false, 0);
358   }
359 
360   ThreadsSMRSupport::log_statistics();
361 
362   ClassLoader::print_counters(tty);
363 }
364 
365 // Note: before_exit() can be executed only once, if more than one threads
366 //       are trying to shutdown the VM at the same time, only one thread
367 //       can run before_exit() and all other threads must wait.
368 void before_exit(JavaThread* thread, bool halt) {
369   #define BEFORE_EXIT_NOT_RUN 0
370   #define BEFORE_EXIT_RUNNING 1
371   #define BEFORE_EXIT_DONE    2
372   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
373 
374   Events::log(thread, "Before exit entered");
375 
376   // Note: don't use a Mutex to guard the entire before_exit(), as
377   // JVMTI post_thread_end_event and post_vm_death_event will run native code.
378   // A CAS or OSMutex would work just fine but then we need to manipulate
379   // thread state for Safepoint. Here we use Monitor wait() and notify_all()
380   // for synchronization.
381   { MonitorLocker ml(BeforeExit_lock);
382     switch (_before_exit_status) {

402   // this thread finishes before_exit().
403 
404   // Do not add any additional shutdown logic between the above mutex logic and
405   // leak sanitizer logic below. Any additional shutdown code which performs some
406   // cleanup should be added after the leak sanitizer logic below.
407 
408 #ifdef LEAK_SANITIZER
409   // If we are built with LSan, we need to perform leak checking. If we are
410   // terminating normally, not halting and no VM error, we perform a normal
411   // leak check which terminates if leaks are found. If we are not terminating
412   // normally, halting or VM error, we perform a recoverable leak check which
413   // prints leaks but will not terminate.
414   if (!halt && !VMError::is_error_reported()) {
415     LSAN_DO_LEAK_CHECK();
416   } else {
417     // Ignore the return value.
418     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
419   }
420 #endif
421 
422 #if INCLUDE_CDS
423   // Dynamic CDS dumping must happen whilst we can still reliably
424   // run Java code.
425   DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);
426   assert(!thread->has_pending_exception(), "must be");
427 #endif
428 
429 
430   // Actual shutdown logic begins here.
431 
432 #if INCLUDE_JVMCI
433   if (EnableJVMCI) {
434     JVMCI::shutdown(thread);
435   }
436 #endif
437 
438 #if INCLUDE_CDS
439   ClassListWriter::write_resolved_constants();











440 #endif
441 


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





507   print_statistics();
508   Universe::heap()->print_tracing_info();
509 
510   { MutexLocker ml(BeforeExit_lock);
511     _before_exit_status = BEFORE_EXIT_DONE;
512     BeforeExit_lock->notify_all();
513   }
514 
515   if (VerifyStringTableAtExit) {
516     size_t fail_cnt = StringTable::verify_and_compare_entries();
517     if (fail_cnt != 0) {
518       tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt);
519       guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
520     }
521   }
522 
523   #undef BEFORE_EXIT_NOT_RUN
524   #undef BEFORE_EXIT_RUNNING
525   #undef BEFORE_EXIT_DONE
526 }

  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/classPreloader.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/compilationPolicy.hpp"
 43 #include "compiler/compileBroker.hpp"
 44 #include "compiler/compilerOracle.hpp"
 45 #include "gc/shared/collectedHeap.hpp"
 46 #include "gc/shared/stringdedup/stringDedup.hpp"
 47 #include "interpreter/bytecodeHistogram.hpp"
 48 #include "interpreter/interpreterRuntime.hpp"
 49 #include "jfr/jfrEvents.hpp"
 50 #include "jfr/support/jfrThreadId.hpp"
 51 #include "jvm.h"
 52 #include "logging/log.hpp"
 53 #include "logging/logStream.hpp"
 54 #include "memory/metaspaceUtils.hpp"
 55 #include "memory/oopFactory.hpp"
 56 #include "memory/resourceArea.hpp"
 57 #include "memory/universe.hpp"
 58 #include "nmt/memMapPrinter.hpp"
 59 #include "nmt/memTracker.hpp"
 60 #include "oops/constantPool.hpp"
 61 #include "oops/generateOopMap.hpp"
 62 #include "oops/instanceKlass.hpp"
 63 #include "oops/instanceOop.hpp"
 64 #include "oops/klassVtable.hpp"
 65 #include "oops/method.hpp"
 66 #include "oops/objArrayOop.hpp"
 67 #include "oops/oop.inline.hpp"
 68 #include "oops/symbol.hpp"
 69 #include "oops/trainingData.hpp"
 70 #include "prims/jvmtiAgentList.hpp"
 71 #include "prims/jvmtiExport.hpp"
 72 #include "prims/methodHandles.hpp"
 73 #include "runtime/continuation.hpp"
 74 #include "runtime/deoptimization.hpp"
 75 #include "runtime/flags/flagSetting.hpp"
 76 #include "runtime/globals_extension.hpp"
 77 #include "runtime/handles.inline.hpp"
 78 #include "runtime/init.hpp"
 79 #include "runtime/interfaceSupport.inline.hpp"
 80 #include "runtime/java.hpp"
 81 #include "runtime/javaThread.hpp"
 82 #include "runtime/sharedRuntime.hpp"
 83 #include "runtime/statSampler.hpp"
 84 #include "runtime/stubRoutines.hpp"
 85 #include "runtime/task.hpp"
 86 #include "runtime/threads.hpp"
 87 #include "runtime/timer.hpp"
 88 #include "runtime/trimNativeHeap.hpp"
 89 #include "runtime/vmOperations.hpp"
 90 #include "runtime/vmThread.hpp"
 91 #include "runtime/vm_version.hpp"
 92 #include "sanitizers/leak.hpp"
 93 #include "utilities/dtrace.hpp"
 94 #include "utilities/events.hpp"
 95 #include "utilities/globalDefinitions.hpp"
 96 #include "utilities/macros.hpp"

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

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






321 }
322 
323 #else
324 
325 static void print_method_invocation_histogram() {}

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

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

495   // this thread finishes before_exit().
496 
497   // Do not add any additional shutdown logic between the above mutex logic and
498   // leak sanitizer logic below. Any additional shutdown code which performs some
499   // cleanup should be added after the leak sanitizer logic below.
500 
501 #ifdef LEAK_SANITIZER
502   // If we are built with LSan, we need to perform leak checking. If we are
503   // terminating normally, not halting and no VM error, we perform a normal
504   // leak check which terminates if leaks are found. If we are not terminating
505   // normally, halting or VM error, we perform a recoverable leak check which
506   // prints leaks but will not terminate.
507   if (!halt && !VMError::is_error_reported()) {
508     LSAN_DO_LEAK_CHECK();
509   } else {
510     // Ignore the return value.
511     static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
512   }
513 #endif
514 
515   MethodProfiler::process_method_hotness();






516 
517   // Actual shutdown logic begins here.
518 
519 #if INCLUDE_JVMCI
520   if (EnableJVMCI) {
521     JVMCI::shutdown(thread);
522   }
523 #endif
524 
525 #if INCLUDE_CDS
526   ClassListWriter::write_resolved_constants();
527   ClassListWriter::write_reflection_data();
528   ClassListWriter::write_loader_negative_lookup_cache();
529   // Dynamic CDS dumping must happen whilst we can still reliably
530   // run Java code.
531   if (CDSConfig::is_dumping_preimage_static_archive()) {
532     // Creating the hotspot.cds.preimage file
533     MetaspaceShared::preload_and_dump(thread);
534   } else {
535     DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);
536   }
537   assert(!thread->has_pending_exception(), "must be");
538 #endif
539 
540   SCCache::close(); // Write final data and close archive
541 
542   // Hang forever on exit if we're reporting an error.
543   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
544     os::infinite_sleep();
545   }
546 
547   EventThreadEnd event;
548   if (event.should_commit()) {
549     event.set_thread(JFR_JVM_THREAD_ID(thread));
550     event.commit();
551   }
552 
553   JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
554 
555   // Stop the WatcherThread. We do this before disenrolling various
556   // PeriodicTasks to reduce the likelihood of races.
557   WatcherThread::stop();
558 
559   // shut down the StatSampler task
560   StatSampler::disengage();
561   StatSampler::destroy();
562 
563   NativeHeapTrimmer::cleanup();
564 
565   // Stop concurrent GC threads
566   Universe::heap()->stop();
567 
568   // Print GC/heap related information.
569   Log(gc, heap, exit) log;
570   if (log.is_info()) {
571     ResourceMark rm;
572     LogStream ls_info(log.info());
573     Universe::print_on(&ls_info);
574     if (log.is_trace()) {
575       LogStream ls_trace(log.trace());
576       MutexLocker mcld(ClassLoaderDataGraph_lock);
577       ClassLoaderDataGraph::print_on(&ls_trace);
578     }
579   }
580 
581   if (PrintBytecodeHistogram) {
582     BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
583   }
584 
585 #ifdef LINUX
586   if (DumpPerfMapAtExit) {
587     CodeCache::write_perf_map();
588   }
589   if (PrintMemoryMapAtExit) {
590     MemMapPrinter::print_all_mappings(tty);
591   }
592 #endif
593 
594   if (JvmtiExport::should_post_thread_life()) {
595     JvmtiExport::post_thread_end(thread);
596   }
597 
598   // Always call even when there are not JVMTI environments yet, since environments
599   // may be attached late and JVMTI must track phases of VM execution
600   JvmtiExport::post_vm_death();
601   JvmtiAgentList::unload_agents();
602 
603   // Terminate the signal thread
604   // Note: we don't wait until it actually dies.
605   os::terminate_signal_thread();
606 
607   if (VerifyTrainingData) {
608     EXCEPTION_MARK;
609     CompilationPolicy::replay_training_at_init(true, THREAD); // implies TrainingData::verify()
610   }
611 
612   print_statistics();
613   Universe::heap()->print_tracing_info();
614 
615   { MutexLocker ml(BeforeExit_lock);
616     _before_exit_status = BEFORE_EXIT_DONE;
617     BeforeExit_lock->notify_all();
618   }
619 
620   if (VerifyStringTableAtExit) {
621     size_t fail_cnt = StringTable::verify_and_compare_entries();
622     if (fail_cnt != 0) {
623       tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt);
624       guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
625     }
626   }
627 
628   #undef BEFORE_EXIT_NOT_RUN
629   #undef BEFORE_EXIT_RUNNING
630   #undef BEFORE_EXIT_DONE
631 }
< prev index next >