New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For Android compatibility, make Statics.releaseFence()
also catch NoSuchMethodException
for java.lang.invoke.VarHandle.releaseFence()
call
#9739
Conversation
…arHandle.releaseFence invocation
b044a18
to
aeda5d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I don't see how this could break anything. still would definitely like to hear Jason's thoughts
Looks safe to me too, but @nwk37011 do we know if this actually fixes
|
review by @makingthematrix perhaps? (and/or, can you suggest anyone else with Android knowledge who might like to take a look?) |
Looks good to me. If you want me to test it, I can maybe do it on Sunday. |
What is Olaf's plugin and how does it work around the issue? |
I don't know exactly but here's the code and here's the discussion about it. |
The end of the discussion leads to a github repo with Statics.java patched in which does exactly the same thing. From own testing of the code, Android gives a log of java.lang.invoke.VarHandle.releaseFence() being blacklisted along with NoSuchMethodException and across various Android SDK versions catching it enabled to fall back to calling sun.misc.Unsafe.storeFence() without any problem so I believe it must be pretty safe. The worst possible case I can imagine is possibly becoming just as the same as how it was before, returning ExceptionInInitializerError, if somehow google decides to explicitly block sun.misc.Unsafe.storeFence() in future Android releases. However, sun.misc.Unsafe.storeFence() has been around for pretty long time and according to https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces it is stated as not blacklisted across many versions of releases so I doubt if it will happen anytime soon |
I'm happy to merge this, but it'd be great if @makingthematrix you could test it. If it makes testing easier, we can merge this now so that an integration build will be available on https://scala-ci.typesafe.com/ui/native/scala-integration. |
That would be great. Thank you! |
Version |
@lrytz On the other hand, it also doesn't make anything worse. Yay, I guess?... |
There are a lot of pieces in this puzzle I don't know of, or anything about :-) I guess you made sure to remove the workaround(s), like Maybe no workarounds are needed anymore with recent GraalVM versions? oracle/graal#2761 (comment) says
The original description of this PR says
I actually don't understand yet what this means - @nwk37011 / @makingthematrix could you clarify?
|
@lrytz : But that means I can test this once again, this time with an older GraalVM. I will do it and come back to you. The code snipped linked by @nwk37011 a few comments above is from a different attempt to build Android apps with Scala, in a more standard way, without GraalVM Native Image. |
@lrytz |
OK, so it's actually possible to run Java 8 bytecode on android these days, officially supported by Google. I wasn't aware, that's awesome! IIUC https://developer.android.com/studio/write/java8-support.html#supported_features
I played around a little and managed to run
there are a bunch of
The same happens with the scala-library-2.13.7-bin-768001e.jar (after this PR). But anyway, adding I converted this back to a Anyway, nothing else to be done here, we can keep the change of this PR. It's really great to have multiple options available for Scala on Android (native code through GraalVM, translation of classfiles like Kotlin / Java 8, Scala.js and React Native). |
Statics.releaseFence()
also catch NoSuchMethodException
for java.lang.invoke.VarHandle.releaseFence()
call
Statics.releaseFence()
also catch NoSuchMethodException
for java.lang.invoke.VarHandle.releaseFence()
callStatics.releaseFence()
also catch NoSuchMethodException
for java.lang.invoke.VarHandle.releaseFence()
call
Currently Statics.releaseFence() call catches ClassNotFoundException only for the java.lang.invoke.VarHandle.releaseFence() call. However, there are cases where java.lang.invoke.VarHandle exists but not releaseFence() such as Android, this commit tries to handle such cases more properly by catching NoSuchMethodException thus allowing such systems to fallback to sun.misc.Unsafe.storeFence()