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

Commit fb84ce0d authored by Brian Carlstrom's avatar Brian Carlstrom Committed by Android (Google) Code Review
Browse files

Merge "Don't use local ref for cached jclass reference in JNI code"

parents 95527665 46e18c11
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -137,7 +137,6 @@ static JNINativeMethod gMethods[] = {

#define RETURN_ERR_IF_NULL(value)   do { if (!(value)) { assert(0); return -1; } } while (false)

int register_android_graphics_Movie(JNIEnv* env);
int register_android_graphics_Movie(JNIEnv* env)
{
    gMovie_class = env->FindClass(kClassPathName);
+5 −8
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ static const char* const kClassPathName = "android/media/AudioRecord";

struct fields_t {
    // these fields provide access from C++ to the...
    jclass    audioRecordClass;      //... AudioRecord class
    jmethodID postNativeEventInJava; //... event post callback method
    int       PCM16;                 //...  format constants
    int       PCM8;                  //...  format constants
@@ -520,22 +519,20 @@ extern bool android_media_getIntConstantFromClass(JNIEnv* pEnv,
// ----------------------------------------------------------------------------
int register_android_media_AudioRecord(JNIEnv *env)
{
    javaAudioRecordFields.audioRecordClass = NULL;
    javaAudioRecordFields.postNativeEventInJava = NULL;
    javaAudioRecordFields.nativeRecorderInJavaObj = NULL;
    javaAudioRecordFields.nativeCallbackCookie = NULL;
    

    // Get the AudioRecord class
    javaAudioRecordFields.audioRecordClass = env->FindClass(kClassPathName);
    if (javaAudioRecordFields.audioRecordClass == NULL) {
    jclass audioRecordClass = env->FindClass(kClassPathName);
    if (audioRecordClass == NULL) {
        LOGE("Can't find %s", kClassPathName);
        return -1;
    }
    
    // Get the postEvent method
    javaAudioRecordFields.postNativeEventInJava = env->GetStaticMethodID(
            javaAudioRecordFields.audioRecordClass,
            audioRecordClass,
            JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
    if (javaAudioRecordFields.postNativeEventInJava == NULL) {
        LOGE("Can't find AudioRecord.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -545,7 +542,7 @@ int register_android_media_AudioRecord(JNIEnv *env)
    // Get the variables
    //    mNativeRecorderInJavaObj
    javaAudioRecordFields.nativeRecorderInJavaObj = 
        env->GetFieldID(javaAudioRecordFields.audioRecordClass,
        env->GetFieldID(audioRecordClass,
                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
    if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
        LOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
@@ -553,7 +550,7 @@ int register_android_media_AudioRecord(JNIEnv *env)
    }
    //     mNativeCallbackCookie
    javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
            javaAudioRecordFields.audioRecordClass,
            audioRecordClass,
            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
    if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
        LOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
+7 −9
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ static const char* const kClassPathName = "android/media/AudioTrack";

struct fields_t {
    // these fields provide access from C++ to the...
    jclass    audioTrackClass;       //... AudioTrack class
    jmethodID postNativeEventInJava; //... event post callback method
    int       PCM16;                 //...  format constants
    int       PCM8;                  //...  format constants
@@ -915,20 +914,19 @@ bool android_media_getIntConstantFromClass(JNIEnv* pEnv, jclass theClass, const
// ----------------------------------------------------------------------------
int register_android_media_AudioTrack(JNIEnv *env)
{
    javaAudioTrackFields.audioTrackClass = NULL;
    javaAudioTrackFields.nativeTrackInJavaObj = NULL;
    javaAudioTrackFields.postNativeEventInJava = NULL;

    // Get the AudioTrack class
    javaAudioTrackFields.audioTrackClass = env->FindClass(kClassPathName);
    if (javaAudioTrackFields.audioTrackClass == NULL) {
    jclass audioTrackClass = env->FindClass(kClassPathName);
    if (audioTrackClass == NULL) {
        LOGE("Can't find %s", kClassPathName);
        return -1;
    }

    // Get the postEvent method
    javaAudioTrackFields.postNativeEventInJava = env->GetStaticMethodID(
            javaAudioTrackFields.audioTrackClass,
            audioTrackClass,
            JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
    if (javaAudioTrackFields.postNativeEventInJava == NULL) {
        LOGE("Can't find AudioTrack.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -938,7 +936,7 @@ int register_android_media_AudioTrack(JNIEnv *env)
    // Get the variables fields
    //      nativeTrackInJavaObj
    javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
            javaAudioTrackFields.audioTrackClass,
            audioTrackClass,
            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
    if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
        LOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
@@ -946,7 +944,7 @@ int register_android_media_AudioTrack(JNIEnv *env)
    }
    //      jniData;
    javaAudioTrackFields.jniData = env->GetFieldID(
            javaAudioTrackFields.audioTrackClass,
            audioTrackClass,
            JAVA_JNIDATA_FIELD_NAME, "I");
    if (javaAudioTrackFields.jniData == NULL) {
        LOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
@@ -954,10 +952,10 @@ int register_android_media_AudioTrack(JNIEnv *env)
    }

    // Get the memory mode constants
    if ( !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
    if ( !android_media_getIntConstantFromClass(env, audioTrackClass,
               kClassPathName, 
               JAVA_CONST_MODE_STATIC_NAME, &(javaAudioTrackFields.MODE_STATIC))
         || !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
         || !android_media_getIntConstantFromClass(env, audioTrackClass,
               kClassPathName, 
               JAVA_CONST_MODE_STREAM_NAME, &(javaAudioTrackFields.MODE_STREAM)) ) {
        // error log performed in android_media_getIntConstantFromClass() 
+11 −13
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ namespace android {
 * to look them up every time.
 */
static struct fieldIds {
    jclass dhcpInfoInternalClass;
    jmethodID constructorId;
    jfieldID ipaddress;
    jfieldID gateway;
@@ -163,7 +162,7 @@ static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring if
    result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
                                        dns1, dns2, server, &lease);
    env->ReleaseStringUTFChars(ifname, nameStr);
    if (result == 0 && dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
    if (result == 0) {
        env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr));
        env->SetObjectField(info, dhcpInfoInternalFieldIds.gateway, env->NewStringUTF(gateway));
        env->SetIntField(info, dhcpInfoInternalFieldIds.prefixLength, prefixLength);
@@ -229,17 +228,16 @@ int register_android_net_NetworkUtils(JNIEnv* env)
    jclass netutils = env->FindClass(NETUTILS_PKG_NAME);
    LOG_FATAL_IF(netutils == NULL, "Unable to find class " NETUTILS_PKG_NAME);

    dhcpInfoInternalFieldIds.dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
    if (dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
        dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "<init>", "()V");
        dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
        dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
        dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "prefixLength", "I");
        dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
        dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
        dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
        dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "leaseDuration", "I");
    }
    jclass dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
    LOG_FATAL_IF(dhcpInfoInternalClass == NULL, "Unable to find class android/net/DhcpInfoInternal");
    dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalClass, "<init>", "()V");
    dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
    dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
    dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalClass, "prefixLength", "I");
    dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
    dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
    dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
    dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalClass, "leaseDuration", "I");

    return AndroidRuntime::registerNativeMethods(env,
            NETUTILS_PKG_NAME, gNetworkUtilMethods, NELEM(gNetworkUtilMethods));
+2 −2
Original line number Diff line number Diff line
@@ -736,9 +736,9 @@ const char* const kActivityThreadPathName = "android/app/ActivityThread";

int register_android_app_ActivityThread(JNIEnv* env)
{
    jclass gFileDescriptorClass = env->FindClass("java/io/FileDescriptor");
    jclass fileDescriptorClass = env->FindClass("java/io/FileDescriptor");
    LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
    gFileDescriptorField = env->GetFieldID(gFileDescriptorClass, "descriptor", "I");
    gFileDescriptorField = env->GetFieldID(fileDescriptorClass, "descriptor", "I");
    LOG_FATAL_IF(gFileDescriptorField == NULL,
                 "Unable to find descriptor field in java.io.FileDescriptor");

Loading