7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/cds_globals.hpp"
27 #include "cds/dynamicArchive.hpp"
28 #include "classfile/classLoaderDataGraph.hpp"
29 #include "classfile/javaClasses.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/symbolTable.hpp"
32 #include "classfile/systemDictionary.hpp"
33 #include "code/codeCache.hpp"
34 #include "compiler/compilationMemoryStatistic.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/compilerOracle.hpp"
37 #include "gc/shared/collectedHeap.hpp"
38 #include "gc/shared/stringdedup/stringDedup.hpp"
39 #include "interpreter/bytecodeHistogram.hpp"
40 #include "jfr/jfrEvents.hpp"
41 #include "jfr/support/jfrThreadId.hpp"
42 #include "jvm.h"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/metaspaceUtils.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "memory/universe.hpp"
49 #include "nmt/memTracker.hpp"
50 #include "oops/constantPool.hpp"
51 #include "oops/generateOopMap.hpp"
52 #include "oops/instanceKlass.hpp"
53 #include "oops/instanceOop.hpp"
54 #include "oops/klassVtable.hpp"
55 #include "oops/method.hpp"
56 #include "oops/objArrayOop.hpp"
57 #include "oops/oop.inline.hpp"
58 #include "oops/symbol.hpp"
59 #include "prims/jvmtiAgentList.hpp"
60 #include "prims/jvmtiExport.hpp"
61 #include "runtime/continuation.hpp"
62 #include "runtime/deoptimization.hpp"
63 #include "runtime/flags/flagSetting.hpp"
64 #include "runtime/handles.inline.hpp"
65 #include "runtime/init.hpp"
66 #include "runtime/interfaceSupport.inline.hpp"
67 #include "runtime/java.hpp"
68 #include "runtime/javaThread.hpp"
69 #include "runtime/sharedRuntime.hpp"
70 #include "runtime/statSampler.hpp"
71 #include "runtime/stubRoutines.hpp"
72 #include "runtime/task.hpp"
73 #include "runtime/threads.hpp"
74 #include "runtime/timer.hpp"
75 #include "runtime/trimNativeHeap.hpp"
76 #include "runtime/vmOperations.hpp"
77 #include "runtime/vmThread.hpp"
78 #include "runtime/vm_version.hpp"
79 #include "sanitizers/leak.hpp"
80 #include "utilities/dtrace.hpp"
81 #include "utilities/events.hpp"
82 #include "utilities/globalDefinitions.hpp"
83 #include "utilities/macros.hpp"
139
140 ss.print_cr("------------------------------------------------------------------------");
141 m->print_invocation_count(&ss);
142 ss.print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
143 ss.cr();
144 // Dump data on parameters if any
145 if (m->method_data() != nullptr && m->method_data()->parameters_type_data() != nullptr) {
146 ss.fill_to(2);
147 m->method_data()->parameters_type_data()->print_data_on(&ss);
148 }
149 m->print_codes_on(&ss);
150 tty->print("%s", ss.as_string()); // print all at once
151 total_size += m->method_data()->size_in_bytes();
152 }
153 tty->print_cr("------------------------------------------------------------------------");
154 tty->print_cr("Total MDO size: %d bytes", total_size);
155 }
156 }
157 }
158
159
160 #ifndef PRODUCT
161
162 // Statistics printing (method invocation histogram)
163
164 GrowableArray<Method*>* collected_invoked_methods;
165
166 static void collect_invoked_methods(Method* m) {
167 if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
168 collected_invoked_methods->push(m);
169 }
170 }
171
172
173 // Invocation count accumulators should be unsigned long to shift the
174 // overflow border. Longer-running workloads tend to create invocation
175 // counts which already overflow 32-bit counters for individual methods.
176 static void print_method_invocation_histogram() {
177 ResourceMark rm;
178 collected_invoked_methods = new GrowableArray<Method*>(1024);
207 if (m->is_synchronized()) synch_total += iic + cic;
208 if (m->is_native()) native_total += iic + cic;
209 if (m->is_accessor()) access_total += iic + cic;
210 }
211 tty->cr();
212 total = int_total + comp_total;
213 special_total = final_total + static_total +synch_total + native_total + access_total;
214 tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
215 double total_div = (double)total;
216 tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%) total", total);
217 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total, 100.0 * (double)int_total / total_div);
218 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled", comp_total, 100.0 * (double)comp_total / total_div);
219 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
220 special_total, 100.0 * (double)special_total/ total_div);
221 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- synchronized",synch_total, 100.0 * (double)synch_total / total_div);
222 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- final", final_total, 100.0 * (double)final_total / total_div);
223 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- static", static_total, 100.0 * (double)static_total / total_div);
224 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- native", native_total, 100.0 * (double)native_total / total_div);
225 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- accessor", access_total, 100.0 * (double)access_total / total_div);
226 tty->cr();
227 SharedRuntime::print_call_statistics(comp_total);
228 }
229
230 static void print_bytecode_count() {
231 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
232 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
233 }
234 }
235
236 #else
237
238 static void print_method_invocation_histogram() {}
239 static void print_bytecode_count() {}
240
241 #endif // PRODUCT
242
243
244 // General statistics printing (profiling ...)
245 void print_statistics() {
246 if (CITime) {
247 CompileBroker::print_times();
248 }
249
250 #ifdef COMPILER1
251 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
252 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
253 Runtime1::print_statistics();
254 SharedRuntime::print_statistics();
255 }
256 #endif /* COMPILER1 */
257
258 #ifdef COMPILER2
259 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
260 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
261 Compile::print_statistics();
262 Deoptimization::print_statistics();
263 #ifndef COMPILER1
264 SharedRuntime::print_statistics();
265 #endif //COMPILER1
266 }
267
268 if (PrintLockStatistics || PrintPreciseRTMLockingStatistics) {
269 OptoRuntime::print_named_counters();
270 }
271 #ifdef ASSERT
272 if (CollectIndexSetStatistics) {
273 IndexSet::print_statistics();
300 if (PrintSymbolTableSizeHistogram) {
301 SymbolTable::print_histogram();
302 }
303 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
304 BytecodeCounter::print();
305 }
306 if (PrintBytecodePairHistogram) {
307 BytecodePairHistogram::print();
308 }
309
310 if (PrintCodeCache) {
311 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
312 CodeCache::print();
313 }
314
315 // CodeHeap State Analytics.
316 if (PrintCodeHeapAnalytics) {
317 CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
318 }
319
320 #ifndef PRODUCT
321 if (PrintCodeCache2) {
322 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
323 CodeCache::print_internals();
324 }
325 #endif
326
327 if (VerifyOops && Verbose) {
328 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
329 }
330
331 print_bytecode_count();
332
333 if (PrintSystemDictionaryAtExit) {
334 ResourceMark rm;
335 MutexLocker mcld(ClassLoaderDataGraph_lock);
336 SystemDictionary::print();
337 }
338
339 if (PrintClassLoaderDataGraphAtExit) {
340 ResourceMark rm;
341 MutexLocker mcld(ClassLoaderDataGraph_lock);
342 ClassLoaderDataGraph::print();
343 }
344
345 // Native memory tracking data
346 if (PrintNMTStatistics) {
347 MemTracker::final_report(tty);
348 }
349
350 if (PrintMetaspaceStatisticsAtExit) {
351 MetaspaceUtils::print_basic_report(tty, 0);
352 }
353
354 if (CompilerOracle::should_print_final_memstat_report()) {
355 CompilationMemoryStatistic::print_all_by_size(tty, false, 0);
356 }
357
358 ThreadsSMRSupport::log_statistics();
359 }
360
361 // Note: before_exit() can be executed only once, if more than one threads
362 // are trying to shutdown the VM at the same time, only one thread
363 // can run before_exit() and all other threads must wait.
364 void before_exit(JavaThread* thread, bool halt) {
365 #define BEFORE_EXIT_NOT_RUN 0
366 #define BEFORE_EXIT_RUNNING 1
367 #define BEFORE_EXIT_DONE 2
368 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
369
370 Events::log(thread, "Before exit entered");
371
372 // Note: don't use a Mutex to guard the entire before_exit(), as
373 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
374 // A CAS or OSMutex would work just fine but then we need to manipulate
375 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
376 // for synchronization.
377 { MonitorLocker ml(BeforeExit_lock);
378 switch (_before_exit_status) {
398 // this thread finishes before_exit().
399
400 // Do not add any additional shutdown logic between the above mutex logic and
401 // leak sanitizer logic below. Any additional shutdown code which performs some
402 // cleanup should be added after the leak sanitizer logic below.
403
404 #ifdef LEAK_SANITIZER
405 // If we are built with LSan, we need to perform leak checking. If we are
406 // terminating normally, not halting and no VM error, we perform a normal
407 // leak check which terminates if leaks are found. If we are not terminating
408 // normally, halting or VM error, we perform a recoverable leak check which
409 // prints leaks but will not terminate.
410 if (!halt && !VMError::is_error_reported()) {
411 LSAN_DO_LEAK_CHECK();
412 } else {
413 // Ignore the return value.
414 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
415 }
416 #endif
417
418 #if INCLUDE_CDS
419 // Dynamic CDS dumping must happen whilst we can still reliably
420 // run Java code.
421 DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);
422 assert(!thread->has_pending_exception(), "must be");
423 #endif
424
425
426 // Actual shutdown logic begins here.
427
428 #if INCLUDE_JVMCI
429 if (EnableJVMCI) {
430 JVMCI::shutdown(thread);
431 }
432 #endif
433
434 // Hang forever on exit if we're reporting an error.
435 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
436 os::infinite_sleep();
437 }
438
439 EventThreadEnd event;
440 if (event.should_commit()) {
441 event.set_thread(JFR_JVM_THREAD_ID(thread));
442 event.commit();
443 }
444
445 JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
446
447 // Stop the WatcherThread. We do this before disenrolling various
448 // PeriodicTasks to reduce the likelihood of races.
449 WatcherThread::stop();
450
451 // shut down the StatSampler task
452 StatSampler::disengage();
453 StatSampler::destroy();
454
455 NativeHeapTrimmer::cleanup();
456
457 // Stop concurrent GC threads
458 Universe::heap()->stop();
459
460 // Print GC/heap related information.
461 Log(gc, heap, exit) log;
462 if (log.is_info()) {
463 ResourceMark rm;
464 LogStream ls_info(log.info());
465 Universe::print_on(&ls_info);
466 if (log.is_trace()) {
467 LogStream ls_trace(log.trace());
468 MutexLocker mcld(ClassLoaderDataGraph_lock);
469 ClassLoaderDataGraph::print_on(&ls_trace);
470 }
471 }
472
473 if (PrintBytecodeHistogram) {
474 BytecodeHistogram::print();
475 }
476
477 #ifdef LINUX
478 if (DumpPerfMapAtExit) {
479 CodeCache::write_perf_map();
480 }
481 #endif
482
483 if (JvmtiExport::should_post_thread_life()) {
484 JvmtiExport::post_thread_end(thread);
485 }
486
487 // Always call even when there are not JVMTI environments yet, since environments
488 // may be attached late and JVMTI must track phases of VM execution
489 JvmtiExport::post_vm_death();
490 JvmtiAgentList::unload_agents();
491
492 // Terminate the signal thread
493 // Note: we don't wait until it actually dies.
494 os::terminate_signal_thread();
495
496 print_statistics();
497 Universe::heap()->print_tracing_info();
498
499 { MutexLocker ml(BeforeExit_lock);
500 _before_exit_status = BEFORE_EXIT_DONE;
501 BeforeExit_lock->notify_all();
502 }
503
504 if (VerifyStringTableAtExit) {
505 size_t fail_cnt = StringTable::verify_and_compare_entries();
506 if (fail_cnt != 0) {
507 tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt);
508 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
509 }
510 }
511
512 #undef BEFORE_EXIT_NOT_RUN
513 #undef BEFORE_EXIT_RUNNING
514 #undef BEFORE_EXIT_DONE
515 }
|
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/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.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();
178 ClassPreloader::print_counters();
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 (SCCache::is_on_for_read()) {
215 log.print_cr("Startup Code Cache: ");
216 SCCache::print_statistics_on(&log);
217 log.cr();
218 SCCache::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 Runtime1::print_counters_on(&log);
230 OptoRuntime::print_counters_on(&log);
231 InterpreterRuntime::print_counters_on(&log);
232 Deoptimization::print_counters_on(&log);
233 } else {
234 log.print_cr(": no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
235 }
236 log.cr();
237 perf_jvm_print_on(&log);
238 log.cr();
239 MethodHandles::print_counters_on(&log);
240 }
241 }
242
243 void print_bytecode_count() {
244 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
245 tty->print_cr("[BytecodeCounter::counter_value = %ld]", BytecodeCounter::counter_value());
246 }
247 }
248
249 #ifndef PRODUCT
250
251 // Statistics printing (method invocation histogram)
252
253 GrowableArray<Method*>* collected_invoked_methods;
254
255 static void collect_invoked_methods(Method* m) {
256 if (m->invocation_count() + m->compiled_invocation_count() >= 1) {
257 collected_invoked_methods->push(m);
258 }
259 }
260
261
262 // Invocation count accumulators should be unsigned long to shift the
263 // overflow border. Longer-running workloads tend to create invocation
264 // counts which already overflow 32-bit counters for individual methods.
265 static void print_method_invocation_histogram() {
266 ResourceMark rm;
267 collected_invoked_methods = new GrowableArray<Method*>(1024);
296 if (m->is_synchronized()) synch_total += iic + cic;
297 if (m->is_native()) native_total += iic + cic;
298 if (m->is_accessor()) access_total += iic + cic;
299 }
300 tty->cr();
301 total = int_total + comp_total;
302 special_total = final_total + static_total +synch_total + native_total + access_total;
303 tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length());
304 double total_div = (double)total;
305 tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%) total", total);
306 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total, 100.0 * (double)int_total / total_div);
307 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled", comp_total, 100.0 * (double)comp_total / total_div);
308 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)",
309 special_total, 100.0 * (double)special_total/ total_div);
310 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- synchronized",synch_total, 100.0 * (double)synch_total / total_div);
311 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- final", final_total, 100.0 * (double)final_total / total_div);
312 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- static", static_total, 100.0 * (double)static_total / total_div);
313 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- native", native_total, 100.0 * (double)native_total / total_div);
314 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- accessor", access_total, 100.0 * (double)access_total / total_div);
315 tty->cr();
316 SharedRuntime::print_call_statistics_on(tty);
317 }
318
319 #else
320
321 static void print_method_invocation_histogram() {}
322
323 #endif // PRODUCT
324
325
326 // General statistics printing (profiling ...)
327 void print_statistics() {
328 if (ReplayTraining && PrintTrainingInfo) {
329 TrainingData::print_archived_training_data_on(tty);
330 }
331 if (CITime) {
332 CompileBroker::print_times();
333 }
334
335 #ifdef COMPILER1
336 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
337 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
338 Runtime1::print_statistics_on(tty);
339 SharedRuntime::print_statistics();
340 }
341 #endif /* COMPILER1 */
342
343 #ifdef COMPILER2
344 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
345 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
346 Compile::print_statistics();
347 Deoptimization::print_statistics();
348 #ifndef COMPILER1
349 SharedRuntime::print_statistics();
350 #endif //COMPILER1
351 }
352
353 if (PrintLockStatistics || PrintPreciseRTMLockingStatistics) {
354 OptoRuntime::print_named_counters();
355 }
356 #ifdef ASSERT
357 if (CollectIndexSetStatistics) {
358 IndexSet::print_statistics();
385 if (PrintSymbolTableSizeHistogram) {
386 SymbolTable::print_histogram();
387 }
388 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
389 BytecodeCounter::print();
390 }
391 if (PrintBytecodePairHistogram) {
392 BytecodePairHistogram::print();
393 }
394
395 if (PrintCodeCache) {
396 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
397 CodeCache::print();
398 }
399
400 // CodeHeap State Analytics.
401 if (PrintCodeHeapAnalytics) {
402 CompileBroker::print_heapinfo(nullptr, "all", 4096); // details
403 }
404
405 LogStreamHandle(Debug, codecache, nmethod) log;
406 if (log.is_enabled()) {
407 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
408 CodeCache::print_nmethods_on(&log);
409 }
410
411 #ifndef PRODUCT
412 if (PrintCodeCache2) {
413 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
414 CodeCache::print_internals();
415 }
416 #endif
417
418 if (VerifyOops && Verbose) {
419 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
420 }
421
422 print_bytecode_count();
423
424 if (PrintSystemDictionaryAtExit) {
425 ResourceMark rm;
426 MutexLocker mcld(ClassLoaderDataGraph_lock);
427 SystemDictionary::print();
428 }
429
430 if (PrintClassLoaderDataGraphAtExit) {
431 ResourceMark rm;
432 MutexLocker mcld(ClassLoaderDataGraph_lock);
433 ClassLoaderDataGraph::print();
434 }
435
436 // Native memory tracking data
437 if (PrintNMTStatistics) {
438 MemTracker::final_report(tty);
439 }
440
441 if (PrintMetaspaceStatisticsAtExit) {
442 MetaspaceUtils::print_basic_report(tty, 0);
443 }
444
445 if (CompilerOracle::should_print_final_memstat_report()) {
446 CompilationMemoryStatistic::print_all_by_size(tty, false, 0);
447 }
448
449 ThreadsSMRSupport::log_statistics();
450
451 log_vm_init_stats();
452 }
453
454 // Note: before_exit() can be executed only once, if more than one threads
455 // are trying to shutdown the VM at the same time, only one thread
456 // can run before_exit() and all other threads must wait.
457 void before_exit(JavaThread* thread, bool halt) {
458 #define BEFORE_EXIT_NOT_RUN 0
459 #define BEFORE_EXIT_RUNNING 1
460 #define BEFORE_EXIT_DONE 2
461 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
462
463 Events::log(thread, "Before exit entered");
464
465 // Note: don't use a Mutex to guard the entire before_exit(), as
466 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
467 // A CAS or OSMutex would work just fine but then we need to manipulate
468 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
469 // for synchronization.
470 { MonitorLocker ml(BeforeExit_lock);
471 switch (_before_exit_status) {
491 // this thread finishes before_exit().
492
493 // Do not add any additional shutdown logic between the above mutex logic and
494 // leak sanitizer logic below. Any additional shutdown code which performs some
495 // cleanup should be added after the leak sanitizer logic below.
496
497 #ifdef LEAK_SANITIZER
498 // If we are built with LSan, we need to perform leak checking. If we are
499 // terminating normally, not halting and no VM error, we perform a normal
500 // leak check which terminates if leaks are found. If we are not terminating
501 // normally, halting or VM error, we perform a recoverable leak check which
502 // prints leaks but will not terminate.
503 if (!halt && !VMError::is_error_reported()) {
504 LSAN_DO_LEAK_CHECK();
505 } else {
506 // Ignore the return value.
507 static_cast<void>(LSAN_DO_RECOVERABLE_LEAK_CHECK());
508 }
509 #endif
510
511 MethodProfiler::process_method_hotness();
512
513 #if INCLUDE_CDS
514 ClassListWriter::write_resolved_constants();
515 ClassListWriter::write_reflection_data();
516 ClassListWriter::write_loader_negative_lookup_cache();
517 // Dynamic CDS dumping must happen whilst we can still reliably
518 // run Java code.
519 if (CDSConfig::is_dumping_preimage_static_archive()) {
520 // Creating the hotspot.cds.preimage file
521 MetaspaceShared::preload_and_dump();
522 } else {
523 DynamicArchive::dump_at_exit(thread, ArchiveClassesAtExit);
524 }
525 assert(!thread->has_pending_exception(), "must be");
526 #endif
527
528 // Actual shutdown logic begins here.
529
530 #if INCLUDE_JVMCI
531 if (EnableJVMCI) {
532 JVMCI::shutdown(thread);
533 }
534 #endif
535
536 SCCache::close(); // Write final data and close archive
537
538 // Hang forever on exit if we're reporting an error.
539 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
540 os::infinite_sleep();
541 }
542
543 EventThreadEnd event;
544 if (event.should_commit()) {
545 event.set_thread(JFR_JVM_THREAD_ID(thread));
546 event.commit();
547 }
548
549 JFR_ONLY(Jfr::on_vm_shutdown(false, halt);)
550
551 // Stop the WatcherThread. We do this before disenrolling various
552 // PeriodicTasks to reduce the likelihood of races.
553 WatcherThread::stop();
554
555 // shut down the StatSampler task
556 StatSampler::disengage();
557 StatSampler::destroy();
558
559 NativeHeapTrimmer::cleanup();
560
561 // Stop concurrent GC threads
562 Universe::heap()->stop();
563
564 // Print GC/heap related information.
565 Log(gc, heap, exit) log;
566 if (log.is_info()) {
567 ResourceMark rm;
568 LogStream ls_info(log.info());
569 Universe::print_on(&ls_info);
570 if (log.is_trace()) {
571 LogStream ls_trace(log.trace());
572 MutexLocker mcld(ClassLoaderDataGraph_lock);
573 ClassLoaderDataGraph::print_on(&ls_trace);
574 }
575 }
576
577 if (PrintBytecodeHistogram) {
578 BytecodeHistogram::print(PrintBytecodeHistogramCutoff);
579 }
580
581 #ifdef LINUX
582 if (DumpPerfMapAtExit) {
583 CodeCache::write_perf_map();
584 }
585 #endif
586
587 if (JvmtiExport::should_post_thread_life()) {
588 JvmtiExport::post_thread_end(thread);
589 }
590
591 // Always call even when there are not JVMTI environments yet, since environments
592 // may be attached late and JVMTI must track phases of VM execution
593 JvmtiExport::post_vm_death();
594 JvmtiAgentList::unload_agents();
595
596 // Terminate the signal thread
597 // Note: we don't wait until it actually dies.
598 os::terminate_signal_thread();
599
600 if (VerifyTrainingData) {
601 EXCEPTION_MARK;
602 CompilationPolicy::replay_training_at_init(true, THREAD); // implies TrainingData::verify()
603 }
604
605 print_statistics();
606 Universe::heap()->print_tracing_info();
607
608 { MutexLocker ml(BeforeExit_lock);
609 _before_exit_status = BEFORE_EXIT_DONE;
610 BeforeExit_lock->notify_all();
611 }
612
613 if (VerifyStringTableAtExit) {
614 size_t fail_cnt = StringTable::verify_and_compare_entries();
615 if (fail_cnt != 0) {
616 tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt);
617 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
618 }
619 }
620
621 #undef BEFORE_EXIT_NOT_RUN
622 #undef BEFORE_EXIT_RUNNING
623 #undef BEFORE_EXIT_DONE
624 }
|