633 |
633 |
634 void *lib_handle = os::native_java_library(); |
634 void *lib_handle = os::native_java_library(); |
635 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, |
635 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t, |
636 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); |
636 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0")); |
637 |
637 |
638 if (func == NULL) { |
638 assert(func != NULL, "Support for JDK 1.5 or older has been removed after JEP-223"); |
639 // JDK older than 1.6 |
639 |
640 _current._partially_initialized = true; |
640 (*func)(&info, sizeof(info)); |
641 } else { |
641 |
642 (*func)(&info, sizeof(info)); |
642 int major = JDK_VERSION_MAJOR(info.jdk_version); |
643 |
643 int minor = JDK_VERSION_MINOR(info.jdk_version); |
644 int major = JDK_VERSION_MAJOR(info.jdk_version); |
644 int security = JDK_VERSION_SECURITY(info.jdk_version); |
645 int minor = JDK_VERSION_MINOR(info.jdk_version); |
645 int build = JDK_VERSION_BUILD(info.jdk_version); |
646 int security = JDK_VERSION_SECURITY(info.jdk_version); |
646 |
647 int build = JDK_VERSION_BUILD(info.jdk_version); |
647 // Incompatible with pre-4243978 JDK. |
648 |
648 if (info.pending_list_uses_discovered_field == 0) { |
649 // Incompatible with pre-4243978 JDK. |
649 vm_exit_during_initialization( |
650 if (info.pending_list_uses_discovered_field == 0) { |
650 "Incompatible JDK is not using Reference.discovered field for pending list"); |
651 vm_exit_during_initialization( |
651 } |
652 "Incompatible JDK is not using Reference.discovered field for pending list"); |
652 _current = JDK_Version(major, minor, security, info.patch_version, build, |
653 } |
653 info.thread_park_blocker == 1, |
654 _current = JDK_Version(major, minor, security, info.update_version, |
654 info.post_vm_init_hook_enabled == 1); |
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 } |
655 } |
675 |
656 |
676 void JDK_Version_init() { |
657 void JDK_Version_init() { |
677 JDK_Version::initialize(); |
658 JDK_Version::initialize(); |
678 } |
659 } |
679 |
660 |
680 static int64_t encode_jdk_version(const JDK_Version& v) { |
661 static int64_t encode_jdk_version(const JDK_Version& v) { |
681 return |
662 return |
682 ((int64_t)v.major_version() << (BitsPerByte * 5)) | |
663 ((int64_t)v.major_version() << (BitsPerByte * 4)) | |
683 ((int64_t)v.minor_version() << (BitsPerByte * 4)) | |
664 ((int64_t)v.minor_version() << (BitsPerByte * 3)) | |
684 ((int64_t)v.security_version() << (BitsPerByte * 3)) | |
665 ((int64_t)v.security_version() << (BitsPerByte * 2)) | |
685 ((int64_t)v.update_version() << (BitsPerByte * 2)) | |
666 ((int64_t)v.patch_version() << (BitsPerByte * 1)) | |
686 ((int64_t)v.special_update_version() << (BitsPerByte * 1)) | |
|
687 ((int64_t)v.build_number() << (BitsPerByte * 0)); |
667 ((int64_t)v.build_number() << (BitsPerByte * 0)); |
688 } |
668 } |
689 |
669 |
690 int JDK_Version::compare(const JDK_Version& other) const { |
670 int JDK_Version::compare(const JDK_Version& other) const { |
691 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); |
671 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)"); |
692 if (!is_partially_initialized() && other.is_partially_initialized()) { |
672 uint64_t e = encode_jdk_version(*this); |
693 return -(other.compare(*this)); // flip the comparators |
673 uint64_t o = encode_jdk_version(other); |
694 } |
674 return (e > o) ? 1 : ((e == o) ? 0 : -1); |
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 } |
675 } |
706 |
676 |
707 void JDK_Version::to_string(char* buffer, size_t buflen) const { |
677 void JDK_Version::to_string(char* buffer, size_t buflen) const { |
708 assert(buffer && buflen > 0, "call with useful buffer"); |
678 assert(buffer && buflen > 0, "call with useful buffer"); |
709 size_t index = 0; |
679 size_t index = 0; |
710 |
680 |
711 if (!is_valid()) { |
681 if (!is_valid()) { |
712 jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); |
682 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 { |
683 } else { |
716 int rc = jio_snprintf( |
684 int rc = jio_snprintf( |
717 &buffer[index], buflen - index, "%d.%d", _major, _minor); |
685 &buffer[index], buflen - index, "%d.%d", _major, _minor); |
718 if (rc == -1) return; |
686 if (rc == -1) return; |
719 index += rc; |
687 index += rc; |
720 if (_security > 0) { |
688 if (_security > 0) { |
721 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security); |
689 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security); |
722 } |
690 } |
723 if (_update > 0) { |
691 if (_patch > 0) { |
724 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); |
692 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch); |
725 if (rc == -1) return; |
693 if (rc == -1) return; |
726 index += rc; |
694 index += rc; |
727 } |
695 } |
728 if (_special > 0) { |
696 if (_build > 0) { |
729 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special); |
697 rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build); |
730 if (rc == -1) return; |
698 if (rc == -1) return; |
731 index += rc; |
699 index += rc; |
732 } |
700 } |
733 if (_build > 0) { |
701 } |
734 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); |
702 } |
735 if (rc == -1) return; |
|
736 index += rc; |
|
737 } |
|
738 } |
|
739 } |
|