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

Commit 06b30aa5 authored by Jared Duke's avatar Jared Duke
Browse files

Update @CriticalNative usage for framework methods

Annotate a number of framework JNI methods as @CriticalNative.
Methods have been manually audited to not throw or perform significant
IO or other blocking operations.

Bug: 374158990
Test: Presubmit
Flag: EXEMPT JNI annotations not easily flagged, risk is relatively low
Change-Id: I9270f90cca024b2fa2689b7a41cab60d016ee9d6
parent 13d3234e
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.ravenwood.annotation.RavenwoodRedirect;
import android.ravenwood.annotation.RavenwoodRedirectionClass;
import android.ravenwood.annotation.RavenwoodThrow;

import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import dalvik.system.CloseGuard;

@@ -94,24 +95,24 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {

    // Below native methods don't do unconstrained work, so are FastNative for performance

    @FastNative
    @CriticalNative
    @RavenwoodThrow
    private static native void nativeClear(long windowPtr);

    @FastNative
    @CriticalNative
    @RavenwoodRedirect
    private static native int nativeGetNumRows(long windowPtr);
    @FastNative
    @CriticalNative
    @RavenwoodRedirect
    private static native boolean nativeSetNumColumns(long windowPtr, int columnNum);
    @FastNative
    @RavenwoodRedirect
    private static native boolean nativeAllocRow(long windowPtr);
    @FastNative
    @CriticalNative
    @RavenwoodThrow
    private static native void nativeFreeLastRow(long windowPtr);

    @FastNative
    @CriticalNative
    @RavenwoodRedirect
    private static native int nativeGetType(long windowPtr, int row, int column);
    @FastNative
@@ -121,13 +122,13 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
    @RavenwoodRedirect
    private static native double nativeGetDouble(long windowPtr, int row, int column);

    @FastNative
    @CriticalNative
    @RavenwoodRedirect
    private static native boolean nativePutLong(long windowPtr, long value, int row, int column);
    @FastNative
    @CriticalNative
    @RavenwoodRedirect
    private static native boolean nativePutDouble(long windowPtr, double value, int row, int column);
    @FastNative
    @CriticalNative
    @RavenwoodThrow
    private static native boolean nativePutNull(long windowPtr, int row, int column);

+1 −0
Original line number Diff line number Diff line
@@ -1365,6 +1365,7 @@ public class Binder implements IBinder {
        }
    }

    @CriticalNative
    private static native long getNativeBBinderHolder();

    /**
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public final class Trace {
    private static native void nativeTraceCounter(long tag, String name, long value);
    @FastNative
    private static native void nativeTraceBegin(long tag, String name);
    @FastNative
    @CriticalNative
    private static native void nativeTraceEnd(long tag);
    @FastNative
    private static native void nativeAsyncTraceBegin(long tag, String name, int cookie);
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.proto.ProtoInputStream;

import dalvik.annotation.optimization.CriticalNative;

/**
 * Templated base class meant to be derived by embedders to create a custom data
 * source.
@@ -194,9 +196,13 @@ public abstract class DataSource<DataSourceInstanceType extends DataSourceInstan
    private static native void nativeStopDonePerfettoInstanceLocked(
            long dataSourcePtr, int dsInstanceIdx);

    @CriticalNative
    private static native boolean nativePerfettoDsTraceIterateBegin(long dataSourcePtr);
    @CriticalNative
    private static native boolean nativePerfettoDsTraceIterateNext(long dataSourcePtr);
    @CriticalNative
    private static native void nativePerfettoDsTraceIterateBreak(long dataSourcePtr);
    @CriticalNative
    private static native int nativeGetPerfettoDsInstanceIndex(long dataSourcePtr);

    private static native void nativeWritePackets(long dataSourcePtr, byte[][] packetData);
+21 −22
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jlong windowPtr,
    }
}

static void nativeClear(JNIEnv * env, jclass clazz, jlong windowPtr) {
static void nativeClear(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    LOG_WINDOW("Clearing window %p", window);
    status_t status = window->clear();
@@ -164,13 +164,12 @@ static void nativeClear(JNIEnv * env, jclass clazz, jlong windowPtr) {
    }
}

static jint nativeGetNumRows(JNIEnv* env, jclass clazz, jlong windowPtr) {
static jint nativeGetNumRows(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    return window->getNumRows();
}

static jboolean nativeSetNumColumns(JNIEnv* env, jclass clazz, jlong windowPtr,
        jint columnNum) {
static jboolean nativeSetNumColumns(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr, jint columnNum) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    status_t status = window->setNumColumns(columnNum);
    return status == OK;
@@ -182,13 +181,12 @@ static jboolean nativeAllocRow(JNIEnv* env, jclass clazz, jlong windowPtr) {
    return status == OK;
}

static void nativeFreeLastRow(JNIEnv* env, jclass clazz, jlong windowPtr) {
static void nativeFreeLastRow(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    window->freeLastRow();
}

static jint nativeGetType(JNIEnv* env, jclass clazz, jlong windowPtr,
        jint row, jint column) {
static jint nativeGetType(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr, jint row, jint column) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    LOG_WINDOW("returning column type affinity for %d,%d from %p", row, column, window);

@@ -478,8 +476,8 @@ static jboolean nativePutString(JNIEnv* env, jclass clazz, jlong windowPtr,
    return true;
}

static jboolean nativePutLong(JNIEnv* env, jclass clazz, jlong windowPtr,
        jlong value, jint row, jint column) {
static jboolean nativePutLong(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr, jlong value, jint row,
                              jint column) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    status_t status = window->putLong(row, column, value);

@@ -492,8 +490,8 @@ static jboolean nativePutLong(JNIEnv* env, jclass clazz, jlong windowPtr,
    return true;
}

static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jlong windowPtr,
        jdouble value, jint row, jint column) {
static jboolean nativePutDouble(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr, jdouble value, jint row,
                                jint column) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    status_t status = window->putDouble(row, column, value);

@@ -506,8 +504,7 @@ static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jlong windowPtr,
    return true;
}

static jboolean nativePutNull(JNIEnv* env, jclass clazz, jlong windowPtr,
        jint row, jint column) {
static jboolean nativePutNull(CRITICAL_JNI_PARAMS_COMMA jlong windowPtr, jint row, jint column) {
    CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
    status_t status = window->putNull(row, column);

@@ -546,23 +543,25 @@ static const JNINativeMethod sMethods[] =
            (void*)nativePutString },

    // ------- @FastNative below here ----------------------
    { "nativeAllocRow", "(J)Z",
            (void*)nativeAllocRow },
    { "nativeGetLong", "(JII)J",
            (void*)nativeGetLong },
    { "nativeGetDouble", "(JII)D",
            (void*)nativeGetDouble },


    // ------- @CriticalNative below here ------------------
    { "nativeClear", "(J)V",
            (void*)nativeClear },
    { "nativeGetNumRows", "(J)I",
            (void*)nativeGetNumRows },
    { "nativeSetNumColumns", "(JI)Z",
            (void*)nativeSetNumColumns },
    { "nativeAllocRow", "(J)Z",
            (void*)nativeAllocRow },
    { "nativeFreeLastRow", "(J)V",
            (void*)nativeFreeLastRow },
    { "nativeGetType", "(JII)I",
            (void*)nativeGetType },
    { "nativeGetLong", "(JII)J",
            (void*)nativeGetLong },
    { "nativeGetDouble", "(JII)D",
            (void*)nativeGetDouble },

    { "nativeSetNumColumns", "(JI)Z",
            (void*)nativeSetNumColumns },
    { "nativePutLong", "(JJII)Z",
            (void*)nativePutLong },
    { "nativePutDouble", "(JDII)Z",
Loading