-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Use default property values to work on Graal. #7112
Conversation
Graal Native Image seems to not define java.runtime.name, which means without a default, `isAndroid` would call `.contains("Android")` on null, and crash.
Isn't it maybe the better solution, to force UIUtil to run the static initializer at build time, not at run time? |
But UIUtils is also used by non-Graal environments that are cross-platform; that's its whole point for existing. So no, it isn't safe to do it at build time.
Sure, but I don't know what that is, so PR away, just not here. This is a fix for an NPE that happens in UIUtils because it made the incorrect assumption that a specific property would always be defined. |
Sorry, I think I haven't phrased myself well! The "native-image.properties" file is related to this, because it is the way to automatically configure a native-image execution, therefor automazing passing the "--initialize-at-build-time" argument. |
I mean, last I checked, LWJGL3 needed a lot of hoops to jump through to build any native image, and LWJGL2 wouldn't work at all. The way I remember used a repo by anyicomplex , required a dependency on all of Graal, and had some other drawbacks. If anyone has a convenient way to build native images of libGDX games, that would be really nice to hear about. |
I have build libGDX games with native-image for MOE (iOS). I also maintain a fork of your mentioned library: https://github.com/Berstanio/gdx-graalhelper |
I think Graal has some real advantages for games, but like you said, the shared libraries are what's problematic for LWJGL3. Maybe there's a way to have that handled better by native-image.properties, though I want to point out, that is outside this PR's scope. I'll create an issue to bundle up Graal discussion and maybe spread knowledge between the various people who have used native-image. |
Yes, agreed. I think I also misunderstood, based on the diff I thought "os.name" also isn't set, but thats not the case, right? If it's really just "java.runtime.name" thats missing, which is only used for determining android, than I guess the empty default string is totally fine imo. However a little question on the default of "os.name": If it is not set, it will result in silent failure of platform detection, right? I've never heard about a case where "os.name" is not set, but maybe it's still better to add some kind of warning, if it isn't present? Just in case, to not have to deal with potential silent platform detection failure? |
If os.name isn't set, then osName becomes |
Yes, I'm aware. My point is, whether it is a good idea to have "If we don't know, we assume it's iOS" without any warning in the log. I was thinking about something like: static {
if (System.getProperty("os.name") == null) {
System.err.println("Warning: os.name isn't set, host OS can't be determined.");
}
} |
If |
Okay, fair points! |
One thing did just occur to me though -- a novel JVM (like Graal, but maybe even more experimental) might not define |
I agree that a default value for
I think that raises a valid point. Silently failing isn't very nice, even if it is unlikely to ever happen. |
It wouldn't be hard to add an |
https://github.com/MobiVM/robovm/blob/c526f714ed2b7f26bd96a62ed6378545da9b73c7/compiler/vm/rt/robovm/java_lang_System.c#L49-L57 |
MOE seems to delegate to the OS to return os.name from |
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.
It looks good to me.
As osName and jrName are imutable static final String they migth be named as constant OS_NAME and JR_NAME ?
(Having a isUnknownOS() just in case may be good to)
This is listed as a requirement (?) for the next release, and the unknown OS check hasn't ever been needed so far, so maybe the changes to have a default setting should be considered as-they-are-now (with one approval), and the unknown OS check can be discussed later. |
Can't we just just revert the default value for "os.name" instead? The linked issue is only about |
If we don't have a default value for os.name, then the property will be null and will lead to crashes if os.name isn't defined. This has not happened yet and I wouldn't really worry about it, whether the default is in or out. However, allowing null at all for a property that we call On all platforms except Graal Native-Image, this will behave the same as before. With a check for an unknown os.name, and without such a check, that does not affect the rest of the PR. We have not encountered a single case of os.name being undefined. |
Yes, I'm aware and I do think, crashing is the correct behaviour. In my opinion, if |
Wait, what's unrecoverable about having os.name unset? If an OS and JVM can run without that property being set, that could be intended for some hypothetical OS/JVM combination, and it doesn't prevent anything else from functioning (except that the OS will detect as iOS). |
Whoops, I always forget that this is not about SharedLibraryLoader code. But looking at |
So then this is all moot, since if os.name is unset, the core of libGDX will fail in SharedLibraryLoader -- we'll never encounter it. |
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.
Yep, seems like it!
In that case, I'm fine with this
I think for consistency's sake we should keep the OS checks the same in SharedLibraryLoader and UIUtils, but if you all agree on the opposite, we can go ahead and merge this anyways. |
Good point, couldn't we just rewrite UIUitls, so it references SharedLibraryLoader.isXX? |
SharedLibraryLoader isn't available on GWT. We could maybe go the other way, and have some core class make these checks and make the results available to UIUtils and SharedLibraryLoader. |
As part of #5960 I thought about adding a |
Thats not a problem, since GWT has it's own UIUtil class:
I think this is not a bad idea, but it would take some time to implement, right? If we want to merge this soon, I think the cleanest way is using the results of SharedLibraryLoader for the moment. |
This UIUtils class isn't used on GWT, so SharedLibraryLoader should be safe to use in all cases. I've built the tests to target GWT, Android, LWJGL, and LWJGL3, but not iOS because I don't have a Mac. On the four platforms I built the tests on, the build succeeded; I ran the tests without issue on LWJGL 2 and 3. I should note that GWT failed to build once due to some bug internal to Spotless (related to OSGi?), but built fine on the next attempt. That might explain some random failures in automated tests...
OK, I switched to using SharedLibraryLoader, and that does look much more clean. |
Graal Native Image seems to not define java.runtime.name, which means without a default,
isAndroid
would call.contains("Android")
on null, and crash. Adding defaults forSystem.getProperty()
seems like a vital step for anywhere that gets String properties. This fixes #7111 . Thanks to authorZhao for finding the bug and suggesting a fix.