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

Commit 7232f492 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add JNI method to skip epoll_wait if possible" into main

parents 773228d4 49594067
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -120,6 +120,12 @@ public final class MessageQueue {
    private static boolean sUseConcurrentInitialized = false;
    private static boolean sUseConcurrent;

    /**
     * Determine if the native looper will skip epoll_wait syscalls if nativePollOnce is called with
     * a timeout of 0, which indicates that there are already pending messages.
     */
    private static boolean sSkipEpollWaitForZeroTimeoutInitialized = false;

    /**
     * Caches process-level checks that determine `sUseConcurrent`.
     * This is to avoid redoing checks that shouldn't change during the process's lifetime.
@@ -141,6 +147,8 @@ public final class MessageQueue {
    @RavenwoodRedirect
    private native static void nativeSetFileDescriptorEvents(long ptr, int fd, int events);

    private native static void nativeSetSkipEpollWaitForZeroTimeout(long ptr);

    MessageQueue(boolean quitAllowed) {
        getUseConcurrent();
        mQuitAllowed = quitAllowed;
@@ -148,6 +156,7 @@ public final class MessageQueue {
        mLooperThread = Thread.currentThread();
        mThreadName = mLooperThread.getName();
        mTid = Process.myTid();
        setSkipEpollWaitForZeroTimeout(mPtr);
    }

    static boolean getUseConcurrent() {
@@ -210,6 +219,16 @@ public final class MessageQueue {
        return false;
    }

    static void setSkipEpollWaitForZeroTimeout(long ptr) {
        if (sSkipEpollWaitForZeroTimeoutInitialized) {
            return;
        }
        if (Flags.nativeLooperSkipEpollWaitForZeroTimeout()) {
            nativeSetSkipEpollWaitForZeroTimeout(ptr);
        }
        sSkipEpollWaitForZeroTimeoutInitialized = true;
    }

    @Override
    protected void finalize() throws Throwable {
        try {
+7 −0
Original line number Diff line number Diff line
@@ -431,6 +431,13 @@ flag {
     bug: "330345513"
}

flag {
    namespace: "system_performance"
    name: "native_looper_skip_epoll_wait_for_zero_timeout"
    description: "Skips epoll_wait if pollOnce is called with a timeout of 0."
    bug: "410218466"
}

flag {
     namespace: "system_performance"
     name: "parcel_marshall_bytebuffer"
+16 −8
Original line number Diff line number Diff line
@@ -242,6 +242,12 @@ static void android_os_MessageQueue_nativeSetFileDescriptorEvents(JNIEnv* env, j
    nativeMessageQueue->setFileDescriptorEvents(fd, events);
}

static void android_os_MessageQueue_nativeSetSkipEpollWaitForZeroTimeout(JNIEnv* env, jclass clazz,
                                                                         jlong ptr) {
    NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
    nativeMessageQueue->getLooper()->setSkipEpollWaitForZeroTimeout();
}

// ----------------------------------------------------------------------------

static const JNINativeMethod gMessageQueueMethods[] = {
@@ -253,6 +259,8 @@ static const JNINativeMethod gMessageQueueMethods[] = {
        {"nativeIsPolling", "(J)Z", (void*)android_os_MessageQueue_nativeIsPolling},
        {"nativeSetFileDescriptorEvents", "(JII)V",
         (void*)android_os_MessageQueue_nativeSetFileDescriptorEvents},
        {"nativeSetSkipEpollWaitForZeroTimeout", "(J)V",
         (void*)android_os_MessageQueue_nativeSetSkipEpollWaitForZeroTimeout},
};

int register_android_os_MessageQueue(JNIEnv* env) {