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

Memory leaks in nashorn sources and tests found by jhat analysis

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b105
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      The following memory leaks were found in nashorn sources and test sources using jhat against a test dump. The test dump was produced by running

         ant -Drun.test.xmx=512m clean test

      Leaks found:

      * codegen.CompileUnit keeps classEmitter alive even after code is loaded and Class object is set. Clearing this by null will allow ClassEmitter and transitive data such as bytecode to be collected.

      * "source" field in every script class is unused and so can be removed (one less link for Source object)

      * InvokeByName and "dynamic invoke" method handles are kept as static fields in many classes such as NativeArray, UserAccessorProperty, NativeJSON and so on. These are effectively "call sites" in java code. These callsites keep many script "world" objects like property maps, script function data, script function etc. alive through the life of the process. These should be scoped to particular (current) global instance. Perhaps global instance should have a Map of InvokeByName objects and "dynamic invokers".

      * RecompilableScriptFunctionData keeps FunctionNode around - even for functions that cannot be specialized. For lazy functions (that can not be specialized), we can clear functionNode field to null. This will allow all transitive IR nodes to be collected. We can cache Source object and token alone in separate fields (to compute source of the function).

      * JavaAdapterClassLoader's classBytes can be cleared to null after Class is loaded - for "instance" adapter Classes. Otherwise generated adapter code is kept alive even after the class is loaded into VM to make Class object.

      * test/src/jdk/nashorn/api/javaaccess/*.java tests should have @AfterClass method where static script engine field is cleared to null. After running a specific test class's methods, we don't need to keep ScriptEngine object alive.

        Attachments

          Activity

            People

            Assignee:
            sundar Sundararajan Athijegannathan
            Reporter:
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: