src/share/vm/runtime/java.cpp

Wed, 16 Jan 2013 16:30:04 +0100

author
sla
date
Wed, 16 Jan 2013 16:30:04 +0100
changeset 4462
e94ed1591b42
parent 4428
e0cf9af8978e
child 4439
212c5b9c38e7
permissions
-rw-r--r--

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

mercurial