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/cds_globals.hpp"
26 #include "cds/cdsConfig.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.inline.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 = %zu]", 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 (PrintCompilerMemoryStatisticsAtExit) {
357 CompilationMemoryStatistic::print_final_report(tty);
358 }
359
360 ThreadsSMRSupport::log_statistics();
361
362 if (log_is_enabled(Info, perf, class, link)) {
363 LogStreamHandle(Info, perf, class, link) log;
364 log.print_cr("At VM exit:");
365 ClassLoader::print_counters(&log);
366 }
367 }
368
369 // Note: before_exit() can be executed only once, if more than one threads
370 // are trying to shutdown the VM at the same time, only one thread
371 // can run before_exit() and all other threads must wait.
372 void before_exit(JavaThread* thread, bool halt) {
373 #define BEFORE_EXIT_NOT_RUN 0
374 #define BEFORE_EXIT_RUNNING 1
375 #define BEFORE_EXIT_DONE 2
376 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
377
378 Events::log(thread, "Before exit entered");
379
380 // Note: don't use a Mutex to guard the entire before_exit(), as
381 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
407
408 // Do not add any additional shutdown logic between the above mutex logic and
409 // leak sanitizer logic below. Any additional shutdown code which performs some
410 // cleanup should be added after the leak sanitizer logic below.
411
412 #ifdef LEAK_SANITIZER
413 // If we are built with LSan, we need to perform leak checking. If we are
414 // terminating normally, not halting and no VM error, we perform a normal
415 // leak check which terminates if leaks are found. If we are not terminating
416 // normally, halting or VM error, we perform a recoverable leak check which
417 // prints leaks but will not terminate.
418 if (!halt && !VMError::is_error_reported()) {
419 LSAN_DO_LEAK_CHECK();
420 } else {
421 // Ignore the return value.
422 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
423 }
424 #endif
425
426 #if INCLUDE_CDS
427 // Dynamic CDS dumping must happen whilst we can still reliably
428 // run Java code.
429 DynamicArchive::dump_at_exit(thread);
430 assert(!thread->has_pending_exception(), "must be");
431 #endif
432
433 // Actual shutdown logic begins here.
434
435 #if INCLUDE_JVMCI
436 if (EnableJVMCI) {
437 JVMCI::shutdown(thread);
438 }
439 #endif
440
441 #if INCLUDE_CDS
442 ClassListWriter::write_resolved_constants();
443
444 if (CDSConfig::is_dumping_preimage_static_archive()) {
445 MetaspaceShared::preload_and_dump(thread);
446 }
447 #endif
448
449 // Hang forever on exit if we're reporting an error.
450 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
451 os::infinite_sleep();
452 }
453
454 EventThreadEnd event;
455 if (event.should_commit()) {
456 event.set_thread(JFR_JVM_THREAD_ID(thread));
457 event.commit();
458 }
459
460 JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
461
462 // Stop the WatcherThread. We do this before disenrolling various
463 // PeriodicTasks to reduce the likelihood of races.
464 WatcherThread::stop();
465
466 // shut down the StatSampler task
467 StatSampler::disengage();
468 StatSampler::destroy();
469
470 NativeHeapTrimmer::cleanup();
471
472 // Stop concurrent GC threads
473 Universe::heap()->stop();
474
475 // Print GC/heap related information.
476 Log(gc, heap, exit) log;
477 if (log.is_info()) {
478 LogStream ls_info(log.info());
479 Universe::print_on(&ls_info);
480 if (log.is_trace()) {
481 LogStream ls_trace(log.trace());
482 MutexLocker mcld(ClassLoaderDataGraph_lock);
483 ClassLoaderDataGraph::print_on(&ls_trace);
484 }
485 }
486
487 if (PrintBytecodeHistogram) {
488 BytecodeHistogram::print();
489 }
490
491 #ifdef LINUX
492 if (DumpPerfMapAtExit) {
493 CodeCache::write_perf_map(nullptr, tty);
494 }
495 if (PrintMemoryMapAtExit) {
496 MemMapPrinter::print_all_mappings(tty);
497 }
498 #endif
499
500 if (JvmtiExport::should_post_thread_life()) {
501 JvmtiExport::post_thread_end(thread);
502 }
503
504 // Always call even when there are not JVMTI environments yet, since environments
505 // may be attached late and JVMTI must track phases of VM execution
506 JvmtiExport::post_vm_death();
507 JvmtiAgentList::unload_agents();
508
509 // Terminate the signal thread
510 // Note: we don't wait until it actually dies.
511 os::terminate_signal_thread();
512
513 print_statistics();
514 Universe::heap()->print_tracing_info();
515
516 { MutexLocker ml(BeforeExit_lock);
517 _before_exit_status = BEFORE_EXIT_DONE;
518 BeforeExit_lock->notify_all();
519 }
520
521 if (VerifyStringTableAtExit) {
522 size_t fail_cnt = StringTable::verify_and_compare_entries();
523 if (fail_cnt != 0) {
524 tty->print_cr("ERROR: fail_cnt=%zu", fail_cnt);
525 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
526 }
527 }
528
529 #undef BEFORE_EXIT_NOT_RUN
530 #undef BEFORE_EXIT_RUNNING
531 #undef BEFORE_EXIT_DONE
532 }
|
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/cds_globals.hpp"
27 #include "cds/cdsConfig.hpp"
28 #include "cds/classListWriter.hpp"
29 #include "cds/dynamicArchive.hpp"
30 #include "cds/methodProfiler.hpp"
31 #include "cds/metaspaceShared.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/codeCache.hpp"
39 #include "code/aotCodeCache.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/sharedRuntime.hpp"
82 #include "runtime/statSampler.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/vmOperations.hpp"
89 #include "runtime/vmThread.hpp"
90 #include "runtime/vm_version.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"
151
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 m->print_codes_on(&ss);
162 tty->print("%s", ss.as_string()); // print all at once
163 total_size += m->method_data()->size_in_bytes();
164 }
165 tty->print_cr("------------------------------------------------------------------------");
166 tty->print_cr("Total MDO size: %d bytes", total_size);
167 }
168 }
169 }
170
171 void perf_jvm_print_on(outputStream* st);
172
173 void log_vm_init_stats() {
174 LogStreamHandle(Info, init) log;
175 if (log.is_enabled()) {
176 SharedRuntime::print_counters_on(&log);
177 ClassLoader::print_counters(&log);
178 AOTLinkedClassBulkLoader::print_counters_on(&log);
179 log.cr();
180 // FIXME: intermittent crashes
181 // if (CountBytecodesPerThread) {
182 // log.print_cr("Thread info:");
183 // class PrintThreadInfo : public ThreadClosure {
184 // outputStream* _st;
185 // public:
186 // PrintThreadInfo(outputStream* st) : ThreadClosure(), _st(st) {}
187 // void do_thread(Thread* thread) {
188 // JavaThread* jt = JavaThread::cast(thread);
189 // if (jt->bc_counter_value() > 0) {
190 // _st->print_cr(" Thread " INTPTR_FORMAT ": %ld bytecodes executed (clinit: %ld)",
191 // p2i(jt), /*jt->name(),*/ jt->bc_counter_value(), jt->clinit_bc_counter_value());
192 // }
193 // }
194 // };
195 // PrintThreadInfo cl(&log);
196 // Threads::java_threads_do(&cl);
197 // }
198 // log.cr();
199 log.print_cr("Deoptimization events: ");
200 Deoptimization::print_statistics_on(&log);
201 log.cr();
202
203 log.print("Compilation statistics: ");
204 CompileBroker::print_statistics_on(&log);
205 log.cr();
206
207 {
208 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
209 log.print("Code cache statistics: ");
210 CodeCache::print_nmethod_statistics_on(&log);
211 log.cr();
212 }
213
214 if (AOTCodeCache::is_on_for_read()) {
215 log.print_cr("Startup Code Cache: ");
216 AOTCodeCache::print_statistics_on(&log);
217 log.cr();
218 AOTCodeCache::print_timers_on(&log);
219 }
220
221 VMThread::print_counters_on(&log);
222 log.cr();
223 MutexLockerImpl::print_counters_on(&log);
224 log.cr();
225 log.print("Runtime events for thread \"main\"");
226 if (ProfileRuntimeCalls) {
227 log.print_cr(" (%d nested events):", ProfileVMCallContext::nested_runtime_calls_count());
228
229 InterpreterRuntime::print_counters_on(&log);
230 #ifdef COMPILER1
231 Runtime1::print_counters_on(&log);
232 #endif
233 #ifdef COMPILER2
234 OptoRuntime::print_counters_on(&log);
235 Deoptimization::print_counters_on(&log);
236 #endif
237 } else {
238 log.print_cr(": no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
239 }
240 log.cr();
241 perf_jvm_print_on(&log);
242 log.cr();
243 MethodHandles::print_counters_on(&log);
244 }
245 }
246
247 void print_bytecode_count() {
248 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
249 tty->print_cr("[BytecodeCounter::counter_value = %zu]", 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
324 #else
325
326 static void print_method_invocation_histogram() {}
327
328 #endif // PRODUCT
329
330
331 // General statistics printing (profiling ...)
332 void print_statistics() {
333 #if INCLUDE_CDS
334 if (AOTReplayTraining && AOTPrintTrainingInfo) {
335 TrainingData::print_archived_training_data_on(tty);
336 }
337 #endif
338 if (CITime) {
339 CompileBroker::print_times();
340 }
341
342 #ifdef COMPILER1
343 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
344 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
345 Runtime1::print_statistics_on(tty);
346 SharedRuntime::print_statistics();
347 }
348 #endif /* COMPILER1 */
349
350 #ifdef COMPILER2
351 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
352 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
353 Compile::print_statistics();
354 Deoptimization::print_statistics();
355 #ifndef COMPILER1
356 SharedRuntime::print_statistics();
357 #endif //COMPILER1
358 }
359
360 if (PrintLockStatistics) {
361 OptoRuntime::print_named_counters();
362 }
363 #ifdef ASSERT
364 if (CollectIndexSetStatistics) {
365 IndexSet::print_statistics();
392 if (PrintSymbolTableSizeHistogram) {
393 SymbolTable::print_histogram();
394 }
395 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
396 BytecodeCounter::print();
397 }
398 if (PrintBytecodePairHistogram) {
399 BytecodePairHistogram::print();
400 }
401
402 if (PrintCodeCache) {
403 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
404 CodeCache::print();
405 }
406
407 // CodeHeap State Analytics.
408 if (PrintCodeHeapAnalytics) {
409 CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
410 }
411
412 LogStreamHandle(Debug, codecache, nmethod) log;
413 if (log.is_enabled()) {
414 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
415 CodeCache::print_nmethods_on(&log);
416 }
417
418 #ifndef PRODUCT
419 if (PrintCodeCache2) {
420 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
421 CodeCache::print_internals();
422 }
423 #endif
424
425 if (VerifyOops && Verbose) {
426 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
427 }
428
429 print_bytecode_count();
430
431 if (PrintSystemDictionaryAtExit) {
432 ResourceMark rm;
433 MutexLocker mcld(ClassLoaderDataGraph_lock);
434 SystemDictionary::print();
435 }
436
437 if (PrintClassLoaderDataGraphAtExit) {
438 ResourceMark rm;
439 MutexLocker mcld(ClassLoaderDataGraph_lock);
440 ClassLoaderDataGraph::print();
441 }
442
443 // Native memory tracking data
444 if (PrintNMTStatistics) {
445 MemTracker::final_report(tty);
446 }
447
448 if (PrintMetaspaceStatisticsAtExit) {
449 MetaspaceUtils::print_basic_report(tty, 0);
450 }
451
452 if (PrintCompilerMemoryStatisticsAtExit) {
453 CompilationMemoryStatistic::print_final_report(tty);
454 }
455
456 ThreadsSMRSupport::log_statistics();
457
458 log_vm_init_stats();
459
460 if (log_is_enabled(Info, perf, class, link)) {
461 LogStreamHandle(Info, perf, class, link) log;
462 log.print_cr("At VM exit:");
463 ClassLoader::print_counters(&log);
464 }
465 }
466
467 // Note: before_exit() can be executed only once, if more than one threads
468 // are trying to shutdown the VM at the same time, only one thread
469 // can run before_exit() and all other threads must wait.
470 void before_exit(JavaThread* thread, bool halt) {
471 #define BEFORE_EXIT_NOT_RUN 0
472 #define BEFORE_EXIT_RUNNING 1
473 #define BEFORE_EXIT_DONE 2
474 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
475
476 Events::log(thread, "Before exit entered");
477
478 // Note: don't use a Mutex to guard the entire before_exit(), as
479 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
505
506 // Do not add any additional shutdown logic between the above mutex logic and
507 // leak sanitizer logic below. Any additional shutdown code which performs some
508 // cleanup should be added after the leak sanitizer logic below.
509
510 #ifdef LEAK_SANITIZER
511 // If we are built with LSan, we need to perform leak checking. If we are
512 // terminating normally, not halting and no VM error, we perform a normal
513 // leak check which terminates if leaks are found. If we are not terminating
514 // normally, halting or VM error, we perform a recoverable leak check which
515 // prints leaks but will not terminate.
516 if (!halt && !VMError::is_error_reported()) {
517 LSAN_DO_LEAK_CHECK();
518 } else {
519 // Ignore the return value.
520 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
521 }
522 #endif
523
524 #if INCLUDE_CDS
525 MethodProfiler::process_method_hotness();
526 // Dynamic CDS dumping must happen whilst we can still reliably
527 // run Java code.
528 DynamicArchive::dump_at_exit(thread);
529 assert(!thread->has_pending_exception(), "must be");
530 #endif
531
532 // Actual shutdown logic begins here.
533
534 #if INCLUDE_JVMCI
535 if (EnableJVMCI) {
536 JVMCI::shutdown(thread);
537 }
538 #endif
539
540 #if INCLUDE_CDS
541 ClassListWriter::write_resolved_constants();
542 ClassListWriter::write_reflection_data();
543 ClassListWriter::write_loader_negative_lookup_cache();
544 if (CDSConfig::is_dumping_preimage_static_archive()) {
545 // Creating the hotspot.cds.preimage file
546 MetaspaceShared::preload_and_dump(thread);
547 assert(!thread->has_pending_exception(), "must be");
548 }
549 #endif
550
551 AOTCodeCache::close(); // Write final data and close archive
552
553 // Hang forever on exit if we're reporting an error.
554 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
555 os::infinite_sleep();
556 }
557
558 EventThreadEnd event;
559 if (event.should_commit()) {
560 event.set_thread(JFR_JVM_THREAD_ID(thread));
561 event.commit();
562 }
563
564 JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
565
566 // Stop the WatcherThread. We do this before disenrolling various
567 // PeriodicTasks to reduce the likelihood of races.
568 WatcherThread::stop();
569
570 // shut down the StatSampler task
571 StatSampler::disengage();
572 StatSampler::destroy();
573
574 NativeHeapTrimmer::cleanup();
575
576 // Stop concurrent GC threads
577 Universe::heap()->stop();
578
579 // Print GC/heap related information.
580 Log(gc, heap, exit) log;
581 if (log.is_info()) {
582 LogStream ls_info(log.info());
583 Universe::print_on(&ls_info);
584 if (log.is_trace()) {
585 LogStream ls_trace(log.trace());
586 MutexLocker mcld(ClassLoaderDataGraph_lock);
587 ClassLoaderDataGraph::print_on(&ls_trace);
588 }
589 }
590
591 if (PrintBytecodeHistogram) {
592 BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
593 }
594
595 #ifdef LINUX
596 if (DumpPerfMapAtExit) {
597 CodeCache::write_perf_map(nullptr, tty);
598 }
599 if (PrintMemoryMapAtExit) {
600 MemMapPrinter::print_all_mappings(tty);
601 }
602 #endif
603
604 if (JvmtiExport::should_post_thread_life()) {
605 JvmtiExport::post_thread_end(thread);
606 }
607
608 // Always call even when there are not JVMTI environments yet, since environments
609 // may be attached late and JVMTI must track phases of VM execution
610 JvmtiExport::post_vm_death();
611 JvmtiAgentList::unload_agents();
612
613 // Terminate the signal thread
614 // Note: we don't wait until it actually dies.
615 os::terminate_signal_thread();
616
617 if (AOTVerifyTrainingData) {
618 EXCEPTION_MARK;
619 CompilationPolicy::flush_replay_training_at_init(THREAD);
620 TrainingData::verify();
621 }
622
623 print_statistics();
624 Universe::heap()->print_tracing_info();
625
626 { MutexLocker ml(BeforeExit_lock);
627 _before_exit_status = BEFORE_EXIT_DONE;
628 BeforeExit_lock->notify_all();
629 }
630
631 if (VerifyStringTableAtExit) {
632 size_t fail_cnt = StringTable::verify_and_compare_entries();
633 if (fail_cnt != 0) {
634 tty->print_cr("ERROR: fail_cnt=%zu", fail_cnt);
635 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
636 }
637 }
638
639 #undef BEFORE_EXIT_NOT_RUN
640 #undef BEFORE_EXIT_RUNNING
641 #undef BEFORE_EXIT_DONE
642 }
|