Mercurial > hg > truffle
comparison src/os/bsd/vm/os_bsd.cpp @ 8883:b9a918201d47
Merge with hsx25
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Sat, 06 Apr 2013 20:04:06 +0200 |
parents | b8f261ba79c6 754c24457b20 |
children | 89e4d67fdd2a |
comparison
equal
deleted
inserted
replaced
8660:d47b52b0ff68 | 8883:b9a918201d47 |
---|---|
55 #include "runtime/stubRoutines.hpp" | 55 #include "runtime/stubRoutines.hpp" |
56 #include "runtime/thread.inline.hpp" | 56 #include "runtime/thread.inline.hpp" |
57 #include "runtime/threadCritical.hpp" | 57 #include "runtime/threadCritical.hpp" |
58 #include "runtime/timer.hpp" | 58 #include "runtime/timer.hpp" |
59 #include "services/attachListener.hpp" | 59 #include "services/attachListener.hpp" |
60 #include "services/memTracker.hpp" | |
60 #include "services/runtimeService.hpp" | 61 #include "services/runtimeService.hpp" |
61 #include "utilities/decoder.hpp" | 62 #include "utilities/decoder.hpp" |
62 #include "utilities/defaultStream.hpp" | 63 #include "utilities/defaultStream.hpp" |
63 #include "utilities/events.hpp" | 64 #include "utilities/events.hpp" |
64 #include "utilities/growableArray.hpp" | 65 #include "utilities/growableArray.hpp" |
162 return physical_memory() >> 2; | 163 return physical_memory() >> 2; |
163 } | 164 } |
164 | 165 |
165 julong os::physical_memory() { | 166 julong os::physical_memory() { |
166 return Bsd::physical_memory(); | 167 return Bsd::physical_memory(); |
167 } | |
168 | |
169 julong os::allocatable_physical_memory(julong size) { | |
170 #ifdef _LP64 | |
171 return size; | |
172 #else | |
173 julong result = MIN2(size, (julong)3800*M); | |
174 if (!is_allocatable(result)) { | |
175 // See comments under solaris for alignment considerations | |
176 julong reasonable_size = (julong)2*G - 2 * os::vm_page_size(); | |
177 result = MIN2(size, reasonable_size); | |
178 } | |
179 return result; | |
180 #endif // _LP64 | |
181 } | 168 } |
182 | 169 |
183 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
184 // environment support | 171 // environment support |
185 | 172 |
2273 warning(msg); | 2260 warning(msg); |
2274 } | 2261 } |
2275 return NULL; | 2262 return NULL; |
2276 } | 2263 } |
2277 | 2264 |
2265 // The memory is committed | |
2266 address pc = CALLER_PC; | |
2267 MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc); | |
2268 MemTracker::record_virtual_memory_commit((address)addr, bytes, pc); | |
2269 | |
2278 return addr; | 2270 return addr; |
2279 } | 2271 } |
2280 | 2272 |
2281 bool os::release_memory_special(char* base, size_t bytes) { | 2273 bool os::release_memory_special(char* base, size_t bytes) { |
2282 // detaching the SHM segment will also delete it, see reserve_memory_special() | 2274 // detaching the SHM segment will also delete it, see reserve_memory_special() |
2283 int rslt = shmdt(base); | 2275 int rslt = shmdt(base); |
2284 return rslt == 0; | 2276 if (rslt == 0) { |
2277 MemTracker::record_virtual_memory_uncommit((address)base, bytes); | |
2278 MemTracker::record_virtual_memory_release((address)base, bytes); | |
2279 return true; | |
2280 } else { | |
2281 return false; | |
2282 } | |
2283 | |
2285 } | 2284 } |
2286 | 2285 |
2287 size_t os::large_page_size() { | 2286 size_t os::large_page_size() { |
2288 return _large_page_size; | 2287 return _large_page_size; |
2289 } | 2288 } |
2693 Thread* thread = Thread::current(); | 2692 Thread* thread = Thread::current(); |
2694 OSThread* osthread = thread->osthread(); | 2693 OSThread* osthread = thread->osthread(); |
2695 assert(thread->is_VM_thread(), "Must be VMThread"); | 2694 assert(thread->is_VM_thread(), "Must be VMThread"); |
2696 // read current suspend action | 2695 // read current suspend action |
2697 int action = osthread->sr.suspend_action(); | 2696 int action = osthread->sr.suspend_action(); |
2698 if (action == SR_SUSPEND) { | 2697 if (action == os::Bsd::SuspendResume::SR_SUSPEND) { |
2699 suspend_save_context(osthread, siginfo, context); | 2698 suspend_save_context(osthread, siginfo, context); |
2700 | 2699 |
2701 // Notify the suspend action is about to be completed. do_suspend() | 2700 // Notify the suspend action is about to be completed. do_suspend() |
2702 // waits until SR_SUSPENDED is set and then returns. We will wait | 2701 // waits until SR_SUSPENDED is set and then returns. We will wait |
2703 // here for a resume signal and that completes the suspend-other | 2702 // here for a resume signal and that completes the suspend-other |
2715 | 2714 |
2716 // wait here until we are resumed | 2715 // wait here until we are resumed |
2717 do { | 2716 do { |
2718 sigsuspend(&suspend_set); | 2717 sigsuspend(&suspend_set); |
2719 // ignore all returns until we get a resume signal | 2718 // ignore all returns until we get a resume signal |
2720 } while (osthread->sr.suspend_action() != SR_CONTINUE); | 2719 } while (osthread->sr.suspend_action() != os::Bsd::SuspendResume::SR_CONTINUE); |
2721 | 2720 |
2722 resume_clear_context(osthread); | 2721 resume_clear_context(osthread); |
2723 | 2722 |
2724 } else { | 2723 } else { |
2725 assert(action == SR_CONTINUE, "unexpected sr action"); | 2724 assert(action == os::Bsd::SuspendResume::SR_CONTINUE, "unexpected sr action"); |
2726 // nothing special to do - just leave the handler | 2725 // nothing special to do - just leave the handler |
2727 } | 2726 } |
2728 | 2727 |
2729 errno = old_errno; | 2728 errno = old_errno; |
2730 } | 2729 } |
2774 | 2773 |
2775 // returns true on success and false on error - really an error is fatal | 2774 // returns true on success and false on error - really an error is fatal |
2776 // but this seems the normal response to library errors | 2775 // but this seems the normal response to library errors |
2777 static bool do_suspend(OSThread* osthread) { | 2776 static bool do_suspend(OSThread* osthread) { |
2778 // mark as suspended and send signal | 2777 // mark as suspended and send signal |
2779 osthread->sr.set_suspend_action(SR_SUSPEND); | 2778 osthread->sr.set_suspend_action(os::Bsd::SuspendResume::SR_SUSPEND); |
2780 int status = pthread_kill(osthread->pthread_id(), SR_signum); | 2779 int status = pthread_kill(osthread->pthread_id(), SR_signum); |
2781 assert_status(status == 0, status, "pthread_kill"); | 2780 assert_status(status == 0, status, "pthread_kill"); |
2782 | 2781 |
2783 // check status and wait until notified of suspension | 2782 // check status and wait until notified of suspension |
2784 if (status == 0) { | 2783 if (status == 0) { |
2785 for (int i = 0; !osthread->sr.is_suspended(); i++) { | 2784 for (int i = 0; !osthread->sr.is_suspended(); i++) { |
2786 os::yield_all(i); | 2785 os::yield_all(i); |
2787 } | 2786 } |
2788 osthread->sr.set_suspend_action(SR_NONE); | 2787 osthread->sr.set_suspend_action(os::Bsd::SuspendResume::SR_NONE); |
2789 return true; | 2788 return true; |
2790 } | 2789 } |
2791 else { | 2790 else { |
2792 osthread->sr.set_suspend_action(SR_NONE); | 2791 osthread->sr.set_suspend_action(os::Bsd::SuspendResume::SR_NONE); |
2793 return false; | 2792 return false; |
2794 } | 2793 } |
2795 } | 2794 } |
2796 | 2795 |
2797 static void do_resume(OSThread* osthread) { | 2796 static void do_resume(OSThread* osthread) { |
2798 assert(osthread->sr.is_suspended(), "thread should be suspended"); | 2797 assert(osthread->sr.is_suspended(), "thread should be suspended"); |
2799 osthread->sr.set_suspend_action(SR_CONTINUE); | 2798 osthread->sr.set_suspend_action(os::Bsd::SuspendResume::SR_CONTINUE); |
2800 | 2799 |
2801 int status = pthread_kill(osthread->pthread_id(), SR_signum); | 2800 int status = pthread_kill(osthread->pthread_id(), SR_signum); |
2802 assert_status(status == 0, status, "pthread_kill"); | 2801 assert_status(status == 0, status, "pthread_kill"); |
2803 // check status and wait unit notified of resumption | 2802 // check status and wait unit notified of resumption |
2804 if (status == 0) { | 2803 if (status == 0) { |
2805 for (int i = 0; osthread->sr.is_suspended(); i++) { | 2804 for (int i = 0; osthread->sr.is_suspended(); i++) { |
2806 os::yield_all(i); | 2805 os::yield_all(i); |
2807 } | 2806 } |
2808 } | 2807 } |
2809 osthread->sr.set_suspend_action(SR_NONE); | 2808 osthread->sr.set_suspend_action(os::Bsd::SuspendResume::SR_NONE); |
2810 } | 2809 } |
2811 | 2810 |
2812 //////////////////////////////////////////////////////////////////////////////// | 2811 //////////////////////////////////////////////////////////////////////////////// |
2813 // interrupt support | 2812 // interrupt support |
2814 | 2813 |
3901 // the fast estimate available on the platform. | 3900 // the fast estimate available on the platform. |
3902 | 3901 |
3903 jlong os::current_thread_cpu_time() { | 3902 jlong os::current_thread_cpu_time() { |
3904 #ifdef __APPLE__ | 3903 #ifdef __APPLE__ |
3905 return os::thread_cpu_time(Thread::current(), true /* user + sys */); | 3904 return os::thread_cpu_time(Thread::current(), true /* user + sys */); |
3905 #else | |
3906 Unimplemented(); | |
3907 return 0; | |
3906 #endif | 3908 #endif |
3907 } | 3909 } |
3908 | 3910 |
3909 jlong os::thread_cpu_time(Thread* thread) { | 3911 jlong os::thread_cpu_time(Thread* thread) { |
3912 #ifdef __APPLE__ | |
3913 return os::thread_cpu_time(thread, true /* user + sys */); | |
3914 #else | |
3915 Unimplemented(); | |
3916 return 0; | |
3917 #endif | |
3910 } | 3918 } |
3911 | 3919 |
3912 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) { | 3920 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) { |
3913 #ifdef __APPLE__ | 3921 #ifdef __APPLE__ |
3914 return os::thread_cpu_time(Thread::current(), user_sys_cpu_time); | 3922 return os::thread_cpu_time(Thread::current(), user_sys_cpu_time); |
3923 #else | |
3924 Unimplemented(); | |
3925 return 0; | |
3915 #endif | 3926 #endif |
3916 } | 3927 } |
3917 | 3928 |
3918 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { | 3929 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { |
3919 #ifdef __APPLE__ | 3930 #ifdef __APPLE__ |
3933 nanos += ((jlong) tinfo.system_time.microseconds + (jlong) tinfo.user_time.microseconds) * (jlong)1000; | 3944 nanos += ((jlong) tinfo.system_time.microseconds + (jlong) tinfo.user_time.microseconds) * (jlong)1000; |
3934 return nanos; | 3945 return nanos; |
3935 } else { | 3946 } else { |
3936 return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000); | 3947 return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000); |
3937 } | 3948 } |
3949 #else | |
3950 Unimplemented(); | |
3951 return 0; | |
3938 #endif | 3952 #endif |
3939 } | 3953 } |
3940 | 3954 |
3941 | 3955 |
3942 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { | 3956 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { |