src/os/aix/vm/os_aix.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2014 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


2812 }
2813 
2814 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
2815 void os::infinite_sleep() {
2816   while (true) {    // sleep forever ...
2817     ::sleep(100);   // ... 100 seconds at a time
2818   }
2819 }
2820 
2821 // Used to convert frequent JVM_Yield() to nops
2822 bool os::dont_yield() {
2823   return DontYieldALot;
2824 }
2825 
2826 void os::yield() {
2827   sched_yield();
2828 }
2829 
2830 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
2831 
2832 void os::yield_all(int attempts) {
2833   // Yields to all threads, including threads with lower priorities
2834   // Threads on Linux are all with same priority. The Solaris style
2835   // os::yield_all() with nanosleep(1ms) is not necessary.
2836   sched_yield();
2837 }
2838 
2839 // Called from the tight loops to possibly influence time-sharing heuristics
2840 void os::loop_breaker(int attempts) {
2841   os::yield_all(attempts);
2842 }
2843 
2844 ////////////////////////////////////////////////////////////////////////////////
2845 // thread priority support
2846 
2847 // From AIX manpage to pthread_setschedparam
2848 // (see: http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
2849 //    topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_setschedparam.htm):
2850 //
2851 // "If schedpolicy is SCHED_OTHER, then sched_priority must be in the
2852 // range from 40 to 80, where 40 is the least favored priority and 80
2853 // is the most favored."
2854 //
2855 // (Actually, I doubt this even has an impact on AIX, as we do kernel
2856 // scheduling there; however, this still leaves iSeries.)
2857 //
2858 // We use the same values for AIX and PASE.
2859 int os::java_to_os_priority[CriticalPriority + 1] = {
2860   54,             // 0 Entry should never be used
2861 
2862   55,             // 1 MinPriority
2863   55,             // 2


3080   if (sr_notify(osthread) != 0) {
3081     // try to cancel, switch to running
3082 
3083     os::SuspendResume::State result = osthread->sr.cancel_suspend();
3084     if (result == os::SuspendResume::SR_RUNNING) {
3085       // cancelled
3086       return false;
3087     } else if (result == os::SuspendResume::SR_SUSPENDED) {
3088       // somehow managed to suspend
3089       return true;
3090     } else {
3091       ShouldNotReachHere();
3092       return false;
3093     }
3094   }
3095 
3096   // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED
3097 
3098   for (int n = 0; !osthread->sr.is_suspended(); n++) {
3099     for (int i = 0; i < RANDOMLY_LARGE_INTEGER2 && !osthread->sr.is_suspended(); i++) {
3100       os::yield_all(i);
3101     }
3102 
3103     // timeout, try to cancel the request
3104     if (n >= RANDOMLY_LARGE_INTEGER) {
3105       os::SuspendResume::State cancelled = osthread->sr.cancel_suspend();
3106       if (cancelled == os::SuspendResume::SR_RUNNING) {
3107         return false;
3108       } else if (cancelled == os::SuspendResume::SR_SUSPENDED) {
3109         return true;
3110       } else {
3111         ShouldNotReachHere();
3112         return false;
3113       }
3114     }
3115   }
3116 
3117   guarantee(osthread->sr.is_suspended(), "Must be suspended");
3118   return true;
3119 }
3120 
3121 static void do_resume(OSThread* osthread) {
3122   //assert(osthread->sr.is_suspended(), "thread should be suspended");
3123 
3124   if (osthread->sr.request_wakeup() != os::SuspendResume::SR_WAKEUP_REQUEST) {
3125     // failed to switch to WAKEUP_REQUEST
3126     ShouldNotReachHere();
3127     return;
3128   }
3129 
3130   while (!osthread->sr.is_running()) {
3131     if (sr_notify(osthread) == 0) {
3132       for (int n = 0; n < RANDOMLY_LARGE_INTEGER && !osthread->sr.is_running(); n++) {
3133         for (int i = 0; i < 100 && !osthread->sr.is_running(); i++) {
3134           os::yield_all(i);
3135         }
3136       }
3137     } else {
3138       ShouldNotReachHere();
3139     }
3140   }
3141 
3142   guarantee(osthread->sr.is_running(), "Must be running!");
3143 }
3144 
3145 ///////////////////////////////////////////////////////////////////////////////////
3146 // signal handling (except suspend/resume)
3147 
3148 // This routine may be used by user applications as a "hook" to catch signals.
3149 // The user-defined signal handler must pass unrecognized signals to this
3150 // routine, and if it returns true (non-zero), then the signal handler must
3151 // return immediately. If the flag "abort_if_unrecognized" is true, then this
3152 // routine will never retun false (zero), but instead will execute a VM panic
3153 // routine kill the process.
3154 //


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2014 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


2812 }
2813 
2814 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
2815 void os::infinite_sleep() {
2816   while (true) {    // sleep forever ...
2817     ::sleep(100);   // ... 100 seconds at a time
2818   }
2819 }
2820 
2821 // Used to convert frequent JVM_Yield() to nops
2822 bool os::dont_yield() {
2823   return DontYieldALot;
2824 }
2825 
2826 void os::yield() {
2827   sched_yield();
2828 }
2829 
2830 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
2831 
2832 void os::yield_all() {
2833   // Yields to all threads, including threads with lower priorities
2834   // Threads on Linux are all with same priority. The Solaris style
2835   // os::yield_all() with nanosleep(1ms) is not necessary.
2836   sched_yield();
2837 }
2838 





2839 ////////////////////////////////////////////////////////////////////////////////
2840 // thread priority support
2841 
2842 // From AIX manpage to pthread_setschedparam
2843 // (see: http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
2844 //    topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_setschedparam.htm):
2845 //
2846 // "If schedpolicy is SCHED_OTHER, then sched_priority must be in the
2847 // range from 40 to 80, where 40 is the least favored priority and 80
2848 // is the most favored."
2849 //
2850 // (Actually, I doubt this even has an impact on AIX, as we do kernel
2851 // scheduling there; however, this still leaves iSeries.)
2852 //
2853 // We use the same values for AIX and PASE.
2854 int os::java_to_os_priority[CriticalPriority + 1] = {
2855   54,             // 0 Entry should never be used
2856 
2857   55,             // 1 MinPriority
2858   55,             // 2


3075   if (sr_notify(osthread) != 0) {
3076     // try to cancel, switch to running
3077 
3078     os::SuspendResume::State result = osthread->sr.cancel_suspend();
3079     if (result == os::SuspendResume::SR_RUNNING) {
3080       // cancelled
3081       return false;
3082     } else if (result == os::SuspendResume::SR_SUSPENDED) {
3083       // somehow managed to suspend
3084       return true;
3085     } else {
3086       ShouldNotReachHere();
3087       return false;
3088     }
3089   }
3090 
3091   // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED
3092 
3093   for (int n = 0; !osthread->sr.is_suspended(); n++) {
3094     for (int i = 0; i < RANDOMLY_LARGE_INTEGER2 && !osthread->sr.is_suspended(); i++) {
3095       os::yield_all();
3096     }
3097 
3098     // timeout, try to cancel the request
3099     if (n >= RANDOMLY_LARGE_INTEGER) {
3100       os::SuspendResume::State cancelled = osthread->sr.cancel_suspend();
3101       if (cancelled == os::SuspendResume::SR_RUNNING) {
3102         return false;
3103       } else if (cancelled == os::SuspendResume::SR_SUSPENDED) {
3104         return true;
3105       } else {
3106         ShouldNotReachHere();
3107         return false;
3108       }
3109     }
3110   }
3111 
3112   guarantee(osthread->sr.is_suspended(), "Must be suspended");
3113   return true;
3114 }
3115 
3116 static void do_resume(OSThread* osthread) {
3117   //assert(osthread->sr.is_suspended(), "thread should be suspended");
3118 
3119   if (osthread->sr.request_wakeup() != os::SuspendResume::SR_WAKEUP_REQUEST) {
3120     // failed to switch to WAKEUP_REQUEST
3121     ShouldNotReachHere();
3122     return;
3123   }
3124 
3125   while (!osthread->sr.is_running()) {
3126     if (sr_notify(osthread) == 0) {
3127       for (int n = 0; n < RANDOMLY_LARGE_INTEGER && !osthread->sr.is_running(); n++) {
3128         for (int i = 0; i < 100 && !osthread->sr.is_running(); i++) {
3129           os::yield_all();
3130         }
3131       }
3132     } else {
3133       ShouldNotReachHere();
3134     }
3135   }
3136 
3137   guarantee(osthread->sr.is_running(), "Must be running!");
3138 }
3139 
3140 ///////////////////////////////////////////////////////////////////////////////////
3141 // signal handling (except suspend/resume)
3142 
3143 // This routine may be used by user applications as a "hook" to catch signals.
3144 // The user-defined signal handler must pass unrecognized signals to this
3145 // routine, and if it returns true (non-zero), then the signal handler must
3146 // return immediately. If the flag "abort_if_unrecognized" is true, then this
3147 // routine will never retun false (zero), but instead will execute a VM panic
3148 // routine kill the process.
3149 //