Skip to content

Commit a34e705

Browse files
committed
(These changes apply ONLY to our Google-internal Android-specific copy of Guava.)
- Hackily disable use of Unsafe and ClassValue as a temporary measure. - Strip comment reference to @ForOverride, which was impeding import stripping. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=101034385
1 parent 1f2b877 commit a34e705

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

guava/src/com/google/common/util/concurrent/AbstractFuture.java

+39-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.common.annotations.Beta;
2424
import com.google.common.annotations.GwtCompatible;
2525
import com.google.common.base.Throwables;
26-
import com.google.errorprone.annotations.ForOverride;
2726

2827
import java.security.AccessController;
2928
import java.security.PrivilegedActionException;
@@ -110,7 +109,7 @@ abstract static class TrustedFuture<V> extends AbstractFuture<V> {
110109
static {
111110
AtomicHelper helper = null;
112111
try {
113-
helper = new UnsafeAtomicHelper();
112+
helper = UnsafeAtomicHelperFactory.values()[0].tryCreateUnsafeAtomicHelper();
114113
} catch (Throwable e) {
115114
// catch absolutely everything and fall through
116115
}
@@ -764,7 +763,6 @@ private void complete() {
764763
*
765764
* <p>This is called exactly once, after all listeners have executed. By default it does nothing.
766765
*/
767-
// TODO(cpovirk): @ForOverride if https://github.com/google/error-prone/issues/342 permits
768766
void done() {}
769767

770768
/**
@@ -848,12 +846,40 @@ private abstract static class AtomicHelper {
848846
abstract boolean casValue(AbstractFuture future, Object expected, Object v);
849847
}
850848

849+
/**
850+
* Temporary hack to hide the reference to {@link UnsafeAtomicHelper} from Android. The caller of
851+
* this code will execute {@link #tryCreateUnsafeAtomicHelper} on the <b>first</b> enum value
852+
* present. On the server, this will try to create {@link UnsafeAtomicHelper}. On Android, it will
853+
* just return {@code null}.
854+
*/
855+
private enum UnsafeAtomicHelperFactory {
856+
@SuppressUnderAndroid // temporarily while we make Proguard tolerate Unsafe
857+
REALLY_TRY_TO_CREATE {
858+
@Override
859+
AtomicHelper tryCreateUnsafeAtomicHelper() {
860+
return new UnsafeAtomicHelper();
861+
}
862+
},
863+
864+
DONT_EVEN_TRY_TO_CREATE {
865+
@Override
866+
AtomicHelper tryCreateUnsafeAtomicHelper() {
867+
return null;
868+
}
869+
},
870+
871+
;
872+
873+
abstract AtomicHelper tryCreateUnsafeAtomicHelper();
874+
}
875+
851876
/**
852877
* {@link AtomicHelper} based on {@link sun.misc.Unsafe}.
853878
*
854879
* <p>Static initialization of this class will fail if the {@link sun.misc.Unsafe} object cannot
855880
* be accessed.
856881
*/
882+
@SuppressUnderAndroid // temporarily while we make Proguard tolerate Unsafe
857883
private static final class UnsafeAtomicHelper extends AtomicHelper {
858884
static final sun.misc.Unsafe UNSAFE;
859885
static final long LISTENERS_OFFSET;
@@ -899,26 +925,31 @@ private static final class UnsafeAtomicHelper extends AtomicHelper {
899925
}
900926
}
901927

902-
@Override void putThread(Waiter waiter, Thread thread) {
928+
@Override
929+
void putThread(Waiter waiter, Thread thread) {
903930
UNSAFE.putObject(waiter, WAITER_THREAD_OFFSET, thread);
904931
}
905932

906-
@Override void putNext(Waiter waiter, Waiter next) {
933+
@Override
934+
void putNext(Waiter waiter, Waiter next) {
907935
UNSAFE.putObject(waiter, WAITER_NEXT_OFFSET, next);
908936
}
909937

910938
/** Performs a CAS operation on the {@link #waiters} field. */
911-
@Override boolean casWaiters(AbstractFuture future, Waiter curr, Waiter next) {
939+
@Override
940+
boolean casWaiters(AbstractFuture future, Waiter curr, Waiter next) {
912941
return UNSAFE.compareAndSwapObject(future, WAITERS_OFFSET, curr, next);
913942
}
914943

915944
/** Performs a CAS operation on the {@link #listeners} field. */
916-
@Override boolean casListeners(AbstractFuture future, Listener curr, Listener next) {
945+
@Override
946+
boolean casListeners(AbstractFuture future, Listener curr, Listener next) {
917947
return UNSAFE.compareAndSwapObject(future, LISTENERS_OFFSET, curr, next);
918948
}
919949

920950
/** Performs a CAS operation on the {@link #value} field. */
921-
@Override boolean casValue(AbstractFuture future, Object expected, Object v) {
951+
@Override
952+
boolean casValue(AbstractFuture future, Object expected, Object v) {
922953
return UNSAFE.compareAndSwapObject(future, VALUE_OFFSET, expected, v);
923954
}
924955
}

guava/src/com/google/common/util/concurrent/FuturesGetChecked.java

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static GetCheckedTypeValidator weakSetValidator() {
100100
}
101101

102102
@J2ObjCIncompatible // ClassValue
103+
@SuppressUnderAndroid // ClassValue
103104
@VisibleForTesting
104105
static GetCheckedTypeValidator classValueValidator() {
105106
return GetCheckedTypeValidatorHolder.ClassValueValidator.INSTANCE;
@@ -120,6 +121,7 @@ static class GetCheckedTypeValidatorHolder {
120121

121122
@IgnoreJRERequirement // getChecked falls back to another implementation if necessary
122123
@J2ObjCIncompatible // ClassValue
124+
@SuppressUnderAndroid // ClassValue
123125
enum ClassValueValidator implements GetCheckedTypeValidator {
124126
INSTANCE;
125127

guava-tests/test/com/google/common/util/concurrent/SuppressUnderAndroid.java guava/src/com/google/common/util/concurrent/SuppressUnderAndroid.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
import java.lang.annotation.Target;
3030

3131
/**
32-
* Signifies that a test should not be run under Android. This annotation is respected only by our
33-
* Google-internal Android suite generators. Note that those generators also suppress any test
34-
* annotated with MediumTest or LargeTest.
32+
* Signifies that a member should be stripped from the internal Android flavor of Guava. This
33+
* annotation is respected only by our Google-internal build system. Note that that system also
34+
* strips any test annotated with MediumTest or LargeTest.
35+
*
36+
* TODO(cpovirk): Replicate this revised description to other copies of the annotation, or better
37+
* yet, eliminate the need to use it in prod code, revert the description, and move it back to the
38+
* test directory.
3539
*
3640
* <p>For more discussion, see {@linkplain com.google.common.base.SuppressUnderAndroid the
3741
* documentation on another copy of this annotation}.

0 commit comments

Comments
 (0)