src/share/vm/runtime/java.cpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 8604
04d83ba48607
child 9756
2be326848943
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

aoqi@0 1 /*
shshahma@8584 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #include "precompiled.hpp"
aoqi@0 32 #include "classfile/classLoader.hpp"
aoqi@0 33 #include "classfile/symbolTable.hpp"
aoqi@0 34 #include "classfile/systemDictionary.hpp"
aoqi@0 35 #include "code/codeCache.hpp"
aoqi@0 36 #include "compiler/compileBroker.hpp"
aoqi@0 37 #include "compiler/compilerOracle.hpp"
aoqi@0 38 #include "interpreter/bytecodeHistogram.hpp"
aoqi@0 39 #include "memory/genCollectedHeap.hpp"
aoqi@0 40 #include "memory/oopFactory.hpp"
aoqi@0 41 #include "memory/universe.hpp"
aoqi@0 42 #include "oops/constantPool.hpp"
aoqi@0 43 #include "oops/generateOopMap.hpp"
aoqi@0 44 #include "oops/instanceKlass.hpp"
aoqi@0 45 #include "oops/instanceOop.hpp"
aoqi@0 46 #include "oops/method.hpp"
aoqi@0 47 #include "oops/objArrayOop.hpp"
aoqi@0 48 #include "oops/oop.inline.hpp"
aoqi@0 49 #include "oops/symbol.hpp"
aoqi@0 50 #include "prims/jvmtiExport.hpp"
aoqi@0 51 #include "runtime/arguments.hpp"
aoqi@0 52 #include "runtime/biasedLocking.hpp"
aoqi@0 53 #include "runtime/compilationPolicy.hpp"
aoqi@0 54 #include "runtime/fprofiler.hpp"
aoqi@0 55 #include "runtime/init.hpp"
aoqi@0 56 #include "runtime/interfaceSupport.hpp"
aoqi@0 57 #include "runtime/java.hpp"
aoqi@0 58 #include "runtime/memprofiler.hpp"
aoqi@0 59 #include "runtime/sharedRuntime.hpp"
aoqi@0 60 #include "runtime/statSampler.hpp"
aoqi@0 61 #include "runtime/sweeper.hpp"
aoqi@0 62 #include "runtime/task.hpp"
aoqi@0 63 #include "runtime/thread.inline.hpp"
aoqi@0 64 #include "runtime/timer.hpp"
aoqi@0 65 #include "runtime/vm_operations.hpp"
aoqi@0 66 #include "services/memTracker.hpp"
aoqi@0 67 #include "trace/tracing.hpp"
aoqi@0 68 #include "utilities/dtrace.hpp"
aoqi@0 69 #include "utilities/globalDefinitions.hpp"
aoqi@0 70 #include "utilities/histogram.hpp"
aoqi@0 71 #include "utilities/macros.hpp"
aoqi@0 72 #include "utilities/vmError.hpp"
aoqi@0 73 #ifdef TARGET_ARCH_x86
aoqi@0 74 # include "vm_version_x86.hpp"
aoqi@0 75 #endif
aoqi@0 76 #ifdef TARGET_ARCH_sparc
aoqi@0 77 # include "vm_version_sparc.hpp"
aoqi@0 78 #endif
aoqi@0 79 #ifdef TARGET_ARCH_zero
aoqi@0 80 # include "vm_version_zero.hpp"
aoqi@0 81 #endif
aoqi@0 82 #ifdef TARGET_ARCH_arm
aoqi@0 83 # include "vm_version_arm.hpp"
aoqi@0 84 #endif
aoqi@0 85 #ifdef TARGET_ARCH_ppc
aoqi@0 86 # include "vm_version_ppc.hpp"
aoqi@0 87 #endif
aoqi@1 88 #ifdef TARGET_ARCH_mips
aoqi@1 89 # include "vm_version_mips.hpp"
aoqi@1 90 #endif
aoqi@0 91 #if INCLUDE_ALL_GCS
aoqi@0 92 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
aoqi@0 93 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
aoqi@0 94 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
aoqi@0 95 #endif // INCLUDE_ALL_GCS
aoqi@0 96 #ifdef COMPILER1
aoqi@0 97 #include "c1/c1_Compiler.hpp"
aoqi@0 98 #include "c1/c1_Runtime1.hpp"
aoqi@0 99 #endif
aoqi@0 100 #ifdef COMPILER2
aoqi@0 101 #include "code/compiledIC.hpp"
aoqi@0 102 #include "compiler/methodLiveness.hpp"
aoqi@0 103 #include "opto/compile.hpp"
aoqi@0 104 #include "opto/indexSet.hpp"
aoqi@0 105 #include "opto/runtime.hpp"
aoqi@0 106 #endif
aoqi@0 107
aoqi@0 108 #ifndef USDT2
aoqi@0 109 HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown);
aoqi@0 110 #endif /* !USDT2 */
aoqi@0 111
aoqi@0 112 #ifndef PRODUCT
aoqi@0 113
aoqi@0 114 // Statistics printing (method invocation histogram)
aoqi@0 115
aoqi@0 116 GrowableArray<Method*>* collected_invoked_methods;
aoqi@0 117
aoqi@0 118 void collect_invoked_methods(Method* m) {
aoqi@0 119 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) {
aoqi@0 120 collected_invoked_methods->push(m);
aoqi@0 121 }
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 125
aoqi@0 126 GrowableArray<Method*>* collected_profiled_methods;
aoqi@0 127
aoqi@0 128 void collect_profiled_methods(Method* m) {
aoqi@0 129 Thread* thread = Thread::current();
aoqi@0 130 // This HandleMark prevents a huge amount of handles from being added
aoqi@0 131 // to the metadata_handles() array on the thread.
aoqi@0 132 HandleMark hm(thread);
aoqi@0 133 methodHandle mh(thread, m);
aoqi@0 134 if ((m->method_data() != NULL) &&
aoqi@0 135 (PrintMethodData || CompilerOracle::should_print(mh))) {
aoqi@0 136 collected_profiled_methods->push(m);
aoqi@0 137 }
aoqi@0 138 }
aoqi@0 139
aoqi@0 140
aoqi@0 141 int compare_methods(Method** a, Method** b) {
aoqi@0 142 // %%% there can be 32-bit overflow here
aoqi@0 143 return ((*b)->invocation_count() + (*b)->compiled_invocation_count())
aoqi@0 144 - ((*a)->invocation_count() + (*a)->compiled_invocation_count());
aoqi@0 145 }
aoqi@0 146
aoqi@0 147
aoqi@0 148 void print_method_invocation_histogram() {
aoqi@0 149 ResourceMark rm;
aoqi@0 150 HandleMark hm;
aoqi@0 151 collected_invoked_methods = new GrowableArray<Method*>(1024);
aoqi@0 152 SystemDictionary::methods_do(collect_invoked_methods);
aoqi@0 153 collected_invoked_methods->sort(&compare_methods);
aoqi@0 154 //
aoqi@0 155 tty->cr();
aoqi@0 156 tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff);
aoqi@0 157 tty->cr();
aoqi@0 158 tty->print_cr("____Count_(I+C)____Method________________________Module_________________");
aoqi@0 159 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,
aoqi@0 160 synch_total = 0, nativ_total = 0, acces_total = 0;
aoqi@0 161 for (int index = 0; index < collected_invoked_methods->length(); index++) {
aoqi@0 162 Method* m = collected_invoked_methods->at(index);
aoqi@0 163 int c = m->invocation_count() + m->compiled_invocation_count();
aoqi@0 164 if (c >= MethodHistogramCutoff) m->print_invocation_count();
aoqi@0 165 int_total += m->invocation_count();
aoqi@0 166 comp_total += m->compiled_invocation_count();
aoqi@0 167 if (m->is_final()) final_total += c;
aoqi@0 168 if (m->is_static()) static_total += c;
aoqi@0 169 if (m->is_synchronized()) synch_total += c;
aoqi@0 170 if (m->is_native()) nativ_total += c;
aoqi@0 171 if (m->is_accessor()) acces_total += c;
aoqi@0 172 }
aoqi@0 173 tty->cr();
aoqi@0 174 total = int_total + comp_total;
aoqi@0 175 tty->print_cr("Invocations summary:");
aoqi@0 176 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total);
aoqi@0 177 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total);
aoqi@0 178 tty->print_cr("\t%9d (100%%) total", total);
aoqi@0 179 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total);
aoqi@0 180 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total);
aoqi@0 181 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total);
aoqi@0 182 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total);
aoqi@0 183 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total);
aoqi@0 184 tty->cr();
aoqi@0 185 SharedRuntime::print_call_statistics(comp_total);
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 void print_method_profiling_data() {
aoqi@0 189 ResourceMark rm;
aoqi@0 190 HandleMark hm;
aoqi@0 191 collected_profiled_methods = new GrowableArray<Method*>(1024);
aoqi@0 192 SystemDictionary::methods_do(collect_profiled_methods);
aoqi@0 193 collected_profiled_methods->sort(&compare_methods);
aoqi@0 194
aoqi@0 195 int count = collected_profiled_methods->length();
aoqi@0 196 int total_size = 0;
aoqi@0 197 if (count > 0) {
aoqi@0 198 for (int index = 0; index < count; index++) {
aoqi@0 199 Method* m = collected_profiled_methods->at(index);
aoqi@0 200 ttyLocker ttyl;
aoqi@0 201 tty->print_cr("------------------------------------------------------------------------");
aoqi@0 202 //m->print_name(tty);
aoqi@0 203 m->print_invocation_count();
aoqi@0 204 tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
aoqi@0 205 tty->cr();
aoqi@0 206 // Dump data on parameters if any
aoqi@0 207 if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) {
aoqi@0 208 tty->fill_to(2);
aoqi@0 209 m->method_data()->parameters_type_data()->print_data_on(tty);
aoqi@0 210 }
aoqi@0 211 m->print_codes();
aoqi@0 212 total_size += m->method_data()->size_in_bytes();
aoqi@0 213 }
aoqi@0 214 tty->print_cr("------------------------------------------------------------------------");
aoqi@0 215 tty->print_cr("Total MDO size: %d bytes", total_size);
aoqi@0 216 }
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 void print_bytecode_count() {
aoqi@0 220 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
aoqi@0 221 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 AllocStats alloc_stats;
aoqi@0 226
aoqi@0 227
aoqi@0 228
aoqi@0 229 // General statistics printing (profiling ...)
aoqi@0 230 void print_statistics() {
aoqi@0 231 #ifdef ASSERT
aoqi@0 232
aoqi@0 233 if (CountRuntimeCalls) {
aoqi@0 234 extern Histogram *RuntimeHistogram;
aoqi@0 235 RuntimeHistogram->print();
aoqi@0 236 }
aoqi@0 237
aoqi@0 238 if (CountJNICalls) {
aoqi@0 239 extern Histogram *JNIHistogram;
aoqi@0 240 JNIHistogram->print();
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 if (CountJVMCalls) {
aoqi@0 244 extern Histogram *JVMHistogram;
aoqi@0 245 JVMHistogram->print();
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 #endif
aoqi@0 249
aoqi@0 250 if (MemProfiling) {
aoqi@0 251 MemProfiler::disengage();
aoqi@0 252 }
aoqi@0 253
aoqi@0 254 if (CITime) {
aoqi@0 255 CompileBroker::print_times();
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 #ifdef COMPILER1
aoqi@0 259 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
aoqi@0 260 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
aoqi@0 261 Runtime1::print_statistics();
aoqi@0 262 Deoptimization::print_statistics();
aoqi@0 263 SharedRuntime::print_statistics();
aoqi@0 264 nmethod::print_statistics();
aoqi@0 265 }
aoqi@0 266 #endif /* COMPILER1 */
aoqi@0 267
aoqi@0 268 #ifdef COMPILER2
aoqi@0 269 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
aoqi@0 270 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
aoqi@0 271 Compile::print_statistics();
aoqi@0 272 #ifndef COMPILER1
aoqi@0 273 Deoptimization::print_statistics();
aoqi@0 274 nmethod::print_statistics();
aoqi@0 275 SharedRuntime::print_statistics();
aoqi@0 276 #endif //COMPILER1
aoqi@0 277 os::print_statistics();
aoqi@0 278 }
aoqi@0 279
aoqi@0 280 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
aoqi@0 281 OptoRuntime::print_named_counters();
aoqi@0 282 }
aoqi@0 283
aoqi@0 284 if (TimeLivenessAnalysis) {
aoqi@0 285 MethodLiveness::print_times();
aoqi@0 286 }
aoqi@0 287 #ifdef ASSERT
aoqi@0 288 if (CollectIndexSetStatistics) {
aoqi@0 289 IndexSet::print_statistics();
aoqi@0 290 }
aoqi@0 291 #endif // ASSERT
aoqi@0 292 #endif // COMPILER2
aoqi@0 293 if (CountCompiledCalls) {
aoqi@0 294 print_method_invocation_histogram();
aoqi@0 295 }
aoqi@0 296 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) {
aoqi@0 297 print_method_profiling_data();
aoqi@0 298 }
aoqi@0 299 if (TimeCompiler) {
aoqi@0 300 COMPILER2_PRESENT(Compile::print_timers();)
aoqi@0 301 }
aoqi@0 302 if (TimeCompilationPolicy) {
aoqi@0 303 CompilationPolicy::policy()->print_time();
aoqi@0 304 }
aoqi@0 305 if (TimeOopMap) {
aoqi@0 306 GenerateOopMap::print_time();
aoqi@0 307 }
aoqi@0 308 if (ProfilerCheckIntervals) {
aoqi@0 309 PeriodicTask::print_intervals();
aoqi@0 310 }
aoqi@0 311 if (PrintSymbolTableSizeHistogram) {
aoqi@0 312 SymbolTable::print_histogram();
aoqi@0 313 }
aoqi@0 314 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
aoqi@0 315 BytecodeCounter::print();
aoqi@0 316 }
aoqi@0 317 if (PrintBytecodePairHistogram) {
aoqi@0 318 BytecodePairHistogram::print();
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 if (PrintCodeCache) {
aoqi@0 322 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 323 CodeCache::print();
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 if (PrintMethodFlushingStatistics) {
aoqi@0 327 NMethodSweeper::print();
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 if (PrintCodeCache2) {
aoqi@0 331 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 332 CodeCache::print_internals();
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 if (PrintClassStatistics) {
aoqi@0 336 SystemDictionary::print_class_statistics();
aoqi@0 337 }
aoqi@0 338 if (PrintMethodStatistics) {
aoqi@0 339 SystemDictionary::print_method_statistics();
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 if (PrintVtableStats) {
aoqi@0 343 klassVtable::print_statistics();
aoqi@0 344 klassItable::print_statistics();
aoqi@0 345 }
aoqi@0 346 if (VerifyOops) {
aoqi@0 347 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 print_bytecode_count();
aoqi@0 351 if (PrintMallocStatistics) {
aoqi@0 352 tty->print("allocation stats: ");
aoqi@0 353 alloc_stats.print();
aoqi@0 354 tty->cr();
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 if (PrintSystemDictionaryAtExit) {
aoqi@0 358 SystemDictionary::print();
aoqi@0 359 }
aoqi@0 360
aoqi@0 361 if (PrintBiasedLockingStatistics) {
aoqi@0 362 BiasedLocking::print_counters();
aoqi@0 363 }
aoqi@0 364
aoqi@0 365 #ifdef ENABLE_ZAP_DEAD_LOCALS
aoqi@0 366 #ifdef COMPILER2
aoqi@0 367 if (ZapDeadCompiledLocals) {
aoqi@0 368 tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count);
aoqi@0 369 tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count);
aoqi@0 370 }
aoqi@0 371 #endif // COMPILER2
aoqi@0 372 #endif // ENABLE_ZAP_DEAD_LOCALS
aoqi@0 373 // Native memory tracking data
aoqi@0 374 if (PrintNMTStatistics) {
zgu@7074 375 MemTracker::final_report(tty);
aoqi@0 376 }
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 #else // PRODUCT MODE STATISTICS
aoqi@0 380
aoqi@0 381 void print_statistics() {
aoqi@0 382
aoqi@0 383 if (CITime) {
aoqi@0 384 CompileBroker::print_times();
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 if (PrintCodeCache) {
aoqi@0 388 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 389 CodeCache::print();
aoqi@0 390 }
aoqi@0 391
aoqi@0 392 if (PrintMethodFlushingStatistics) {
aoqi@0 393 NMethodSweeper::print();
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 #ifdef COMPILER2
aoqi@0 397 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
aoqi@0 398 OptoRuntime::print_named_counters();
aoqi@0 399 }
aoqi@0 400 #endif
aoqi@0 401 if (PrintBiasedLockingStatistics) {
aoqi@0 402 BiasedLocking::print_counters();
aoqi@0 403 }
aoqi@0 404
aoqi@0 405 // Native memory tracking data
aoqi@0 406 if (PrintNMTStatistics) {
zgu@7074 407 MemTracker::final_report(tty);
aoqi@0 408 }
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 #endif
aoqi@0 412
aoqi@0 413
aoqi@0 414 // Helper class for registering on_exit calls through JVM_OnExit
aoqi@0 415
aoqi@0 416 extern "C" {
aoqi@0 417 typedef void (*__exit_proc)(void);
aoqi@0 418 }
aoqi@0 419
aoqi@0 420 class ExitProc : public CHeapObj<mtInternal> {
aoqi@0 421 private:
aoqi@0 422 __exit_proc _proc;
aoqi@0 423 // void (*_proc)(void);
aoqi@0 424 ExitProc* _next;
aoqi@0 425 public:
aoqi@0 426 // ExitProc(void (*proc)(void)) {
aoqi@0 427 ExitProc(__exit_proc proc) {
aoqi@0 428 _proc = proc;
aoqi@0 429 _next = NULL;
aoqi@0 430 }
aoqi@0 431 void evaluate() { _proc(); }
aoqi@0 432 ExitProc* next() const { return _next; }
aoqi@0 433 void set_next(ExitProc* next) { _next = next; }
aoqi@0 434 };
aoqi@0 435
aoqi@0 436
aoqi@0 437 // Linked list of registered on_exit procedures
aoqi@0 438
aoqi@0 439 static ExitProc* exit_procs = NULL;
aoqi@0 440
aoqi@0 441
aoqi@0 442 extern "C" {
aoqi@0 443 void register_on_exit_function(void (*func)(void)) {
aoqi@0 444 ExitProc *entry = new ExitProc(func);
aoqi@0 445 // Classic vm does not throw an exception in case the allocation failed,
aoqi@0 446 if (entry != NULL) {
aoqi@0 447 entry->set_next(exit_procs);
aoqi@0 448 exit_procs = entry;
aoqi@0 449 }
aoqi@0 450 }
aoqi@0 451 }
aoqi@0 452
aoqi@0 453 // Note: before_exit() can be executed only once, if more than one threads
aoqi@0 454 // are trying to shutdown the VM at the same time, only one thread
aoqi@0 455 // can run before_exit() and all other threads must wait.
aoqi@0 456 void before_exit(JavaThread * thread) {
aoqi@0 457 #define BEFORE_EXIT_NOT_RUN 0
aoqi@0 458 #define BEFORE_EXIT_RUNNING 1
aoqi@0 459 #define BEFORE_EXIT_DONE 2
aoqi@0 460 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
aoqi@0 461
aoqi@0 462 // Note: don't use a Mutex to guard the entire before_exit(), as
aoqi@0 463 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
aoqi@0 464 // A CAS or OSMutex would work just fine but then we need to manipulate
aoqi@0 465 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
aoqi@0 466 // for synchronization.
aoqi@0 467 { MutexLocker ml(BeforeExit_lock);
aoqi@0 468 switch (_before_exit_status) {
aoqi@0 469 case BEFORE_EXIT_NOT_RUN:
aoqi@0 470 _before_exit_status = BEFORE_EXIT_RUNNING;
aoqi@0 471 break;
aoqi@0 472 case BEFORE_EXIT_RUNNING:
aoqi@0 473 while (_before_exit_status == BEFORE_EXIT_RUNNING) {
aoqi@0 474 BeforeExit_lock->wait();
aoqi@0 475 }
aoqi@0 476 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
aoqi@0 477 return;
aoqi@0 478 case BEFORE_EXIT_DONE:
aoqi@0 479 return;
aoqi@0 480 }
aoqi@0 481 }
aoqi@0 482
aoqi@0 483 // The only difference between this and Win32's _onexit procs is that
aoqi@0 484 // this version is invoked before any threads get killed.
aoqi@0 485 ExitProc* current = exit_procs;
aoqi@0 486 while (current != NULL) {
aoqi@0 487 ExitProc* next = current->next();
aoqi@0 488 current->evaluate();
aoqi@0 489 delete current;
aoqi@0 490 current = next;
aoqi@0 491 }
aoqi@0 492
aoqi@0 493 // Hang forever on exit if we're reporting an error.
aoqi@0 494 if (ShowMessageBoxOnError && is_error_reported()) {
aoqi@0 495 os::infinite_sleep();
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 // Terminate watcher thread - must before disenrolling any periodic task
aoqi@0 499 if (PeriodicTask::num_tasks() > 0)
aoqi@0 500 WatcherThread::stop();
aoqi@0 501
aoqi@0 502 // Print statistics gathered (profiling ...)
aoqi@0 503 if (Arguments::has_profile()) {
aoqi@0 504 FlatProfiler::disengage();
aoqi@0 505 FlatProfiler::print(10);
aoqi@0 506 }
aoqi@0 507
aoqi@0 508 // shut down the StatSampler task
aoqi@0 509 StatSampler::disengage();
aoqi@0 510 StatSampler::destroy();
aoqi@0 511
aoqi@0 512 // Stop concurrent GC threads
aoqi@0 513 Universe::heap()->stop();
aoqi@0 514
aoqi@0 515 // Print GC/heap related information.
aoqi@0 516 if (PrintGCDetails) {
aoqi@0 517 Universe::print();
aoqi@0 518 AdaptiveSizePolicyOutput(0);
aoqi@0 519 if (Verbose) {
aoqi@0 520 ClassLoaderDataGraph::dump_on(gclog_or_tty);
aoqi@0 521 }
aoqi@0 522 }
aoqi@0 523
aoqi@0 524 if (PrintBytecodeHistogram) {
aoqi@0 525 BytecodeHistogram::print();
aoqi@0 526 }
aoqi@0 527
aoqi@0 528 if (JvmtiExport::should_post_thread_life()) {
aoqi@0 529 JvmtiExport::post_thread_end(thread);
aoqi@0 530 }
aoqi@0 531
aoqi@0 532
aoqi@0 533 EventThreadEnd event;
aoqi@0 534 if (event.should_commit()) {
aoqi@0 535 event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj()));
aoqi@0 536 event.commit();
aoqi@0 537 }
aoqi@0 538
aoqi@0 539 // Always call even when there are not JVMTI environments yet, since environments
aoqi@0 540 // may be attached late and JVMTI must track phases of VM execution
aoqi@0 541 JvmtiExport::post_vm_death();
aoqi@0 542 Threads::shutdown_vm_agents();
aoqi@0 543
aoqi@0 544 // Terminate the signal thread
aoqi@0 545 // Note: we don't wait until it actually dies.
aoqi@0 546 os::terminate_signal_thread();
aoqi@0 547
aoqi@0 548 print_statistics();
aoqi@0 549 Universe::heap()->print_tracing_info();
aoqi@0 550
aoqi@0 551 { MutexLocker ml(BeforeExit_lock);
aoqi@0 552 _before_exit_status = BEFORE_EXIT_DONE;
aoqi@0 553 BeforeExit_lock->notify_all();
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 if (VerifyStringTableAtExit) {
aoqi@0 557 int fail_cnt = 0;
aoqi@0 558 {
aoqi@0 559 MutexLocker ml(StringTable_lock);
aoqi@0 560 fail_cnt = StringTable::verify_and_compare_entries();
aoqi@0 561 }
aoqi@0 562
aoqi@0 563 if (fail_cnt != 0) {
aoqi@0 564 tty->print_cr("ERROR: fail_cnt=%d", fail_cnt);
aoqi@0 565 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
aoqi@0 566 }
aoqi@0 567 }
aoqi@0 568
aoqi@0 569 #undef BEFORE_EXIT_NOT_RUN
aoqi@0 570 #undef BEFORE_EXIT_RUNNING
aoqi@0 571 #undef BEFORE_EXIT_DONE
aoqi@0 572 }
aoqi@0 573
aoqi@0 574 void vm_exit(int code) {
aoqi@0 575 Thread* thread = ThreadLocalStorage::is_initialized() ?
aoqi@0 576 ThreadLocalStorage::get_thread_slow() : NULL;
aoqi@0 577 if (thread == NULL) {
aoqi@0 578 // we have serious problems -- just exit
aoqi@0 579 vm_direct_exit(code);
aoqi@0 580 }
aoqi@0 581
aoqi@0 582 if (VMThread::vm_thread() != NULL) {
aoqi@0 583 // Fire off a VM_Exit operation to bring VM to a safepoint and exit
aoqi@0 584 VM_Exit op(code);
aoqi@0 585 if (thread->is_Java_thread())
aoqi@0 586 ((JavaThread*)thread)->set_thread_state(_thread_in_vm);
aoqi@0 587 VMThread::execute(&op);
aoqi@0 588 // should never reach here; but in case something wrong with VM Thread.
aoqi@0 589 vm_direct_exit(code);
aoqi@0 590 } else {
aoqi@0 591 // VM thread is gone, just exit
aoqi@0 592 vm_direct_exit(code);
aoqi@0 593 }
aoqi@0 594 ShouldNotReachHere();
aoqi@0 595 }
aoqi@0 596
aoqi@0 597 void notify_vm_shutdown() {
aoqi@0 598 // For now, just a dtrace probe.
aoqi@0 599 #ifndef USDT2
aoqi@0 600 HS_DTRACE_PROBE(hotspot, vm__shutdown);
aoqi@0 601 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
aoqi@0 602 #else /* USDT2 */
aoqi@0 603 HOTSPOT_VM_SHUTDOWN();
aoqi@0 604 #endif /* USDT2 */
aoqi@0 605 }
aoqi@0 606
aoqi@0 607 void vm_direct_exit(int code) {
aoqi@0 608 notify_vm_shutdown();
aoqi@0 609 os::wait_for_keypress_at_exit();
aoqi@0 610 ::exit(code);
aoqi@0 611 }
aoqi@0 612
aoqi@0 613 void vm_perform_shutdown_actions() {
aoqi@0 614 // Warning: do not call 'exit_globals()' here. All threads are still running.
aoqi@0 615 // Calling 'exit_globals()' will disable thread-local-storage and cause all
aoqi@0 616 // kinds of assertions to trigger in debug mode.
aoqi@0 617 if (is_init_completed()) {
aoqi@0 618 Thread* thread = ThreadLocalStorage::is_initialized() ?
aoqi@0 619 ThreadLocalStorage::get_thread_slow() : NULL;
aoqi@0 620 if (thread != NULL && thread->is_Java_thread()) {
aoqi@0 621 // We are leaving the VM, set state to native (in case any OS exit
aoqi@0 622 // handlers call back to the VM)
aoqi@0 623 JavaThread* jt = (JavaThread*)thread;
aoqi@0 624 // Must always be walkable or have no last_Java_frame when in
aoqi@0 625 // thread_in_native
aoqi@0 626 jt->frame_anchor()->make_walkable(jt);
aoqi@0 627 jt->set_thread_state(_thread_in_native);
aoqi@0 628 }
aoqi@0 629 }
aoqi@0 630 notify_vm_shutdown();
aoqi@0 631 }
aoqi@0 632
aoqi@0 633 void vm_shutdown()
aoqi@0 634 {
aoqi@0 635 vm_perform_shutdown_actions();
aoqi@0 636 os::wait_for_keypress_at_exit();
aoqi@0 637 os::shutdown();
aoqi@0 638 }
aoqi@0 639
aoqi@0 640 void vm_abort(bool dump_core) {
aoqi@0 641 vm_perform_shutdown_actions();
aoqi@0 642 os::wait_for_keypress_at_exit();
aoqi@0 643 os::abort(dump_core);
aoqi@0 644 ShouldNotReachHere();
aoqi@0 645 }
aoqi@0 646
aoqi@0 647 void vm_notify_during_shutdown(const char* error, const char* message) {
aoqi@0 648 if (error != NULL) {
aoqi@0 649 tty->print_cr("Error occurred during initialization of VM");
aoqi@0 650 tty->print("%s", error);
aoqi@0 651 if (message != NULL) {
aoqi@0 652 tty->print_cr(": %s", message);
aoqi@0 653 }
aoqi@0 654 else {
aoqi@0 655 tty->cr();
aoqi@0 656 }
aoqi@0 657 }
aoqi@0 658 if (ShowMessageBoxOnError && WizardMode) {
aoqi@0 659 fatal("Error occurred during initialization of VM");
aoqi@0 660 }
aoqi@0 661 }
aoqi@0 662
aoqi@0 663 void vm_exit_during_initialization(Handle exception) {
aoqi@0 664 tty->print_cr("Error occurred during initialization of VM");
aoqi@0 665 // If there are exceptions on this thread it must be cleared
aoqi@0 666 // first and here. Any future calls to EXCEPTION_MARK requires
aoqi@0 667 // that no pending exceptions exist.
aoqi@0 668 Thread *THREAD = Thread::current();
aoqi@0 669 if (HAS_PENDING_EXCEPTION) {
aoqi@0 670 CLEAR_PENDING_EXCEPTION;
aoqi@0 671 }
aoqi@0 672 java_lang_Throwable::print(exception, tty);
aoqi@0 673 tty->cr();
aoqi@0 674 java_lang_Throwable::print_stack_trace(exception(), tty);
aoqi@0 675 tty->cr();
aoqi@0 676 vm_notify_during_shutdown(NULL, NULL);
aoqi@0 677
aoqi@0 678 // Failure during initialization, we don't want to dump core
aoqi@0 679 vm_abort(false);
aoqi@0 680 }
aoqi@0 681
aoqi@0 682 void vm_exit_during_initialization(Symbol* ex, const char* message) {
aoqi@0 683 ResourceMark rm;
aoqi@0 684 vm_notify_during_shutdown(ex->as_C_string(), message);
aoqi@0 685
aoqi@0 686 // Failure during initialization, we don't want to dump core
aoqi@0 687 vm_abort(false);
aoqi@0 688 }
aoqi@0 689
aoqi@0 690 void vm_exit_during_initialization(const char* error, const char* message) {
aoqi@0 691 vm_notify_during_shutdown(error, message);
aoqi@0 692
aoqi@0 693 // Failure during initialization, we don't want to dump core
aoqi@0 694 vm_abort(false);
aoqi@0 695 }
aoqi@0 696
aoqi@0 697 void vm_shutdown_during_initialization(const char* error, const char* message) {
aoqi@0 698 vm_notify_during_shutdown(error, message);
aoqi@0 699 vm_shutdown();
aoqi@0 700 }
aoqi@0 701
aoqi@0 702 JDK_Version JDK_Version::_current;
aoqi@0 703 const char* JDK_Version::_runtime_name;
aoqi@0 704 const char* JDK_Version::_runtime_version;
aoqi@0 705
aoqi@0 706 void JDK_Version::initialize() {
aoqi@0 707 jdk_version_info info;
aoqi@0 708 assert(!_current.is_valid(), "Don't initialize twice");
aoqi@0 709
aoqi@0 710 void *lib_handle = os::native_java_library();
aoqi@0 711 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
aoqi@0 712 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
aoqi@0 713
aoqi@0 714 if (func == NULL) {
aoqi@0 715 // JDK older than 1.6
aoqi@0 716 _current._partially_initialized = true;
aoqi@0 717 } else {
aoqi@0 718 (*func)(&info, sizeof(info));
aoqi@0 719
aoqi@0 720 int major = JDK_VERSION_MAJOR(info.jdk_version);
aoqi@0 721 int minor = JDK_VERSION_MINOR(info.jdk_version);
aoqi@0 722 int micro = JDK_VERSION_MICRO(info.jdk_version);
aoqi@0 723 int build = JDK_VERSION_BUILD(info.jdk_version);
aoqi@0 724 if (major == 1 && minor > 4) {
aoqi@0 725 // We represent "1.5.0" as "5.0", but 1.4.2 as itself.
aoqi@0 726 major = minor;
aoqi@0 727 minor = micro;
aoqi@0 728 micro = 0;
aoqi@0 729 }
aoqi@0 730 _current = JDK_Version(major, minor, micro, info.update_version,
aoqi@0 731 info.special_update_version, build,
aoqi@0 732 info.thread_park_blocker == 1,
aoqi@0 733 info.post_vm_init_hook_enabled == 1,
aoqi@0 734 info.pending_list_uses_discovered_field == 1);
aoqi@0 735 }
aoqi@0 736 }
aoqi@0 737
aoqi@0 738 void JDK_Version::fully_initialize(
aoqi@0 739 uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {
aoqi@0 740 // This is only called when current is less than 1.6 and we've gotten
aoqi@0 741 // far enough in the initialization to determine the exact version.
aoqi@0 742 assert(major < 6, "not needed for JDK version >= 6");
aoqi@0 743 assert(is_partially_initialized(), "must not initialize");
aoqi@0 744 if (major < 5) {
aoqi@0 745 // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.
aoqi@0 746 micro = minor;
aoqi@0 747 minor = major;
aoqi@0 748 major = 1;
aoqi@0 749 }
aoqi@0 750 _current = JDK_Version(major, minor, micro, update);
aoqi@0 751 }
aoqi@0 752
aoqi@0 753 void JDK_Version_init() {
aoqi@0 754 JDK_Version::initialize();
aoqi@0 755 }
aoqi@0 756
aoqi@0 757 static int64_t encode_jdk_version(const JDK_Version& v) {
aoqi@0 758 return
aoqi@0 759 ((int64_t)v.major_version() << (BitsPerByte * 5)) |
aoqi@0 760 ((int64_t)v.minor_version() << (BitsPerByte * 4)) |
aoqi@0 761 ((int64_t)v.micro_version() << (BitsPerByte * 3)) |
aoqi@0 762 ((int64_t)v.update_version() << (BitsPerByte * 2)) |
aoqi@0 763 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) |
aoqi@0 764 ((int64_t)v.build_number() << (BitsPerByte * 0));
aoqi@0 765 }
aoqi@0 766
aoqi@0 767 int JDK_Version::compare(const JDK_Version& other) const {
aoqi@0 768 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
aoqi@0 769 if (!is_partially_initialized() && other.is_partially_initialized()) {
aoqi@0 770 return -(other.compare(*this)); // flip the comparators
aoqi@0 771 }
aoqi@0 772 assert(!other.is_partially_initialized(), "Not initialized yet");
aoqi@0 773 if (is_partially_initialized()) {
aoqi@0 774 assert(other.major_version() >= 6,
aoqi@0 775 "Invalid JDK version comparison during initialization");
aoqi@0 776 return -1;
aoqi@0 777 } else {
aoqi@0 778 uint64_t e = encode_jdk_version(*this);
aoqi@0 779 uint64_t o = encode_jdk_version(other);
aoqi@0 780 return (e > o) ? 1 : ((e == o) ? 0 : -1);
aoqi@0 781 }
aoqi@0 782 }
aoqi@0 783
aoqi@0 784 void JDK_Version::to_string(char* buffer, size_t buflen) const {
shshahma@8584 785 assert(buffer && buflen > 0, "call with useful buffer");
aoqi@0 786 size_t index = 0;
aoqi@0 787 if (!is_valid()) {
aoqi@0 788 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
aoqi@0 789 } else if (is_partially_initialized()) {
aoqi@0 790 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
aoqi@0 791 } else {
shshahma@8584 792 int rc = jio_snprintf(
aoqi@0 793 &buffer[index], buflen - index, "%d.%d", _major, _minor);
shshahma@8584 794 if (rc == -1) return;
shshahma@8584 795 index += rc;
aoqi@0 796 if (_micro > 0) {
shshahma@8584 797 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
shshahma@8584 798 if (rc == -1) return;
shshahma@8584 799 index += rc;
aoqi@0 800 }
aoqi@0 801 if (_update > 0) {
shshahma@8584 802 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
shshahma@8584 803 if (rc == -1) return;
shshahma@8584 804 index += rc;
aoqi@0 805 }
aoqi@0 806 if (_special > 0) {
shshahma@8584 807 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
shshahma@8584 808 if (rc == -1) return;
shshahma@8584 809 index += rc;
aoqi@0 810 }
aoqi@0 811 if (_build > 0) {
shshahma@8584 812 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
shshahma@8584 813 if (rc == -1) return;
shshahma@8584 814 index += rc;
aoqi@0 815 }
aoqi@0 816 }
aoqi@0 817 }

mercurial