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

Commit 1f90b78c authored by Steven Moreland's avatar Steven Moreland
Browse files

Assert Parcel not in pool when used (partial reland^2)

This reverts commit 98636f80.

Use in a single function now that should not be inlined
so much, as adding to writeInt caused too much
frameworks.jar increase.

This costs only 0.026% of frameworks.jar
(8979000 -> 8981400)

Test: boot
Bug: 381155347
Change-Id: I84c9079090ec89a269be177d8679ed326776ab38
parent 1e002dc4
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.internal.util.ArrayUtils;

import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import dalvik.annotation.optimization.NeverInline;

import java.nio.BufferOverflowException;
import java.nio.ReadOnlyBufferException;
@@ -641,6 +642,21 @@ public final class Parcel {
        }
    }

    @NeverInline
    private void errorUsedWhileRecycling() {
        String error = "Parcel used while recycled. "
                + Log.getStackTraceString(new Throwable())
                + " Original recycle call (if DEBUG_RECYCLE): ", mStack;
        Log.wtf(TAG, error);
        // TODO(b/381155347): harder error
    }

    // TODO: call in more places, it costs a _lot_ to use this in many
    // places, see b/390748425 for instance. Used as canary for now.
    private void assertNotRecycled() {
        if (mRecycled) errorUsedWhileRecycling();
    }

    /**
     * Set a {@link ReadWriteHelper}, which can be used to avoid having duplicate strings, for
     * example.
@@ -5203,6 +5219,7 @@ public final class Parcel {
    @SuppressWarnings("unchecked")
    @Nullable
    private <T> T readParcelableInternal(@Nullable ClassLoader loader, @Nullable Class<T> clazz) {
        assertNotRecycled();
        Parcelable.Creator<?> creator = readParcelableCreatorInternal(loader, clazz);
        if (creator == null) {
            return null;