1.1 --- a/src/share/vm/runtime/java.hpp Sat Jul 19 17:38:22 2008 -0400 1.2 +++ b/src/share/vm/runtime/java.hpp Mon Jul 28 14:07:44 2008 -0400 1.3 @@ -48,100 +48,163 @@ 1.4 extern void vm_exit_during_initialization(const char* error, const char* message = NULL); 1.5 extern void vm_shutdown_during_initialization(const char* error, const char* message = NULL); 1.6 1.7 -class JDK_Version : AllStatic { 1.8 +/** 1.9 + * Discovering the JDK_Version during initialization is tricky when the 1.10 + * running JDK is less than JDK6. For JDK6 and greater, a "GetVersion" 1.11 + * function exists in libjava.so and we simply call it during the 1.12 + * 'initialize()' call to find the version. For JDKs with version < 6, no 1.13 + * such call exists and we have to probe the JDK in order to determine 1.14 + * the exact version. This probing cannot happen during late in 1.15 + * the VM initialization process so there's a period of time during 1.16 + * initialization when we don't know anything about the JDK version other than 1.17 + * that it less than version 6. This is the "partially initialized" time, 1.18 + * when we can answer only certain version queries (such as, is the JDK 1.19 + * version greater than 5? Answer: no). Once the JDK probing occurs, we 1.20 + * know the version and are considered fully initialized. 1.21 + */ 1.22 +class JDK_Version VALUE_OBJ_CLASS_SPEC { 1.23 friend class VMStructs; 1.24 + friend class Universe; 1.25 + friend void JDK_Version_init(); 1.26 private: 1.27 - static jdk_version_info _version_info; 1.28 - static bool _pre_jdk16_version; 1.29 - static int _jdk_version; // JDK version number representing the release 1.30 - // i.e. n in 1.n.x (= jdk_minor_version()) 1.31 + 1.32 + static JDK_Version _current; 1.33 + 1.34 + // In this class, we promote the minor version of release to be the 1.35 + // major version for releases >= 5 in anticipation of the JDK doing the 1.36 + // same thing. For example, we represent "1.5.0" as major version 5 (we 1.37 + // drop the leading 1 and use 5 as the 'major'). 1.38 + 1.39 + uint8_t _major; 1.40 + uint8_t _minor; 1.41 + uint8_t _micro; 1.42 + uint8_t _update; 1.43 + uint8_t _special; 1.44 + uint8_t _build; 1.45 + 1.46 + // If partially initialized, the above fields are invalid and we know 1.47 + // that we're less than major version 6. 1.48 + bool _partially_initialized; 1.49 + 1.50 + bool _thread_park_blocker; 1.51 + 1.52 + bool is_valid() const { 1.53 + return (_major != 0 || _partially_initialized); 1.54 + } 1.55 + 1.56 + // initializes or partially initializes the _current static field 1.57 + static void initialize(); 1.58 + 1.59 + // Completes initialization for a pre-JDK6 version. 1.60 + static void fully_initialize(uint8_t major, uint8_t minor = 0, 1.61 + uint8_t micro = 0, uint8_t update = 0); 1.62 1.63 public: 1.64 - static void initialize(); 1.65 - static int jdk_major_version() { return JDK_VERSION_MAJOR(_version_info.jdk_version); } 1.66 - static int jdk_minor_version() { return JDK_VERSION_MINOR(_version_info.jdk_version); } 1.67 - static int jdk_micro_version() { return JDK_VERSION_MICRO(_version_info.jdk_version); } 1.68 - static int jdk_build_number() { return JDK_VERSION_BUILD(_version_info.jdk_version); } 1.69 1.70 - static bool is_pre_jdk16_version() { return _pre_jdk16_version; } 1.71 - static bool is_jdk12x_version() { assert(is_jdk_version_initialized(), "must have been initialized"); return _jdk_version == 2; } 1.72 - static bool is_jdk13x_version() { assert(is_jdk_version_initialized(), "must have been initialized"); return _jdk_version == 3; } 1.73 - static bool is_jdk14x_version() { assert(is_jdk_version_initialized(), "must have been initialized"); return _jdk_version == 4; } 1.74 - static bool is_jdk15x_version() { assert(is_jdk_version_initialized(), "must have been initialized"); return _jdk_version == 5; } 1.75 + // Returns true if the the current version has only been partially initialized 1.76 + static bool is_partially_initialized() { 1.77 + return _current._partially_initialized; 1.78 + } 1.79 1.80 - static bool is_jdk16x_version() { 1.81 - if (is_jdk_version_initialized()) { 1.82 - return _jdk_version == 6; 1.83 + JDK_Version() : _major(0), _minor(0), _micro(0), _update(0), 1.84 + _special(0), _build(0), _partially_initialized(false), 1.85 + _thread_park_blocker(false) {} 1.86 + 1.87 + JDK_Version(uint8_t major, uint8_t minor = 0, uint8_t micro = 0, 1.88 + uint8_t update = 0, uint8_t special = 0, uint8_t build = 0, 1.89 + bool thread_park_blocker = false) : 1.90 + _major(major), _minor(minor), _micro(micro), _update(update), 1.91 + _special(special), _build(build), _partially_initialized(false), 1.92 + _thread_park_blocker(thread_park_blocker) {} 1.93 + 1.94 + // Returns the current running JDK version 1.95 + static JDK_Version current() { return _current; } 1.96 + 1.97 + // Factory methods for convenience 1.98 + static JDK_Version jdk(uint8_t m) { 1.99 + return JDK_Version(m); 1.100 + } 1.101 + 1.102 + static JDK_Version jdk_update(uint8_t major, uint8_t update_number) { 1.103 + return JDK_Version(major, 0, 0, update_number); 1.104 + } 1.105 + 1.106 + uint8_t major_version() const { return _major; } 1.107 + uint8_t minor_version() const { return _minor; } 1.108 + uint8_t micro_version() const { return _micro; } 1.109 + uint8_t update_version() const { return _update; } 1.110 + uint8_t special_update_version() const { return _special; } 1.111 + uint8_t build_number() const { return _build; } 1.112 + 1.113 + bool supports_thread_park_blocker() const { 1.114 + return _thread_park_blocker; 1.115 + } 1.116 + 1.117 + // Performs a full ordering comparison using all fields (update, build, etc.) 1.118 + int compare(const JDK_Version& other) const; 1.119 + 1.120 + /** 1.121 + * Performs comparison using only the major version, returning negative 1.122 + * if the major version of 'this' is less than the parameter, 0 if it is 1.123 + * equal, and a positive value if it is greater. 1.124 + */ 1.125 + int compare_major(int version) const { 1.126 + if (_partially_initialized) { 1.127 + if (version >= 6) { 1.128 + return -1; 1.129 + } else { 1.130 + assert(false, "Can't make this comparison during init time"); 1.131 + return -1; // conservative 1.132 + } 1.133 } else { 1.134 - assert(is_pre_jdk16_version(), "must have been initialized"); 1.135 - return false; 1.136 + return major_version() - version; 1.137 } 1.138 } 1.139 1.140 - static bool is_jdk17x_version() { 1.141 - if (is_jdk_version_initialized()) { 1.142 - return _jdk_version == 7; 1.143 - } else { 1.144 - assert(is_pre_jdk16_version(), "must have been initialized"); 1.145 - return false; 1.146 - } 1.147 + void to_string(char* buffer, size_t buflen) const; 1.148 + 1.149 + // Convenience methods for queries on the current major/minor version 1.150 + static bool is_jdk12x_version() { 1.151 + return current().compare_major(2) == 0; 1.152 } 1.153 1.154 - static bool supports_thread_park_blocker() { return _version_info.thread_park_blocker; } 1.155 + static bool is_jdk13x_version() { 1.156 + return current().compare_major(3) == 0; 1.157 + } 1.158 + 1.159 + static bool is_jdk14x_version() { 1.160 + return current().compare_major(4) == 0; 1.161 + } 1.162 + 1.163 + static bool is_jdk15x_version() { 1.164 + return current().compare_major(5) == 0; 1.165 + } 1.166 + 1.167 + static bool is_jdk16x_version() { 1.168 + return current().compare_major(6) == 0; 1.169 + } 1.170 + 1.171 + static bool is_jdk17x_version() { 1.172 + return current().compare_major(7) == 0; 1.173 + } 1.174 + 1.175 + static bool is_gte_jdk13x_version() { 1.176 + return current().compare_major(3) >= 0; 1.177 + } 1.178 1.179 static bool is_gte_jdk14x_version() { 1.180 - // Keep the semantics of this that the version number is >= 1.4 1.181 - assert(is_jdk_version_initialized(), "Not initialized"); 1.182 - return _jdk_version >= 4; 1.183 + return current().compare_major(4) >= 0; 1.184 } 1.185 + 1.186 static bool is_gte_jdk15x_version() { 1.187 - // Keep the semantics of this that the version number is >= 1.5 1.188 - assert(is_jdk_version_initialized(), "Not initialized"); 1.189 - return _jdk_version >= 5; 1.190 + return current().compare_major(5) >= 0; 1.191 } 1.192 + 1.193 static bool is_gte_jdk16x_version() { 1.194 - // Keep the semantics of this that the version number is >= 1.6 1.195 - if (is_jdk_version_initialized()) { 1.196 - return _jdk_version >= 6; 1.197 - } else { 1.198 - assert(is_pre_jdk16_version(), "Not initialized"); 1.199 - return false; 1.200 - } 1.201 + return current().compare_major(6) >= 0; 1.202 } 1.203 1.204 static bool is_gte_jdk17x_version() { 1.205 - // Keep the semantics of this that the version number is >= 1.7 1.206 - if (is_jdk_version_initialized()) { 1.207 - return _jdk_version >= 7; 1.208 - } else { 1.209 - assert(is_pre_jdk16_version(), "Not initialized"); 1.210 - return false; 1.211 - } 1.212 - } 1.213 - 1.214 - static bool is_jdk_version_initialized() { 1.215 - return _jdk_version > 0; 1.216 - } 1.217 - 1.218 - // These methods are defined to deal with pre JDK 1.6 versions 1.219 - static void set_jdk12x_version() { 1.220 - assert(_pre_jdk16_version && !is_jdk_version_initialized(), "must not initialize"); 1.221 - _jdk_version = 2; 1.222 - _version_info.jdk_version = (1 << 24) | (2 << 16); 1.223 - } 1.224 - static void set_jdk13x_version() { 1.225 - assert(_pre_jdk16_version && !is_jdk_version_initialized(), "must not initialize"); 1.226 - _jdk_version = 3; 1.227 - _version_info.jdk_version = (1 << 24) | (3 << 16); 1.228 - } 1.229 - static void set_jdk14x_version() { 1.230 - assert(_pre_jdk16_version && !is_jdk_version_initialized(), "must not initialize"); 1.231 - _jdk_version = 4; 1.232 - _version_info.jdk_version = (1 << 24) | (4 << 16); 1.233 - } 1.234 - static void set_jdk15x_version() { 1.235 - assert(_pre_jdk16_version && !is_jdk_version_initialized(), "must not initialize"); 1.236 - _jdk_version = 5; 1.237 - _version_info.jdk_version = (1 << 24) | (5 << 16); 1.238 + return current().compare_major(7) >= 0; 1.239 } 1.240 };