760 // u_longlong_t real_total Total real memory (in 4 KB pages).
761 // u_longlong_t real_free Free real memory (in 4 KB pages).
762 // u_longlong_t pgsp_total Total paging space (in 4 KB pages).
763 // u_longlong_t pgsp_free Free paging space (in 4 KB pages).
764
765 pmi->virt_total = psmt.virt_total * 4096;
766 pmi->real_total = psmt.real_total * 4096;
767 pmi->real_free = psmt.real_free * 4096;
768 pmi->pgsp_total = psmt.pgsp_total * 4096;
769 pmi->pgsp_free = psmt.pgsp_free * 4096;
770
771 return true;
772
773 }
774 } // end os::Aix::get_meminfo
775
776 //////////////////////////////////////////////////////////////////////////////
777 // create new thread
778
779 // Thread start routine for all newly created threads
780 static void *java_start(Thread *thread) {
781
782 // find out my own stack dimensions
783 {
784 // actually, this should do exactly the same as thread->record_stack_base_and_size...
785 address base = 0;
786 size_t size = 0;
787 query_stack_dimensions(&base, &size);
788 thread->set_stack_base(base);
789 thread->set_stack_size(size);
790 }
791
792 const pthread_t pthread_id = ::pthread_self();
793 const tid_t kernel_thread_id = ::thread_self();
794
795 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
796 os::current_thread_id(), (uintx) kernel_thread_id);
797
798 // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc()
799 // by the pthread library). In rare cases, this may not be the case, e.g. when third-party
800 // tools hook pthread_create(). In this case, we may run into problems establishing
821 // Thread_id is pthread id.
822 osthread->set_thread_id(pthread_id);
823
824 // .. but keep kernel thread id too for diagnostics
825 osthread->set_kernel_thread_id(kernel_thread_id);
826
827 // Initialize signal mask for this thread.
828 os::Aix::hotspot_sigmask(thread);
829
830 // Initialize floating point control register.
831 os::Aix::init_thread_fpu_state();
832
833 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
834
835 // Call one more level start routine.
836 thread->run();
837
838 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
839 os::current_thread_id(), (uintx) kernel_thread_id);
840
841 return 0;
842 }
843
844 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
845
846 assert(thread->osthread() == NULL, "caller responsible");
847
848 // Allocate the OSThread object
849 OSThread* osthread = new OSThread(NULL, NULL);
850 if (osthread == NULL) {
851 return false;
852 }
853
854 // set the correct thread state
855 osthread->set_thread_type(thr_type);
856
857 // Initial state is ALLOCATED but not INITIALIZED
858 osthread->set_state(ALLOCATED);
859
860 thread->set_osthread(osthread);
885 break;
886 case os::compiler_thread:
887 if (CompilerThreadStackSize > 0) {
888 stack_size = (size_t)(CompilerThreadStackSize * K);
889 break;
890 } // else fall through:
891 // use VMThreadStackSize if CompilerThreadStackSize is not defined
892 case os::vm_thread:
893 case os::pgc_thread:
894 case os::cgc_thread:
895 case os::watcher_thread:
896 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
897 break;
898 }
899 }
900
901 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
902 pthread_attr_setstacksize(&attr, stack_size);
903
904 pthread_t tid;
905 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
906
907
908 char buf[64];
909 if (ret == 0) {
910 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
911 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
912 } else {
913 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
914 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
915 }
916
917 pthread_attr_destroy(&attr);
918
919 if (ret != 0) {
920 // Need to clean up stuff we've allocated so far
921 thread->set_osthread(NULL);
922 delete osthread;
923 return false;
924 }
925
976
977 // initialize signal mask for this thread
978 // and save the caller's signal mask
979 os::Aix::hotspot_sigmask(thread);
980
981 log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
982 os::current_thread_id(), (uintx) kernel_thread_id);
983
984 return true;
985 }
986
987 void os::pd_start_thread(Thread* thread) {
988 int status = pthread_continue_np(thread->osthread()->pthread_id());
989 assert(status == 0, "thr_continue failed");
990 }
991
992 // Free OS resources related to the OSThread
993 void os::free_thread(OSThread* osthread) {
994 assert(osthread != NULL, "osthread not set");
995
996 if (Thread::current()->osthread() == osthread) {
997 // Restore caller's signal mask
998 sigset_t sigmask = osthread->caller_sigmask();
999 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1000 }
1001
1002 delete osthread;
1003 }
1004
1005 ////////////////////////////////////////////////////////////////////////////////
1006 // time support
1007
1008 // Time since start-up in seconds to a fine granularity.
1009 // Used by VMSelfDestructTimer and the MemProfiler.
1010 double os::elapsedTime() {
1011 return (double)(os::elapsed_counter()) * 0.000001;
1012 }
1013
1014 jlong os::elapsed_counter() {
1015 timeval time;
1016 int status = gettimeofday(&time, NULL);
1017 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1018 }
1019
1020 jlong os::elapsed_frequency() {
|
760 // u_longlong_t real_total Total real memory (in 4 KB pages).
761 // u_longlong_t real_free Free real memory (in 4 KB pages).
762 // u_longlong_t pgsp_total Total paging space (in 4 KB pages).
763 // u_longlong_t pgsp_free Free paging space (in 4 KB pages).
764
765 pmi->virt_total = psmt.virt_total * 4096;
766 pmi->real_total = psmt.real_total * 4096;
767 pmi->real_free = psmt.real_free * 4096;
768 pmi->pgsp_total = psmt.pgsp_total * 4096;
769 pmi->pgsp_free = psmt.pgsp_free * 4096;
770
771 return true;
772
773 }
774 } // end os::Aix::get_meminfo
775
776 //////////////////////////////////////////////////////////////////////////////
777 // create new thread
778
779 // Thread start routine for all newly created threads
780 static void *thread_native_entry(Thread *thread) {
781
782 // find out my own stack dimensions
783 {
784 // actually, this should do exactly the same as thread->record_stack_base_and_size...
785 address base = 0;
786 size_t size = 0;
787 query_stack_dimensions(&base, &size);
788 thread->set_stack_base(base);
789 thread->set_stack_size(size);
790 }
791
792 const pthread_t pthread_id = ::pthread_self();
793 const tid_t kernel_thread_id = ::thread_self();
794
795 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
796 os::current_thread_id(), (uintx) kernel_thread_id);
797
798 // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc()
799 // by the pthread library). In rare cases, this may not be the case, e.g. when third-party
800 // tools hook pthread_create(). In this case, we may run into problems establishing
821 // Thread_id is pthread id.
822 osthread->set_thread_id(pthread_id);
823
824 // .. but keep kernel thread id too for diagnostics
825 osthread->set_kernel_thread_id(kernel_thread_id);
826
827 // Initialize signal mask for this thread.
828 os::Aix::hotspot_sigmask(thread);
829
830 // Initialize floating point control register.
831 os::Aix::init_thread_fpu_state();
832
833 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
834
835 // Call one more level start routine.
836 thread->run();
837
838 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
839 os::current_thread_id(), (uintx) kernel_thread_id);
840
841 // If a thread has not deleted itself ("delete this") as part of its
842 // termination sequence, we have to ensure thread-local-storage is
843 // cleared before we actually terminate. No threads should ever be
844 // deleted asynchronously with respect to their termination.
845 if (Thread::current_or_null_safe() != NULL) {
846 assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
847 thread->clear_thread_current();
848 }
849
850 return 0;
851 }
852
853 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
854
855 assert(thread->osthread() == NULL, "caller responsible");
856
857 // Allocate the OSThread object
858 OSThread* osthread = new OSThread(NULL, NULL);
859 if (osthread == NULL) {
860 return false;
861 }
862
863 // set the correct thread state
864 osthread->set_thread_type(thr_type);
865
866 // Initial state is ALLOCATED but not INITIALIZED
867 osthread->set_state(ALLOCATED);
868
869 thread->set_osthread(osthread);
894 break;
895 case os::compiler_thread:
896 if (CompilerThreadStackSize > 0) {
897 stack_size = (size_t)(CompilerThreadStackSize * K);
898 break;
899 } // else fall through:
900 // use VMThreadStackSize if CompilerThreadStackSize is not defined
901 case os::vm_thread:
902 case os::pgc_thread:
903 case os::cgc_thread:
904 case os::watcher_thread:
905 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
906 break;
907 }
908 }
909
910 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
911 pthread_attr_setstacksize(&attr, stack_size);
912
913 pthread_t tid;
914 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
915
916
917 char buf[64];
918 if (ret == 0) {
919 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
920 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
921 } else {
922 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
923 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
924 }
925
926 pthread_attr_destroy(&attr);
927
928 if (ret != 0) {
929 // Need to clean up stuff we've allocated so far
930 thread->set_osthread(NULL);
931 delete osthread;
932 return false;
933 }
934
985
986 // initialize signal mask for this thread
987 // and save the caller's signal mask
988 os::Aix::hotspot_sigmask(thread);
989
990 log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
991 os::current_thread_id(), (uintx) kernel_thread_id);
992
993 return true;
994 }
995
996 void os::pd_start_thread(Thread* thread) {
997 int status = pthread_continue_np(thread->osthread()->pthread_id());
998 assert(status == 0, "thr_continue failed");
999 }
1000
1001 // Free OS resources related to the OSThread
1002 void os::free_thread(OSThread* osthread) {
1003 assert(osthread != NULL, "osthread not set");
1004
1005 // We are told to free resources of the argument thread,
1006 // but we can only really operate on the current thread.
1007 assert(Thread::current()->osthread() == osthread,
1008 "os::free_thread but not current thread");
1009
1010 // Restore caller's signal mask
1011 sigset_t sigmask = osthread->caller_sigmask();
1012 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1013
1014 delete osthread;
1015 }
1016
1017 ////////////////////////////////////////////////////////////////////////////////
1018 // time support
1019
1020 // Time since start-up in seconds to a fine granularity.
1021 // Used by VMSelfDestructTimer and the MemProfiler.
1022 double os::elapsedTime() {
1023 return (double)(os::elapsed_counter()) * 0.000001;
1024 }
1025
1026 jlong os::elapsed_counter() {
1027 timeval time;
1028 int status = gettimeofday(&time, NULL);
1029 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1030 }
1031
1032 jlong os::elapsed_frequency() {
|