diff options
| -rw-r--r-- | runtime/native/dalvik_system_VMRuntime.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc index d81c13df11..6ca951fd53 100644 --- a/runtime/native/dalvik_system_VMRuntime.cc +++ b/runtime/native/dalvik_system_VMRuntime.cc @@ -17,6 +17,8 @@ #include "dalvik_system_VMRuntime.h" #ifdef ART_TARGET_ANDROID +#include <sys/time.h> +#include <sys/resource.h> extern "C" void android_set_application_target_sdk_version(uint32_t version); #endif #include <limits.h> @@ -625,6 +627,23 @@ static jboolean VMRuntime_didPruneDalvikCache(JNIEnv* env ATTRIBUTE_UNUSED, return Runtime::Current()->GetPrunedDalvikCache() ? JNI_TRUE : JNI_FALSE; } +static void VMRuntime_setSystemDaemonThreadPriority(JNIEnv* env ATTRIBUTE_UNUSED, + jclass klass ATTRIBUTE_UNUSED) { +#ifdef ART_TARGET_ANDROID + Thread* self = Thread::Current(); + DCHECK(self != nullptr); + pid_t tid = self->GetTid(); + // We use a priority lower than the default for the system daemon threads (eg HeapTaskDaemon) to + // avoid jank due to CPU contentions between GC and other UI-related threads. b/36631902. + // We may use a native priority that doesn't have a corresponding java.lang.Thread-level priority. + static constexpr int kSystemDaemonNiceValue = 4; // priority 124 + if (setpriority(PRIO_PROCESS, tid, kSystemDaemonNiceValue) != 0) { + PLOG(INFO) << *self << " setpriority(PRIO_PROCESS, " << tid << ", " + << kSystemDaemonNiceValue << ") failed"; + } +#endif +} + static JNINativeMethod gMethods[] = { FAST_NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"), NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"), @@ -662,6 +681,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(VMRuntime, isBootClassPathOnDisk, "(Ljava/lang/String;)Z"), NATIVE_METHOD(VMRuntime, getCurrentInstructionSet, "()Ljava/lang/String;"), NATIVE_METHOD(VMRuntime, didPruneDalvikCache, "()Z"), + NATIVE_METHOD(VMRuntime, setSystemDaemonThreadPriority, "()V"), }; void register_dalvik_system_VMRuntime(JNIEnv* env) { |