< prev index next >

hotspot/src/share/vm/runtime/java.cpp

Print this page




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


 634   void *lib_handle = os::native_java_library();
 635   jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
 636      os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
 637 
 638   if (func == NULL) {
 639     // JDK older than 1.6
 640     _current._partially_initialized = true;
 641   } else {
 642     (*func)(&info, sizeof(info));
 643 
 644     int major = JDK_VERSION_MAJOR(info.jdk_version);
 645     int minor = JDK_VERSION_MINOR(info.jdk_version);
 646     int security = JDK_VERSION_SECURITY(info.jdk_version);
 647     int build = JDK_VERSION_BUILD(info.jdk_version);
 648 
 649     // Incompatible with pre-4243978 JDK.
 650     if (info.pending_list_uses_discovered_field == 0) {
 651       vm_exit_during_initialization(
 652         "Incompatible JDK is not using Reference.discovered field for pending list");
 653     }
 654     _current = JDK_Version(major, minor, security, info.patch_version, build,

 655                            info.thread_park_blocker == 1,
 656                            info.post_vm_init_hook_enabled == 1);
 657   }
 658 }
 659 















 660 void JDK_Version_init() {
 661   JDK_Version::initialize();
 662 }
 663 
 664 static int64_t encode_jdk_version(const JDK_Version& v) {
 665   return
 666     ((int64_t)v.major_version()          << (BitsPerByte * 4)) |
 667     ((int64_t)v.minor_version()          << (BitsPerByte * 3)) |
 668     ((int64_t)v.security_version()       << (BitsPerByte * 2)) |
 669     ((int64_t)v.patch_version()          << (BitsPerByte * 1)) |

 670     ((int64_t)v.build_number()           << (BitsPerByte * 0));
 671 }
 672 
 673 int JDK_Version::compare(const JDK_Version& other) const {
 674   assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
 675   if (!is_partially_initialized() && other.is_partially_initialized()) {
 676     return -(other.compare(*this)); // flip the comparators
 677   }
 678   assert(!other.is_partially_initialized(), "Not initialized yet");
 679   if (is_partially_initialized()) {
 680     assert(other.major_version() >= 6,
 681            "Invalid JDK version comparison during initialization");
 682     return -1;
 683   } else {
 684     uint64_t e = encode_jdk_version(*this);
 685     uint64_t o = encode_jdk_version(other);
 686     return (e > o) ? 1 : ((e == o) ? 0 : -1);
 687   }
 688 }
 689 
 690 void JDK_Version::to_string(char* buffer, size_t buflen) const {
 691   assert(buffer && buflen > 0, "call with useful buffer");
 692   size_t index = 0;
 693 
 694   if (!is_valid()) {
 695     jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
 696   } else if (is_partially_initialized()) {
 697     jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
 698   } else {
 699     int rc = jio_snprintf(
 700         &buffer[index], buflen - index, "%d.%d", _major, _minor);
 701     if (rc == -1) return;
 702     index += rc;
 703     if (_security > 0) {
 704       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
 705     }
 706     if (_patch > 0) {
 707       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch);





 708       if (rc == -1) return;
 709       index += rc;
 710     }
 711     if (_build > 0) {
 712       rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build);
 713       if (rc == -1) return;
 714       index += rc;
 715     }
 716   }
 717 }
< prev index next >