Mercurial > hg > graal-jvmci-8
comparison src/os/bsd/vm/os_bsd.cpp @ 12095:c6ec0a97b30a
8022808: Kitchensink hangs on macos
Summary: Use pthread_mach_thread_np() instead of mach_thread_self() to avoid leaking resources
Reviewed-by: dholmes, rbackman
author | sla |
---|---|
date | Wed, 21 Aug 2013 13:18:52 +0200 |
parents | 59b052799158 |
children | 3a57fa7a4cd0 |
comparison
equal
deleted
inserted
replaced
12069:9d6c9b0a8f15 | 12095:c6ec0a97b30a |
---|---|
640 extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction; | 640 extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction; |
641 objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL; | 641 objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL; |
642 #endif | 642 #endif |
643 | 643 |
644 #ifdef __APPLE__ | 644 #ifdef __APPLE__ |
645 static uint64_t locate_unique_thread_id() { | 645 static uint64_t locate_unique_thread_id(mach_port_t mach_thread_port) { |
646 // Additional thread_id used to correlate threads in SA | 646 // Additional thread_id used to correlate threads in SA |
647 thread_identifier_info_data_t m_ident_info; | 647 thread_identifier_info_data_t m_ident_info; |
648 mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT; | 648 mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT; |
649 | 649 |
650 thread_info(::mach_thread_self(), THREAD_IDENTIFIER_INFO, | 650 thread_info(mach_thread_port, THREAD_IDENTIFIER_INFO, |
651 (thread_info_t) &m_ident_info, &count); | 651 (thread_info_t) &m_ident_info, &count); |
652 | |
652 return m_ident_info.thread_id; | 653 return m_ident_info.thread_id; |
653 } | 654 } |
654 #endif | 655 #endif |
655 | 656 |
656 // Thread start routine for all newly created threads | 657 // Thread start routine for all newly created threads |
677 sync->notify_all(); | 678 sync->notify_all(); |
678 return NULL; | 679 return NULL; |
679 } | 680 } |
680 | 681 |
681 #ifdef __APPLE__ | 682 #ifdef __APPLE__ |
682 // thread_id is mach thread on macos | 683 // thread_id is mach thread on macos, which pthreads graciously caches and provides for us |
683 osthread->set_thread_id(::mach_thread_self()); | 684 mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self()); |
684 osthread->set_unique_thread_id(locate_unique_thread_id()); | 685 guarantee(thread_id != 0, "thread id missing from pthreads"); |
686 osthread->set_thread_id(thread_id); | |
687 | |
688 uint64_t unique_thread_id = locate_unique_thread_id(thread_id); | |
689 guarantee(unique_thread_id != 0, "unique thread id was not found"); | |
690 osthread->set_unique_thread_id(unique_thread_id); | |
685 #else | 691 #else |
686 // thread_id is pthread_id on BSD | 692 // thread_id is pthread_id on BSD |
687 osthread->set_thread_id(::pthread_self()); | 693 osthread->set_thread_id(::pthread_self()); |
688 #endif | 694 #endif |
689 // initialize signal mask for this thread | 695 // initialize signal mask for this thread |
841 return false; | 847 return false; |
842 } | 848 } |
843 | 849 |
844 // Store pthread info into the OSThread | 850 // Store pthread info into the OSThread |
845 #ifdef __APPLE__ | 851 #ifdef __APPLE__ |
846 osthread->set_thread_id(::mach_thread_self()); | 852 // thread_id is mach thread on macos, which pthreads graciously caches and provides for us |
847 osthread->set_unique_thread_id(locate_unique_thread_id()); | 853 mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self()); |
854 guarantee(thread_id != 0, "just checking"); | |
855 osthread->set_thread_id(thread_id); | |
856 | |
857 uint64_t unique_thread_id = locate_unique_thread_id(thread_id); | |
858 guarantee(unique_thread_id != 0, "just checking"); | |
859 osthread->set_unique_thread_id(unique_thread_id); | |
848 #else | 860 #else |
849 osthread->set_thread_id(::pthread_self()); | 861 osthread->set_thread_id(::pthread_self()); |
850 #endif | 862 #endif |
851 osthread->set_pthread_id(::pthread_self()); | 863 osthread->set_pthread_id(::pthread_self()); |
852 | 864 |
1113 return n; | 1125 return n; |
1114 } | 1126 } |
1115 | 1127 |
1116 intx os::current_thread_id() { | 1128 intx os::current_thread_id() { |
1117 #ifdef __APPLE__ | 1129 #ifdef __APPLE__ |
1118 return (intx)::mach_thread_self(); | 1130 return (intx)::pthread_mach_thread_np(::pthread_self()); |
1119 #else | 1131 #else |
1120 return (intx)::pthread_self(); | 1132 return (intx)::pthread_self(); |
1121 #endif | 1133 #endif |
1122 } | 1134 } |
1123 int os::current_process_id() { | 1135 int os::current_process_id() { |