Mercurial > hg > truffle
comparison src/os/bsd/vm/os_bsd.cpp @ 4006:436b4a3231bf
7098194: integrate macosx-port changes
Summary: Integrate bsd-port/hotspot and macosx-port/hotspot changes as of 2011.09.29.
Reviewed-by: kvn, dholmes, never, phh
Contributed-by: Christos Zoulas <christos@zoulas.com>, Greg Lewis <glewis@eyesbeyond.com>, Kurt Miller <kurt@intricatesoftware.com>, Alexander Strange <astrange@apple.com>, Mike Swingler <swingler@apple.com>, Roger Hoover <rhoover@apple.com>, Victor Hernandez <vhernandez@apple.com>, Pratik Solanki <psolanki@apple.com>
author | dcubed |
---|---|
date | Thu, 13 Oct 2011 09:35:42 -0700 |
parents | f08d439fab8c |
children | 36b057451829 |
comparison
equal
deleted
inserted
replaced
4005:2ef3386478e6 | 4006:436b4a3231bf |
---|---|
134 #if defined(__FreeBSD__) || defined(__NetBSD__) | 134 #if defined(__FreeBSD__) || defined(__NetBSD__) |
135 # include <elf.h> | 135 # include <elf.h> |
136 #endif | 136 #endif |
137 | 137 |
138 #ifdef __APPLE__ | 138 #ifdef __APPLE__ |
139 #include <mach/mach.h> // semaphore_* API | 139 # include <mach/mach.h> // semaphore_* API |
140 #include <mach-o/dyld.h> | 140 # include <mach-o/dyld.h> |
141 # include <sys/proc_info.h> | |
142 # include <objc/objc-auto.h> | |
141 #endif | 143 #endif |
142 | 144 |
143 #ifndef MAP_ANONYMOUS | 145 #ifndef MAP_ANONYMOUS |
144 #define MAP_ANONYMOUS MAP_ANON | 146 #define MAP_ANONYMOUS MAP_ANON |
145 #endif | 147 #endif |
383 fclose(fp); | 385 fclose(fp); |
384 } | 386 } |
385 } | 387 } |
386 _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE); | 388 _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE); |
387 assert(processor_count() > 0, "bsd error"); | 389 assert(processor_count() > 0, "bsd error"); |
390 } | |
391 #endif | |
392 | |
393 #ifdef __APPLE__ | |
394 static const char *get_home() { | |
395 const char *home_dir = ::getenv("HOME"); | |
396 if ((home_dir == NULL) || (*home_dir == '\0')) { | |
397 struct passwd *passwd_info = getpwuid(geteuid()); | |
398 if (passwd_info != NULL) { | |
399 home_dir = passwd_info->pw_dir; | |
400 } | |
401 } | |
402 | |
403 return home_dir; | |
388 } | 404 } |
389 #endif | 405 #endif |
390 | 406 |
391 void os::init_system_properties_values() { | 407 void os::init_system_properties_values() { |
392 // char arch[12]; | 408 // char arch[12]; |
436 | 452 |
437 #define EXTENSIONS_DIR "/lib/ext" | 453 #define EXTENSIONS_DIR "/lib/ext" |
438 #define ENDORSED_DIR "/lib/endorsed" | 454 #define ENDORSED_DIR "/lib/endorsed" |
439 #define REG_DIR "/usr/java/packages" | 455 #define REG_DIR "/usr/java/packages" |
440 | 456 |
457 #ifdef __APPLE__ | |
458 #define SYS_EXTENSIONS_DIR "/Library/Java/Extensions" | |
459 #define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java" | |
460 const char *user_home_dir = get_home(); | |
461 // the null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir | |
462 int system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) + | |
463 sizeof(SYS_EXTENSIONS_DIRS); | |
464 #endif | |
465 | |
441 { | 466 { |
442 /* sysclasspath, java_home, dll_dir */ | 467 /* sysclasspath, java_home, dll_dir */ |
443 { | 468 { |
444 char *home_path; | 469 char *home_path; |
445 char *dll_path; | 470 char *dll_path; |
460 Arguments::set_dll_dir(dll_path); | 485 Arguments::set_dll_dir(dll_path); |
461 | 486 |
462 if (pslash != NULL) { | 487 if (pslash != NULL) { |
463 pslash = strrchr(buf, '/'); | 488 pslash = strrchr(buf, '/'); |
464 if (pslash != NULL) { | 489 if (pslash != NULL) { |
465 *pslash = '\0'; /* get rid of /<arch> */ | 490 *pslash = '\0'; /* get rid of /<arch> (/lib on macosx) */ |
491 #ifndef __APPLE__ | |
466 pslash = strrchr(buf, '/'); | 492 pslash = strrchr(buf, '/'); |
467 if (pslash != NULL) | 493 if (pslash != NULL) |
468 *pslash = '\0'; /* get rid of /lib */ | 494 *pslash = '\0'; /* get rid of /lib */ |
495 #endif | |
469 } | 496 } |
470 } | 497 } |
471 | 498 |
472 home_path = malloc(strlen(buf) + 1); | 499 home_path = malloc(strlen(buf) + 1); |
473 if (home_path == NULL) | 500 if (home_path == NULL) |
498 * Construct the invariant part of ld_library_path. Note that the | 525 * Construct the invariant part of ld_library_path. Note that the |
499 * space for the colon and the trailing null are provided by the | 526 * space for the colon and the trailing null are provided by the |
500 * nulls included by the sizeof operator (so actually we allocate | 527 * nulls included by the sizeof operator (so actually we allocate |
501 * a byte more than necessary). | 528 * a byte more than necessary). |
502 */ | 529 */ |
530 #ifdef __APPLE__ | |
531 ld_library_path = (char *) malloc(system_ext_size); | |
532 sprintf(ld_library_path, "%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS, user_home_dir); | |
533 #else | |
503 ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + | 534 ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + |
504 strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); | 535 strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); |
505 sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch); | 536 sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch); |
537 #endif | |
506 | 538 |
507 /* | 539 /* |
508 * Get the user setting of LD_LIBRARY_PATH, and prepended it. It | 540 * Get the user setting of LD_LIBRARY_PATH, and prepended it. It |
509 * should always exist (until the legacy problem cited above is | 541 * should always exist (until the legacy problem cited above is |
510 * addressed). | 542 * addressed). |
511 */ | 543 */ |
512 #ifdef __APPLE__ | 544 #ifdef __APPLE__ |
545 // Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code can specify a directory inside an app wrapper | |
546 char *l = getenv("JAVA_LIBRARY_PATH"); | |
547 if (l != NULL) { | |
548 char *t = ld_library_path; | |
549 /* That's +1 for the colon and +1 for the trailing '\0' */ | |
550 ld_library_path = (char *) malloc(strlen(l) + 1 + strlen(t) + 1); | |
551 sprintf(ld_library_path, "%s:%s", l, t); | |
552 free(t); | |
553 } | |
554 | |
513 char *v = getenv("DYLD_LIBRARY_PATH"); | 555 char *v = getenv("DYLD_LIBRARY_PATH"); |
514 #else | 556 #else |
515 char *v = getenv("LD_LIBRARY_PATH"); | 557 char *v = getenv("LD_LIBRARY_PATH"); |
516 #endif | 558 #endif |
517 if (v != NULL) { | 559 if (v != NULL) { |
518 char *t = ld_library_path; | 560 char *t = ld_library_path; |
519 /* That's +1 for the colon and +1 for the trailing '\0' */ | 561 /* That's +1 for the colon and +1 for the trailing '\0' */ |
520 ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1); | 562 ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1); |
521 sprintf(ld_library_path, "%s:%s", v, t); | 563 sprintf(ld_library_path, "%s:%s", v, t); |
564 free(t); | |
522 } | 565 } |
523 Arguments::set_library_path(ld_library_path); | 566 Arguments::set_library_path(ld_library_path); |
524 } | 567 } |
525 | 568 |
526 /* | 569 /* |
529 * Note that the space for the colon and the trailing null are provided | 572 * Note that the space for the colon and the trailing null are provided |
530 * by the nulls included by the sizeof operator (so actually one byte more | 573 * by the nulls included by the sizeof operator (so actually one byte more |
531 * than necessary is allocated). | 574 * than necessary is allocated). |
532 */ | 575 */ |
533 { | 576 { |
577 #ifdef __APPLE__ | |
578 char *buf = malloc(strlen(Arguments::get_java_home()) + | |
579 sizeof(EXTENSIONS_DIR) + system_ext_size); | |
580 sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":" | |
581 SYS_EXTENSIONS_DIRS, user_home_dir, Arguments::get_java_home()); | |
582 #else | |
534 char *buf = malloc(strlen(Arguments::get_java_home()) + | 583 char *buf = malloc(strlen(Arguments::get_java_home()) + |
535 sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR)); | 584 sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR)); |
536 sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR, | 585 sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR, |
537 Arguments::get_java_home()); | 586 Arguments::get_java_home()); |
587 #endif | |
588 | |
538 Arguments::set_ext_dirs(buf); | 589 Arguments::set_ext_dirs(buf); |
539 } | 590 } |
540 | 591 |
541 /* Endorsed standards default directory. */ | 592 /* Endorsed standards default directory. */ |
542 { | 593 { |
545 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); | 596 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); |
546 Arguments::set_endorsed_dirs(buf); | 597 Arguments::set_endorsed_dirs(buf); |
547 } | 598 } |
548 } | 599 } |
549 | 600 |
601 #ifdef __APPLE__ | |
602 #undef SYS_EXTENSIONS_DIR | |
603 #endif | |
550 #undef malloc | 604 #undef malloc |
551 #undef getenv | 605 #undef getenv |
552 #undef EXTENSIONS_DIR | 606 #undef EXTENSIONS_DIR |
553 #undef ENDORSED_DIR | 607 #undef ENDORSED_DIR |
554 | 608 |
882 return true; | 936 return true; |
883 } | 937 } |
884 #endif | 938 #endif |
885 } | 939 } |
886 | 940 |
941 #ifdef __APPLE__ | |
942 // library handle for calling objc_registerThreadWithCollector() | |
943 // without static linking to the libobjc library | |
944 #define OBJC_LIB "/usr/lib/libobjc.dylib" | |
945 #define OBJC_GCREGISTER "objc_registerThreadWithCollector" | |
946 typedef void (*objc_registerThreadWithCollector_t)(); | |
947 extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction; | |
948 objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL; | |
949 #endif | |
950 | |
887 // Thread start routine for all newly created threads | 951 // Thread start routine for all newly created threads |
888 static void *java_start(Thread *thread) { | 952 static void *java_start(Thread *thread) { |
889 // Try to randomize the cache line index of hot stack frames. | 953 // Try to randomize the cache line index of hot stack frames. |
890 // This helps when threads of the same stack traces evict each other's | 954 // This helps when threads of the same stack traces evict each other's |
891 // cache lines. The threads can be either from the same JVM instance, or | 955 // cache lines. The threads can be either from the same JVM instance, or |
926 // initialize signal mask for this thread | 990 // initialize signal mask for this thread |
927 os::Bsd::hotspot_sigmask(thread); | 991 os::Bsd::hotspot_sigmask(thread); |
928 | 992 |
929 // initialize floating point control register | 993 // initialize floating point control register |
930 os::Bsd::init_thread_fpu_state(); | 994 os::Bsd::init_thread_fpu_state(); |
995 | |
996 #ifdef __APPLE__ | |
997 // register thread with objc gc | |
998 if (objc_registerThreadWithCollectorFunction != NULL) { | |
999 objc_registerThreadWithCollectorFunction(); | |
1000 } | |
1001 #endif | |
931 | 1002 |
932 // handshaking with parent thread | 1003 // handshaking with parent thread |
933 { | 1004 { |
934 MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag); | 1005 MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag); |
935 | 1006 |
1745 | 1816 |
1746 const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; } | 1817 const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; } |
1747 | 1818 |
1748 // This must be hard coded because it's the system's temporary | 1819 // This must be hard coded because it's the system's temporary |
1749 // directory not the java application's temp directory, ala java.io.tmpdir. | 1820 // directory not the java application's temp directory, ala java.io.tmpdir. |
1821 #ifdef __APPLE__ | |
1822 // macosx has a secure per-user temporary directory | |
1823 char temp_path_storage[PATH_MAX]; | |
1824 const char* os::get_temp_directory() { | |
1825 static char *temp_path = NULL; | |
1826 if (temp_path == NULL) { | |
1827 int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, temp_path_storage, PATH_MAX); | |
1828 if (pathSize == 0 || pathSize > PATH_MAX) { | |
1829 strlcpy(temp_path_storage, "/tmp/", sizeof(temp_path_storage)); | |
1830 } | |
1831 temp_path = temp_path_storage; | |
1832 } | |
1833 return temp_path; | |
1834 } | |
1835 #else /* __APPLE__ */ | |
1750 const char* os::get_temp_directory() { return "/tmp"; } | 1836 const char* os::get_temp_directory() { return "/tmp"; } |
1837 #endif /* __APPLE__ */ | |
1751 | 1838 |
1752 static bool file_exists(const char* filename) { | 1839 static bool file_exists(const char* filename) { |
1753 struct stat statbuf; | 1840 struct stat statbuf; |
1754 if (filename == NULL || strlen(filename) == 0) { | 1841 if (filename == NULL || strlen(filename) == 0) { |
1755 return false; | 1842 return false; |
4529 } | 4616 } |
4530 | 4617 |
4531 // initialize thread priority policy | 4618 // initialize thread priority policy |
4532 prio_init(); | 4619 prio_init(); |
4533 | 4620 |
4621 #ifdef __APPLE__ | |
4622 // dynamically link to objective c gc registration | |
4623 void *handleLibObjc = dlopen(OBJC_LIB, RTLD_LAZY); | |
4624 if (handleLibObjc != NULL) { | |
4625 objc_registerThreadWithCollectorFunction = (objc_registerThreadWithCollector_t) dlsym(handleLibObjc, OBJC_GCREGISTER); | |
4626 } | |
4627 #endif | |
4628 | |
4534 return JNI_OK; | 4629 return JNI_OK; |
4535 } | 4630 } |
4536 | 4631 |
4537 // this is called at the end of vm_initialization | 4632 // this is called at the end of vm_initialization |
4538 void os::init_3(void) { } | 4633 void os::init_3(void) { } |
4557 // Bsd doesn't yet have a (official) notion of processor sets, | 4652 // Bsd doesn't yet have a (official) notion of processor sets, |
4558 // so just return the number of online processors. | 4653 // so just return the number of online processors. |
4559 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); | 4654 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); |
4560 assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check"); | 4655 assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check"); |
4561 return online_cpus; | 4656 return online_cpus; |
4657 #endif | |
4658 } | |
4659 | |
4660 void os::set_native_thread_name(const char *name) { | |
4661 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5 | |
4662 // This is only supported in Snow Leopard and beyond | |
4663 if (name != NULL) { | |
4664 // Add a "Java: " prefix to the name | |
4665 char buf[MAXTHREADNAMESIZE]; | |
4666 snprintf(buf, sizeof(buf), "Java: %s", name); | |
4667 pthread_setname_np(buf); | |
4668 } | |
4562 #endif | 4669 #endif |
4563 } | 4670 } |
4564 | 4671 |
4565 bool os::distribute_processes(uint length, uint* distribution) { | 4672 bool os::distribute_processes(uint length, uint* distribution) { |
4566 // Not yet implemented. | 4673 // Not yet implemented. |
5676 // | 5783 // |
5677 bool os::is_headless_jre() { | 5784 bool os::is_headless_jre() { |
5678 struct stat statbuf; | 5785 struct stat statbuf; |
5679 char buf[MAXPATHLEN]; | 5786 char buf[MAXPATHLEN]; |
5680 char libmawtpath[MAXPATHLEN]; | 5787 char libmawtpath[MAXPATHLEN]; |
5681 const char *xawtstr = "/xawt/libmawt.so"; | 5788 const char *xawtstr = "/xawt/libmawt" JNI_LIB_SUFFIX; |
5682 const char *motifstr = "/motif21/libmawt.so"; | 5789 const char *motifstr = "/motif21/libmawt" JNI_LIB_SUFFIX; |
5683 char *p; | 5790 char *p; |
5684 | 5791 |
5685 // Get path to libjvm.so | 5792 // Get path to libjvm.so |
5686 os::jvm_path(buf, sizeof(buf)); | 5793 os::jvm_path(buf, sizeof(buf)); |
5687 | 5794 |