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

OOME raised while `parseClass(scriptText)`

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 3.0.0-rc-3
    • None
    • 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

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              daniel_sun Daniel Sun
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              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