Use AtomicReferenceFieldUpdater
instead of VarHandle
when guava-android
runs under a JVM.
#7770
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
AtomicReferenceFieldUpdater
instead ofVarHandle
whenguava-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 thatUnsafe
is not necessarily faster thanAtomicReferenceFieldUpdater
.)Now that we no longer use
VarHandle
under Android, we can remove some Proguard rules for it:-dontwarn
rule forVarHandleAtomicHelper
, since that type no longer exists inguava-android
.-assumevalues
rule formightBeAndroid
, since it served only to strip theVarHandle
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 runningguava-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 useUnsafe
). (OK, maybe it would be nice to keep the rule just so that Android doesn't have to perform a check of thejava.runtime.name
system property once duringAbstractFutureState
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 #7769
RELNOTES=
util.concurrent
: Removed ourVarHandle
code fromguava-android
. While the code was never used at runtime under Android, it was causing problems under the Android Gradle Plugin with aminSdkVersion
below 26. To continue to avoidsun.misc.Unsafe
under the JVM,guava-android
will now always useAtomicReferenceFieldUpdater
when run there.