| File: | jdk/src/hotspot/share/runtime/java.cpp |
| Warning: | line 555, column 9 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. | |||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
| 4 | * | |||
| 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 "precompiled.hpp" | |||
| 26 | #include "jvm.h" | |||
| 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/compileBroker.hpp" | |||
| 35 | #include "compiler/compilerOracle.hpp" | |||
| 36 | #include "gc/shared/collectedHeap.hpp" | |||
| 37 | #include "gc/shared/stringdedup/stringDedup.hpp" | |||
| 38 | #include "interpreter/bytecodeHistogram.hpp" | |||
| 39 | #include "jfr/jfrEvents.hpp" | |||
| 40 | #include "jfr/support/jfrThreadId.hpp" | |||
| 41 | #if INCLUDE_JVMCI1 | |||
| 42 | #include "jvmci/jvmci.hpp" | |||
| 43 | #endif | |||
| 44 | #include "logging/log.hpp" | |||
| 45 | #include "logging/logStream.hpp" | |||
| 46 | #include "memory/metaspaceUtils.hpp" | |||
| 47 | #include "memory/oopFactory.hpp" | |||
| 48 | #include "memory/resourceArea.hpp" | |||
| 49 | #include "memory/universe.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/jvmtiExport.hpp" | |||
| 60 | #include "runtime/deoptimization.hpp" | |||
| 61 | #include "runtime/flags/flagSetting.hpp" | |||
| 62 | #include "runtime/handles.inline.hpp" | |||
| 63 | #include "runtime/init.hpp" | |||
| 64 | #include "runtime/interfaceSupport.inline.hpp" | |||
| 65 | #include "runtime/java.hpp" | |||
| 66 | #include "runtime/sharedRuntime.hpp" | |||
| 67 | #include "runtime/statSampler.hpp" | |||
| 68 | #include "runtime/stubRoutines.hpp" | |||
| 69 | #include "runtime/sweeper.hpp" | |||
| 70 | #include "runtime/task.hpp" | |||
| 71 | #include "runtime/thread.inline.hpp" | |||
| 72 | #include "runtime/timer.hpp" | |||
| 73 | #include "runtime/vmOperations.hpp" | |||
| 74 | #include "runtime/vmThread.hpp" | |||
| 75 | #include "runtime/vm_version.hpp" | |||
| 76 | #include "services/memTracker.hpp" | |||
| 77 | #include "utilities/dtrace.hpp" | |||
| 78 | #include "utilities/globalDefinitions.hpp" | |||
| 79 | #include "utilities/macros.hpp" | |||
| 80 | #include "utilities/vmError.hpp" | |||
| 81 | #ifdef COMPILER11 | |||
| 82 | #include "c1/c1_Compiler.hpp" | |||
| 83 | #include "c1/c1_Runtime1.hpp" | |||
| 84 | #endif | |||
| 85 | #ifdef COMPILER21 | |||
| 86 | #include "code/compiledIC.hpp" | |||
| 87 | #include "opto/compile.hpp" | |||
| 88 | #include "opto/indexSet.hpp" | |||
| 89 | #include "opto/runtime.hpp" | |||
| 90 | #endif | |||
| 91 | #if INCLUDE_JFR1 | |||
| 92 | #include "jfr/jfr.hpp" | |||
| 93 | #endif | |||
| 94 | ||||
| 95 | GrowableArray<Method*>* collected_profiled_methods; | |||
| 96 | ||||
| 97 | int compare_methods(Method** a, Method** b) { | |||
| 98 | // compiled_invocation_count() returns int64_t, forcing the entire expression | |||
| 99 | // to be evaluated as int64_t. Overflow is not an issue. | |||
| 100 | int64_t diff = (((*b)->invocation_count() + (*b)->compiled_invocation_count()) | |||
| 101 | - ((*a)->invocation_count() + (*a)->compiled_invocation_count())); | |||
| 102 | return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; | |||
| 103 | } | |||
| 104 | ||||
| 105 | void collect_profiled_methods(Method* m) { | |||
| 106 | Thread* thread = Thread::current(); | |||
| 107 | methodHandle mh(thread, m); | |||
| 108 | if ((m->method_data() != NULL__null) && | |||
| 109 | (PrintMethodData || CompilerOracle::should_print(mh))) { | |||
| 110 | collected_profiled_methods->push(m); | |||
| 111 | } | |||
| 112 | } | |||
| 113 | ||||
| 114 | void print_method_profiling_data() { | |||
| 115 | if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)|| C1UpdateMethodData && | |||
| 116 | (PrintMethodData || CompilerOracle::should_print_methods())) { | |||
| 117 | ResourceMark rm; | |||
| 118 | collected_profiled_methods = new GrowableArray<Method*>(1024); | |||
| 119 | SystemDictionary::methods_do(collect_profiled_methods); | |||
| 120 | collected_profiled_methods->sort(&compare_methods); | |||
| 121 | ||||
| 122 | int count = collected_profiled_methods->length(); | |||
| 123 | int total_size = 0; | |||
| 124 | if (count > 0) { | |||
| 125 | for (int index = 0; index < count; index++) { | |||
| 126 | Method* m = collected_profiled_methods->at(index); | |||
| 127 | ttyLocker ttyl; | |||
| 128 | tty->print_cr("------------------------------------------------------------------------"); | |||
| 129 | m->print_invocation_count(); | |||
| 130 | tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes()); | |||
| 131 | tty->cr(); | |||
| 132 | // Dump data on parameters if any | |||
| 133 | if (m->method_data() != NULL__null && m->method_data()->parameters_type_data() != NULL__null) { | |||
| 134 | tty->fill_to(2); | |||
| 135 | m->method_data()->parameters_type_data()->print_data_on(tty); | |||
| 136 | } | |||
| 137 | m->print_codes(); | |||
| 138 | total_size += m->method_data()->size_in_bytes(); | |||
| 139 | } | |||
| 140 | tty->print_cr("------------------------------------------------------------------------"); | |||
| 141 | tty->print_cr("Total MDO size: %d bytes", total_size); | |||
| 142 | } | |||
| 143 | } | |||
| 144 | } | |||
| 145 | ||||
| 146 | ||||
| 147 | #ifndef PRODUCT | |||
| 148 | ||||
| 149 | // Statistics printing (method invocation histogram) | |||
| 150 | ||||
| 151 | GrowableArray<Method*>* collected_invoked_methods; | |||
| 152 | ||||
| 153 | void collect_invoked_methods(Method* m) { | |||
| 154 | if (m->invocation_count() + m->compiled_invocation_count() >= 1) { | |||
| 155 | collected_invoked_methods->push(m); | |||
| 156 | } | |||
| 157 | } | |||
| 158 | ||||
| 159 | ||||
| 160 | // Invocation count accumulators should be unsigned long to shift the | |||
| 161 | // overflow border. Longer-running workloads tend to create invocation | |||
| 162 | // counts which already overflow 32-bit counters for individual methods. | |||
| 163 | void print_method_invocation_histogram() { | |||
| 164 | ResourceMark rm; | |||
| 165 | collected_invoked_methods = new GrowableArray<Method*>(1024); | |||
| 166 | SystemDictionary::methods_do(collect_invoked_methods); | |||
| 167 | collected_invoked_methods->sort(&compare_methods); | |||
| 168 | // | |||
| 169 | tty->cr(); | |||
| 170 | tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT"%" "l" "d" "):", MethodHistogramCutoff); | |||
| 171 | tty->cr(); | |||
| 172 | tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); | |||
| 173 | uint64_t total = 0, | |||
| 174 | int_total = 0, | |||
| 175 | comp_total = 0, | |||
| 176 | special_total= 0, | |||
| 177 | static_total = 0, | |||
| 178 | final_total = 0, | |||
| 179 | synch_total = 0, | |||
| 180 | native_total = 0, | |||
| 181 | access_total = 0; | |||
| 182 | for (int index = 0; index < collected_invoked_methods->length(); index++) { | |||
| 183 | // Counter values returned from getter methods are signed int. | |||
| 184 | // To shift the overflow border by a factor of two, we interpret | |||
| 185 | // them here as unsigned long. A counter can't be negative anyway. | |||
| 186 | Method* m = collected_invoked_methods->at(index); | |||
| 187 | uint64_t iic = (uint64_t)m->invocation_count(); | |||
| 188 | uint64_t cic = (uint64_t)m->compiled_invocation_count(); | |||
| 189 | if ((iic + cic) >= (uint64_t)MethodHistogramCutoff) m->print_invocation_count(); | |||
| 190 | int_total += iic; | |||
| 191 | comp_total += cic; | |||
| 192 | if (m->is_final()) final_total += iic + cic; | |||
| 193 | if (m->is_static()) static_total += iic + cic; | |||
| 194 | if (m->is_synchronized()) synch_total += iic + cic; | |||
| 195 | if (m->is_native()) native_total += iic + cic; | |||
| 196 | if (m->is_accessor()) access_total += iic + cic; | |||
| 197 | } | |||
| 198 | tty->cr(); | |||
| 199 | total = int_total + comp_total; | |||
| 200 | special_total = final_total + static_total +synch_total + native_total + access_total; | |||
| 201 | tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length()); | |||
| 202 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (100%%) total", total); | |||
| 203 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- interpreted", int_total, 100.0 * int_total / total); | |||
| 204 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- compiled", comp_total, 100.0 * comp_total / total); | |||
| 205 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- special methods (interpreted and compiled)", | |||
| 206 | special_total, 100.0 * special_total/ total); | |||
| 207 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- synchronized",synch_total, 100.0 * synch_total / total); | |||
| 208 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- final", final_total, 100.0 * final_total / total); | |||
| 209 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- static", static_total, 100.0 * static_total / total); | |||
| 210 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- native", native_total, 100.0 * native_total / total); | |||
| 211 | tty->print_cr("\t" UINT64_FORMAT_W(12)"%" "12" "l" "u" " (%4.1f%%) |- accessor", access_total, 100.0 * access_total / total); | |||
| 212 | tty->cr(); | |||
| 213 | SharedRuntime::print_call_statistics(comp_total); | |||
| 214 | } | |||
| 215 | ||||
| 216 | void print_bytecode_count() { | |||
| 217 | if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |||
| 218 | tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); | |||
| 219 | } | |||
| 220 | } | |||
| 221 | ||||
| 222 | ||||
| 223 | // General statistics printing (profiling ...) | |||
| 224 | void print_statistics() { | |||
| 225 | if (CITime) { | |||
| 226 | CompileBroker::print_times(); | |||
| 227 | } | |||
| 228 | ||||
| 229 | #ifdef COMPILER11 | |||
| 230 | if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) { | |||
| 231 | FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics); | |||
| 232 | Runtime1::print_statistics(); | |||
| 233 | SharedRuntime::print_statistics(); | |||
| 234 | } | |||
| 235 | #endif /* COMPILER1 */ | |||
| 236 | ||||
| 237 | #ifdef COMPILER21 | |||
| 238 | if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) { | |||
| 239 | FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics); | |||
| 240 | Compile::print_statistics(); | |||
| 241 | Deoptimization::print_statistics(); | |||
| 242 | #ifndef COMPILER11 | |||
| 243 | SharedRuntime::print_statistics(); | |||
| 244 | #endif //COMPILER1 | |||
| 245 | os::print_statistics(); | |||
| 246 | } | |||
| 247 | ||||
| 248 | if (PrintLockStatistics || PrintPreciseRTMLockingStatistics) { | |||
| 249 | OptoRuntime::print_named_counters(); | |||
| 250 | } | |||
| 251 | #ifdef ASSERT1 | |||
| 252 | if (CollectIndexSetStatistics) { | |||
| 253 | IndexSet::print_statistics(); | |||
| 254 | } | |||
| 255 | #endif // ASSERT | |||
| 256 | #else // COMPILER2 | |||
| 257 | #if INCLUDE_JVMCI1 | |||
| 258 | #ifndef COMPILER11 | |||
| 259 | if ((TraceDeoptimization || LogVMOutput || LogCompilation) && UseCompiler) { | |||
| 260 | FlagSetting fs(DisplayVMOutput, DisplayVMOutput && TraceDeoptimization); | |||
| 261 | Deoptimization::print_statistics(); | |||
| 262 | SharedRuntime::print_statistics(); | |||
| 263 | } | |||
| 264 | #endif // COMPILER1 | |||
| 265 | #endif // INCLUDE_JVMCI | |||
| 266 | #endif // COMPILER2 | |||
| 267 | ||||
| 268 | if (PrintNMethodStatistics) { | |||
| 269 | nmethod::print_statistics(); | |||
| 270 | } | |||
| 271 | if (CountCompiledCalls) { | |||
| 272 | print_method_invocation_histogram(); | |||
| 273 | } | |||
| 274 | ||||
| 275 | print_method_profiling_data(); | |||
| 276 | ||||
| 277 | if (TimeOopMap) { | |||
| 278 | GenerateOopMap::print_time(); | |||
| 279 | } | |||
| 280 | if (PrintSymbolTableSizeHistogram) { | |||
| 281 | SymbolTable::print_histogram(); | |||
| 282 | } | |||
| 283 | if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |||
| 284 | BytecodeCounter::print(); | |||
| 285 | } | |||
| 286 | if (PrintBytecodePairHistogram) { | |||
| 287 | BytecodePairHistogram::print(); | |||
| 288 | } | |||
| 289 | ||||
| 290 | if (PrintCodeCache) { | |||
| 291 | MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |||
| 292 | CodeCache::print(); | |||
| 293 | } | |||
| 294 | ||||
| 295 | // CodeHeap State Analytics. | |||
| 296 | // Does also call NMethodSweeper::print(tty) | |||
| 297 | if (PrintCodeHeapAnalytics) { | |||
| 298 | CompileBroker::print_heapinfo(NULL__null, "all", 4096); // details | |||
| 299 | } else if (PrintMethodFlushingStatistics) { | |||
| 300 | NMethodSweeper::print(tty); | |||
| 301 | } | |||
| 302 | ||||
| 303 | if (PrintCodeCache2) { | |||
| 304 | MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |||
| 305 | CodeCache::print_internals(); | |||
| 306 | } | |||
| 307 | ||||
| 308 | if (VerifyOops && Verbose) { | |||
| 309 | tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count()); | |||
| 310 | } | |||
| 311 | ||||
| 312 | print_bytecode_count(); | |||
| 313 | ||||
| 314 | if (PrintSystemDictionaryAtExit) { | |||
| 315 | ResourceMark rm; | |||
| 316 | MutexLocker mcld(ClassLoaderDataGraph_lock); | |||
| 317 | SystemDictionary::print(); | |||
| 318 | } | |||
| 319 | ||||
| 320 | if (PrintClassLoaderDataGraphAtExit) { | |||
| 321 | ResourceMark rm; | |||
| 322 | MutexLocker mcld(ClassLoaderDataGraph_lock); | |||
| 323 | ClassLoaderDataGraph::print(); | |||
| 324 | } | |||
| 325 | ||||
| 326 | if (LogTouchedMethods && PrintTouchedMethodsAtExit) { | |||
| 327 | Method::print_touched_methods(tty); | |||
| 328 | } | |||
| 329 | ||||
| 330 | // Native memory tracking data | |||
| 331 | if (PrintNMTStatistics) { | |||
| 332 | MemTracker::final_report(tty); | |||
| 333 | } | |||
| 334 | ||||
| 335 | if (PrintMetaspaceStatisticsAtExit) { | |||
| 336 | MetaspaceUtils::print_basic_report(tty, 0); | |||
| 337 | } | |||
| 338 | ||||
| 339 | ThreadsSMRSupport::log_statistics(); | |||
| 340 | } | |||
| 341 | ||||
| 342 | #else // PRODUCT MODE STATISTICS | |||
| 343 | ||||
| 344 | void print_statistics() { | |||
| 345 | ||||
| 346 | if (PrintMethodData) { | |||
| 347 | print_method_profiling_data(); | |||
| 348 | } | |||
| 349 | ||||
| 350 | if (CITime) { | |||
| 351 | CompileBroker::print_times(); | |||
| 352 | } | |||
| 353 | ||||
| 354 | #ifdef COMPILER2_OR_JVMCI1 | |||
| 355 | if ((LogVMOutput || LogCompilation) && UseCompiler) { | |||
| 356 | // Only print the statistics to the log file | |||
| 357 | FlagSetting fs(DisplayVMOutput, false); | |||
| 358 | Deoptimization::print_statistics(); | |||
| 359 | } | |||
| 360 | #endif /* COMPILER2 || INCLUDE_JVMCI */ | |||
| 361 | ||||
| 362 | if (PrintCodeCache) { | |||
| 363 | MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |||
| 364 | CodeCache::print(); | |||
| 365 | } | |||
| 366 | ||||
| 367 | // CodeHeap State Analytics. | |||
| 368 | // Does also call NMethodSweeper::print(tty) | |||
| 369 | if (PrintCodeHeapAnalytics) { | |||
| 370 | CompileBroker::print_heapinfo(NULL__null, "all", 4096); // details | |||
| 371 | } else if (PrintMethodFlushingStatistics) { | |||
| 372 | NMethodSweeper::print(tty); | |||
| 373 | } | |||
| 374 | ||||
| 375 | #ifdef COMPILER21 | |||
| 376 | if (PrintPreciseRTMLockingStatistics) { | |||
| 377 | OptoRuntime::print_named_counters(); | |||
| 378 | } | |||
| 379 | #endif | |||
| 380 | ||||
| 381 | // Native memory tracking data | |||
| 382 | if (PrintNMTStatistics) { | |||
| 383 | MemTracker::final_report(tty); | |||
| 384 | } | |||
| 385 | ||||
| 386 | if (PrintMetaspaceStatisticsAtExit) { | |||
| 387 | MetaspaceUtils::print_basic_report(tty, 0); | |||
| 388 | } | |||
| 389 | ||||
| 390 | if (LogTouchedMethods && PrintTouchedMethodsAtExit) { | |||
| 391 | Method::print_touched_methods(tty); | |||
| 392 | } | |||
| 393 | ||||
| 394 | ThreadsSMRSupport::log_statistics(); | |||
| 395 | } | |||
| 396 | ||||
| 397 | #endif | |||
| 398 | ||||
| 399 | // Note: before_exit() can be executed only once, if more than one threads | |||
| 400 | // are trying to shutdown the VM at the same time, only one thread | |||
| 401 | // can run before_exit() and all other threads must wait. | |||
| 402 | void before_exit(JavaThread* thread) { | |||
| 403 | #define BEFORE_EXIT_NOT_RUN 0 | |||
| 404 | #define BEFORE_EXIT_RUNNING 1 | |||
| 405 | #define BEFORE_EXIT_DONE 2 | |||
| 406 | static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; | |||
| 407 | ||||
| 408 | // Note: don't use a Mutex to guard the entire before_exit(), as | |||
| 409 | // JVMTI post_thread_end_event and post_vm_death_event will run native code. | |||
| 410 | // A CAS or OSMutex would work just fine but then we need to manipulate | |||
| 411 | // thread state for Safepoint. Here we use Monitor wait() and notify_all() | |||
| 412 | // for synchronization. | |||
| 413 | { MonitorLocker ml(BeforeExit_lock); | |||
| 414 | switch (_before_exit_status) { | |||
| 415 | case BEFORE_EXIT_NOT_RUN: | |||
| 416 | _before_exit_status = BEFORE_EXIT_RUNNING; | |||
| 417 | break; | |||
| 418 | case BEFORE_EXIT_RUNNING: | |||
| 419 | while (_before_exit_status == BEFORE_EXIT_RUNNING) { | |||
| 420 | ml.wait(); | |||
| 421 | } | |||
| 422 | assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state")do { if (!(_before_exit_status == BEFORE_EXIT_DONE)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 422, "assert(" "_before_exit_status == BEFORE_EXIT_DONE" ") failed" , "invalid state"); ::breakpoint(); } } while (0); | |||
| 423 | return; | |||
| 424 | case BEFORE_EXIT_DONE: | |||
| 425 | // need block to avoid SS compiler bug | |||
| 426 | { | |||
| 427 | return; | |||
| 428 | } | |||
| 429 | } | |||
| 430 | } | |||
| 431 | ||||
| 432 | #if INCLUDE_JVMCI1 | |||
| 433 | if (EnableJVMCI) { | |||
| 434 | JVMCI::shutdown(); | |||
| 435 | } | |||
| 436 | #endif | |||
| 437 | ||||
| 438 | // Hang forever on exit if we're reporting an error. | |||
| 439 | if (ShowMessageBoxOnError && VMError::is_error_reported()) { | |||
| 440 | os::infinite_sleep(); | |||
| 441 | } | |||
| 442 | ||||
| 443 | EventThreadEnd event; | |||
| 444 | if (event.should_commit()) { | |||
| 445 | event.set_thread(JFR_THREAD_ID(thread)((thread)->jfr_thread_local()->thread_id())); | |||
| 446 | event.commit(); | |||
| 447 | } | |||
| 448 | ||||
| 449 | JFR_ONLY(Jfr::on_vm_shutdown();)Jfr::on_vm_shutdown(); | |||
| 450 | ||||
| 451 | // Stop the WatcherThread. We do this before disenrolling various | |||
| 452 | // PeriodicTasks to reduce the likelihood of races. | |||
| 453 | if (PeriodicTask::num_tasks() > 0) { | |||
| 454 | WatcherThread::stop(); | |||
| 455 | } | |||
| 456 | ||||
| 457 | // shut down the StatSampler task | |||
| 458 | StatSampler::disengage(); | |||
| 459 | StatSampler::destroy(); | |||
| 460 | ||||
| 461 | // Shut down string deduplication if running. | |||
| 462 | if (StringDedup::is_enabled()) { | |||
| 463 | StringDedup::stop(); | |||
| 464 | } | |||
| 465 | ||||
| 466 | // Stop concurrent GC threads | |||
| 467 | Universe::heap()->stop(); | |||
| 468 | ||||
| 469 | // Print GC/heap related information. | |||
| 470 | Log(gc, heap, exit)LogImpl<(LogTag::_gc), (LogTag::_heap), (LogTag::_exit), ( LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)> log; | |||
| 471 | if (log.is_info()) { | |||
| 472 | ResourceMark rm; | |||
| 473 | LogStream ls_info(log.info()); | |||
| 474 | Universe::print_on(&ls_info); | |||
| 475 | if (log.is_trace()) { | |||
| 476 | LogStream ls_trace(log.trace()); | |||
| 477 | MutexLocker mcld(ClassLoaderDataGraph_lock); | |||
| 478 | ClassLoaderDataGraph::print_on(&ls_trace); | |||
| 479 | } | |||
| 480 | } | |||
| 481 | ||||
| 482 | if (PrintBytecodeHistogram) { | |||
| 483 | BytecodeHistogram::print(); | |||
| 484 | } | |||
| 485 | ||||
| 486 | #ifdef LINUX1 | |||
| 487 | if (DumpPerfMapAtExit) { | |||
| 488 | CodeCache::write_perf_map(); | |||
| 489 | } | |||
| 490 | #endif | |||
| 491 | ||||
| 492 | if (JvmtiExport::should_post_thread_life()) { | |||
| 493 | JvmtiExport::post_thread_end(thread); | |||
| 494 | } | |||
| 495 | ||||
| 496 | // Always call even when there are not JVMTI environments yet, since environments | |||
| 497 | // may be attached late and JVMTI must track phases of VM execution | |||
| 498 | JvmtiExport::post_vm_death(); | |||
| 499 | Threads::shutdown_vm_agents(); | |||
| 500 | ||||
| 501 | // Terminate the signal thread | |||
| 502 | // Note: we don't wait until it actually dies. | |||
| 503 | os::terminate_signal_thread(); | |||
| 504 | ||||
| 505 | #if INCLUDE_CDS1 | |||
| 506 | if (DynamicArchive::should_dump_at_vm_exit()) { | |||
| 507 | assert(ArchiveClassesAtExit != NULL, "Must be already set")do { if (!(ArchiveClassesAtExit != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 507, "assert(" "ArchiveClassesAtExit != __null" ") failed", "Must be already set"); ::breakpoint(); } } while (0); | |||
| 508 | ExceptionMark em(thread); | |||
| 509 | DynamicArchive::dump(ArchiveClassesAtExit, thread); | |||
| 510 | if (thread->has_pending_exception()) { | |||
| 511 | ResourceMark rm(thread); | |||
| 512 | oop pending_exception = thread->pending_exception(); | |||
| 513 | log_error(cds)(!(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Error))) ? (void)0 : LogImpl<(LogTag ::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Error>("ArchiveClassesAtExit has failed %s: %s", pending_exception->klass()->external_name(), | |||
| 514 | java_lang_String::as_utf8_string(java_lang_Throwable::message(pending_exception))); | |||
| 515 | thread->clear_pending_exception(); | |||
| 516 | } | |||
| 517 | } | |||
| 518 | #endif | |||
| 519 | ||||
| 520 | print_statistics(); | |||
| 521 | Universe::heap()->print_tracing_info(); | |||
| 522 | ||||
| 523 | { MutexLocker ml(BeforeExit_lock); | |||
| 524 | _before_exit_status = BEFORE_EXIT_DONE; | |||
| 525 | BeforeExit_lock->notify_all(); | |||
| 526 | } | |||
| 527 | ||||
| 528 | if (VerifyStringTableAtExit) { | |||
| 529 | size_t fail_cnt = StringTable::verify_and_compare_entries(); | |||
| 530 | if (fail_cnt != 0) { | |||
| 531 | tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT"%" "l" "u", fail_cnt); | |||
| 532 | guarantee(fail_cnt == 0, "unexpected StringTable verification failures")do { if (!(fail_cnt == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 532, "guarantee(" "fail_cnt == 0" ") failed", "unexpected StringTable verification failures" ); ::breakpoint(); } } while (0); | |||
| 533 | } | |||
| 534 | } | |||
| 535 | ||||
| 536 | #undef BEFORE_EXIT_NOT_RUN | |||
| 537 | #undef BEFORE_EXIT_RUNNING | |||
| 538 | #undef BEFORE_EXIT_DONE | |||
| 539 | } | |||
| 540 | ||||
| 541 | void vm_exit(int code) { | |||
| 542 | Thread* thread = | |||
| 543 | ThreadLocalStorage::is_initialized() ? Thread::current_or_null() : NULL__null; | |||
| ||||
| 544 | if (thread
| |||
| 545 | // very early initialization failure -- just exit | |||
| 546 | vm_direct_exit(code); | |||
| 547 | } | |||
| 548 | ||||
| 549 | // We'd like to add an entry to the XML log to show that the VM is | |||
| 550 | // terminating, but we can't safely do that here. The logic to make | |||
| 551 | // XML termination logging safe is tied to the termination of the | |||
| 552 | // VMThread, and it doesn't terminate on this exit path. See 8222534. | |||
| 553 | ||||
| 554 | if (VMThread::vm_thread() != NULL__null) { | |||
| 555 | if (thread->is_Java_thread()) { | |||
| ||||
| 556 | // We must be "in_vm" for the code below to work correctly. | |||
| 557 | // Historically there must have been some exit path for which | |||
| 558 | // that was not the case and so we set it explicitly - even | |||
| 559 | // though we no longer know what that path may be. | |||
| 560 | JavaThread::cast(thread)->set_thread_state(_thread_in_vm); | |||
| 561 | } | |||
| 562 | ||||
| 563 | // Fire off a VM_Exit operation to bring VM to a safepoint and exit | |||
| 564 | VM_Exit op(code); | |||
| 565 | ||||
| 566 | // 4945125 The vm thread comes to a safepoint during exit. | |||
| 567 | // GC vm_operations can get caught at the safepoint, and the | |||
| 568 | // heap is unparseable if they are caught. Grab the Heap_lock | |||
| 569 | // to prevent this. The GC vm_operations will not be able to | |||
| 570 | // queue until after we release it, but we never do that as we | |||
| 571 | // are terminating the VM process. | |||
| 572 | MutexLocker ml(Heap_lock); | |||
| 573 | ||||
| 574 | VMThread::execute(&op); | |||
| 575 | // should never reach here; but in case something wrong with VM Thread. | |||
| 576 | vm_direct_exit(code); | |||
| 577 | } else { | |||
| 578 | // VM thread is gone, just exit | |||
| 579 | vm_direct_exit(code); | |||
| 580 | } | |||
| 581 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 581); ::breakpoint(); } while (0); | |||
| 582 | } | |||
| 583 | ||||
| 584 | void notify_vm_shutdown() { | |||
| 585 | // For now, just a dtrace probe. | |||
| 586 | HOTSPOT_VM_SHUTDOWN(); | |||
| 587 | } | |||
| 588 | ||||
| 589 | void vm_direct_exit(int code) { | |||
| 590 | notify_vm_shutdown(); | |||
| 591 | os::wait_for_keypress_at_exit(); | |||
| 592 | os::exit(code); | |||
| 593 | } | |||
| 594 | ||||
| 595 | void vm_direct_exit(int code, const char* message) { | |||
| 596 | if (message != nullptr) { | |||
| 597 | tty->print_cr("%s", message); | |||
| 598 | } | |||
| 599 | vm_direct_exit(code); | |||
| 600 | } | |||
| 601 | ||||
| 602 | void vm_perform_shutdown_actions() { | |||
| 603 | if (is_init_completed()) { | |||
| 604 | Thread* thread = Thread::current_or_null(); | |||
| 605 | if (thread != NULL__null && thread->is_Java_thread()) { | |||
| 606 | // We are leaving the VM, set state to native (in case any OS exit | |||
| 607 | // handlers call back to the VM) | |||
| 608 | JavaThread* jt = JavaThread::cast(thread); | |||
| 609 | // Must always be walkable or have no last_Java_frame when in | |||
| 610 | // thread_in_native | |||
| 611 | jt->frame_anchor()->make_walkable(jt); | |||
| 612 | jt->set_thread_state(_thread_in_native); | |||
| 613 | } | |||
| 614 | } | |||
| 615 | notify_vm_shutdown(); | |||
| 616 | } | |||
| 617 | ||||
| 618 | void vm_shutdown() | |||
| 619 | { | |||
| 620 | vm_perform_shutdown_actions(); | |||
| 621 | os::wait_for_keypress_at_exit(); | |||
| 622 | os::shutdown(); | |||
| 623 | } | |||
| 624 | ||||
| 625 | void vm_abort(bool dump_core) { | |||
| 626 | vm_perform_shutdown_actions(); | |||
| 627 | os::wait_for_keypress_at_exit(); | |||
| 628 | ||||
| 629 | // Flush stdout and stderr before abort. | |||
| 630 | fflush(stdoutstdout); | |||
| 631 | fflush(stderrstderr); | |||
| 632 | ||||
| 633 | os::abort(dump_core); | |||
| 634 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 634); ::breakpoint(); } while (0); | |||
| 635 | } | |||
| 636 | ||||
| 637 | void vm_notify_during_cds_dumping(const char* error, const char* message) { | |||
| 638 | if (error != NULL__null) { | |||
| 639 | tty->print_cr("Error occurred during CDS dumping"); | |||
| 640 | tty->print("%s", error); | |||
| 641 | if (message != NULL__null) { | |||
| 642 | tty->print_cr(": %s", message); | |||
| 643 | } | |||
| 644 | else { | |||
| 645 | tty->cr(); | |||
| 646 | } | |||
| 647 | } | |||
| 648 | } | |||
| 649 | ||||
| 650 | void vm_exit_during_cds_dumping(const char* error, const char* message) { | |||
| 651 | vm_notify_during_cds_dumping(error, message); | |||
| 652 | ||||
| 653 | // Failure during CDS dumping, we don't want to dump core | |||
| 654 | vm_abort(false); | |||
| 655 | } | |||
| 656 | ||||
| 657 | void vm_notify_during_shutdown(const char* error, const char* message) { | |||
| 658 | if (error != NULL__null) { | |||
| 659 | tty->print_cr("Error occurred during initialization of VM"); | |||
| 660 | tty->print("%s", error); | |||
| 661 | if (message != NULL__null) { | |||
| 662 | tty->print_cr(": %s", message); | |||
| 663 | } | |||
| 664 | else { | |||
| 665 | tty->cr(); | |||
| 666 | } | |||
| 667 | } | |||
| 668 | if (ShowMessageBoxOnError && WizardMode) { | |||
| 669 | fatal("Error occurred during initialization of VM")do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 669, "Error occurred during initialization of VM"); ::breakpoint (); } while (0); | |||
| 670 | } | |||
| 671 | } | |||
| 672 | ||||
| 673 | void vm_exit_during_initialization() { | |||
| 674 | vm_notify_during_shutdown(NULL__null, NULL__null); | |||
| 675 | ||||
| 676 | // Failure during initialization, we don't want to dump core | |||
| 677 | vm_abort(false); | |||
| 678 | } | |||
| 679 | ||||
| 680 | void vm_exit_during_initialization(Handle exception) { | |||
| 681 | tty->print_cr("Error occurred during initialization of VM"); | |||
| 682 | // If there are exceptions on this thread it must be cleared | |||
| 683 | // first and here. Any future calls to EXCEPTION_MARK requires | |||
| 684 | // that no pending exceptions exist. | |||
| 685 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // can't be NULL | |||
| 686 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | |||
| 687 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); | |||
| 688 | } | |||
| 689 | java_lang_Throwable::print_stack_trace(exception, tty); | |||
| 690 | tty->cr(); | |||
| 691 | vm_notify_during_shutdown(NULL__null, NULL__null); | |||
| 692 | ||||
| 693 | // Failure during initialization, we don't want to dump core | |||
| 694 | vm_abort(false); | |||
| 695 | } | |||
| 696 | ||||
| 697 | void vm_exit_during_initialization(Symbol* ex, const char* message) { | |||
| 698 | ResourceMark rm; | |||
| 699 | vm_notify_during_shutdown(ex->as_C_string(), message); | |||
| 700 | ||||
| 701 | // Failure during initialization, we don't want to dump core | |||
| 702 | vm_abort(false); | |||
| 703 | } | |||
| 704 | ||||
| 705 | void vm_exit_during_initialization(const char* error, const char* message) { | |||
| 706 | vm_notify_during_shutdown(error, message); | |||
| 707 | ||||
| 708 | // Failure during initialization, we don't want to dump core | |||
| 709 | vm_abort(false); | |||
| 710 | } | |||
| 711 | ||||
| 712 | void vm_shutdown_during_initialization(const char* error, const char* message) { | |||
| 713 | vm_notify_during_shutdown(error, message); | |||
| 714 | vm_shutdown(); | |||
| 715 | } | |||
| 716 | ||||
| 717 | JDK_Version JDK_Version::_current; | |||
| 718 | const char* JDK_Version::_java_version; | |||
| 719 | const char* JDK_Version::_runtime_name; | |||
| 720 | const char* JDK_Version::_runtime_version; | |||
| 721 | const char* JDK_Version::_runtime_vendor_version; | |||
| 722 | const char* JDK_Version::_runtime_vendor_vm_bug_url; | |||
| 723 | ||||
| 724 | void JDK_Version::initialize() { | |||
| 725 | assert(!_current.is_valid(), "Don't initialize twice")do { if (!(!_current.is_valid())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 725, "assert(" "!_current.is_valid()" ") failed", "Don't initialize twice" ); ::breakpoint(); } } while (0); | |||
| 726 | ||||
| 727 | int major = VM_Version::vm_major_version(); | |||
| 728 | int minor = VM_Version::vm_minor_version(); | |||
| 729 | int security = VM_Version::vm_security_version(); | |||
| 730 | int build = VM_Version::vm_build_number(); | |||
| 731 | int patch = VM_Version::vm_patch_version(); | |||
| 732 | _current = JDK_Version(major, minor, security, patch, build); | |||
| 733 | } | |||
| 734 | ||||
| 735 | void JDK_Version_init() { | |||
| 736 | JDK_Version::initialize(); | |||
| 737 | } | |||
| 738 | ||||
| 739 | static int64_t encode_jdk_version(const JDK_Version& v) { | |||
| 740 | return | |||
| 741 | ((int64_t)v.major_version() << (BitsPerByte * 4)) | | |||
| 742 | ((int64_t)v.minor_version() << (BitsPerByte * 3)) | | |||
| 743 | ((int64_t)v.security_version() << (BitsPerByte * 2)) | | |||
| 744 | ((int64_t)v.patch_version() << (BitsPerByte * 1)) | | |||
| 745 | ((int64_t)v.build_number() << (BitsPerByte * 0)); | |||
| 746 | } | |||
| 747 | ||||
| 748 | int JDK_Version::compare(const JDK_Version& other) const { | |||
| 749 | assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)")do { if (!(is_valid() && other.is_valid())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 749, "assert(" "is_valid() && other.is_valid()" ") failed" , "Invalid version (uninitialized?)"); ::breakpoint(); } } while (0); | |||
| 750 | uint64_t e = encode_jdk_version(*this); | |||
| 751 | uint64_t o = encode_jdk_version(other); | |||
| 752 | return (e > o) ? 1 : ((e == o) ? 0 : -1); | |||
| 753 | } | |||
| 754 | ||||
| 755 | /* See JEP 223 */ | |||
| 756 | void JDK_Version::to_string(char* buffer, size_t buflen) const { | |||
| 757 | assert(buffer && buflen > 0, "call with useful buffer")do { if (!(buffer && buflen > 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/java.cpp" , 757, "assert(" "buffer && buflen > 0" ") failed" , "call with useful buffer"); ::breakpoint(); } } while (0); | |||
| 758 | size_t index = 0; | |||
| 759 | ||||
| 760 | if (!is_valid()) { | |||
| 761 | jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); | |||
| 762 | } else { | |||
| 763 | int rc = jio_snprintf( | |||
| 764 | &buffer[index], buflen - index, "%d.%d", _major, _minor); | |||
| 765 | if (rc == -1) return; | |||
| 766 | index += rc; | |||
| 767 | if (_patch > 0) { | |||
| 768 | rc = jio_snprintf(&buffer[index], buflen - index, ".%d.%d", _security, _patch); | |||
| 769 | if (rc == -1) return; | |||
| 770 | index += rc; | |||
| 771 | } else if (_security > 0) { | |||
| 772 | rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security); | |||
| 773 | if (rc == -1) return; | |||
| 774 | index += rc; | |||
| 775 | } | |||
| 776 | if (_build > 0) { | |||
| 777 | rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build); | |||
| 778 | if (rc == -1) return; | |||
| 779 | index += rc; | |||
| 780 | } | |||
| 781 | } | |||
| 782 | } |