1.1 --- a/src/share/vm/runtime/java.cpp Sat Jul 19 17:38:22 2008 -0400 1.2 +++ b/src/share/vm/runtime/java.cpp Mon Jul 28 14:07:44 2008 -0400 1.3 @@ -563,32 +563,104 @@ 1.4 vm_shutdown(); 1.5 } 1.6 1.7 -jdk_version_info JDK_Version::_version_info = {0}; 1.8 -bool JDK_Version::_pre_jdk16_version = false; 1.9 -int JDK_Version::_jdk_version = 0; 1.10 +JDK_Version JDK_Version::_current; 1.11 1.12 void JDK_Version::initialize() { 1.13 + jdk_version_info info; 1.14 + assert(!_current.is_valid(), "Don't initialize twice"); 1.15 + 1.16 void *lib_handle = os::native_java_library(); 1.17 - jdk_version_info_fn_t func = 1.18 - CAST_TO_FN_PTR(jdk_version_info_fn_t, hpi::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); 1.19 + jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, 1.20 + os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); 1.21 1.22 if (func == NULL) { 1.23 // JDK older than 1.6 1.24 - _pre_jdk16_version = true; 1.25 - return; 1.26 + _current._partially_initialized = true; 1.27 + } else { 1.28 + (*func)(&info, sizeof(info)); 1.29 + 1.30 + int major = JDK_VERSION_MAJOR(info.jdk_version); 1.31 + int minor = JDK_VERSION_MINOR(info.jdk_version); 1.32 + int micro = JDK_VERSION_MICRO(info.jdk_version); 1.33 + int build = JDK_VERSION_BUILD(info.jdk_version); 1.34 + if (major == 1 && minor > 4) { 1.35 + // We represent "1.5.0" as "5.0", but 1.4.2 as itself. 1.36 + major = minor; 1.37 + minor = micro; 1.38 + micro = 0; 1.39 + } 1.40 + _current = JDK_Version(major, minor, micro, info.update_version, 1.41 + info.special_update_version, build, 1.42 + info.thread_park_blocker == 1); 1.43 } 1.44 +} 1.45 1.46 - if (func != NULL) { 1.47 - (*func)(&_version_info, sizeof(_version_info)); 1.48 +void JDK_Version::fully_initialize( 1.49 + uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) { 1.50 + // This is only called when current is less than 1.6 and we've gotten 1.51 + // far enough in the initialization to determine the exact version. 1.52 + assert(major < 6, "not needed for JDK version >= 6"); 1.53 + assert(is_partially_initialized(), "must not initialize"); 1.54 + if (major < 5) { 1.55 + // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc. 1.56 + micro = minor; 1.57 + minor = major; 1.58 + major = 1; 1.59 } 1.60 - if (jdk_major_version() == 1) { 1.61 - _jdk_version = jdk_minor_version(); 1.62 - } else { 1.63 - // If the release version string is changed to n.x.x (e.g. 7.0.0) in a future release 1.64 - _jdk_version = jdk_major_version(); 1.65 - } 1.66 + _current = JDK_Version(major, minor, micro, update); 1.67 } 1.68 1.69 void JDK_Version_init() { 1.70 JDK_Version::initialize(); 1.71 } 1.72 + 1.73 +static int64_t encode_jdk_version(const JDK_Version& v) { 1.74 + return 1.75 + ((int64_t)v.major_version() << (BitsPerByte * 5)) | 1.76 + ((int64_t)v.minor_version() << (BitsPerByte * 4)) | 1.77 + ((int64_t)v.micro_version() << (BitsPerByte * 3)) | 1.78 + ((int64_t)v.update_version() << (BitsPerByte * 2)) | 1.79 + ((int64_t)v.special_update_version() << (BitsPerByte * 1)) | 1.80 + ((int64_t)v.build_number() << (BitsPerByte * 0)); 1.81 +} 1.82 + 1.83 +int JDK_Version::compare(const JDK_Version& other) const { 1.84 + assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); 1.85 + if (!is_partially_initialized() && other.is_partially_initialized()) { 1.86 + return -(other.compare(*this)); // flip the comparators 1.87 + } 1.88 + assert(!other.is_partially_initialized(), "Not initialized yet"); 1.89 + if (is_partially_initialized()) { 1.90 + assert(other.major_version() >= 6, 1.91 + "Invalid JDK version comparison during initialization"); 1.92 + return -1; 1.93 + } else { 1.94 + uint64_t e = encode_jdk_version(*this); 1.95 + uint64_t o = encode_jdk_version(other); 1.96 + return (e > o) ? 1 : ((e == o) ? 0 : -1); 1.97 + } 1.98 +} 1.99 + 1.100 +void JDK_Version::to_string(char* buffer, size_t buflen) const { 1.101 + size_t index = 0; 1.102 + if (!is_valid()) { 1.103 + jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); 1.104 + } else if (is_partially_initialized()) { 1.105 + jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); 1.106 + } else { 1.107 + index += jio_snprintf( 1.108 + &buffer[index], buflen - index, "%d.%d", _major, _minor); 1.109 + if (_micro > 0) { 1.110 + index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); 1.111 + } 1.112 + if (_update > 0) { 1.113 + index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); 1.114 + } 1.115 + if (_special > 0) { 1.116 + index += jio_snprintf(&buffer[index], buflen - index, "%c", _special); 1.117 + } 1.118 + if (_build > 0) { 1.119 + index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); 1.120 + } 1.121 + } 1.122 +}