src/share/vm/runtime/java.cpp

Mon, 17 Sep 2012 07:36:31 -0400

author
dholmes
date
Mon, 17 Sep 2012 07:36:31 -0400
changeset 4077
a7509aff1b06
parent 4037
da91efe96a93
child 4081
9a86ddfc6c8f
permissions
-rw-r--r--

7194254: jstack reports wrong thread priorities
Reviewed-by: dholmes, sla, fparain
Contributed-by: Dmytro Sheyko <dmytro_sheyko@hotmail.com>

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

mercurial