equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
4074 // The following code actually changes the niceness of kernel-thread/LWP. It |
4074 // The following code actually changes the niceness of kernel-thread/LWP. It |
4075 // has an assumption that setpriority() only modifies one kernel-thread/LWP, |
4075 // has an assumption that setpriority() only modifies one kernel-thread/LWP, |
4076 // not the entire user process, and user level threads are 1:1 mapped to kernel |
4076 // not the entire user process, and user level threads are 1:1 mapped to kernel |
4077 // threads. It has always been the case, but could change in the future. For |
4077 // threads. It has always been the case, but could change in the future. For |
4078 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). |
4078 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). |
4079 // It is only used when ThreadPriorityPolicy=1 and requires root privilege. |
4079 // It is only used when ThreadPriorityPolicy=1 and may require system level permission |
|
4080 // (e.g., root privilege or CAP_SYS_NICE capability). |
4080 |
4081 |
4081 int os::java_to_os_priority[CriticalPriority + 1] = { |
4082 int os::java_to_os_priority[CriticalPriority + 1] = { |
4082 19, // 0 Entry should never be used |
4083 19, // 0 Entry should never be used |
4083 |
4084 |
4084 4, // 1 MinPriority |
4085 4, // 1 MinPriority |
4098 -5 // 11 CriticalPriority |
4099 -5 // 11 CriticalPriority |
4099 }; |
4100 }; |
4100 |
4101 |
4101 static int prio_init() { |
4102 static int prio_init() { |
4102 if (ThreadPriorityPolicy == 1) { |
4103 if (ThreadPriorityPolicy == 1) { |
4103 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 |
|
4104 // if effective uid is not root. Perhaps, a more elegant way of doing |
|
4105 // this is to test CAP_SYS_NICE capability, but that will require libcap.so |
|
4106 if (geteuid() != 0) { |
4104 if (geteuid() != 0) { |
4107 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { |
4105 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { |
4108 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); |
4106 warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \ |
|
4107 "e.g., being the root user. If the necessary permission is not " \ |
|
4108 "possessed, changes to priority will be silently ignored."); |
4109 } |
4109 } |
4110 ThreadPriorityPolicy = 0; |
|
4111 } |
4110 } |
4112 } |
4111 } |
4113 if (UseCriticalJavaThreadPriority) { |
4112 if (UseCriticalJavaThreadPriority) { |
4114 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority]; |
4113 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority]; |
4115 } |
4114 } |