Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-4462

Classloader deadlock in Java6 between two bundles



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: framework-4.2.1
    • Fix Version/s: framework-4.4.0
    • Component/s: Framework
    • Labels:
    • Environment:
      MacOS 10.7.5, java version "1.6.0_65", Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609), Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)


      As discussed on the user list ([0]) there is a deadlock in Java 6 (if bug 4670071 [2] is not fixed). The problem is the hidden, implicit ClassLoader.loadClassInternal which is is synchronized(this) in that case.

      Consider the following scenario:

      • bundle 2 wants to load a class of bundle 1 - hence is not synchronized with bundle 1's classloader - thus uses the m_classLocks locking mechanism to lock bundle 1's classloader for the particular class being loaded. Then calls defineClass (with bundle 1's classloader)
      • before it can do so, bundle 1 wants to load the same class (of bundle 1) - hence does a synchronized loadClassInternal. then reaches the m_classLocks locking mechanism and notices that there's another thread loading the class

      -> this results in the deadlock reported.

      There's multiple fixes for this:

      • use Java 7
      • use -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass
      • create a special Java 6 classloader (Java 7 would use the current one) which does a plain synchronized findClass() - and replaces all synchronized(m_classLocks) with synchronized(this)

      [0] http://markmail.org/thread/crwqzqobxgob7q3n
      [1] http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4670071


        1. classLockMonitor.FELIX-4462.patch2
          2 kB
          Stefan Egli
        2. FELIX-4462.txt
          4 kB
          Richard S. Hall
        3. suggested.synchronized.FELIX-4462.patch
          0.6 kB
          Stefan Egli
        4. test.reproducingFELIX-4462.patch
          16 kB
          Stefan Egli

          Issue Links



              • Assignee:
                rickhall Richard S. Hall
                stefanegli Stefan Egli
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: