src/os/solaris/vm/os_solaris.cpp

changeset 6556
6048424d3865
parent 6518
62c54fcc0a35
child 6667
917873d2983d
child 6779
364b73402247
     1.1 --- a/src/os/solaris/vm/os_solaris.cpp	Thu Feb 27 09:37:16 2014 +0100
     1.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Thu Apr 10 04:07:45 2014 -0700
     1.3 @@ -648,9 +648,6 @@
     1.4  
     1.5  
     1.6  void os::init_system_properties_values() {
     1.7 -  char arch[12];
     1.8 -  sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
     1.9 -
    1.10    // The next steps are taken in the product version:
    1.11    //
    1.12    // Obtain the JAVA_HOME value from the location of libjvm.so.
    1.13 @@ -677,218 +674,174 @@
    1.14    // Important note: if the location of libjvm.so changes this
    1.15    // code needs to be changed accordingly.
    1.16  
    1.17 -  // The next few definitions allow the code to be verbatim:
    1.18 -#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
    1.19 -#define free(p) FREE_C_HEAP_ARRAY(char, p, mtInternal)
    1.20 -#define getenv(n) ::getenv(n)
    1.21 -
    1.22 +// Base path of extensions installed on the system.
    1.23 +#define SYS_EXT_DIR     "/usr/jdk/packages"
    1.24  #define EXTENSIONS_DIR  "/lib/ext"
    1.25  #define ENDORSED_DIR    "/lib/endorsed"
    1.26 -#define COMMON_DIR      "/usr/jdk/packages"
    1.27 -
    1.28 +
    1.29 +  char cpu_arch[12];
    1.30 +  // Buffer that fits several sprintfs.
    1.31 +  // Note that the space for the colon and the trailing null are provided
    1.32 +  // by the nulls included by the sizeof operator.
    1.33 +  const size_t bufsize =
    1.34 +    MAX4((size_t)MAXPATHLEN,  // For dll_dir & friends.
    1.35 +         sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch), // invariant ld_library_path
    1.36 +         (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
    1.37 +         (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
    1.38 +  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
    1.39 +
    1.40 +  // sysclasspath, java_home, dll_dir
    1.41    {
    1.42 -    /* sysclasspath, java_home, dll_dir */
    1.43 -    {
    1.44 -        char *home_path;
    1.45 -        char *dll_path;
    1.46 -        char *pslash;
    1.47 -        char buf[MAXPATHLEN];
    1.48 -        os::jvm_path(buf, sizeof(buf));
    1.49 -
    1.50 -        // Found the full path to libjvm.so.
    1.51 -        // Now cut the path to <java_home>/jre if we can.
    1.52 -        *(strrchr(buf, '/')) = '\0';  /* get rid of /libjvm.so */
    1.53 +    char *pslash;
    1.54 +    os::jvm_path(buf, bufsize);
    1.55 +
    1.56 +    // Found the full path to libjvm.so.
    1.57 +    // Now cut the path to <java_home>/jre if we can.
    1.58 +    *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
    1.59 +    pslash = strrchr(buf, '/');
    1.60 +    if (pslash != NULL) {
    1.61 +      *pslash = '\0';            // Get rid of /{client|server|hotspot}.
    1.62 +    }
    1.63 +    Arguments::set_dll_dir(buf);
    1.64 +
    1.65 +    if (pslash != NULL) {
    1.66 +      pslash = strrchr(buf, '/');
    1.67 +      if (pslash != NULL) {
    1.68 +        *pslash = '\0';          // Get rid of /<arch>.
    1.69          pslash = strrchr(buf, '/');
    1.70 -        if (pslash != NULL)
    1.71 -            *pslash = '\0';           /* get rid of /{client|server|hotspot} */
    1.72 -        dll_path = malloc(strlen(buf) + 1);
    1.73 -        if (dll_path == NULL)
    1.74 -            return;
    1.75 -        strcpy(dll_path, buf);
    1.76 -        Arguments::set_dll_dir(dll_path);
    1.77 -
    1.78          if (pslash != NULL) {
    1.79 -            pslash = strrchr(buf, '/');
    1.80 -            if (pslash != NULL) {
    1.81 -                *pslash = '\0';       /* get rid of /<arch> */
    1.82 -                pslash = strrchr(buf, '/');
    1.83 -                if (pslash != NULL)
    1.84 -                    *pslash = '\0';   /* get rid of /lib */
    1.85 -            }
    1.86 +          *pslash = '\0';        // Get rid of /lib.
    1.87          }
    1.88 -
    1.89 -        home_path = malloc(strlen(buf) + 1);
    1.90 -        if (home_path == NULL)
    1.91 -            return;
    1.92 -        strcpy(home_path, buf);
    1.93 -        Arguments::set_java_home(home_path);
    1.94 -
    1.95 -        if (!set_boot_path('/', ':'))
    1.96 -            return;
    1.97 +      }
    1.98      }
    1.99 -
   1.100 -    /*
   1.101 -     * Where to look for native libraries
   1.102 -     */
   1.103 -    {
   1.104 -      // Use dlinfo() to determine the correct java.library.path.
   1.105 -      //
   1.106 -      // If we're launched by the Java launcher, and the user
   1.107 -      // does not set java.library.path explicitly on the commandline,
   1.108 -      // the Java launcher sets LD_LIBRARY_PATH for us and unsets
   1.109 -      // LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64.  In this case
   1.110 -      // dlinfo returns LD_LIBRARY_PATH + crle settings (including
   1.111 -      // /usr/lib), which is exactly what we want.
   1.112 -      //
   1.113 -      // If the user does set java.library.path, it completely
   1.114 -      // overwrites this setting, and always has.
   1.115 -      //
   1.116 -      // If we're not launched by the Java launcher, we may
   1.117 -      // get here with any/all of the LD_LIBRARY_PATH[_32|64]
   1.118 -      // settings.  Again, dlinfo does exactly what we want.
   1.119 -
   1.120 -      Dl_serinfo     _info, *info = &_info;
   1.121 -      Dl_serpath     *path;
   1.122 -      char*          library_path;
   1.123 -      char           *common_path;
   1.124 -      int            i;
   1.125 -
   1.126 -      // determine search path count and required buffer size
   1.127 -      if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) {
   1.128 -        vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror());
   1.129 +    Arguments::set_java_home(buf);
   1.130 +    set_boot_path('/', ':');
   1.131 +  }
   1.132 +
   1.133 +  // Where to look for native libraries.
   1.134 +  {
   1.135 +    // Use dlinfo() to determine the correct java.library.path.
   1.136 +    //
   1.137 +    // If we're launched by the Java launcher, and the user
   1.138 +    // does not set java.library.path explicitly on the commandline,
   1.139 +    // the Java launcher sets LD_LIBRARY_PATH for us and unsets
   1.140 +    // LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64.  In this case
   1.141 +    // dlinfo returns LD_LIBRARY_PATH + crle settings (including
   1.142 +    // /usr/lib), which is exactly what we want.
   1.143 +    //
   1.144 +    // If the user does set java.library.path, it completely
   1.145 +    // overwrites this setting, and always has.
   1.146 +    //
   1.147 +    // If we're not launched by the Java launcher, we may
   1.148 +    // get here with any/all of the LD_LIBRARY_PATH[_32|64]
   1.149 +    // settings.  Again, dlinfo does exactly what we want.
   1.150 +
   1.151 +    Dl_serinfo     info_sz, *info = &info_sz;
   1.152 +    Dl_serpath     *path;
   1.153 +    char           *library_path;
   1.154 +    char           *common_path = buf;
   1.155 +
   1.156 +    // Determine search path count and required buffer size.
   1.157 +    if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) {
   1.158 +      FREE_C_HEAP_ARRAY(char, buf,  mtInternal);
   1.159 +      vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror());
   1.160 +    }
   1.161 +
   1.162 +    // Allocate new buffer and initialize.
   1.163 +    info = (Dl_serinfo*)NEW_C_HEAP_ARRAY(char, info_sz.dls_size, mtInternal);
   1.164 +    info->dls_size = info_sz.dls_size;
   1.165 +    info->dls_cnt = info_sz.dls_cnt;
   1.166 +
   1.167 +    // Obtain search path information.
   1.168 +    if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) {
   1.169 +      FREE_C_HEAP_ARRAY(char, buf,  mtInternal);
   1.170 +      FREE_C_HEAP_ARRAY(char, info, mtInternal);
   1.171 +      vm_exit_during_initialization("dlinfo SERINFO request", dlerror());
   1.172 +    }
   1.173 +
   1.174 +    path = &info->dls_serpath[0];
   1.175 +
   1.176 +    // Note: Due to a legacy implementation, most of the library path
   1.177 +    // is set in the launcher. This was to accomodate linking restrictions
   1.178 +    // on legacy Solaris implementations (which are no longer supported).
   1.179 +    // Eventually, all the library path setting will be done here.
   1.180 +    //
   1.181 +    // However, to prevent the proliferation of improperly built native
   1.182 +    // libraries, the new path component /usr/jdk/packages is added here.
   1.183 +
   1.184 +    // Determine the actual CPU architecture.
   1.185 +    sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch));
   1.186 +#ifdef _LP64
   1.187 +    // If we are a 64-bit vm, perform the following translations:
   1.188 +    //   sparc   -> sparcv9
   1.189 +    //   i386    -> amd64
   1.190 +    if (strcmp(cpu_arch, "sparc") == 0) {
   1.191 +      strcat(cpu_arch, "v9");
   1.192 +    } else if (strcmp(cpu_arch, "i386") == 0) {
   1.193 +      strcpy(cpu_arch, "amd64");
   1.194 +    }
   1.195 +#endif
   1.196 +
   1.197 +    // Construct the invariant part of ld_library_path.
   1.198 +    sprintf(common_path, SYS_EXT_DIR "/lib/%s", cpu_arch);
   1.199 +
   1.200 +    // Struct size is more than sufficient for the path components obtained
   1.201 +    // through the dlinfo() call, so only add additional space for the path
   1.202 +    // components explicitly added here.
   1.203 +    size_t library_path_size = info->dls_size + strlen(common_path);
   1.204 +    library_path = (char *)NEW_C_HEAP_ARRAY(char, library_path_size, mtInternal);
   1.205 +    library_path[0] = '\0';
   1.206 +
   1.207 +    // Construct the desired Java library path from the linker's library
   1.208 +    // search path.
   1.209 +    //
   1.210 +    // For compatibility, it is optimal that we insert the additional path
   1.211 +    // components specific to the Java VM after those components specified
   1.212 +    // in LD_LIBRARY_PATH (if any) but before those added by the ld.so
   1.213 +    // infrastructure.
   1.214 +    if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it.
   1.215 +      strcpy(library_path, common_path);
   1.216 +    } else {
   1.217 +      int inserted = 0;
   1.218 +      int i;
   1.219 +      for (i = 0; i < info->dls_cnt; i++, path++) {
   1.220 +        uint_t flags = path->dls_flags & LA_SER_MASK;
   1.221 +        if (((flags & LA_SER_LIBPATH) == 0) && !inserted) {
   1.222 +          strcat(library_path, common_path);
   1.223 +          strcat(library_path, os::path_separator());
   1.224 +          inserted = 1;
   1.225 +        }
   1.226 +        strcat(library_path, path->dls_name);
   1.227 +        strcat(library_path, os::path_separator());
   1.228        }
   1.229 -
   1.230 -      // allocate new buffer and initialize
   1.231 -      info = (Dl_serinfo*)malloc(_info.dls_size);
   1.232 -      if (info == NULL) {
   1.233 -        vm_exit_out_of_memory(_info.dls_size, OOM_MALLOC_ERROR,
   1.234 -                              "init_system_properties_values info");
   1.235 -      }
   1.236 -      info->dls_size = _info.dls_size;
   1.237 -      info->dls_cnt = _info.dls_cnt;
   1.238 -
   1.239 -      // obtain search path information
   1.240 -      if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) {
   1.241 -        free(info);
   1.242 -        vm_exit_during_initialization("dlinfo SERINFO request", dlerror());
   1.243 -      }
   1.244 -
   1.245 -      path = &info->dls_serpath[0];
   1.246 -
   1.247 -      // Note: Due to a legacy implementation, most of the library path
   1.248 -      // is set in the launcher.  This was to accomodate linking restrictions
   1.249 -      // on legacy Solaris implementations (which are no longer supported).
   1.250 -      // Eventually, all the library path setting will be done here.
   1.251 -      //
   1.252 -      // However, to prevent the proliferation of improperly built native
   1.253 -      // libraries, the new path component /usr/jdk/packages is added here.
   1.254 -
   1.255 -      // Determine the actual CPU architecture.
   1.256 -      char cpu_arch[12];
   1.257 -      sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch));
   1.258 -#ifdef _LP64
   1.259 -      // If we are a 64-bit vm, perform the following translations:
   1.260 -      //   sparc   -> sparcv9
   1.261 -      //   i386    -> amd64
   1.262 -      if (strcmp(cpu_arch, "sparc") == 0)
   1.263 -        strcat(cpu_arch, "v9");
   1.264 -      else if (strcmp(cpu_arch, "i386") == 0)
   1.265 -        strcpy(cpu_arch, "amd64");
   1.266 -#endif
   1.267 -
   1.268 -      // Construct the invariant part of ld_library_path. Note that the
   1.269 -      // space for the colon and the trailing null are provided by the
   1.270 -      // nulls included by the sizeof operator.
   1.271 -      size_t bufsize = sizeof(COMMON_DIR) + sizeof("/lib/") + strlen(cpu_arch);
   1.272 -      common_path = malloc(bufsize);
   1.273 -      if (common_path == NULL) {
   1.274 -        free(info);
   1.275 -        vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
   1.276 -                              "init_system_properties_values common_path");
   1.277 -      }
   1.278 -      sprintf(common_path, COMMON_DIR "/lib/%s", cpu_arch);
   1.279 -
   1.280 -      // struct size is more than sufficient for the path components obtained
   1.281 -      // through the dlinfo() call, so only add additional space for the path
   1.282 -      // components explicitly added here.
   1.283 -      bufsize = info->dls_size + strlen(common_path);
   1.284 -      library_path = malloc(bufsize);
   1.285 -      if (library_path == NULL) {
   1.286 -        free(info);
   1.287 -        free(common_path);
   1.288 -        vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
   1.289 -                              "init_system_properties_values library_path");
   1.290 -      }
   1.291 -      library_path[0] = '\0';
   1.292 -
   1.293 -      // Construct the desired Java library path from the linker's library
   1.294 -      // search path.
   1.295 -      //
   1.296 -      // For compatibility, it is optimal that we insert the additional path
   1.297 -      // components specific to the Java VM after those components specified
   1.298 -      // in LD_LIBRARY_PATH (if any) but before those added by the ld.so
   1.299 -      // infrastructure.
   1.300 -      if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it
   1.301 -        strcpy(library_path, common_path);
   1.302 -      } else {
   1.303 -        int inserted = 0;
   1.304 -        for (i = 0; i < info->dls_cnt; i++, path++) {
   1.305 -          uint_t flags = path->dls_flags & LA_SER_MASK;
   1.306 -          if (((flags & LA_SER_LIBPATH) == 0) && !inserted) {
   1.307 -            strcat(library_path, common_path);
   1.308 -            strcat(library_path, os::path_separator());
   1.309 -            inserted = 1;
   1.310 -          }
   1.311 -          strcat(library_path, path->dls_name);
   1.312 -          strcat(library_path, os::path_separator());
   1.313 -        }
   1.314 -        // eliminate trailing path separator
   1.315 -        library_path[strlen(library_path)-1] = '\0';
   1.316 -      }
   1.317 -
   1.318 -      // happens before argument parsing - can't use a trace flag
   1.319 -      // tty->print_raw("init_system_properties_values: native lib path: ");
   1.320 -      // tty->print_raw_cr(library_path);
   1.321 -
   1.322 -      // callee copies into its own buffer
   1.323 -      Arguments::set_library_path(library_path);
   1.324 -
   1.325 -      free(common_path);
   1.326 -      free(library_path);
   1.327 -      free(info);
   1.328 +      // Eliminate trailing path separator.
   1.329 +      library_path[strlen(library_path)-1] = '\0';
   1.330      }
   1.331  
   1.332 -    /*
   1.333 -     * Extensions directories.
   1.334 -     *
   1.335 -     * Note that the space for the colon and the trailing null are provided
   1.336 -     * by the nulls included by the sizeof operator (so actually one byte more
   1.337 -     * than necessary is allocated).
   1.338 -     */
   1.339 -    {
   1.340 -        char *buf = (char *) malloc(strlen(Arguments::get_java_home()) +
   1.341 -            sizeof(EXTENSIONS_DIR) + sizeof(COMMON_DIR) +
   1.342 -            sizeof(EXTENSIONS_DIR));
   1.343 -        sprintf(buf, "%s" EXTENSIONS_DIR ":" COMMON_DIR EXTENSIONS_DIR,
   1.344 -            Arguments::get_java_home());
   1.345 -        Arguments::set_ext_dirs(buf);
   1.346 -    }
   1.347 -
   1.348 -    /* Endorsed standards default directory. */
   1.349 -    {
   1.350 -        char * buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
   1.351 -        sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
   1.352 -        Arguments::set_endorsed_dirs(buf);
   1.353 -    }
   1.354 -  }
   1.355 -
   1.356 -#undef malloc
   1.357 -#undef free
   1.358 -#undef getenv
   1.359 +    // happens before argument parsing - can't use a trace flag
   1.360 +    // tty->print_raw("init_system_properties_values: native lib path: ");
   1.361 +    // tty->print_raw_cr(library_path);
   1.362 +
   1.363 +    // Callee copies into its own buffer.
   1.364 +    Arguments::set_library_path(library_path);
   1.365 +
   1.366 +    FREE_C_HEAP_ARRAY(char, library_path, mtInternal);
   1.367 +    FREE_C_HEAP_ARRAY(char, info, mtInternal);
   1.368 +  }
   1.369 +
   1.370 +  // Extensions directories.
   1.371 +  sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
   1.372 +  Arguments::set_ext_dirs(buf);
   1.373 +
   1.374 +  // Endorsed standards default directory.
   1.375 +  sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
   1.376 +  Arguments::set_endorsed_dirs(buf);
   1.377 +
   1.378 +  FREE_C_HEAP_ARRAY(char, buf, mtInternal);
   1.379 +
   1.380 +#undef SYS_EXT_DIR
   1.381  #undef EXTENSIONS_DIR
   1.382  #undef ENDORSED_DIR
   1.383 -#undef COMMON_DIR
   1.384 -
   1.385  }
   1.386  
   1.387  void os::breakpoint() {

mercurial