Files
guava/proguard/concurrent.pro
cpovirk 75da92419a Use AtomicReferenceFieldUpdater instead of VarHandle when guava-android runs under a JVM.
For much more discussion, see the code comments, especially in the backport copy of `AbstractFutureState`. (For a bit more on performance, see https://shipilev.net/blog/2015/faster-atomic-fu/, including its notes that `Unsafe` is not necessarily faster than `AtomicReferenceFieldUpdater`.)

Now that we no longer use `VarHandle` under Android, we can remove some Proguard rules for it:
- We no longer need the `-dontwarn` rule for `VarHandleAtomicHelper`, since that type no longer exists in `guava-android`.
- We no longer need the `-assumevalues` rule for `mightBeAndroid`, since it served only to strip the `VarHandle` code (to hide it from optimizers that run on the optimized code). And all else being equal, we'd rather _not_ have that rule _just in case_ someone is running `guava-android` through an optimizer and using it under the JVM (in which case we'd like to follow the JVM code path so that we don't try to use `Unsafe`). (OK, maybe it would be nice to keep the rule just so that Android doesn't have to perform a check of the `java.runtime.name` system property once during `AbstractFutureState` initialization. If anyone finds this to be an issue, please let us know.)

I've also updated the tests to better reflect which ones we run only under a JVM, not in an Android emulator. (I should really have done that back in cl/742859752.)

Fixes https://github.com/google/guava/issues/7769

RELNOTES=`util.concurrent`: Removed our `VarHandle` code from `guava-android`. While the code was never used at runtime under Android, it was causing [problems under the Android Gradle Plugin](https://github.com/google/guava/issues/7769) with a `minSdkVersion` below 26. To continue to avoid `sun.misc.Unsafe` under the JVM, `guava-android` will now always use `AtomicReferenceFieldUpdater` when run there.
PiperOrigin-RevId: 746800729
2025-04-12 06:08:45 -07:00

50 lines
1.7 KiB
Prolog

# Futures.getChecked, in both of its variants, is incompatible with proguard.
# Used by AtomicReferenceFieldUpdater, sun.misc.Unsafe, and VarHandle.
# We could be more precise about which classes these are defined in, but that feels error-prone.
-keepclassmembers class com.google.common.util.concurrent.AbstractFuture** {
*** waitersField;
*** valueField;
*** listenersField;
*** thread;
*** next;
}
-keepclassmembers class com.google.common.util.concurrent.AbstractFutureState** {
*** waitersField;
*** valueField;
*** listenersField;
*** thread;
*** next;
}
-keepclassmembers class com.google.common.util.concurrent.AtomicDouble {
*** value;
}
-keepclassmembers class com.google.common.util.concurrent.AggregateFutureState {
*** remainingField;
*** seenExceptionsField;
}
# Since Unsafe is using the field offsets of these inner classes, we don't want
# to have class merging or similar tricks applied to these classes and their
# fields. It's safe to allow obfuscation, since the by-name references are
# already preserved in the -keep statement above.
-keep,allowshrinking,allowobfuscation class com.google.common.util.concurrent.AbstractFuture** {
<fields>;
}
-keep,allowshrinking,allowobfuscation class com.google.common.util.concurrent.AbstractFutureState** {
<fields>;
}
# AbstractFuture uses this
-dontwarn sun.misc.Unsafe
# MoreExecutors references AppEngine
-dontnote com.google.appengine.api.ThreadManager
-keep class com.google.appengine.api.ThreadManager {
static *** currentRequestThreadFactory(...);
}
-dontnote com.google.apphosting.api.ApiProxy
-keep class com.google.apphosting.api.ApiProxy {
static *** getCurrentEnvironment (...);
}