OSDN Git Service

WTF Logging for catching memory issue in Parcel
authorMichael Wachenschwanz <mwachens@google.com>
Wed, 10 May 2017 18:43:44 +0000 (11:43 -0700)
committerMichael Wachenschwanz <mwachens@google.com>
Wed, 10 May 2017 22:38:30 +0000 (15:38 -0700)
Catch an exception sent from native code looking for a specific known
bug and report via wtf which code path is hitting the bug. Revert this
change once bug has been resolved.

Bug: 37298089
Test: manual

Change-Id: Ieb98a8a82a9a2cffe4d0cfbbc8333f453b3e36d5
Signed-off-by: Michael Wachenschwanz <mwachens@google.com>
core/java/android/os/Parcel.java
core/jni/android_os_Parcel.cpp

index 28bdacf..c5c743b 100644 (file)
@@ -427,7 +427,13 @@ public final class Parcel {
      * @param size The new number of bytes in the Parcel.
      */
     public final void setDataSize(int size) {
-        updateNativeSize(nativeSetDataSize(mNativePtr, size));
+        // STOPSHIP: Try/catch for exception is for temporary debug. Remove once bug resolved
+        try {
+            updateNativeSize(nativeSetDataSize(mNativePtr, size));
+        } catch (IllegalArgumentException iae) {
+            Log.e(TAG,"Caught Exception representing a known bug in Parcel",iae);
+            Log.wtfStack(TAG, "This flow is using SetDataSize incorrectly");
+        }
     }
 
     /**
index d740a76..56f68d4 100644 (file)
@@ -119,7 +119,11 @@ static jlong android_os_Parcel_setDataSize(JNIEnv* env, jclass clazz, jlong nati
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
         const status_t err = parcel->setDataSize(size);
-        if (err != NO_ERROR) {
+        //STOPSHIP: check for BADFLO is for a temporary debug using wtf. Remove once bug resolved.
+        if (err == UNKNOWN_ERROR + 0xBADF10) {
+            jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
+                         "Attempt to resize (size = %d) Parcel would corrupt object memory", size);
+        } else if (err != NO_ERROR) {
             signalExceptionForError(env, clazz, err);
         }
         return parcel->getOpenAshmemSize();