Repository navigation
Use AtomicReferenceFieldUpdater instead of VarHandle when guava-android runs under a JVM. - #7770
Merged
Merged
Conversation
2 tasks done
copybara-service
Bot
force-pushed
the
test_745575600
branch
2 times, most recently
from
April 12, 2025 12:42
ab90d2f to
ef1e1c4
Compare
…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 #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](#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
copybara-service
Bot
force-pushed
the
test_745575600
branch
from
April 12, 2025 13:08
ef1e1c4 to
75da924
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.