626 JDK_Version JDK_Version::_current;
627 const char* JDK_Version::_runtime_name;
628 const char* JDK_Version::_runtime_version;
629
630 void JDK_Version::initialize() {
631 jdk_version_info info;
632 assert(!_current.is_valid(), "Don't initialize twice");
633
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 micro = JDK_VERSION_MICRO(info.jdk_version);
647 int build = JDK_VERSION_BUILD(info.jdk_version);
648 if (major == 1 && minor > 4) {
649 // We represent "1.5.0" as "5.0", but 1.4.2 as itself.
650 major = minor;
651 minor = micro;
652 micro = 0;
653 }
654 // Incompatible with pre-4243978 JDK.
655 if (info.pending_list_uses_discovered_field == 0) {
656 vm_exit_during_initialization(
657 "Incompatible JDK is not using Reference.discovered field for pending list");
658 }
659 _current = JDK_Version(major, minor, micro, info.update_version,
660 info.special_update_version, build,
661 info.thread_park_blocker == 1,
662 info.post_vm_init_hook_enabled == 1);
663 }
664 }
665
666 void JDK_Version::fully_initialize(
667 uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {
668 // This is only called when current is less than 1.6 and we've gotten
669 // far enough in the initialization to determine the exact version.
670 assert(major < 6, "not needed for JDK version >= 6");
671 assert(is_partially_initialized(), "must not initialize");
672 if (major < 5) {
673 // JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.
674 micro = minor;
675 minor = major;
676 major = 1;
677 }
678 _current = JDK_Version(major, minor, micro, update);
679 }
680
681 void JDK_Version_init() {
682 JDK_Version::initialize();
683 }
684
685 static int64_t encode_jdk_version(const JDK_Version& v) {
686 return
687 ((int64_t)v.major_version() << (BitsPerByte * 5)) |
688 ((int64_t)v.minor_version() << (BitsPerByte * 4)) |
689 ((int64_t)v.micro_version() << (BitsPerByte * 3)) |
690 ((int64_t)v.update_version() << (BitsPerByte * 2)) |
691 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) |
692 ((int64_t)v.build_number() << (BitsPerByte * 0));
693 }
694
695 int JDK_Version::compare(const JDK_Version& other) const {
696 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
697 if (!is_partially_initialized() && other.is_partially_initialized()) {
698 return -(other.compare(*this)); // flip the comparators
699 }
700 assert(!other.is_partially_initialized(), "Not initialized yet");
701 if (is_partially_initialized()) {
702 assert(other.major_version() >= 6,
703 "Invalid JDK version comparison during initialization");
704 return -1;
705 } else {
706 uint64_t e = encode_jdk_version(*this);
707 uint64_t o = encode_jdk_version(other);
708 return (e > o) ? 1 : ((e == o) ? 0 : -1);
709 }
710 }
711
712 void JDK_Version::to_string(char* buffer, size_t buflen) const {
713 assert(buffer && buflen > 0, "call with useful buffer");
714 size_t index = 0;
715
716 if (!is_valid()) {
717 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
718 } else if (is_partially_initialized()) {
719 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
720 } else {
721 int rc = jio_snprintf(
722 &buffer[index], buflen - index, "%d.%d", _major, _minor);
723 if (rc == -1) return;
724 index += rc;
725 if (_micro > 0) {
726 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
727 }
728 if (_update > 0) {
729 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
730 if (rc == -1) return;
731 index += rc;
732 }
733 if (_special > 0) {
734 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
735 if (rc == -1) return;
736 index += rc;
737 }
738 if (_build > 0) {
739 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
740 if (rc == -1) return;
741 index += rc;
742 }
743 }
744 }
|
626 JDK_Version JDK_Version::_current;
627 const char* JDK_Version::_runtime_name;
628 const char* JDK_Version::_runtime_version;
629
630 void JDK_Version::initialize() {
631 jdk_version_info info;
632 assert(!_current.is_valid(), "Don't initialize twice");
633
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 }
|