Uploaded image for project: 'Clojure'
  1. CLJ-1620

Constants are leaked in case of a reentrant eval

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: Release 1.7
    • Fix versions: Release 1.11
    • Labels:
    • Approval:
      Incomplete
    • Patch:
      Code

      Description

      Compiling a function that references a non loaded (or uninitialized) class triggers its init static. When the init static loads clojure code, some constants (source code I think) are leaked into the constants pool of the function under compilation.

      It prevented CCW from working in some environments (Rational) because the static init of the resulting function was over 64K.

      Steps to reproduce:

      Load the leak.main ns and run the code in comments: the first function has 15 extra fields despite being identical to the second one.

      (ns leak.main)
      
      (defn first-to-load []
        leak.Klass/foo)
      
      (defn second-to-load []
        leak.Klass/foo)
      
      (comment
      => (map (comp count #(.getFields %) class) [first-to-load second-to-load])
      (16 1)
      )
      
      package leak;
       
      import clojure.lang.IFn;
      import clojure.lang.RT;
      import clojure.lang.Symbol;
       
      public class Klass {
        static {
          RT.var("clojure.core", "require").invoke(Symbol.intern("leak.leaky"));
        }
        public static IFn foo = RT.var("leak.leaky", "foo");
      }
      
      (ns leak.leaky)
      
      (defn foo
        "Some doc"
        []
        "hello")
      
      (def unrelated 42)
      

      https://gist.github.com/cgrand/5dcb6fe5b269aecc6a5b#file-main-clj-L10

      Patch: clj-1620-v5.patch

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cgrand Christophe Grand
            • Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: