src/os/solaris/vm/os_solaris.cpp

changeset 6556
6048424d3865
parent 6518
62c54fcc0a35
child 6667
917873d2983d
child 6779
364b73402247
equal deleted inserted replaced
6555:a57ba009d4dc 6556:6048424d3865
646 return privileges; 646 return privileges;
647 } 647 }
648 648
649 649
650 void os::init_system_properties_values() { 650 void os::init_system_properties_values() {
651 char arch[12];
652 sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
653
654 // The next steps are taken in the product version: 651 // The next steps are taken in the product version:
655 // 652 //
656 // Obtain the JAVA_HOME value from the location of libjvm.so. 653 // Obtain the JAVA_HOME value from the location of libjvm.so.
657 // This library should be located at: 654 // This library should be located at:
658 // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so. 655 // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so.
675 // Otherwise exit. 672 // Otherwise exit.
676 // 673 //
677 // Important note: if the location of libjvm.so changes this 674 // Important note: if the location of libjvm.so changes this
678 // code needs to be changed accordingly. 675 // code needs to be changed accordingly.
679 676
680 // The next few definitions allow the code to be verbatim: 677 // Base path of extensions installed on the system.
681 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) 678 #define SYS_EXT_DIR "/usr/jdk/packages"
682 #define free(p) FREE_C_HEAP_ARRAY(char, p, mtInternal)
683 #define getenv(n) ::getenv(n)
684
685 #define EXTENSIONS_DIR "/lib/ext" 679 #define EXTENSIONS_DIR "/lib/ext"
686 #define ENDORSED_DIR "/lib/endorsed" 680 #define ENDORSED_DIR "/lib/endorsed"
687 #define COMMON_DIR "/usr/jdk/packages" 681
688 682 char cpu_arch[12];
683 // Buffer that fits several sprintfs.
684 // Note that the space for the colon and the trailing null are provided
685 // by the nulls included by the sizeof operator.
686 const size_t bufsize =
687 MAX4((size_t)MAXPATHLEN, // For dll_dir & friends.
688 sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch), // invariant ld_library_path
689 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
690 (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
691 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
692
693 // sysclasspath, java_home, dll_dir
689 { 694 {
690 /* sysclasspath, java_home, dll_dir */ 695 char *pslash;
691 { 696 os::jvm_path(buf, bufsize);
692 char *home_path; 697
693 char *dll_path; 698 // Found the full path to libjvm.so.
694 char *pslash; 699 // Now cut the path to <java_home>/jre if we can.
695 char buf[MAXPATHLEN]; 700 *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
696 os::jvm_path(buf, sizeof(buf)); 701 pslash = strrchr(buf, '/');
697 702 if (pslash != NULL) {
698 // Found the full path to libjvm.so. 703 *pslash = '\0'; // Get rid of /{client|server|hotspot}.
699 // Now cut the path to <java_home>/jre if we can. 704 }
700 *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ 705 Arguments::set_dll_dir(buf);
706
707 if (pslash != NULL) {
708 pslash = strrchr(buf, '/');
709 if (pslash != NULL) {
710 *pslash = '\0'; // Get rid of /<arch>.
701 pslash = strrchr(buf, '/'); 711 pslash = strrchr(buf, '/');
702 if (pslash != NULL)
703 *pslash = '\0'; /* get rid of /{client|server|hotspot} */
704 dll_path = malloc(strlen(buf) + 1);
705 if (dll_path == NULL)
706 return;
707 strcpy(dll_path, buf);
708 Arguments::set_dll_dir(dll_path);
709
710 if (pslash != NULL) { 712 if (pslash != NULL) {
711 pslash = strrchr(buf, '/'); 713 *pslash = '\0'; // Get rid of /lib.
712 if (pslash != NULL) {
713 *pslash = '\0'; /* get rid of /<arch> */
714 pslash = strrchr(buf, '/');
715 if (pslash != NULL)
716 *pslash = '\0'; /* get rid of /lib */
717 }
718 } 714 }
719
720 home_path = malloc(strlen(buf) + 1);
721 if (home_path == NULL)
722 return;
723 strcpy(home_path, buf);
724 Arguments::set_java_home(home_path);
725
726 if (!set_boot_path('/', ':'))
727 return;
728 }
729
730 /*
731 * Where to look for native libraries
732 */
733 {
734 // Use dlinfo() to determine the correct java.library.path.
735 //
736 // If we're launched by the Java launcher, and the user
737 // does not set java.library.path explicitly on the commandline,
738 // the Java launcher sets LD_LIBRARY_PATH for us and unsets
739 // LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64. In this case
740 // dlinfo returns LD_LIBRARY_PATH + crle settings (including
741 // /usr/lib), which is exactly what we want.
742 //
743 // If the user does set java.library.path, it completely
744 // overwrites this setting, and always has.
745 //
746 // If we're not launched by the Java launcher, we may
747 // get here with any/all of the LD_LIBRARY_PATH[_32|64]
748 // settings. Again, dlinfo does exactly what we want.
749
750 Dl_serinfo _info, *info = &_info;
751 Dl_serpath *path;
752 char* library_path;
753 char *common_path;
754 int i;
755
756 // determine search path count and required buffer size
757 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) {
758 vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror());
759 } 715 }
760 716 }
761 // allocate new buffer and initialize 717 Arguments::set_java_home(buf);
762 info = (Dl_serinfo*)malloc(_info.dls_size); 718 set_boot_path('/', ':');
763 if (info == NULL) { 719 }
764 vm_exit_out_of_memory(_info.dls_size, OOM_MALLOC_ERROR, 720
765 "init_system_properties_values info"); 721 // Where to look for native libraries.
722 {
723 // Use dlinfo() to determine the correct java.library.path.
724 //
725 // If we're launched by the Java launcher, and the user
726 // does not set java.library.path explicitly on the commandline,
727 // the Java launcher sets LD_LIBRARY_PATH for us and unsets
728 // LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64. In this case
729 // dlinfo returns LD_LIBRARY_PATH + crle settings (including
730 // /usr/lib), which is exactly what we want.
731 //
732 // If the user does set java.library.path, it completely
733 // overwrites this setting, and always has.
734 //
735 // If we're not launched by the Java launcher, we may
736 // get here with any/all of the LD_LIBRARY_PATH[_32|64]
737 // settings. Again, dlinfo does exactly what we want.
738
739 Dl_serinfo info_sz, *info = &info_sz;
740 Dl_serpath *path;
741 char *library_path;
742 char *common_path = buf;
743
744 // Determine search path count and required buffer size.
745 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) {
746 FREE_C_HEAP_ARRAY(char, buf, mtInternal);
747 vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror());
748 }
749
750 // Allocate new buffer and initialize.
751 info = (Dl_serinfo*)NEW_C_HEAP_ARRAY(char, info_sz.dls_size, mtInternal);
752 info->dls_size = info_sz.dls_size;
753 info->dls_cnt = info_sz.dls_cnt;
754
755 // Obtain search path information.
756 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) {
757 FREE_C_HEAP_ARRAY(char, buf, mtInternal);
758 FREE_C_HEAP_ARRAY(char, info, mtInternal);
759 vm_exit_during_initialization("dlinfo SERINFO request", dlerror());
760 }
761
762 path = &info->dls_serpath[0];
763
764 // Note: Due to a legacy implementation, most of the library path
765 // is set in the launcher. This was to accomodate linking restrictions
766 // on legacy Solaris implementations (which are no longer supported).
767 // Eventually, all the library path setting will be done here.
768 //
769 // However, to prevent the proliferation of improperly built native
770 // libraries, the new path component /usr/jdk/packages is added here.
771
772 // Determine the actual CPU architecture.
773 sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch));
774 #ifdef _LP64
775 // If we are a 64-bit vm, perform the following translations:
776 // sparc -> sparcv9
777 // i386 -> amd64
778 if (strcmp(cpu_arch, "sparc") == 0) {
779 strcat(cpu_arch, "v9");
780 } else if (strcmp(cpu_arch, "i386") == 0) {
781 strcpy(cpu_arch, "amd64");
782 }
783 #endif
784
785 // Construct the invariant part of ld_library_path.
786 sprintf(common_path, SYS_EXT_DIR "/lib/%s", cpu_arch);
787
788 // Struct size is more than sufficient for the path components obtained
789 // through the dlinfo() call, so only add additional space for the path
790 // components explicitly added here.
791 size_t library_path_size = info->dls_size + strlen(common_path);
792 library_path = (char *)NEW_C_HEAP_ARRAY(char, library_path_size, mtInternal);
793 library_path[0] = '\0';
794
795 // Construct the desired Java library path from the linker's library
796 // search path.
797 //
798 // For compatibility, it is optimal that we insert the additional path
799 // components specific to the Java VM after those components specified
800 // in LD_LIBRARY_PATH (if any) but before those added by the ld.so
801 // infrastructure.
802 if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it.
803 strcpy(library_path, common_path);
804 } else {
805 int inserted = 0;
806 int i;
807 for (i = 0; i < info->dls_cnt; i++, path++) {
808 uint_t flags = path->dls_flags & LA_SER_MASK;
809 if (((flags & LA_SER_LIBPATH) == 0) && !inserted) {
810 strcat(library_path, common_path);
811 strcat(library_path, os::path_separator());
812 inserted = 1;
813 }
814 strcat(library_path, path->dls_name);
815 strcat(library_path, os::path_separator());
766 } 816 }
767 info->dls_size = _info.dls_size; 817 // Eliminate trailing path separator.
768 info->dls_cnt = _info.dls_cnt; 818 library_path[strlen(library_path)-1] = '\0';
769 819 }
770 // obtain search path information 820
771 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) { 821 // happens before argument parsing - can't use a trace flag
772 free(info); 822 // tty->print_raw("init_system_properties_values: native lib path: ");
773 vm_exit_during_initialization("dlinfo SERINFO request", dlerror()); 823 // tty->print_raw_cr(library_path);
774 } 824
775 825 // Callee copies into its own buffer.
776 path = &info->dls_serpath[0]; 826 Arguments::set_library_path(library_path);
777 827
778 // Note: Due to a legacy implementation, most of the library path 828 FREE_C_HEAP_ARRAY(char, library_path, mtInternal);
779 // is set in the launcher. This was to accomodate linking restrictions 829 FREE_C_HEAP_ARRAY(char, info, mtInternal);
780 // on legacy Solaris implementations (which are no longer supported). 830 }
781 // Eventually, all the library path setting will be done here. 831
782 // 832 // Extensions directories.
783 // However, to prevent the proliferation of improperly built native 833 sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
784 // libraries, the new path component /usr/jdk/packages is added here. 834 Arguments::set_ext_dirs(buf);
785 835
786 // Determine the actual CPU architecture. 836 // Endorsed standards default directory.
787 char cpu_arch[12]; 837 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
788 sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch)); 838 Arguments::set_endorsed_dirs(buf);
789 #ifdef _LP64 839
790 // If we are a 64-bit vm, perform the following translations: 840 FREE_C_HEAP_ARRAY(char, buf, mtInternal);
791 // sparc -> sparcv9 841
792 // i386 -> amd64 842 #undef SYS_EXT_DIR
793 if (strcmp(cpu_arch, "sparc") == 0)
794 strcat(cpu_arch, "v9");
795 else if (strcmp(cpu_arch, "i386") == 0)
796 strcpy(cpu_arch, "amd64");
797 #endif
798
799 // Construct the invariant part of ld_library_path. Note that the
800 // space for the colon and the trailing null are provided by the
801 // nulls included by the sizeof operator.
802 size_t bufsize = sizeof(COMMON_DIR) + sizeof("/lib/") + strlen(cpu_arch);
803 common_path = malloc(bufsize);
804 if (common_path == NULL) {
805 free(info);
806 vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
807 "init_system_properties_values common_path");
808 }
809 sprintf(common_path, COMMON_DIR "/lib/%s", cpu_arch);
810
811 // struct size is more than sufficient for the path components obtained
812 // through the dlinfo() call, so only add additional space for the path
813 // components explicitly added here.
814 bufsize = info->dls_size + strlen(common_path);
815 library_path = malloc(bufsize);
816 if (library_path == NULL) {
817 free(info);
818 free(common_path);
819 vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
820 "init_system_properties_values library_path");
821 }
822 library_path[0] = '\0';
823
824 // Construct the desired Java library path from the linker's library
825 // search path.
826 //
827 // For compatibility, it is optimal that we insert the additional path
828 // components specific to the Java VM after those components specified
829 // in LD_LIBRARY_PATH (if any) but before those added by the ld.so
830 // infrastructure.
831 if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it
832 strcpy(library_path, common_path);
833 } else {
834 int inserted = 0;
835 for (i = 0; i < info->dls_cnt; i++, path++) {
836 uint_t flags = path->dls_flags & LA_SER_MASK;
837 if (((flags & LA_SER_LIBPATH) == 0) && !inserted) {
838 strcat(library_path, common_path);
839 strcat(library_path, os::path_separator());
840 inserted = 1;
841 }
842 strcat(library_path, path->dls_name);
843 strcat(library_path, os::path_separator());
844 }
845 // eliminate trailing path separator
846 library_path[strlen(library_path)-1] = '\0';
847 }
848
849 // happens before argument parsing - can't use a trace flag
850 // tty->print_raw("init_system_properties_values: native lib path: ");
851 // tty->print_raw_cr(library_path);
852
853 // callee copies into its own buffer
854 Arguments::set_library_path(library_path);
855
856 free(common_path);
857 free(library_path);
858 free(info);
859 }
860
861 /*
862 * Extensions directories.
863 *
864 * Note that the space for the colon and the trailing null are provided
865 * by the nulls included by the sizeof operator (so actually one byte more
866 * than necessary is allocated).
867 */
868 {
869 char *buf = (char *) malloc(strlen(Arguments::get_java_home()) +
870 sizeof(EXTENSIONS_DIR) + sizeof(COMMON_DIR) +
871 sizeof(EXTENSIONS_DIR));
872 sprintf(buf, "%s" EXTENSIONS_DIR ":" COMMON_DIR EXTENSIONS_DIR,
873 Arguments::get_java_home());
874 Arguments::set_ext_dirs(buf);
875 }
876
877 /* Endorsed standards default directory. */
878 {
879 char * buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
880 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
881 Arguments::set_endorsed_dirs(buf);
882 }
883 }
884
885 #undef malloc
886 #undef free
887 #undef getenv
888 #undef EXTENSIONS_DIR 843 #undef EXTENSIONS_DIR
889 #undef ENDORSED_DIR 844 #undef ENDORSED_DIR
890 #undef COMMON_DIR
891
892 } 845 }
893 846
894 void os::breakpoint() { 847 void os::breakpoint() {
895 BREAKPOINT; 848 BREAKPOINT;
896 } 849 }

mercurial