Skip to content
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

Scala.Tuple incorrect work after JIT optimization #9828

Closed
scabug opened this issue Jun 23, 2016 · 8 comments
Closed

Scala.Tuple incorrect work after JIT optimization #9828

scabug opened this issue Jun 23, 2016 · 8 comments
Assignees

Comments

@scabug
Copy link

@scabug scabug commented Jun 23, 2016

Wile constructing Tuple6 inside lambda I'm observing null value passing into the Tuple instead on not null value. This issue occurs only on "warmed-up" JVM after hot spots compilations, which is resulting in hardly trackable, not always reproducible bugs.

Code snippet which causes issue is below:

private Set<Tuple6<Long, Long, Byte, String, Byte, String>> doStuff(List<String> demoIds,
                long programId, long date, TimeShiftingViewingPeriod viewingPeriod, Contribution contribution, String marketBreak) {
            Set<Tuple6<Long, Long, Byte, String, Byte, String>> res = new HashSet<>();
            demoIds.forEach(demoId -> res.add(new Tuple6<>(date, programId, viewingPeriod.getId(), demoId, contribution.getId(), marketBreak)));
            return res;
        }

The issue is that in resulting Set we may get Tuples with null values on third position, which is not possible since viewingPeriod is enum, where id is always not null value specified in constructor, and not modifiable.
Note: Issue is not reproduced if replace Collection.forEach with old style for expression.
Note: Issue is not reproduced if we replace Tuple with any Java Parametrized collection (Map for example)
Note: Issue is not reproduced if we disable JIT
Note: Issue is reproduced in random manner, and we noticed it is more often reproduced in case computer is running under load caused by some other tasks. We started build process for our project in parallel.
Test project: both sources and executable jar is in attachment.

How issue could be observed:
Just run attached executable jar using java -jar and check output.
At some point it starts showing message like: Start reproducing: Thread at step res: <Tuple content, on which issue was detected>.
Here step - is step in loop on which issue starts reproducing.
Sometimes it is necessary to run application several times (up to 10-20 to get this error), we only notice it appears faster in case computer is working under load.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 23, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9828?orig=1
Reporter: Alexey Tsiunchik (alexey.tsiunchik-at-gmail.com)
Attachments:

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 23, 2016

Alexey Tsiunchik (alexey.tsiunchik-at-gmail.com) said:
Example of output.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 23, 2016

@soc said:
I think this bug should be filed in the JIT vendor's bugtracker. I think there is not much we can do here if scalac emits the right bytecode.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 24, 2016

Alexey Tsiunchik (alexey.tsiunchik-at-gmail.com) said:
Well I was going to do this, but while investigating this issue using Java native collections, or custom java classes I cannot reproduce this issue. I think this issue is somewhere at intersection between scala and JVM JIT. I suspect that scala lazy implementation in conjunction with java lambda + JIT optimization gives this effect. Not sure what exactly causing this issue, either byte code produced by scala compiler or JIT itself. But I'm sure it is quite serious since may cause issues which would be very difficult to track in high loaded systems (with many precompiled hot spots) which occurs randomly (depending on load). So I think scala team should be interested in fixing such kind of issues since they affects reliability of solutions build with scala.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 27, 2016

@lrytz said:
This indeed looks like a serious issue. I managed to reproduce the issue from your source code.

I simplified the example quite a lot and managed to make it independent of the Scala library. I pushed the code on this github repository: https://github.com/lrytz/jit-bug/tree/master.

Now we just need to find a way to report that bug to Oracle.. Usually Twitter or StackOverflow work better than trying to go through the contact forms on their website.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 27, 2016

@scabug scabug closed this Jun 27, 2016
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 27, 2016

Alexey Tsiunchik (alexey.tsiunchik-at-gmail.com) said (edited on Jun 27, 2016 9:44:17 AM UTC):
Thank you Lukas for further investigation of this issue and simplified example. I'm going to submit issue to Oracle bug tracker. Will post link here.

@scabug

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.