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
AtomicReferenceFieldUpdaterinstead ofVarHandlewhenguava-androidruns 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 thatUnsafeis not necessarily faster thanAtomicReferenceFieldUpdater.)Now that we no longer use
VarHandleunder Android, we can remove some Proguard rules for it:-dontwarnrule forVarHandleAtomicHelper, since that type no longer exists inguava-android.-assumevaluesrule formightBeAndroid, since it served only to strip theVarHandlecode (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-androidthrough 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.namesystem property once duringAbstractFutureStateinitialization. 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 ourVarHandlecode fromguava-android. While the code was never used at runtime under Android, it was causing problems under the Android Gradle Plugin with aminSdkVersionbelow 26. To continue to avoidsun.misc.Unsafeunder the JVM,guava-androidwill now always useAtomicReferenceFieldUpdaterwhen run there.