Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-9828

Scala.Tuple incorrect work after JIT optimization

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Out of Scope
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Environment:

      Java 1.8.0_60-b27
      Scala: scala-library v 2.10.4

      Description

      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 <jar name> and check output.
      At some point it starts showing message like: Start reproducing: Thread <thread name> at step <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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rytz Lukas Rytz
                Reporter:
                alexey.tsiunchik@gmail.com Alexey Tsiunchik
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: