Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce97e4ad authored by Jared Duke's avatar Jared Duke
Browse files

Optimize Process thread priority method calls

Annotate native calls with @FastNative and @CriticalNative for several
priority-related Process methods. Also ensure the the
Process.setThreadPriority overloads are compiled in the boot image, as
these were only recently made Java methods (versus native trampolines).

Bug: 417492941
Bug: 441066069
Bug: 374158990
Flag: EXEMPT BUGFIX
Test: presubmit
Change-Id: Id6074389ef4dedf13f25119fc35e5f9f968476f1
parent 17cab722
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -87,3 +87,10 @@ HSPLandroid/os/Message;->compareMessages(Landroid/os/Message;Landroid/os/Message
# and is captured with the boot image profiling pipeline.
HSPLcom/android/internal/pm/SystemFeaturesMetadata;->*
Lcom/android/internal/pm/SystemFeaturesMetadata;

# These methods were previously direct `native` JNI calls, but were made into
# Java wrappers with a recent change. Ensure they're compiled to avoid
# regressions on any hot paths.
# TOOD(b/417492941): Remove after inclusion in generated boot-image-profile.txt.
HSPLandroid/os/Process;->setThreadPriority(II)V
HSPLandroid/os/Process;->setThreadPriority(I)V
+5 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.webkit.WebViewZygote;
import com.android.sdksandbox.flags.Flags;

import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import dalvik.system.VMDebug;
import dalvik.system.VMRuntime;

@@ -1127,6 +1128,7 @@ public class Process {
        }
    }

    @FastNative
    private static native void setThreadPriorityNative(int tid,
            @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority)
            throws IllegalArgumentException, SecurityException;
@@ -1141,9 +1143,11 @@ public class Process {
     * @hide
     */
    @RavenwoodRedirect
    @FastNative
    public static final native void setCanSelfBackground(boolean backgroundOk);

    @RavenwoodRedirect
    @CriticalNative
    private static native boolean getCanSelfBackground();

    /**
@@ -1339,6 +1343,7 @@ public class Process {
     */
    @RavenwoodRedirect
    @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST)
    @FastNative
    public static final native int getThreadPriority(int tid)
            throws IllegalArgumentException;

+7 −3
Original line number Diff line number Diff line
@@ -551,7 +551,7 @@ static void android_os_Process_setCanSelfBackground(JNIEnv* env, jobject clazz,
#endif
}

static jboolean android_os_Process_getCanSelfBackground(JNIEnv* env, jclass clazz) {
static jboolean android_os_Process_getCanSelfBackground(CRITICAL_JNI_PARAMS) {
#if GUARD_THREAD_PRIORITY
    void* bgOk = pthread_getspecific(gBgKey);
    if (bgOk == ((void*)0xbaad)) {
@@ -1408,11 +1408,15 @@ void android_os_Process_freezeCgroupUID(JNIEnv* env, jobject clazz, jint uid, jb
static const JNINativeMethod methods[] = {
        {"getUidForName", "(Ljava/lang/String;)I", (void*)android_os_Process_getUidForName},
        {"getGidForName", "(Ljava/lang/String;)I", (void*)android_os_Process_getGidForName},
        {"setThreadPriorityNative", "(II)V", (void*)android_os_Process_setThreadPriorityNative},
        {"setThreadScheduler", "(III)V", (void*)android_os_Process_setThreadScheduler},
        // @FastNative
        {"setThreadPriorityNative", "(II)V", (void*)android_os_Process_setThreadPriorityNative},
        // @FastNative
        {"getThreadPriority", "(I)I", (void*)android_os_Process_getThreadPriority},
        // @FastNative
        {"setCanSelfBackground", "(Z)V", (void*)android_os_Process_setCanSelfBackground},
        // @CriticalNative
        {"getCanSelfBackground", "()Z", (void*)android_os_Process_getCanSelfBackground},
        {"getThreadPriority", "(I)I", (void*)android_os_Process_getThreadPriority},
        {"getThreadScheduler", "(I)I", (void*)android_os_Process_getThreadScheduler},
        {"setThreadGroup", "(II)V", (void*)android_os_Process_setThreadGroup},
        {"setThreadGroupAndCpuset", "(II)V", (void*)android_os_Process_setThreadGroupAndCpuset},