Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/java.cpp
32285 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/classLoader.hpp"26#include "classfile/symbolTable.hpp"27#include "classfile/systemDictionary.hpp"28#include "code/codeCache.hpp"29#include "compiler/compileBroker.hpp"30#include "compiler/compilerOracle.hpp"31#include "interpreter/bytecodeHistogram.hpp"32#include "jfr/jfrEvents.hpp"33#include "jfr/support/jfrThreadId.hpp"34#include "memory/genCollectedHeap.hpp"35#include "memory/oopFactory.hpp"36#include "memory/universe.hpp"37#include "oops/constantPool.hpp"38#include "oops/generateOopMap.hpp"39#include "oops/instanceKlass.hpp"40#include "oops/instanceOop.hpp"41#include "oops/method.hpp"42#include "oops/objArrayOop.hpp"43#include "oops/oop.inline.hpp"44#include "oops/symbol.hpp"45#include "prims/jvmtiExport.hpp"46#include "runtime/arguments.hpp"47#include "runtime/biasedLocking.hpp"48#include "runtime/compilationPolicy.hpp"49#include "runtime/deoptimization.hpp"50#include "runtime/fprofiler.hpp"51#include "runtime/init.hpp"52#include "runtime/interfaceSupport.hpp"53#include "runtime/java.hpp"54#include "runtime/memprofiler.hpp"55#include "runtime/sharedRuntime.hpp"56#include "runtime/statSampler.hpp"57#include "runtime/sweeper.hpp"58#include "runtime/task.hpp"59#include "runtime/thread.inline.hpp"60#include "runtime/timer.hpp"61#include "runtime/vm_operations.hpp"62#include "services/memTracker.hpp"63#include "utilities/dtrace.hpp"64#include "utilities/globalDefinitions.hpp"65#include "utilities/histogram.hpp"66#include "utilities/macros.hpp"67#include "utilities/vmError.hpp"68#ifdef TARGET_ARCH_x8669# include "vm_version_x86.hpp"70#endif71#ifdef TARGET_ARCH_aarch3272# include "vm_version_aarch32.hpp"73#endif74#ifdef TARGET_ARCH_aarch6475# include "vm_version_aarch64.hpp"76#endif77#ifdef TARGET_ARCH_sparc78# include "vm_version_sparc.hpp"79#endif80#ifdef TARGET_ARCH_zero81# include "vm_version_zero.hpp"82#endif83#ifdef TARGET_ARCH_arm84# include "vm_version_arm.hpp"85#endif86#ifdef TARGET_ARCH_ppc87# include "vm_version_ppc.hpp"88#endif89#if INCLUDE_ALL_GCS90#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"91#include "gc_implementation/parallelScavenge/psScavenge.hpp"92#include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"93#endif // INCLUDE_ALL_GCS94#ifdef COMPILER195#include "c1/c1_Compiler.hpp"96#include "c1/c1_Runtime1.hpp"97#endif98#ifdef COMPILER299#include "code/compiledIC.hpp"100#include "compiler/methodLiveness.hpp"101#include "opto/compile.hpp"102#include "opto/indexSet.hpp"103#include "opto/runtime.hpp"104#endif105#if INCLUDE_JFR106#include "jfr/jfr.hpp"107#endif108109#ifndef USDT2110HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown);111#endif /* !USDT2 */112113#ifndef PRODUCT114115// Statistics printing (method invocation histogram)116117GrowableArray<Method*>* collected_invoked_methods;118119void collect_invoked_methods(Method* m) {120if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) {121collected_invoked_methods->push(m);122}123}124125PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC126127GrowableArray<Method*>* collected_profiled_methods;128129void collect_profiled_methods(Method* m) {130Thread* thread = Thread::current();131// This HandleMark prevents a huge amount of handles from being added132// to the metadata_handles() array on the thread.133HandleMark hm(thread);134methodHandle mh(thread, m);135if ((m->method_data() != NULL) &&136(PrintMethodData || CompilerOracle::should_print(mh))) {137collected_profiled_methods->push(m);138}139}140141142int compare_methods(Method** a, Method** b) {143// %%% there can be 32-bit overflow here144return ((*b)->invocation_count() + (*b)->compiled_invocation_count())145- ((*a)->invocation_count() + (*a)->compiled_invocation_count());146}147148149void print_method_invocation_histogram() {150ResourceMark rm;151HandleMark hm;152collected_invoked_methods = new GrowableArray<Method*>(1024);153SystemDictionary::methods_do(collect_invoked_methods);154collected_invoked_methods->sort(&compare_methods);155//156tty->cr();157tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff);158tty->cr();159tty->print_cr("____Count_(I+C)____Method________________________Module_________________");160unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,161synch_total = 0, nativ_total = 0, acces_total = 0;162for (int index = 0; index < collected_invoked_methods->length(); index++) {163Method* m = collected_invoked_methods->at(index);164int c = m->invocation_count() + m->compiled_invocation_count();165if (c >= MethodHistogramCutoff) m->print_invocation_count();166int_total += m->invocation_count();167comp_total += m->compiled_invocation_count();168if (m->is_final()) final_total += c;169if (m->is_static()) static_total += c;170if (m->is_synchronized()) synch_total += c;171if (m->is_native()) nativ_total += c;172if (m->is_accessor()) acces_total += c;173}174tty->cr();175total = int_total + comp_total;176tty->print_cr("Invocations summary:");177tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total);178tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total);179tty->print_cr("\t%9d (100%%) total", total);180tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total);181tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total);182tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total);183tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total);184tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total);185tty->cr();186SharedRuntime::print_call_statistics(comp_total);187}188189void print_method_profiling_data() {190ResourceMark rm;191HandleMark hm;192collected_profiled_methods = new GrowableArray<Method*>(1024);193SystemDictionary::methods_do(collect_profiled_methods);194collected_profiled_methods->sort(&compare_methods);195196int count = collected_profiled_methods->length();197int total_size = 0;198if (count > 0) {199for (int index = 0; index < count; index++) {200Method* m = collected_profiled_methods->at(index);201ttyLocker ttyl;202tty->print_cr("------------------------------------------------------------------------");203//m->print_name(tty);204m->print_invocation_count();205tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());206tty->cr();207// Dump data on parameters if any208if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) {209tty->fill_to(2);210m->method_data()->parameters_type_data()->print_data_on(tty);211}212m->print_codes();213total_size += m->method_data()->size_in_bytes();214}215tty->print_cr("------------------------------------------------------------------------");216tty->print_cr("Total MDO size: %d bytes", total_size);217}218}219220void print_bytecode_count() {221if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {222tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());223}224}225226AllocStats alloc_stats;227228229230// General statistics printing (profiling ...)231void print_statistics() {232#ifdef ASSERT233234if (CountRuntimeCalls) {235extern Histogram *RuntimeHistogram;236RuntimeHistogram->print();237}238239if (CountJNICalls) {240extern Histogram *JNIHistogram;241JNIHistogram->print();242}243244if (CountJVMCalls) {245extern Histogram *JVMHistogram;246JVMHistogram->print();247}248249#endif250251if (MemProfiling) {252MemProfiler::disengage();253}254255if (CITime) {256CompileBroker::print_times();257}258259#ifdef COMPILER1260if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {261FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);262Runtime1::print_statistics();263Deoptimization::print_statistics();264SharedRuntime::print_statistics();265nmethod::print_statistics();266}267#endif /* COMPILER1 */268269#ifdef COMPILER2270if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {271FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);272Compile::print_statistics();273#ifndef COMPILER1274Deoptimization::print_statistics();275nmethod::print_statistics();276SharedRuntime::print_statistics();277#endif //COMPILER1278os::print_statistics();279}280281if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {282OptoRuntime::print_named_counters();283}284285if (TimeLivenessAnalysis) {286MethodLiveness::print_times();287}288#ifdef ASSERT289if (CollectIndexSetStatistics) {290IndexSet::print_statistics();291}292#endif // ASSERT293#endif // COMPILER2294if (CountCompiledCalls) {295print_method_invocation_histogram();296}297if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) {298print_method_profiling_data();299}300if (TimeCompiler) {301COMPILER2_PRESENT(Compile::print_timers();)302}303if (TimeCompilationPolicy) {304CompilationPolicy::policy()->print_time();305}306if (TimeOopMap) {307GenerateOopMap::print_time();308}309if (ProfilerCheckIntervals) {310PeriodicTask::print_intervals();311}312if (PrintSymbolTableSizeHistogram) {313SymbolTable::print_histogram();314}315if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {316BytecodeCounter::print();317}318if (PrintBytecodePairHistogram) {319BytecodePairHistogram::print();320}321322if (PrintCodeCache) {323MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);324CodeCache::print();325}326327if (PrintMethodFlushingStatistics) {328NMethodSweeper::print();329}330331if (PrintCodeCache2) {332MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);333CodeCache::print_internals();334}335336if (PrintClassStatistics) {337SystemDictionary::print_class_statistics();338}339if (PrintMethodStatistics) {340SystemDictionary::print_method_statistics();341}342343if (PrintVtableStats) {344klassVtable::print_statistics();345klassItable::print_statistics();346}347if (VerifyOops && Verbose) {348tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());349}350351print_bytecode_count();352if (PrintMallocStatistics) {353tty->print("allocation stats: ");354alloc_stats.print();355tty->cr();356}357358if (PrintSystemDictionaryAtExit) {359SystemDictionary::print();360}361362if (PrintBiasedLockingStatistics) {363BiasedLocking::print_counters();364}365366#ifdef ENABLE_ZAP_DEAD_LOCALS367#ifdef COMPILER2368if (ZapDeadCompiledLocals) {369tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count);370tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count);371}372#endif // COMPILER2373#endif // ENABLE_ZAP_DEAD_LOCALS374// Native memory tracking data375if (PrintNMTStatistics) {376MemTracker::final_report(tty);377}378}379380#else // PRODUCT MODE STATISTICS381382void print_statistics() {383384if (CITime) {385CompileBroker::print_times();386}387388if (PrintCodeCache) {389MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);390CodeCache::print();391}392393if (PrintMethodFlushingStatistics) {394NMethodSweeper::print();395}396397#ifdef COMPILER2398if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {399OptoRuntime::print_named_counters();400}401#endif402if (PrintBiasedLockingStatistics) {403BiasedLocking::print_counters();404}405406// Native memory tracking data407if (PrintNMTStatistics) {408MemTracker::final_report(tty);409}410}411412#endif413414415// Helper class for registering on_exit calls through JVM_OnExit416417extern "C" {418typedef void (*__exit_proc)(void);419}420421class ExitProc : public CHeapObj<mtInternal> {422private:423__exit_proc _proc;424// void (*_proc)(void);425ExitProc* _next;426public:427// ExitProc(void (*proc)(void)) {428ExitProc(__exit_proc proc) {429_proc = proc;430_next = NULL;431}432void evaluate() { _proc(); }433ExitProc* next() const { return _next; }434void set_next(ExitProc* next) { _next = next; }435};436437438// Linked list of registered on_exit procedures439440static ExitProc* exit_procs = NULL;441442443extern "C" {444void register_on_exit_function(void (*func)(void)) {445ExitProc *entry = new ExitProc(func);446// Classic vm does not throw an exception in case the allocation failed,447if (entry != NULL) {448entry->set_next(exit_procs);449exit_procs = entry;450}451}452}453454// Note: before_exit() can be executed only once, if more than one threads455// are trying to shutdown the VM at the same time, only one thread456// can run before_exit() and all other threads must wait.457void before_exit(JavaThread * thread) {458#define BEFORE_EXIT_NOT_RUN 0459#define BEFORE_EXIT_RUNNING 1460#define BEFORE_EXIT_DONE 2461static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;462463// Note: don't use a Mutex to guard the entire before_exit(), as464// JVMTI post_thread_end_event and post_vm_death_event will run native code.465// A CAS or OSMutex would work just fine but then we need to manipulate466// thread state for Safepoint. Here we use Monitor wait() and notify_all()467// for synchronization.468{ MutexLocker ml(BeforeExit_lock);469switch (_before_exit_status) {470case BEFORE_EXIT_NOT_RUN:471_before_exit_status = BEFORE_EXIT_RUNNING;472break;473case BEFORE_EXIT_RUNNING:474while (_before_exit_status == BEFORE_EXIT_RUNNING) {475BeforeExit_lock->wait();476}477assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");478return;479case BEFORE_EXIT_DONE:480return;481}482}483484// The only difference between this and Win32's _onexit procs is that485// this version is invoked before any threads get killed.486ExitProc* current = exit_procs;487while (current != NULL) {488ExitProc* next = current->next();489current->evaluate();490delete current;491current = next;492}493494// Hang forever on exit if we're reporting an error.495if (ShowMessageBoxOnError && is_error_reported()) {496os::infinite_sleep();497}498499// Terminate watcher thread - must before disenrolling any periodic task500if (PeriodicTask::num_tasks() > 0)501WatcherThread::stop();502503// Print statistics gathered (profiling ...)504if (Arguments::has_profile()) {505FlatProfiler::disengage();506FlatProfiler::print(10);507}508509// shut down the StatSampler task510StatSampler::disengage();511StatSampler::destroy();512513// Stop concurrent GC threads514Universe::heap()->stop();515516// Print GC/heap related information.517if (PrintGCDetails) {518Universe::print();519AdaptiveSizePolicyOutput(0);520if (Verbose) {521ClassLoaderDataGraph::dump_on(gclog_or_tty);522}523}524525if (PrintBytecodeHistogram) {526BytecodeHistogram::print();527}528529if (JvmtiExport::should_post_thread_life()) {530JvmtiExport::post_thread_end(thread);531}532533534EventThreadEnd event;535if (event.should_commit()) {536event.set_thread(JFR_THREAD_ID(thread));537event.commit();538}539540JFR_ONLY(Jfr::on_vm_shutdown();)541542// Always call even when there are not JVMTI environments yet, since environments543// may be attached late and JVMTI must track phases of VM execution544JvmtiExport::post_vm_death();545Threads::shutdown_vm_agents();546547// Terminate the signal thread548// Note: we don't wait until it actually dies.549os::terminate_signal_thread();550551print_statistics();552Universe::heap()->print_tracing_info();553554{ MutexLocker ml(BeforeExit_lock);555_before_exit_status = BEFORE_EXIT_DONE;556BeforeExit_lock->notify_all();557}558559if (VerifyStringTableAtExit) {560int fail_cnt = 0;561{562MutexLocker ml(StringTable_lock);563fail_cnt = StringTable::verify_and_compare_entries();564}565566if (fail_cnt != 0) {567tty->print_cr("ERROR: fail_cnt=%d", fail_cnt);568guarantee(fail_cnt == 0, "unexpected StringTable verification failures");569}570}571572#undef BEFORE_EXIT_NOT_RUN573#undef BEFORE_EXIT_RUNNING574#undef BEFORE_EXIT_DONE575}576577void vm_exit(int code) {578Thread* thread = ThreadLocalStorage::is_initialized() ?579ThreadLocalStorage::get_thread_slow() : NULL;580if (thread == NULL) {581// we have serious problems -- just exit582vm_direct_exit(code);583}584585if (VMThread::vm_thread() != NULL) {586// Fire off a VM_Exit operation to bring VM to a safepoint and exit587VM_Exit op(code);588if (thread->is_Java_thread())589((JavaThread*)thread)->set_thread_state(_thread_in_vm);590VMThread::execute(&op);591// should never reach here; but in case something wrong with VM Thread.592vm_direct_exit(code);593} else {594// VM thread is gone, just exit595vm_direct_exit(code);596}597ShouldNotReachHere();598}599600void notify_vm_shutdown() {601// For now, just a dtrace probe.602#ifndef USDT2603HS_DTRACE_PROBE(hotspot, vm__shutdown);604HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();605#else /* USDT2 */606HOTSPOT_VM_SHUTDOWN();607#endif /* USDT2 */608}609610void vm_direct_exit(int code) {611notify_vm_shutdown();612os::wait_for_keypress_at_exit();613::exit(code);614}615616void vm_perform_shutdown_actions() {617// Warning: do not call 'exit_globals()' here. All threads are still running.618// Calling 'exit_globals()' will disable thread-local-storage and cause all619// kinds of assertions to trigger in debug mode.620if (is_init_completed()) {621Thread* thread = ThreadLocalStorage::is_initialized() ?622ThreadLocalStorage::get_thread_slow() : NULL;623if (thread != NULL && thread->is_Java_thread()) {624// We are leaving the VM, set state to native (in case any OS exit625// handlers call back to the VM)626JavaThread* jt = (JavaThread*)thread;627// Must always be walkable or have no last_Java_frame when in628// thread_in_native629jt->frame_anchor()->make_walkable(jt);630jt->set_thread_state(_thread_in_native);631}632}633notify_vm_shutdown();634}635636void vm_shutdown()637{638vm_perform_shutdown_actions();639os::wait_for_keypress_at_exit();640os::shutdown();641}642643void vm_abort(bool dump_core) {644vm_perform_shutdown_actions();645os::wait_for_keypress_at_exit();646os::abort(dump_core);647ShouldNotReachHere();648}649650void vm_notify_during_shutdown(const char* error, const char* message) {651if (error != NULL) {652tty->print_cr("Error occurred during initialization of VM");653tty->print("%s", error);654if (message != NULL) {655tty->print_cr(": %s", message);656}657else {658tty->cr();659}660}661if (ShowMessageBoxOnError && WizardMode) {662fatal("Error occurred during initialization of VM");663}664}665666void vm_exit_during_initialization(Handle exception) {667tty->print_cr("Error occurred during initialization of VM");668// If there are exceptions on this thread it must be cleared669// first and here. Any future calls to EXCEPTION_MARK requires670// that no pending exceptions exist.671Thread *THREAD = Thread::current();672if (HAS_PENDING_EXCEPTION) {673CLEAR_PENDING_EXCEPTION;674}675java_lang_Throwable::print(exception, tty);676tty->cr();677java_lang_Throwable::print_stack_trace(exception(), tty);678tty->cr();679vm_notify_during_shutdown(NULL, NULL);680681// Failure during initialization, we don't want to dump core682vm_abort(false);683}684685void vm_exit_during_initialization(Symbol* ex, const char* message) {686ResourceMark rm;687vm_notify_during_shutdown(ex->as_C_string(), message);688689// Failure during initialization, we don't want to dump core690vm_abort(false);691}692693void vm_exit_during_initialization(const char* error, const char* message) {694vm_notify_during_shutdown(error, message);695696// Failure during initialization, we don't want to dump core697vm_abort(false);698}699700void vm_shutdown_during_initialization(const char* error, const char* message) {701vm_notify_during_shutdown(error, message);702vm_shutdown();703}704705JDK_Version JDK_Version::_current;706const char* JDK_Version::_runtime_name;707const char* JDK_Version::_runtime_version;708709void JDK_Version::initialize() {710jdk_version_info info;711assert(!_current.is_valid(), "Don't initialize twice");712713void *lib_handle = os::native_java_library();714jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,715os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));716717if (func == NULL) {718// JDK older than 1.6719_current._partially_initialized = true;720} else {721(*func)(&info, sizeof(info));722723int major = JDK_VERSION_MAJOR(info.jdk_version);724int minor = JDK_VERSION_MINOR(info.jdk_version);725int micro = JDK_VERSION_MICRO(info.jdk_version);726int build = JDK_VERSION_BUILD(info.jdk_version);727if (major == 1 && minor > 4) {728// We represent "1.5.0" as "5.0", but 1.4.2 as itself.729major = minor;730minor = micro;731micro = 0;732}733_current = JDK_Version(major, minor, micro, info.update_version,734info.special_update_version, build,735info.thread_park_blocker == 1,736info.post_vm_init_hook_enabled == 1,737info.pending_list_uses_discovered_field == 1);738}739}740741void JDK_Version::fully_initialize(742uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {743// This is only called when current is less than 1.6 and we've gotten744// far enough in the initialization to determine the exact version.745assert(major < 6, "not needed for JDK version >= 6");746assert(is_partially_initialized(), "must not initialize");747if (major < 5) {748// JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.749micro = minor;750minor = major;751major = 1;752}753_current = JDK_Version(major, minor, micro, update);754}755756void JDK_Version_init() {757JDK_Version::initialize();758}759760static int64_t encode_jdk_version(const JDK_Version& v) {761return762((int64_t)v.major_version() << (BitsPerByte * 5)) |763((int64_t)v.minor_version() << (BitsPerByte * 4)) |764((int64_t)v.micro_version() << (BitsPerByte * 3)) |765((int64_t)v.update_version() << (BitsPerByte * 2)) |766((int64_t)v.special_update_version() << (BitsPerByte * 1)) |767((int64_t)v.build_number() << (BitsPerByte * 0));768}769770int JDK_Version::compare(const JDK_Version& other) const {771assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");772if (!is_partially_initialized() && other.is_partially_initialized()) {773return -(other.compare(*this)); // flip the comparators774}775assert(!other.is_partially_initialized(), "Not initialized yet");776if (is_partially_initialized()) {777assert(other.major_version() >= 6,778"Invalid JDK version comparison during initialization");779return -1;780} else {781uint64_t e = encode_jdk_version(*this);782uint64_t o = encode_jdk_version(other);783return (e > o) ? 1 : ((e == o) ? 0 : -1);784}785}786787void JDK_Version::to_string(char* buffer, size_t buflen) const {788assert(buffer && buflen > 0, "call with useful buffer");789size_t index = 0;790if (!is_valid()) {791jio_snprintf(buffer, buflen, "%s", "(uninitialized)");792} else if (is_partially_initialized()) {793jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");794} else {795int rc = jio_snprintf(796&buffer[index], buflen - index, "%d.%d", _major, _minor);797if (rc == -1) return;798index += rc;799if (_micro > 0) {800rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);801if (rc == -1) return;802index += rc;803}804if (_update > 0) {805rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);806if (rc == -1) return;807index += rc;808}809if (_special > 0) {810rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);811if (rc == -1) return;812index += rc;813}814if (_build > 0) {815rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);816if (rc == -1) return;817index += rc;818}819}820}821822823