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/sharedRuntime.hpp"
75 #include "runtime/stubRoutines.hpp"
76 #include "runtime/task.hpp"
77 #include "runtime/threads.hpp"
78 #include "runtime/timer.hpp"
79 #include "runtime/trimNativeHeap.hpp"
80 #include "runtime/vm_version.hpp"
81 #include "runtime/vmOperations.hpp"
82 #include "runtime/vmThread.hpp"
83 #include "sanitizers/leak.hpp"
84 #include "utilities/dtrace.hpp"
85 #include "utilities/events.hpp"
86 #include "utilities/globalDefinitions.hpp"
87 #include "utilities/macros.hpp"
88 #include "utilities/vmError.hpp"
143
144 ss.print_cr("------------------------------------------------------------------------");
145 m->print_invocation_count(&ss);
146 ss.print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
147 ss.cr();
148 // Dump data on parameters if any
149 if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
150 ss.fill_to(2);
151 m->method_data()->parameters_type_data()->print_data_on(&ss);
152 }
153 m->print_codes_on(&ss);
154 tty->print("%s", ss.as_string()); // print all at once
155 total_size += m->method_data()->size_in_bytes();
156 }
157 tty->print_cr("------------------------------------------------------------------------");
158 tty->print_cr("Total MDO size: %d bytes", total_size);
159 }
160 }
161 }
162
163 #ifndef PRODUCT
164
165 // Statistics printing (method invocation histogram)
166
167 GrowableArray<Method*>* collected_invoked_methods;
168
169 static void collect_invoked_methods(Method* m) {
170 if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
171 collected_invoked_methods->push(m);
172 }
173 }
174
175
176 // Invocation count accumulators should be unsigned long to shift the
177 // overflow border. Longer-running workloads tend to create invocation
178 // counts which already overflow 32-bit counters for individual methods.
179 static void print_method_invocation_histogram() {
180 ResourceMark rm;
181 collected_invoked_methods = new GrowableArray<Method*>(1024);
182 SystemDictionary::methods_do(collect_invoked_methods);
210 if (m->is_synchronized()) synch_total += iic + cic;
211 if (m->is_native()) native_total += iic + cic;
212 if (m->is_accessor()) access_total += iic + cic;
213 }
214 tty->cr();
215 total = int_total + comp_total;
216 special_total = final_total + static_total +synch_total + native_total + access_total;
217 tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
218 double total_div = (double)total;
219 tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%) total", total);
220 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total, 100.0 * (double)int_total / total_div);
221 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled", comp_total, 100.0 * (double)comp_total / total_div);
222 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
223 special_total, 100.0 * (double)special_total/ total_div);
224 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- synchronized",synch_total, 100.0 * (double)synch_total / total_div);
225 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- final", final_total, 100.0 * (double)final_total / total_div);
226 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- static", static_total, 100.0 * (double)static_total / total_div);
227 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- native", native_total, 100.0 * (double)native_total / total_div);
228 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- accessor", access_total, 100.0 * (double)access_total / total_div);
229 tty->cr();
230 SharedRuntime::print_call_statistics(comp_total);
231 }
232
233 static void print_bytecode_count() {
234 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
235 tty->print_cr("[BytecodeCounter::counter_value = %zu]", BytecodeCounter::counter_value());
236 }
237 }
238
239 #else
240
241 static void print_method_invocation_histogram() {}
242 static void print_bytecode_count() {}
243
244 #endif // PRODUCT
245
246
247 // General statistics printing (profiling ...)
248 void print_statistics() {
249 if (CITime) {
250 CompileBroker::print_times();
251 }
252
253 #ifdef COMPILER1
254 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
255 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
256 Runtime1::print_statistics();
257 SharedRuntime::print_statistics();
258 }
259 #endif /* COMPILER1 */
260
261 #ifdef COMPILER2
262 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
263 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
264 Compile::print_statistics();
265 Deoptimization::print_statistics();
266 #ifndef COMPILER1
267 SharedRuntime::print_statistics();
268 #endif //COMPILER1
269 }
270
271 if (PrintLockStatistics) {
272 OptoRuntime::print_named_counters();
273 }
274 #ifdef ASSERT
275 if (CollectIndexSetStatistics) {
276 IndexSet::print_statistics();
303 if (PrintSymbolTableSizeHistogram) {
304 SymbolTable::print_histogram();
305 }
306 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
307 BytecodeCounter::print();
308 }
309 if (PrintBytecodePairHistogram) {
310 BytecodePairHistogram::print();
311 }
312
313 if (PrintCodeCache) {
314 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
315 CodeCache::print();
316 }
317
318 // CodeHeap State Analytics.
319 if (PrintCodeHeapAnalytics) {
320 CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
321 }
322
323 #ifndef PRODUCT
324 if (PrintCodeCache2) {
325 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
326 CodeCache::print_internals();
327 }
328 #endif
329
330 if (VerifyOops && Verbose) {
331 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
332 }
333
334 print_bytecode_count();
335
336 if (PrintVMInfoAtExit) {
337 // Use an intermediate stream to prevent deadlocking on tty_lock
338 stringStream ss;
339 VMError::print_vm_info(&ss);
340 tty->print_raw(ss.base());
341 }
342
350 ResourceMark rm;
351 MutexLocker mcld(ClassLoaderDataGraph_lock);
352 ClassLoaderDataGraph::print();
353 }
354
355 // Native memory tracking data
356 if (PrintNMTStatistics) {
357 MemTracker::final_report(tty);
358 }
359
360 if (PrintMetaspaceStatisticsAtExit) {
361 MetaspaceUtils::print_basic_report(tty, 0);
362 }
363
364 if (PrintCompilerMemoryStatisticsAtExit) {
365 CompilationMemoryStatistic::print_final_report(tty);
366 }
367
368 ThreadsSMRSupport::log_statistics();
369
370 if (log_is_enabled(Info, perf, class, link)) {
371 LogStreamHandle(Info, perf, class, link) log;
372 log.print_cr("At VM exit:");
373 ClassLoader::print_counters(&log);
374 }
375 }
376
377 // Note: before_exit() can be executed only once, if more than one threads
378 // are trying to shutdown the VM at the same time, only one thread
379 // can run before_exit() and all other threads must wait.
380 void before_exit(JavaThread* thread, bool halt) {
381 #define BEFORE_EXIT_NOT_RUN 0
382 #define BEFORE_EXIT_RUNNING 1
383 #define BEFORE_EXIT_DONE 2
384 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
385
386 Events::log(thread, "Before exit entered");
387
388 // Note: don't use a Mutex to guard the entire before_exit(), as
389 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
415
416 // Do not add any additional shutdown logic between the above mutex logic and
417 // leak sanitizer logic below. Any additional shutdown code which performs some
418 // cleanup should be added after the leak sanitizer logic below.
419
420 #ifdef LEAK_SANITIZER
421 // If we are built with LSan, we need to perform leak checking. If we are
422 // terminating normally, not halting and no VM error, we perform a normal
423 // leak check which terminates if leaks are found. If we are not terminating
424 // normally, halting or VM error, we perform a recoverable leak check which
425 // prints leaks but will not terminate.
426 if (!halt && !VMError::is_error_reported()) {
427 LSAN_DO_LEAK_CHECK();
428 } else {
429 // Ignore the return value.
430 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
431 }
432 #endif
433
434 #if INCLUDE_CDS
435 // Dynamic CDS dumping must happen whilst we can still reliably
436 // run Java code.
437 DynamicArchive::dump_at_exit(thread);
438 assert(!thread->has_pending_exception(), "must be");
439 #endif
440
441 // Actual shutdown logic begins here.
442
443 #if INCLUDE_JVMCI
444 if (EnableJVMCI) {
445 JVMCI::shutdown(thread);
446 }
447 #endif
448
449 #if INCLUDE_CDS
450 ClassListWriter::write_resolved_constants();
451
452 if (CDSConfig::is_dumping_preimage_static_archive()) {
453 AOTMetaspace::preload_and_dump(thread);
454 }
455 #endif
456
457 // Hang forever on exit if we're reporting an error.
458 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
459 os::infinite_sleep();
460 }
461
462 EventThreadEnd event;
463 if (event.should_commit()) {
464 event.set_thread(JFR_JVM_THREAD_ID(thread));
465 event.commit();
466 }
467
468 // 2nd argument (emit_event_shutdown) should be set to false
469 // because EventShutdown would be emitted at Threads::destroy_vm().
470 // (one of the callers of before_exit())
471 JFR_ONLY(Jfr::on_vm_shutdown(true, false, halt);)
472
473 // Stop the WatcherThread. We do this before disenrolling various
474 // PeriodicTasks to reduce the likelihood of races.
475 WatcherThread::stop();
476
477 NativeHeapTrimmer::cleanup();
478
479 // Run before exit and then stop concurrent GC threads
480 Universe::before_exit();
481
482 if (PrintBytecodeHistogram) {
483 BytecodeHistogram::print();
484 }
485
486 #ifdef LINUX
487 if (DumpPerfMapAtExit) {
488 CodeCache::write_perf_map(nullptr, tty);
489 }
490 if (PrintMemoryMapAtExit) {
491 MemMapPrinter::print_all_mappings(tty);
492 }
493 #endif
494
495 if (JvmtiExport::should_post_thread_life()) {
496 JvmtiExport::post_thread_end(thread);
497 }
498
499 // Always call even when there are not JVMTI environments yet, since environments
500 // may be attached late and JVMTI must track phases of VM execution
501 JvmtiExport::post_vm_death();
502 JvmtiAgentList::unload_agents();
503
|
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/sharedRuntime.hpp"
82 #include "runtime/stubRoutines.hpp"
83 #include "runtime/task.hpp"
84 #include "runtime/threads.hpp"
85 #include "runtime/timer.hpp"
86 #include "runtime/trimNativeHeap.hpp"
87 #include "runtime/vm_version.hpp"
88 #include "runtime/vmOperations.hpp"
89 #include "runtime/vmThread.hpp"
90 #include "sanitizers/leak.hpp"
91 #include "utilities/dtrace.hpp"
92 #include "utilities/events.hpp"
93 #include "utilities/globalDefinitions.hpp"
94 #include "utilities/macros.hpp"
95 #include "utilities/vmError.hpp"
150
151 ss.print_cr("------------------------------------------------------------------------");
152 m->print_invocation_count(&ss);
153 ss.print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
154 ss.cr();
155 // Dump data on parameters if any
156 if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
157 ss.fill_to(2);
158 m->method_data()->parameters_type_data()->print_data_on(&ss);
159 }
160 m->print_codes_on(&ss);
161 tty->print("%s", ss.as_string()); // print all at once
162 total_size += m->method_data()->size_in_bytes();
163 }
164 tty->print_cr("------------------------------------------------------------------------");
165 tty->print_cr("Total MDO size: %d bytes", total_size);
166 }
167 }
168 }
169
170 void perf_jvm_print_on(outputStream* st);
171
172 void log_vm_init_stats() {
173 LogStreamHandle(Info, init) log;
174 if (log.is_enabled()) {
175 SharedRuntime::print_counters_on(&log);
176 ClassLoader::print_counters(&log);
177 AOTLinkedClassBulkLoader::print_counters_on(&log);
178 log.cr();
179 // FIXME: intermittent crashes
180 // if (CountBytecodesPerThread) {
181 // log.print_cr("Thread info:");
182 // class PrintThreadInfo : public ThreadClosure {
183 // outputStream* _st;
184 // public:
185 // PrintThreadInfo(outputStream* st) : ThreadClosure(), _st(st) {}
186 // void do_thread(Thread* thread) {
187 // JavaThread* jt = JavaThread::cast(thread);
188 // if (jt->bc_counter_value() > 0) {
189 // _st->print_cr(" Thread " INTPTR_FORMAT ": %ld bytecodes executed (clinit: %ld)",
190 // p2i(jt), /*jt->name(),*/ jt->bc_counter_value(), jt->clinit_bc_counter_value());
191 // }
192 // }
193 // };
194 // PrintThreadInfo cl(&log);
195 // Threads::java_threads_do(&cl);
196 // }
197 // log.cr();
198 log.print_cr("Deoptimization events: ");
199 Deoptimization::print_statistics_on(&log);
200 log.cr();
201
202 log.print("Compilation statistics: ");
203 CompileBroker::print_statistics_on(&log);
204 log.cr();
205
206 {
207 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
208 log.print("Code cache statistics: ");
209 CodeCache::print_nmethod_statistics_on(&log);
210 log.cr();
211 }
212
213 if (AOTCodeCache::is_on_for_use()) {
214 log.print_cr("Startup Code Cache: ");
215 AOTCodeCache::print_statistics_on(&log);
216 log.cr();
217 AOTCodeCache::print_timers_on(&log);
218 }
219
220 VMThread::print_counters_on(&log);
221 log.cr();
222 MutexLockerImpl::print_counters_on(&log);
223 log.cr();
224 log.print("Runtime events for thread \"main\"");
225 if (ProfileRuntimeCalls) {
226 log.print_cr(" (%d nested events):", ProfileVMCallContext::nested_runtime_calls_count());
227
228 InterpreterRuntime::print_counters_on(&log);
229 #ifdef COMPILER1
230 Runtime1::print_counters_on(&log);
231 #endif
232 #ifdef COMPILER2
233 OptoRuntime::print_counters_on(&log);
234 Deoptimization::print_counters_on(&log);
235 #endif
236 } else {
237 log.print_cr(": no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
238 }
239 log.cr();
240 perf_jvm_print_on(&log);
241 log.cr();
242 MethodHandles::print_counters_on(&log);
243 }
244 }
245
246 void print_bytecode_count() {
247 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
248 tty->print_cr("[BytecodeCounter::counter_value = %zu]", BytecodeCounter::counter_value());
249 }
250 }
251
252 #ifndef PRODUCT
253
254 // Statistics printing (method invocation histogram)
255
256 GrowableArray<Method*>* collected_invoked_methods;
257
258 static void collect_invoked_methods(Method* m) {
259 if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
260 collected_invoked_methods->push(m);
261 }
262 }
263
264
265 // Invocation count accumulators should be unsigned long to shift the
266 // overflow border. Longer-running workloads tend to create invocation
267 // counts which already overflow 32-bit counters for individual methods.
268 static void print_method_invocation_histogram() {
269 ResourceMark rm;
270 collected_invoked_methods = new GrowableArray<Method*>(1024);
271 SystemDictionary::methods_do(collect_invoked_methods);
299 if (m->is_synchronized()) synch_total += iic + cic;
300 if (m->is_native()) native_total += iic + cic;
301 if (m->is_accessor()) access_total += iic + cic;
302 }
303 tty->cr();
304 total = int_total + comp_total;
305 special_total = final_total + static_total +synch_total + native_total + access_total;
306 tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
307 double total_div = (double)total;
308 tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%) total", total);
309 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total, 100.0 * (double)int_total / total_div);
310 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled", comp_total, 100.0 * (double)comp_total / total_div);
311 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
312 special_total, 100.0 * (double)special_total/ total_div);
313 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- synchronized",synch_total, 100.0 * (double)synch_total / total_div);
314 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- final", final_total, 100.0 * (double)final_total / total_div);
315 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- static", static_total, 100.0 * (double)static_total / total_div);
316 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- native", native_total, 100.0 * (double)native_total / total_div);
317 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- accessor", access_total, 100.0 * (double)access_total / total_div);
318 tty->cr();
319 SharedRuntime::print_call_statistics_on(tty);
320
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 INCLUDE_CDS
333 if (AOTReplayTraining && AOTPrintTrainingInfo) {
334 TrainingData::print_archived_training_data_on(tty);
335 }
336 #endif
337 if (CITime) {
338 CompileBroker::print_times();
339 }
340
341 #ifdef COMPILER1
342 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
343 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
344 Runtime1::print_statistics_on(tty);
345 SharedRuntime::print_statistics();
346 }
347 #endif /* COMPILER1 */
348
349 #ifdef COMPILER2
350 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
351 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
352 Compile::print_statistics();
353 Deoptimization::print_statistics();
354 #ifndef COMPILER1
355 SharedRuntime::print_statistics();
356 #endif //COMPILER1
357 }
358
359 if (PrintLockStatistics) {
360 OptoRuntime::print_named_counters();
361 }
362 #ifdef ASSERT
363 if (CollectIndexSetStatistics) {
364 IndexSet::print_statistics();
391 if (PrintSymbolTableSizeHistogram) {
392 SymbolTable::print_histogram();
393 }
394 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
395 BytecodeCounter::print();
396 }
397 if (PrintBytecodePairHistogram) {
398 BytecodePairHistogram::print();
399 }
400
401 if (PrintCodeCache) {
402 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
403 CodeCache::print();
404 }
405
406 // CodeHeap State Analytics.
407 if (PrintCodeHeapAnalytics) {
408 CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
409 }
410
411 LogStreamHandle(Debug, codecache, nmethod) log;
412 if (log.is_enabled()) {
413 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
414 CodeCache::print_nmethods_on(&log);
415 }
416
417 #ifndef PRODUCT
418 if (PrintCodeCache2) {
419 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
420 CodeCache::print_internals();
421 }
422 #endif
423
424 if (VerifyOops && Verbose) {
425 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
426 }
427
428 print_bytecode_count();
429
430 if (PrintVMInfoAtExit) {
431 // Use an intermediate stream to prevent deadlocking on tty_lock
432 stringStream ss;
433 VMError::print_vm_info(&ss);
434 tty->print_raw(ss.base());
435 }
436
444 ResourceMark rm;
445 MutexLocker mcld(ClassLoaderDataGraph_lock);
446 ClassLoaderDataGraph::print();
447 }
448
449 // Native memory tracking data
450 if (PrintNMTStatistics) {
451 MemTracker::final_report(tty);
452 }
453
454 if (PrintMetaspaceStatisticsAtExit) {
455 MetaspaceUtils::print_basic_report(tty, 0);
456 }
457
458 if (PrintCompilerMemoryStatisticsAtExit) {
459 CompilationMemoryStatistic::print_final_report(tty);
460 }
461
462 ThreadsSMRSupport::log_statistics();
463
464 log_vm_init_stats();
465
466 if (log_is_enabled(Info, perf, class, link)) {
467 LogStreamHandle(Info, perf, class, link) log;
468 log.print_cr("At VM exit:");
469 ClassLoader::print_counters(&log);
470 }
471 }
472
473 // Note: before_exit() can be executed only once, if more than one threads
474 // are trying to shutdown the VM at the same time, only one thread
475 // can run before_exit() and all other threads must wait.
476 void before_exit(JavaThread* thread, bool halt) {
477 #define BEFORE_EXIT_NOT_RUN 0
478 #define BEFORE_EXIT_RUNNING 1
479 #define BEFORE_EXIT_DONE 2
480 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
481
482 Events::log(thread, "Before exit entered");
483
484 // Note: don't use a Mutex to guard the entire before_exit(), as
485 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
511
512 // Do not add any additional shutdown logic between the above mutex logic and
513 // leak sanitizer logic below. Any additional shutdown code which performs some
514 // cleanup should be added after the leak sanitizer logic below.
515
516 #ifdef LEAK_SANITIZER
517 // If we are built with LSan, we need to perform leak checking. If we are
518 // terminating normally, not halting and no VM error, we perform a normal
519 // leak check which terminates if leaks are found. If we are not terminating
520 // normally, halting or VM error, we perform a recoverable leak check which
521 // prints leaks but will not terminate.
522 if (!halt && !VMError::is_error_reported()) {
523 LSAN_DO_LEAK_CHECK();
524 } else {
525 // Ignore the return value.
526 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
527 }
528 #endif
529
530 #if INCLUDE_CDS
531 MethodProfiler::process_method_hotness();
532 // Dynamic CDS dumping must happen whilst we can still reliably
533 // run Java code.
534 DynamicArchive::dump_at_exit(thread);
535 assert(!thread->has_pending_exception(), "must be");
536 #endif
537
538 // Actual shutdown logic begins here.
539
540 #if INCLUDE_JVMCI
541 if (EnableJVMCI) {
542 JVMCI::shutdown(thread);
543 }
544 #endif
545
546 #if INCLUDE_CDS
547 ClassListWriter::write_resolved_constants();
548 ClassListWriter::write_reflection_data();
549 ClassListWriter::write_loader_negative_lookup_cache();
550 if (CDSConfig::is_dumping_preimage_static_archive()) {
551 AOTMetaspace::preload_and_dump(thread);
552 }
553 #endif
554
555 // Hang forever on exit if we're reporting an error.
556 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
557 os::infinite_sleep();
558 }
559
560 EventThreadEnd event;
561 if (event.should_commit()) {
562 event.set_thread(JFR_JVM_THREAD_ID(thread));
563 event.commit();
564 }
565
566 // 2nd argument (emit_event_shutdown) should be set to false
567 // because EventShutdown would be emitted at Threads::destroy_vm().
568 // (one of the callers of before_exit())
569 JFR_ONLY(Jfr::on_vm_shutdown(true, false, halt);)
570
571 // Stop the WatcherThread. We do this before disenrolling various
572 // PeriodicTasks to reduce the likelihood of races.
573 WatcherThread::stop();
574
575 NativeHeapTrimmer::cleanup();
576
577 // Run before exit and then stop concurrent GC threads
578 Universe::before_exit();
579
580 if (PrintBytecodeHistogram) {
581 BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
582 }
583
584 #ifdef LINUX
585 if (DumpPerfMapAtExit) {
586 CodeCache::write_perf_map(nullptr, tty);
587 }
588 if (PrintMemoryMapAtExit) {
589 MemMapPrinter::print_all_mappings(tty);
590 }
591 #endif
592
593 if (JvmtiExport::should_post_thread_life()) {
594 JvmtiExport::post_thread_end(thread);
595 }
596
597 // Always call even when there are not JVMTI environments yet, since environments
598 // may be attached late and JVMTI must track phases of VM execution
599 JvmtiExport::post_vm_death();
600 JvmtiAgentList::unload_agents();
601
|