8232107: support ThreadPriorityPolicy flag on AIX
authormbaesken
Thu, 10 Oct 2019 14:20:43 +0200
changeset 58591 9770ff6f0b20
parent 58590 97974e906efb
child 58602 d97e1ee31e2b
8232107: support ThreadPriorityPolicy flag on AIX Reviewed-by: clanger, dholmes
src/hotspot/os/aix/os_aix.cpp
--- a/src/hotspot/os/aix/os_aix.cpp	Mon Oct 14 22:20:03 2019 -0400
+++ b/src/hotspot/os/aix/os_aix.cpp	Thu Oct 10 14:20:43 2019 +0200
@@ -2643,8 +2643,24 @@
   60              // 11 CriticalPriority
 };
 
+static int prio_init() {
+  if (ThreadPriorityPolicy == 1) {
+    if (geteuid() != 0) {
+      if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
+        warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \
+                "e.g., being the root user. If the necessary permission is not " \
+                "possessed, changes to priority will be silently ignored.");
+      }
+    }
+  }
+  if (UseCriticalJavaThreadPriority) {
+    os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority];
+  }
+  return 0;
+}
+
 OSReturn os::set_native_priority(Thread* thread, int newpri) {
-  if (!UseThreadPriorities) return OS_OK;
+  if (!UseThreadPriorities || ThreadPriorityPolicy == 0) return OS_OK;
   pthread_t thr = thread->osthread()->pthread_id();
   int policy = SCHED_OTHER;
   struct sched_param param;
@@ -2659,7 +2675,7 @@
 }
 
 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
-  if (!UseThreadPriorities) {
+  if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
     *priority_ptr = java_to_os_priority[NormPriority];
     return OS_OK;
   }
@@ -3569,6 +3585,9 @@
     }
   }
 
+  // initialize thread priority policy
+  prio_init();
+
   return JNI_OK;
 }