Loading core/java/android/os/CombinedMessageQueue/MessageQueue.java +19 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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; Loading @@ -148,6 +156,7 @@ public final class MessageQueue { mLooperThread = Thread.currentThread(); mThreadName = mLooperThread.getName(); mTid = Process.myTid(); setSkipEpollWaitForZeroTimeout(mPtr); } static boolean getUseConcurrent() { Loading Loading @@ -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 { Loading core/java/android/os/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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" Loading core/jni/android_os_MessageQueue.cpp +16 −8 Original line number Diff line number Diff line Loading @@ -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[] = { Loading @@ -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) { Loading Loading
core/java/android/os/CombinedMessageQueue/MessageQueue.java +19 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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; Loading @@ -148,6 +156,7 @@ public final class MessageQueue { mLooperThread = Thread.currentThread(); mThreadName = mLooperThread.getName(); mTid = Process.myTid(); setSkipEpollWaitForZeroTimeout(mPtr); } static boolean getUseConcurrent() { Loading Loading @@ -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 { Loading
core/java/android/os/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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" Loading
core/jni/android_os_MessageQueue.cpp +16 −8 Original line number Diff line number Diff line Loading @@ -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[] = { Loading @@ -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) { Loading