Details

    • Number of attachments :
      0

      Description

      While fixing JRUBY-6522, I found that there are a few additional places where we have static ThreadLocals that can cause ClassLoader leaks in environments where a pool of threads may encounter multiple JRuby runtimes, such as when applications are redeployed to a webapp server.

      I audited for static threadlocals, and found the following:

      org.jruby.ext.ffi.AutoPointer:25

      private static final ThreadLocal<ReaperGroup> currentReaper = new ThreadLocal<ReaperGroup>();
      

      org.jruby.ext.ffi.jffi.AllocatedNativeMemoryIO:14

      private static final ThreadLocal<AllocationGroup> currentBucket = new ThreadLocal<AllocationGroup>();
      

      org.jruby.ext.ffi.jffi.TransientNativeMemoryIO:43

      private static final ThreadLocal<Magazine> currentMagazine = new ThreadLocal<Magazine>();
      

      org.jruby.interpreter.IRBreakJump:13

         private static ThreadLocal<IRBreakJump> threadLocalBJ = new ThreadLocal<IRBreakJump>() {
             public IRBreakJump initialValue() { return new IRBreakJump(); }
          };
      

      org.jruby.interpreter.IRReturnJump:11

          private static ThreadLocal<IRReturnJump> threadLocalRJ = new ThreadLocal<IRReturnJump>() {
             public IRReturnJump initialValue() { return new IRReturnJump(); }
          };
      

      There's also this in org.jruby.Ruby, but I'm not sure if it's a risk; it's explicitly used for thread-local stuff, but via an API we don't publish or recommend. Perhaps it should be removed?

      private static ThreadLocal<Ruby> threadLocalRuntime = new ThreadLocal<Ruby>();
      

        Activity

        Hide
        Wayne Meissner added a comment -

        I fixed the FFI ones in commit a0decb7e151103f802db72cad5ba380c59eefd60

        Show
        Wayne Meissner added a comment - I fixed the FFI ones in commit a0decb7e151103f802db72cad5ba380c59eefd60
        Hide
        Charles Oliver Nutter added a comment -

        Thanks Wayne!

        Show
        Charles Oliver Nutter added a comment - Thanks Wayne!
        Hide
        Charles Oliver Nutter added a comment -

        I resolved the remaining issues on master by not using a cached IRBreakJump/IRReturnJump. Tom or Subbu may want to reenable caching using some other mechanism, but for now it's safe.

        commit 030284a28c6474e216c8b24f5df5d276c298d3a5
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Sun Mar 4 09:48:39 2012 -0600
        
            Remaining fixes for JRUBY-6523.
        
        Show
        Charles Oliver Nutter added a comment - I resolved the remaining issues on master by not using a cached IRBreakJump/IRReturnJump. Tom or Subbu may want to reenable caching using some other mechanism, but for now it's safe. commit 030284a28c6474e216c8b24f5df5d276c298d3a5 Author: Charles Oliver Nutter <headius@headius.com> Date: Sun Mar 4 09:48:39 2012 -0600 Remaining fixes for JRUBY-6523.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Charles Oliver Nutter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: