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

Commit 979f61ae authored by Shai Barack's avatar Shai Barack
Browse files

Remove JniStringCache

Unfortunately the overhead from JNI functions was found to be unaffordable high.
The root causes are unfixable.
See investigation in b/443641982.

I may revisit this problem with a Java-side cache, such as by resuming work on ag/35275812.

Bug: 443641982
Bug: 442140362
Flag: android.os.parcel_string_cache_enabled
Change-Id: Ie77174731976c4adf2754134596df8a8f567a19e
parent 63f40c42
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -246,7 +246,6 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.os.BinderCallsStats;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.DebugStore;
import com.android.internal.os.JniStringCache;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.SafeZipPathValidatorCallback;
import com.android.internal.os.SomeArgs;
@@ -1954,7 +1953,6 @@ public final class ActivityThread extends ClientTransactionHandler
            }

            pw.println(" ");
            JniStringCache.dump(pw);
        }

        @NeverCompile
@@ -7693,10 +7691,6 @@ public final class ActivityThread extends ClientTransactionHandler
        }
        if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level);

        if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
            JniStringCache.clear();
        }

        try {
            if (skipBgMemTrimOnFgApp()
                    && mLastProcessState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
+0 −67
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.os;

import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.NeverCompile;
import java.io.PrintWriter;

/** Java companion to native JNIStringCache class. */
public final class JniStringCache {

    /** Dumps cache statistics to the given writer. */
    @NeverCompile
    public static void dump(PrintWriter pw) {
        if (!android.os.Flags.parcelStringCacheEnabled()) {
            return;
        }

        pw.println("JniStringCache");
        pw.format(
                "                Hits: %,10d    Misses: %,10d\n",
                nativeHits(), nativeMisses());
        pw.format(
                "           Evictions: %,10d     Skips: %,10d\n",
                nativeEvictions(), nativeSkips());
        pw.flush();
        pw.println(" ");
    }

    /** Clears the cache. */
    public static void clear() {
        if (!android.os.Flags.parcelStringCacheEnabled()) {
            return;
        }

        nativeClear();
    }

    @CriticalNative
    private static native long nativeHits();

    @CriticalNative
    private static native long nativeMisses();

    @CriticalNative
    private static native long nativeEvictions();

    @CriticalNative
    private static native long nativeSkips();

    @CriticalNative
    private static native void nativeClear();
}
+0 −3
Original line number Diff line number Diff line
@@ -22,6 +22,3 @@ per-file *ApplicationSharedMemory* = file:/PERFORMANCE_OWNERS

# Memcg memory accounting
per-file MemcgProcMemoryUtil.java = file:/PERFORMANCE_OWNERS

# JniStringCache
per-file *JniStringCache* = file:/PERFORMANCE_OWNERS
+0 −1
Original line number Diff line number Diff line
@@ -258,7 +258,6 @@ cc_defaults_for_libandroid_runtime {
                "com_android_internal_os_ClassLoaderFactory.cpp",
                "com_android_internal_os_DebugStore.cpp",
                "com_android_internal_os_FuseAppLoop.cpp",
                "com_android_internal_os_JniStringCache.cpp",
                "com_android_internal_os_KernelAllocationStats.cpp",
                "com_android_internal_os_KernelCpuBpfTracking.cpp",
                "com_android_internal_os_KernelCpuTotalBpfMapReader.cpp",
+0 −7
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@
#include <dlfcn.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JniInvocation.h>
#include "com_android_internal_os_JniStringCache.h"
#include <server_configurable_flags/get_flags.h>
#include <signal.h>
#include <stdio.h>
@@ -110,10 +109,6 @@ extern int register_android_media_ToneGenerator(JNIEnv *env);
extern int register_android_media_audio_common_AidlConversion(JNIEnv* env);
extern int register_android_media_midi(JNIEnv *env);

extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
    JniStringCache::Unload(vm);
}

namespace android {

/*
@@ -222,7 +217,6 @@ extern int register_com_android_internal_os_ApplicationSharedMemory(JNIEnv *env)
extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
extern int register_com_android_internal_os_DebugStore(JNIEnv* env);
extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
extern int register_com_android_internal_os_JniStringCache(JNIEnv* env);
extern int register_com_android_internal_os_KernelAllocationStats(JNIEnv* env);
extern int register_com_android_internal_os_KernelCpuBpfTracking(JNIEnv* env);
extern int register_com_android_internal_os_KernelCpuTotalBpfMapReader(JNIEnv* env);
@@ -1725,7 +1719,6 @@ static const RegJNIRec gRegJNI[] = {
        REG_JNI(register_com_android_internal_content_F2fsUtils),
        REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
        REG_JNI(register_com_android_internal_os_FuseAppLoop),
        REG_JNI(register_com_android_internal_os_JniStringCache),
        REG_JNI(register_com_android_internal_os_KernelAllocationStats),
        REG_JNI(register_com_android_internal_os_KernelCpuBpfTracking),
        REG_JNI(register_com_android_internal_os_KernelCpuTotalBpfMapReader),
Loading