aboutsummaryrefslogtreecommitdiff
path: root/android/guava/src/com/google/common/base/internal/Finalizer.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava/src/com/google/common/base/internal/Finalizer.java')
-rw-r--r--android/guava/src/com/google/common/base/internal/Finalizer.java65
1 files changed, 43 insertions, 22 deletions
diff --git a/android/guava/src/com/google/common/base/internal/Finalizer.java b/android/guava/src/com/google/common/base/internal/Finalizer.java
index b45ec1578..e8ddf320c 100644
--- a/android/guava/src/com/google/common/base/internal/Finalizer.java
+++ b/android/guava/src/com/google/common/base/internal/Finalizer.java
@@ -153,41 +153,62 @@ public class Finalizer implements Runnable {
}
/**
- * Cleans up a single reference. Catches and logs all throwables.
+ * Cleans up the given reference and any other references already in the queue. Catches and logs
+ * all throwables.
*
- * @return true if the caller should continue, false if the associated FinalizableReferenceQueue
- * is no longer referenced.
+ * @return true if the caller should continue to wait for more references to be added to the
+ * queue, false if the associated FinalizableReferenceQueue is no longer referenced.
*/
- private boolean cleanUp(Reference<?> reference) {
+ private boolean cleanUp(Reference<?> firstReference) {
Method finalizeReferentMethod = getFinalizeReferentMethod();
if (finalizeReferentMethod == null) {
return false;
}
- do {
- /*
- * This is for the benefit of phantom references. Weak and soft references will have already
- * been cleared by this point.
- */
- reference.clear();
- if (reference == frqReference) {
- /*
- * The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
- */
+ if (!finalizeReference(firstReference, finalizeReferentMethod)) {
+ return false;
+ }
+
+ /*
+ * Loop as long as we have references available so as not to waste CPU looking up the Method
+ * over and over again.
+ */
+ while (true) {
+ Reference<?> furtherReference = queue.poll();
+ if (furtherReference == null) {
+ return true;
+ }
+ if (!finalizeReference(furtherReference, finalizeReferentMethod)) {
return false;
}
+ }
+ }
- try {
- finalizeReferentMethod.invoke(reference);
- } catch (Throwable t) {
- logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
- }
+ /**
+ * Cleans up the given reference. Catches and logs all throwables.
+ *
+ * @return true if the caller should continue to clean up references from the queue, false if the
+ * associated FinalizableReferenceQueue is no longer referenced.
+ */
+ private boolean finalizeReference(Reference<?> reference, Method finalizeReferentMethod) {
+ /*
+ * This is for the benefit of phantom references. Weak and soft references will have already
+ * been cleared by this point.
+ */
+ reference.clear();
+ if (reference == frqReference) {
/*
- * Loop as long as we have references available so as not to waste CPU looking up the Method
- * over and over again.
+ * The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
*/
- } while ((reference = queue.poll()) != null);
+ return false;
+ }
+
+ try {
+ finalizeReferentMethod.invoke(reference);
+ } catch (Throwable t) {
+ logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
+ }
return true;
}