|
65 | 65 | @GwtCompatible |
66 | 66 | /* |
67 | 67 | * TODO(cpovirk): Do we still need @ReflectionSupport on *this* class now that the fields live in |
68 | | - * the superclass? Note that Listener (which we also reflect on) still leaves here. |
| 68 | + * the superclass? Note that Listener (which we also reflect on) still lives here. |
69 | 69 | */ |
70 | 70 | @ReflectionSupport(value = ReflectionSupport.Level.FULL) |
71 | 71 | public abstract class AbstractFuture<V extends @Nullable Object> extends AbstractFutureState<V> { |
@@ -126,7 +126,7 @@ public final boolean cancel(boolean mayInterruptIfRunning) { |
126 | 126 | } |
127 | 127 | } |
128 | 128 |
|
129 | | - /** Listeners also form a stack through the {@link #listeners} field. */ |
| 129 | + /** Listeners form a Treiber stack through the {@link #listeners} field. */ |
130 | 130 | static final class Listener { |
131 | 131 | static final Listener TOMBSTONE = new Listener(); |
132 | 132 | // null only for TOMBSTONE |
@@ -362,21 +362,21 @@ mayInterruptIfRunning, new CancellationException("Future.cancel() was called.")) |
362 | 362 | // care if we are successful or not. |
363 | 363 | ListenableFuture<?> futureToPropagateTo = ((DelegatingToFuture) localValue).future; |
364 | 364 | if (futureToPropagateTo instanceof Trusted) { |
365 | | - // If the future is a TrustedFuture then we specifically avoid calling cancel() |
| 365 | + // If the future is a Trusted instance then we specifically avoid calling cancel() |
366 | 366 | // this has 2 benefits |
367 | 367 | // 1. for long chains of futures strung together with setFuture we consume less stack |
368 | 368 | // 2. we avoid allocating Cancellation objects at every level of the cancellation |
369 | 369 | // chain |
370 | | - // We can only do this for TrustedFuture, because TrustedFuture.cancel is final and |
371 | | - // does nothing but delegate to this method. |
| 370 | + // We can only do this for Trusted, because Trusted implementations of cancel do |
| 371 | + // nothing but delegate to this method and do not permit user overrides. |
372 | 372 | AbstractFuture<?> trusted = (AbstractFuture<?>) futureToPropagateTo; |
373 | 373 | localValue = trusted.value(); |
374 | 374 | if (localValue == null | localValue instanceof DelegatingToFuture) { |
375 | 375 | abstractFuture = trusted; |
376 | 376 | continue; // loop back up and try to complete the new future |
377 | 377 | } |
378 | 378 | } else { |
379 | | - // not a TrustedFuture, call cancel directly. |
| 379 | + // not a Trusted instance, call cancel directly. |
380 | 380 | futureToPropagateTo.cancel(mayInterruptIfRunning); |
381 | 381 | } |
382 | 382 | } |
@@ -597,10 +597,10 @@ protected boolean setFuture(ListenableFuture<? extends V> future) { |
597 | 597 | */ |
598 | 598 | private static Object getFutureValue(ListenableFuture<?> future) { |
599 | 599 | if (future instanceof Trusted) { |
600 | | - // Break encapsulation for TrustedFuture instances since we know that subclasses cannot |
601 | | - // override .get() (since it is final) and therefore this is equivalent to calling .get() |
602 | | - // and unpacking the exceptions like we do below (just much faster because it is a single |
603 | | - // field read instead of a read, several branches and possibly creating exceptions). |
| 600 | + // Break encapsulation for Trusted instances since we know that subclasses cannot override |
| 601 | + // .get() and therefore this is equivalent to calling .get() and unpacking the exceptions like |
| 602 | + // we do below (just much faster because it is a single field read instead of a read, several |
| 603 | + // branches and possibly creating exceptions). |
604 | 604 | Object v = ((AbstractFuture<?>) future).value(); |
605 | 605 | if (v instanceof Cancellation) { |
606 | 606 | // If the other future was interrupted, clear the interrupted bit while preserving the cause |
|
0 commit comments