Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9329

OOME raised while `parseClass(scriptText)`

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0-rc-3
    • Component/s: None
    • Labels:
      None

      Description

      Many groovy users have encountered the OOME while parseClass(scriptText) even if the scriptText has not been changed.

      The cause of the issue is the script file name is generated via System.currentTimeMillis(), so the script file name will change even if the script text is not changed. As a result, many class instances are created and cached in groovy.lang.GroovyClassLoader#classCache, the classes can not be GCed, which causes OOME.

      The solution is very simple, the script file name could be generated via md5, which will not change if the script text is not changed.

      def gcl = new GroovyClassLoader()
      
      while (true) {
          gcl.parseClass('def x = 1')
      }
      

      Error message:

      java.lang.OutOfMemoryError: Compressed class space
      
      	at ConsoleScript6.run(ConsoleScript6:4)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              daniel_sun Daniel Sun

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 20m
                1h 20m

                  Issue deployment