-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
TimeZone ID parsing loses offset in native image #2234
Comments
Same behavior on: Linux sergej-P50 4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux I think there is something wrong here:
JDK impl:
When running on JDK, following branch is taken: tz is set in the JDK and returned. EDIT: The issue is, that the string is not parsed. If I were to call parseCustomTimeZone, the result will be valid. Therefore the parsed String will be found in the HashMap. The requeted String must be first normalized before asking the HashMap to search for it. I just copied it from TimeZone#parseCustomTimeZone
Changes must be made here:
EDIT2:
It looks like getDefaultRef must be overwritten, the rest can be removed. |
@vjovanov , as I see it, you created the File, therefore I am adressing you. Doing following change will result in a correct behavior. I actually do not know, what will happen, if a native-image is created and will be run on a computer, which has a different "default" TimeZone. To me, it looks like the default TimeZone will be written to the image heap during generation time. When the feature is disabled for good, a linking issue is printed, which I do not understand. EDIT:
When using TimeZone in a application as given by Issue-Owner, the size is as follows: (with changes)
an empty main is as follows (with changes)
empty main with default 20.0 native-image (without IncludeAllTimeZones)
main with TimeZone used as given by Issue-Owner with default 20.0 native-image
|
I'm not sure if there is anything official yet, but I have been working on a proof of concept for the Spring Framework that allows JUnit 5 tests (e.g., JUnit Jupiter) to be executed within a native image within a Gradle build. If you're interested, you can see my POC here for inspiration. |
I actually think the problem is in a bug supporting custom time zones. @sbrannen once we fix the bug you should be able to use custom time zones via the |
@SergejIsbrecht would you be able to paste the whole output of the failure? |
@eginez, Currently all time-zones are added to a HashMap and later and will be asked for, when #getTimeZone is called. When you look at the JDK implementation, you see that #parseCustomTimeZone is called in some circumstances. Current substitution takes the input string GMT+2 and ask for it in the HashMap, which contains: [...,Etc/GMT, Etc/GMT+0, Etc/GMT+1, Etc/GMT+10, Etc/GMT+11, Etc/GMT+12, Etc/GMT+2, Etc/GMT+3, Etc/GMT+4, Etc/GMT+5, Etc/GMT+6, Etc/GMT+7, Etc/GMT+8, Etc/GMT+9, Etc/GMT-0, Etc/GMT-1, Etc/GMT-10, Etc/GMT-11, Etc/GMT-12, Etc/GMT-13, Etc/GMT-14, Etc/GMT-2, Etc/GMT-3, Etc/GMT-4, Etc/GMT-5, Etc/GMT-6, Etc/GMT-7, Etc/GMT-8, Etc/GMT-9, Etc/GMT0, Etc/Greenwich, Etc/UCT, Etc/UTC, ...] It does not find it without calling #parseCustomTimeZone. Why not just use the JDK impl, by just delegating the calls to it? To me it looks like the Feature is not needed at all, because the JDK implementation, at least at JDK11 is sufficient. As you see in my earlier post, the solution could overwriting getDefaultRef and disabling the feature. The size will not increase, if the JDK impl inits all TimeZones. Furthermore I was thinking, what would happen, if I were to disable the substitution/ feature. Well, there is a linking issue in gcc. The full log can be found here: https://gist.github.com/SergejIsbrecht/387b85e56f052962dd205303e47a2ab7 I looked into TimeZone and the class is used during image generation time and will probably always be written to the image heap. Maybe there is some issue with some native calls during init? |
OK. We'll wait to see how this issue is resolved. Please note, however, that we are not interested in having to configure multiple "custom time zones" explicitly. Rather, enterprise applications need to be able to support whatever time zone is supplied by the user (i.e., GMT with any supported positive or negative offset in hours). The best would be if this were supported out of the box. If that's not possible, a single flag that enables this support would be greatly appreciated. |
@sbrannen yes it would be ideal to be able to lift such restriction, but bear in mind that currently you have to specify timezones for the image at build-time. I am looking for ways to do so but those limitations enable us to keep the image small |
@eginez , did you measure the impact, when all TimeZones are pre-init? I did it and it looks like there are only some bytes (~50KiB) overhead. Maybe I measured it wrong. |
The first thing is to fix the linking error you are getting above, that happens because the extra JDK code brings in symbols that are currently not define. I think I have a solution for that |
@sbrannen, @SergejIsbrecht I think I found a way to lift the substitution and restore the JDK time zone code without impact the image size dramatically. we are still running more tests but we are getting close and should have a fix soon |
That's great news. Looking forward to trying it out! |
All we hit a problem with windows in our test. The code in the JDK that deals with time zones reads a file in the native code: https://github.com/openjdk/jdk/blob/e9494f2155bd8d3468b666df876f0bdf65cbf045/src/java.base/windows/native/libjava/TimeZone_md.c#L439 I am currently looking for ways around this. |
Thanks for keeping us posted. Good luck! |
All 03d7d0c adds complete support for time zones in native-image. Do test it and let us know if you are still having problems with this. |
I wanted to try it out with "GraalVM CE 20.1.0-dev-20200407_0218" (on Mac OS)...
... but I get the following during the native image build.
|
@sbrannen I can't reproduce your issue running on the latest master. In fact this seems like a different problem. If that is the case would you mind opening a different issue for it? |
This issue shows up when you run with the agent and this class gets into your reflection config. Try removing this class from the config. @peter-hofer what is the best place to filter this type out in the agent? |
I can confirm that the example now works with GraalVM CE 20.1.0-dev-20200411_0336. |
Indeed, the following now shows up in {
"name":"org.graalvm.compiler.hotspot.management.SVMToHotSpotEntryPoints",
"methods":[
{"name":"getFactory","parameterTypes":[] },
{"name":"signal","parameterTypes":["org.graalvm.compiler.hotspot.management.SVMMBean$Factory","long"] }
]
},
I removed the entry for
Sure, I'll open a new issue for that regression. |
See #2341 |
Overview
When parsing a time zone ID with
java.util.TimeZone.getTimeZone(String)
, if the supplied ID contains an offset (e.g.,"GMT+2"
), the ID in the parsedTimeZone
loses the offset.For example, given the following test case...
The output when using a standard JDK results in the following.
Whereas, if you compile the test case into a native image, the output is the following.
Specifying
-H:+IncludeAllTimeZones
results in the same failure.See https://github.com/sbrannen/graalvm-playground/tree/master/timezone for the full example.
Environment
The text was updated successfully, but these errors were encountered: