Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8162955

Activate anonymous class loading for small sources

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • None
    • core-libs
    • b131
    • generic
    • generic

      There are several bug reports of Nashorn taking much longer to compile and evaluate many small scripts than Rhino.

      JDK-8034959, JDK-8143347, JDK-8162414

      While this is expected (Rhino is interpreted while Nashorn always generates Java bytecode) and there's little we can do in the short term to catch up with Rhino, there are two issues in JDK 9 that add additional overhead compared to Nashorn in JDK 8. One is class loading, which seems to have become much slower in JDK 9 recently, and the other is optimistic types, which is enabled by default in JDK 9.

      For the class loading slowness, we have a solution in JDK 9 which is anonymous classes. Anonymous classes load very fast (faster than normal classes in JDK 8), but for some reason code loaded anonymously is not treated the same way as normal code during optimization, which is why it remains slower after warmup.

      Because of this, we currently use anonymous classes for script based eval in JDK 9, assuming that evals are used for short, throw-away scripts where max performance is not so important. However, as is shown by the bugs above, short, throwaway scripts are often evaluated through Java script API. For this reason, I propose to use anonymous loading for all short scripts (using a size threshold that is tbd), regardless of how they are evaluated.

            hannesw Hannes Wallnoefer
            hannesw Hannes Wallnoefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: