hotspot/src/share/vm/runtime/java.cpp
changeset 33971 d67c7d278ecc
parent 32349 8b5eb3750c41
parent 33965 e03572caaf4c
child 33976 160793725e6f
equal deleted inserted replaced
32464:a5a4cade399d 33971:d67c7d278ecc
   634 
   634 
   635   void *lib_handle = os::native_java_library();
   635   void *lib_handle = os::native_java_library();
   636   jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
   636   jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
   637      os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
   637      os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
   638 
   638 
   639   if (func == NULL) {
   639   assert(func != NULL, "Support for JDK 1.5 or older has been removed after JEP-223");
   640     // JDK older than 1.6
   640 
   641     _current._partially_initialized = true;
   641   (*func)(&info, sizeof(info));
   642   } else {
   642 
   643     (*func)(&info, sizeof(info));
   643   int major = JDK_VERSION_MAJOR(info.jdk_version);
   644 
   644   int minor = JDK_VERSION_MINOR(info.jdk_version);
   645     int major = JDK_VERSION_MAJOR(info.jdk_version);
   645   int security = JDK_VERSION_SECURITY(info.jdk_version);
   646     int minor = JDK_VERSION_MINOR(info.jdk_version);
   646   int build = JDK_VERSION_BUILD(info.jdk_version);
   647     int micro = JDK_VERSION_MICRO(info.jdk_version);
   647 
   648     int build = JDK_VERSION_BUILD(info.jdk_version);
   648   // Incompatible with pre-4243978 JDK.
   649     if (major == 1 && minor > 4) {
   649   if (info.pending_list_uses_discovered_field == 0) {
   650       // We represent "1.5.0" as "5.0", but 1.4.2 as itself.
   650     vm_exit_during_initialization(
   651       major = minor;
   651       "Incompatible JDK is not using Reference.discovered field for pending list");
   652       minor = micro;
   652   }
   653       micro = 0;
   653   _current = JDK_Version(major, minor, security, info.patch_version, build,
   654     }
   654                          info.thread_park_blocker == 1,
   655     // Incompatible with pre-4243978 JDK.
   655                          info.post_vm_init_hook_enabled == 1);
   656     if (info.pending_list_uses_discovered_field == 0) {
       
   657       vm_exit_during_initialization(
       
   658         "Incompatible JDK is not using Reference.discovered field for pending list");
       
   659     }
       
   660     _current = JDK_Version(major, minor, micro, info.update_version,
       
   661                            info.special_update_version, build,
       
   662                            info.thread_park_blocker == 1,
       
   663                            info.post_vm_init_hook_enabled == 1);
       
   664   }
       
   665 }
       
   666 
       
   667 void JDK_Version::fully_initialize(
       
   668     uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {
       
   669   // This is only called when current is less than 1.6 and we've gotten
       
   670   // far enough in the initialization to determine the exact version.
       
   671   assert(major < 6, "not needed for JDK version >= 6");
       
   672   assert(is_partially_initialized(), "must not initialize");
       
   673   if (major < 5) {
       
   674     // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.
       
   675     micro = minor;
       
   676     minor = major;
       
   677     major = 1;
       
   678   }
       
   679   _current = JDK_Version(major, minor, micro, update);
       
   680 }
   656 }
   681 
   657 
   682 void JDK_Version_init() {
   658 void JDK_Version_init() {
   683   JDK_Version::initialize();
   659   JDK_Version::initialize();
   684 }
   660 }
   685 
   661 
   686 static int64_t encode_jdk_version(const JDK_Version& v) {
   662 static int64_t encode_jdk_version(const JDK_Version& v) {
   687   return
   663   return
   688     ((int64_t)v.major_version()          << (BitsPerByte * 5)) |
   664     ((int64_t)v.major_version()          << (BitsPerByte * 4)) |
   689     ((int64_t)v.minor_version()          << (BitsPerByte * 4)) |
   665     ((int64_t)v.minor_version()          << (BitsPerByte * 3)) |
   690     ((int64_t)v.micro_version()          << (BitsPerByte * 3)) |
   666     ((int64_t)v.security_version()       << (BitsPerByte * 2)) |
   691     ((int64_t)v.update_version()         << (BitsPerByte * 2)) |
   667     ((int64_t)v.patch_version()          << (BitsPerByte * 1)) |
   692     ((int64_t)v.special_update_version() << (BitsPerByte * 1)) |
       
   693     ((int64_t)v.build_number()           << (BitsPerByte * 0));
   668     ((int64_t)v.build_number()           << (BitsPerByte * 0));
   694 }
   669 }
   695 
   670 
   696 int JDK_Version::compare(const JDK_Version& other) const {
   671 int JDK_Version::compare(const JDK_Version& other) const {
   697   assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
   672   assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
   698   if (!is_partially_initialized() && other.is_partially_initialized()) {
   673   uint64_t e = encode_jdk_version(*this);
   699     return -(other.compare(*this)); // flip the comparators
   674   uint64_t o = encode_jdk_version(other);
   700   }
   675   return (e > o) ? 1 : ((e == o) ? 0 : -1);
   701   assert(!other.is_partially_initialized(), "Not initialized yet");
       
   702   if (is_partially_initialized()) {
       
   703     assert(other.major_version() >= 6,
       
   704            "Invalid JDK version comparison during initialization");
       
   705     return -1;
       
   706   } else {
       
   707     uint64_t e = encode_jdk_version(*this);
       
   708     uint64_t o = encode_jdk_version(other);
       
   709     return (e > o) ? 1 : ((e == o) ? 0 : -1);
       
   710   }
       
   711 }
   676 }
   712 
   677 
   713 void JDK_Version::to_string(char* buffer, size_t buflen) const {
   678 void JDK_Version::to_string(char* buffer, size_t buflen) const {
   714   assert(buffer && buflen > 0, "call with useful buffer");
   679   assert(buffer && buflen > 0, "call with useful buffer");
   715   size_t index = 0;
   680   size_t index = 0;
   716 
   681 
   717   if (!is_valid()) {
   682   if (!is_valid()) {
   718     jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
   683     jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
   719   } else if (is_partially_initialized()) {
       
   720     jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
       
   721   } else {
   684   } else {
   722     int rc = jio_snprintf(
   685     int rc = jio_snprintf(
   723         &buffer[index], buflen - index, "%d.%d", _major, _minor);
   686         &buffer[index], buflen - index, "%d.%d", _major, _minor);
   724     if (rc == -1) return;
   687     if (rc == -1) return;
   725     index += rc;
   688     index += rc;
   726     if (_micro > 0) {
   689     if (_security > 0) {
   727       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
   690       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
   728     }
   691     }
   729     if (_update > 0) {
   692     if (_patch > 0) {
   730       rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
   693       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch);
   731       if (rc == -1) return;
   694       if (rc == -1) return;
   732       index += rc;
   695       index += rc;
   733     }
   696     }
   734     if (_special > 0) {
   697     if (_build > 0) {
   735       rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
   698       rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build);
   736       if (rc == -1) return;
   699       if (rc == -1) return;
   737       index += rc;
   700       index += rc;
   738     }
   701     }
   739     if (_build > 0) {
   702   }
   740       rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
   703 }
   741       if (rc == -1) return;
       
   742       index += rc;
       
   743     }
       
   744   }
       
   745 }