289 _physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
290 }
291 #endif
292 }
293
294 #ifdef __APPLE__
295 static const char *get_home() {
296 const char *home_dir = ::getenv("HOME");
297 if ((home_dir == NULL) || (*home_dir == '\0')) {
298 struct passwd *passwd_info = getpwuid(geteuid());
299 if (passwd_info != NULL) {
300 home_dir = passwd_info->pw_dir;
301 }
302 }
303
304 return home_dir;
305 }
306 #endif
307
308 void os::init_system_properties_values() {
309 // char arch[12];
310 // sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
311
312 // The next steps are taken in the product version:
313 //
314 // Obtain the JAVA_HOME value from the location of libjvm.so.
315 // This library should be located at:
316 // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so.
317 //
318 // If "/jre/lib/" appears at the right place in the path, then we
319 // assume libjvm.so is installed in a JDK and we use this path.
320 //
321 // Otherwise exit with message: "Could not create the Java virtual machine."
322 //
323 // The following extra steps are taken in the debugging version:
324 //
325 // If "/jre/lib/" does NOT appear at the right place in the path
326 // instead of exit check for $JAVA_HOME environment variable.
327 //
328 // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
329 // then we append a fake suffix "hotspot/libjvm.so" to this path so
330 // it looks like libjvm.so is installed there
331 // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so.
332 //
333 // Otherwise exit.
334 //
335 // Important note: if the location of libjvm.so changes this
336 // code needs to be changed accordingly.
337
338 // The next few definitions allow the code to be verbatim:
339 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
340 #define getenv(n) ::getenv(n)
341
342 /*
343 * See ld(1):
344 * The linker uses the following search paths to locate required
345 * shared libraries:
346 * 1: ...
347 * ...
348 * 7: The default directories, normally /lib and /usr/lib.
349 */
350 #ifndef DEFAULT_LIBPATH
351 #define DEFAULT_LIBPATH "/lib:/usr/lib"
352 #endif
353
354 #define EXTENSIONS_DIR "/lib/ext"
355 #define ENDORSED_DIR "/lib/endorsed"
356 #define REG_DIR "/usr/java/packages"
357
358 #ifdef __APPLE__
359 #define SYS_EXTENSIONS_DIR "/Library/Java/Extensions"
360 #define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java"
361 const char *user_home_dir = get_home();
362 // the null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir
363 int system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) +
364 sizeof(SYS_EXTENSIONS_DIRS);
365 #endif
366
367 {
368 /* sysclasspath, java_home, dll_dir */
369 {
370 char *home_path;
371 char *dll_path;
372 char *pslash;
373 char buf[MAXPATHLEN];
374 os::jvm_path(buf, sizeof(buf));
375
376 // Found the full path to libjvm.so.
377 // Now cut the path to <java_home>/jre if we can.
378 *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */
379 pslash = strrchr(buf, '/');
380 if (pslash != NULL)
381 *pslash = '\0'; /* get rid of /{client|server|hotspot} */
382 dll_path = malloc(strlen(buf) + 1);
383 if (dll_path == NULL)
384 return;
385 strcpy(dll_path, buf);
386 Arguments::set_dll_dir(dll_path);
387
388 if (pslash != NULL) {
389 pslash = strrchr(buf, '/');
390 if (pslash != NULL) {
391 *pslash = '\0'; /* get rid of /<arch> (/lib on macosx) */
392 #ifndef __APPLE__
393 pslash = strrchr(buf, '/');
394 if (pslash != NULL)
395 *pslash = '\0'; /* get rid of /lib */
396 #endif
397 }
398 }
399
400 home_path = malloc(strlen(buf) + 1);
401 if (home_path == NULL)
402 return;
403 strcpy(home_path, buf);
404 Arguments::set_java_home(home_path);
405
406 if (!set_boot_path('/', ':'))
407 return;
408 }
409
410 /*
411 * Where to look for native libraries
412 *
413 * Note: Due to a legacy implementation, most of the library path
414 * is set in the launcher. This was to accomodate linking restrictions
415 * on legacy Bsd implementations (which are no longer supported).
416 * Eventually, all the library path setting will be done here.
417 *
418 * However, to prevent the proliferation of improperly built native
419 * libraries, the new path component /usr/java/packages is added here.
420 * Eventually, all the library path setting will be done here.
421 */
422 {
423 char *ld_library_path;
424
425 /*
426 * Construct the invariant part of ld_library_path. Note that the
427 * space for the colon and the trailing null are provided by the
428 * nulls included by the sizeof operator (so actually we allocate
429 * a byte more than necessary).
430 */
431 #ifdef __APPLE__
432 ld_library_path = (char *) malloc(system_ext_size);
433 sprintf(ld_library_path, "%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS, user_home_dir);
434 #else
435 ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") +
436 strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH));
437 sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch);
438 #endif
439
440 /*
441 * Get the user setting of LD_LIBRARY_PATH, and prepended it. It
442 * should always exist (until the legacy problem cited above is
443 * addressed).
444 */
445 #ifdef __APPLE__
446 // Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code can specify a directory inside an app wrapper
447 char *l = getenv("JAVA_LIBRARY_PATH");
448 if (l != NULL) {
449 char *t = ld_library_path;
450 /* That's +1 for the colon and +1 for the trailing '\0' */
451 ld_library_path = (char *) malloc(strlen(l) + 1 + strlen(t) + 1);
452 sprintf(ld_library_path, "%s:%s", l, t);
453 free(t);
454 }
455
456 char *v = getenv("DYLD_LIBRARY_PATH");
457 #else
458 char *v = getenv("LD_LIBRARY_PATH");
459 #endif
460 if (v != NULL) {
461 char *t = ld_library_path;
462 /* That's +1 for the colon and +1 for the trailing '\0' */
463 ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
464 sprintf(ld_library_path, "%s:%s", v, t);
465 free(t);
466 }
467
468 #ifdef __APPLE__
469 // Apple's Java6 has "." at the beginning of java.library.path.
470 // OpenJDK on Windows has "." at the end of java.library.path.
471 // OpenJDK on Linux and Solaris don't have "." in java.library.path
472 // at all. To ease the transition from Apple's Java6 to OpenJDK7,
473 // "." is appended to the end of java.library.path. Yes, this
474 // could cause a change in behavior, but Apple's Java6 behavior
475 // can be achieved by putting "." at the beginning of the
476 // JAVA_LIBRARY_PATH environment variable.
477 {
478 char *t = ld_library_path;
479 // that's +3 for appending ":." and the trailing '\0'
480 ld_library_path = (char *) malloc(strlen(t) + 3);
481 sprintf(ld_library_path, "%s:%s", t, ".");
482 free(t);
483 }
484 #endif
485
486 Arguments::set_library_path(ld_library_path);
487 }
488
489 /*
490 * Extensions directories.
491 *
492 * Note that the space for the colon and the trailing null are provided
493 * by the nulls included by the sizeof operator (so actually one byte more
494 * than necessary is allocated).
495 */
496 {
497 #ifdef __APPLE__
498 char *buf = malloc(strlen(Arguments::get_java_home()) +
499 sizeof(EXTENSIONS_DIR) + system_ext_size);
500 sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":"
501 SYS_EXTENSIONS_DIRS, user_home_dir, Arguments::get_java_home());
502 #else
503 char *buf = malloc(strlen(Arguments::get_java_home()) +
504 sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR));
505 sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR,
506 Arguments::get_java_home());
507 #endif
508
509 Arguments::set_ext_dirs(buf);
510 }
511
512 /* Endorsed standards default directory. */
513 {
514 char * buf;
515 buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
516 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
517 Arguments::set_endorsed_dirs(buf);
518 }
519 }
520
521 #ifdef __APPLE__
522 #undef SYS_EXTENSIONS_DIR
523 #endif
524 #undef malloc
525 #undef getenv
526 #undef EXTENSIONS_DIR
527 #undef ENDORSED_DIR
528
529 // Done
530 return;
531 }
532
533 ////////////////////////////////////////////////////////////////////////////////
534 // breakpoint support
535
536 void os::breakpoint() {
537 BREAKPOINT;
538 }
539
540 extern "C" void breakpoint() {
541 // use debugger to set breakpoint here
542 }
543
544 ////////////////////////////////////////////////////////////////////////////////
545 // signal support
546
547 debug_only(static bool signal_sets_initialized = false);
548 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
549
550 bool os::Bsd::is_sig_ignored(int sig) {
|
289 _physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
290 }
291 #endif
292 }
293
294 #ifdef __APPLE__
295 static const char *get_home() {
296 const char *home_dir = ::getenv("HOME");
297 if ((home_dir == NULL) || (*home_dir == '\0')) {
298 struct passwd *passwd_info = getpwuid(geteuid());
299 if (passwd_info != NULL) {
300 home_dir = passwd_info->pw_dir;
301 }
302 }
303
304 return home_dir;
305 }
306 #endif
307
308 void os::init_system_properties_values() {
309 // The next steps are taken in the product version:
310 //
311 // Obtain the JAVA_HOME value from the location of libjvm.so.
312 // This library should be located at:
313 // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so.
314 //
315 // If "/jre/lib/" appears at the right place in the path, then we
316 // assume libjvm.so is installed in a JDK and we use this path.
317 //
318 // Otherwise exit with message: "Could not create the Java virtual machine."
319 //
320 // The following extra steps are taken in the debugging version:
321 //
322 // If "/jre/lib/" does NOT appear at the right place in the path
323 // instead of exit check for $JAVA_HOME environment variable.
324 //
325 // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
326 // then we append a fake suffix "hotspot/libjvm.so" to this path so
327 // it looks like libjvm.so is installed there
328 // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so.
329 //
330 // Otherwise exit.
331 //
332 // Important note: if the location of libjvm.so changes this
333 // code needs to be changed accordingly.
334
335 // See ld(1):
336 // The linker uses the following search paths to locate required
337 // shared libraries:
338 // 1: ...
339 // ...
340 // 7: The default directories, normally /lib and /usr/lib.
341 #ifndef DEFAULT_LIBPATH
342 #define DEFAULT_LIBPATH "/lib:/usr/lib"
343 #endif
344
345 // Base path of extensions installed on the system.
346 #define SYS_EXT_DIR "/usr/java/packages"
347 #define EXTENSIONS_DIR "/lib/ext"
348 #define ENDORSED_DIR "/lib/endorsed"
349
350 #ifndef __APPLE__
351
352 // Buffer that fits several sprintfs.
353 // Note that the space for the colon and the trailing null are provided
354 // by the nulls included by the sizeof operator.
355 const size_t bufsize =
356 MAX4((size_t)MAXPATHLEN, // For dll_dir & friends.
357 sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH), // invariant ld_library_path
358 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
359 (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
360 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
361
362 // sysclasspath, java_home, dll_dir
363 {
364 char *pslash;
365 os::jvm_path(buf, bufsize);
366
367 // Found the full path to libjvm.so.
368 // Now cut the path to <java_home>/jre if we can.
369 *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
370 pslash = strrchr(buf, '/');
371 if (pslash != NULL) {
372 *pslash = '\0'; // Get rid of /{client|server|hotspot}.
373 }
374 Arguments::set_dll_dir(buf);
375
376 if (pslash != NULL) {
377 pslash = strrchr(buf, '/');
378 if (pslash != NULL) {
379 *pslash = '\0'; // Get rid of /<arch>.
380 pslash = strrchr(buf, '/');
381 if (pslash != NULL) {
382 *pslash = '\0'; // Get rid of /lib.
383 }
384 }
385 }
386 Arguments::set_java_home(buf);
387
388 if (!set_boot_path('/', ':')) {
389 return;
390 }
391 }
392
393 // Where to look for native libraries.
394 //
395 // Note: Due to a legacy implementation, most of the library path
396 // is set in the launcher. This was to accomodate linking restrictions
397 // on legacy Bsd implementations (which are no longer supported).
398 // Eventually, all the library path setting will be done here.
399 //
400 // However, to prevent the proliferation of improperly built native
401 // libraries, the new path component /usr/java/packages is added here.
402 // Eventually, all the library path setting will be done here.
403 {
404 char *ld_library_path_inv = buf;
405
406 // Construct the invariant part of ld_library_path.
407 sprintf(ld_library_path_inv, SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch);
408
409 // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
410 // should always exist (until the legacy problem cited above is
411 // addressed).
412 char *v = ::getenv("LD_LIBRARY_PATH");
413 if (v != NULL) {
414 // That's +1 for the colon and +1 for the trailing '\0'.
415 char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + strlen(ld_library_path_inv) + 1, mtInternal);
416 sprintf(ld_library_path, "%s:%s", v, ld_library_path_inv);
417 Arguments::set_library_path(ld_library_path);
418 FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
419 } else {
420 Arguments::set_library_path(ld_library_path_inv);
421 }
422 }
423
424 // Extensions directories.
425 sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
426 Arguments::set_ext_dirs(buf);
427
428 // Endorsed standards default directory.
429 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
430 Arguments::set_endorsed_dirs(buf);
431
432 FREE_C_HEAP_ARRAY(char, buf, mtInternal);
433
434 #else // __APPLE__
435
436 #define SYS_EXTENSIONS_DIR "/Library/Java/Extensions"
437 #define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java"
438
439 const char *user_home_dir = get_home();
440 // The null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir.
441 size_t system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) +
442 sizeof(SYS_EXTENSIONS_DIRS);
443
444 // Buffer that fits several sprintfs.
445 // Note that the space for the colon and the trailing null are provided
446 // by the nulls included by the sizeof operator.
447 const size_t bufsize =
448 MAX4((size_t)MAXPATHLEN, // for dll_dir & friends.
449 system_ext_size, // reg dir
450 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size, // extensions dir
451 (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
452 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
453
454 // sysclasspath, java_home, dll_dir
455 {
456 char *pslash;
457 os::jvm_path(buf, bufsize);
458
459 // Found the full path to libjvm.so.
460 // Now cut the path to <java_home>/jre if we can.
461 *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
462 pslash = strrchr(buf, '/');
463 if (pslash != NULL) {
464 *pslash = '\0'; // Get rid of /{client|server|hotspot}.
465 }
466 Arguments::set_dll_dir(buf);
467
468 if (pslash != NULL) {
469 pslash = strrchr(buf, '/');
470 if (pslash != NULL) {
471 *pslash = '\0'; // Get rid of /lib.
472 }
473 }
474 Arguments::set_java_home(buf);
475
476 if (!set_boot_path('/', ':')) {
477 return;
478 }
479 }
480
481 // Where to look for native libraries.
482 //
483 // Note: Due to a legacy implementation, most of the library path
484 // is set in the launcher. This was to accomodate linking restrictions
485 // on legacy Bsd implementations (which are no longer supported).
486 // Eventually, all the library path setting will be done here.
487 //
488 // However, to prevent the proliferation of improperly built native
489 // libraries, the new path component /usr/java/packages is added here.
490 // Eventually, all the library path setting will be done here.
491 {
492 char *ld_library_path = buf;
493
494 // Construct the invariant part of ld_library_path.
495 sprintf(ld_library_path, "%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS, user_home_dir);
496
497 // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
498 // should always exist (until the legacy problem cited above is
499 // addressed).
500 // Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code
501 // can specify a directory inside an app wrapper
502 char *l = ::getenv("JAVA_LIBRARY_PATH");
503 if (l != NULL) {
504 char *t = ld_library_path;
505 // That's +1 for the colon and +1 for the trailing '\0'.
506 ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(l) + 1 + strlen(t) + 1, mtInternal);
507 sprintf(ld_library_path, "%s:%s", l, ld_library_path);
508 // Don't free t, it's buf which is used further down.
509 }
510
511 char *v = ::getenv("DYLD_LIBRARY_PATH");
512 if (v != NULL) {
513 char *t = ld_library_path;
514 // That's +1 for the colon and +1 for the trailing '\0'.
515 ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + strlen(t) + 1, mtInternal);
516 sprintf(ld_library_path, "%s:%s", v, t);
517 if (t != buf) { FREE_C_HEAP_ARRAY(char, t, mtInternal); }
518 }
519
520 // Apple's Java6 has "." at the beginning of java.library.path.
521 // OpenJDK on Windows has "." at the end of java.library.path.
522 // OpenJDK on Linux and Solaris don't have "." in java.library.path
523 // at all. To ease the transition from Apple's Java6 to OpenJDK7,
524 // "." is appended to the end of java.library.path. Yes, this
525 // could cause a change in behavior, but Apple's Java6 behavior
526 // can be achieved by putting "." at the beginning of the
527 // JAVA_LIBRARY_PATH environment variable.
528 {
529 char *t = ld_library_path;
530 // that's +3 for appending ":." and the trailing '\0'
531 ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(t) + 3, mtInternal);
532 sprintf(ld_library_path, "%s:%s", t, ".");
533 if (t != buf) { FREE_C_HEAP_ARRAY(char, t, mtInternal); }
534 }
535
536 Arguments::set_library_path(ld_library_path);
537 if (ld_library_path != buf) { FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal); }
538 }
539
540 // Extensions directories.
541 //
542 // Note that the space for the colon and the trailing null are provided
543 // by the nulls included by the sizeof operator (so actually one byte more
544 // than necessary is allocated).
545 sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS,
546 user_home_dir, Arguments::get_java_home());
547 Arguments::set_ext_dirs(buf);
548
549 // Endorsed standards default directory.
550 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
551 Arguments::set_endorsed_dirs(buf);
552
553 FREE_C_HEAP_ARRAY(char, buf, mtInternal);
554
555 #undef SYS_EXTENSIONS_DIR
556 #undef SYS_EXTENSIONS_DIRS
557
558 #endif // __APPLE__
559
560 #undef SYS_EXT_DIR
561 #undef EXTENSIONS_DIR
562 #undef ENDORSED_DIR
563 }
564
565 ////////////////////////////////////////////////////////////////////////////////
566 // breakpoint support
567
568 void os::breakpoint() {
569 BREAKPOINT;
570 }
571
572 extern "C" void breakpoint() {
573 // use debugger to set breakpoint here
574 }
575
576 ////////////////////////////////////////////////////////////////////////////////
577 // signal support
578
579 debug_only(static bool signal_sets_initialized = false);
580 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
581
582 bool os::Bsd::is_sig_ignored(int sig) {
|