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

Commit bf4b36c6 authored by Kevin Jeon's avatar Kevin Jeon
Browse files

Don't add removed messages to the heap

A message in the stack that is already marked for removal doesn't need
to be added to the heap. Its heap index is -1, so we won't attempt to
remove the not-in-heap message from the heap later.

Test: presubmit (FrameworksCoreTests_messagequeue)
Bug: 444085764
Bug: 444109907
Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
Change-Id: I3f940eda440dd050b58cd117e83a3f5bebc1d1c9
parent fff1d506
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -153,8 +153,11 @@ public final class Message implements Parcelable {
     * The CAS loop shouldn't fail due to FLAG_IN_USE or FLAG_ASYNCHRONOUS being set because those
     * are only changed when a message is initially created and enqueued. However, we loop anyways
     * in case additional flags that can be modified are added in the future.
     *
     * @hide
     */
    boolean markRemoved() {
    @VisibleForTesting
    public boolean markRemoved() {
        int localFlags;
        do {
            localFlags = this.flags;
+3 −3
Original line number Diff line number Diff line
@@ -215,9 +215,9 @@ public final class MessageStack {
            }
            // MessageHeap will maintain its own ordering of Messages, so it doesn't matter that we
            // insert these Messages in a different order than submitted to the stack.
            // TODO: Removed messages shouldn't be added to the heap, and possibly not into the
            // stack either.
            if (!current.isRemoved()) {
                getHeap(current).add(current);
            }
            current = current.next;
        }

+13 −0
Original line number Diff line number Diff line
@@ -50,6 +50,19 @@ public final class MessageStackTest {
        assertEquals(10, stack.sizeForTest());
    }

    /**
     * Check that the stack doesn't sweep already-removed messages.
     */
    @Test
    public void testPushRemovedMessage() {
        MessageStack stack = new MessageStack();
        Message m = new Message();
        m.markRemoved();
        stack.pushMessage(m);
        stack.heapSweep();
        assertEquals(0, stack.combinedHeapSizesForTest());
    }

    /**
     * Verify quitting state
     */