From a05e22948de8285f0157e318e9d06e562f4a9440 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 15 Oct 2014 18:02:56 -0700 Subject: Fix ReferenceQueueDaemon.enqueue to start at element 1 of the list Previously we started at element 2 and had that element 1 was the last one finalized. This caused System.runFinalzition to occasionally finish before all of the objects were finalized. Bug: 17932313 Change-Id: I410dc1ef97ecd30c35f0fc0c3fdfbcc9caa585dd --- libart/src/main/java/java/lang/Daemons.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/libart/src/main/java/java/lang/Daemons.java b/libart/src/main/java/java/lang/Daemons.java index 71a8d86..a414c49 100644 --- a/libart/src/main/java/java/lang/Daemons.java +++ b/libart/src/main/java/java/lang/Daemons.java @@ -143,20 +143,14 @@ public final class Daemons { } private void enqueue(Reference list) { - while (list != null) { - Reference reference; - // pendingNext is owned by the GC so no synchronization is required - if (list == list.pendingNext) { - reference = list; - reference.pendingNext = null; - list = null; - } else { - reference = list.pendingNext; - list.pendingNext = reference.pendingNext; - reference.pendingNext = null; - } - reference.enqueueInternal(); - } + Reference start = list; + do { + // pendingNext is owned by the GC so no synchronization is required. + Reference next = list.pendingNext; + list.pendingNext = null; + list.enqueueInternal(); + list = next; + } while (list != start); } } -- cgit v1.1