You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2015/03/09 23:34:15 UTC

[Bug 57681] New: Allow parallel class loading in web application class loader by synchronizing on class specific object

https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

            Bug ID: 57681
           Summary: Allow parallel class loading in web application class
                    loader by synchronizing on class specific object
           Product: Tomcat 7
           Version: trunk
          Hardware: PC
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: koturano@amazon.com

Created attachment 32553
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32553&action=edit
Parallel classloading port from Tc8.0 into Tc7.0

Related to fix in Tomcat8.0:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56530
Add a web application class loader implementation that supports the parallel
loading of web application classes.

Source file to patch:
https://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?revision=1661811&view=markup

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #3 from Alex Koturanov <ko...@amazon.com> ---
The fix in bug 56530 is for Tomcat 8, not Tomcat 7. Why my request is marked as
resolved?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #10 from Mark Thomas <ma...@apache.org> ---
(In reply to Alex Koturanov from comment #8)
> Comment on attachment 32554 [details]
> Patch to work with JDK1.6

Doesn't implement parallel loading.

Creates significant risk of a ConcurrentModificationException during the lock
free read.

Ignores the discussion in bug 56530.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Mark Thomas <ma...@apache.org> ---


*** This bug has been marked as a duplicate of bug 56530 ***

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #8 from Alex Koturanov <ko...@amazon.com> ---
Comment on attachment 32554
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32554
Patch to work with JDK1.6

--- WebappClassLoader_r1661811.java    2015-03-09 21:53:27.000000000 +0000
+++ WebappClassLoader_patch.java    2015-03-17 14:21:56.000000000 +0000
@@ -1599,7 +1599,25 @@ public class WebappClassLoader
      * @exception ClassNotFoundException if the class was not found
      */
     @Override
-    public synchronized Class<?> loadClass(String name, boolean resolve)
+    public Class<?> loadClass(String name, boolean resolve)
+        throws ClassNotFoundException {
+        // check local cache without entering the global synchronized block
and return if the class is found
+        if (resourceEntries.containsKey(name)) {
+            Class<?> clazz = findLoadedClass0(name);
+            if (clazz != null) {
+                if (log.isDebugEnabled())
+                    log.debug("  Returning class from cache");
+                if (resolve)
+                    resolveClass(clazz);
+                return (clazz);
+            }
+            
+        }
+        // class is not found in local cache - call the original synchronized
method
+        return loadClass0(name, resolve);
+    }
+
+    private synchronized Class<?> loadClass0(String name, boolean resolve)
         throws ClassNotFoundException {

         if (log.isDebugEnabled())

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #14 from Mark Thomas <ma...@apache.org> ---
Removing deprecated code is not an option since it may break existing code.
That is why it was deprecated rather than deleted in the first place. The patch
needs to be re-worked not to do this.

I've started to add some of the external plumbing required by this feature so
the patch should be a little smaller.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #18 from Huxing Zhang <hu...@gmail.com> ---
Hi Mark,

Glad to hear the patch has been accepted! Thanks for your hard work!
BTW, I am interested in becoming a tomcat committer, any advice on that?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Alex Koturanov <ko...@amazon.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #32554|0                           |1
        is obsolete|                            |

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Alex Koturanov <ko...@amazon.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #32553|0                           |1
        is obsolete|                            |

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Huxing Zhang <hu...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |huxing.zhang@gmail.com

--- Comment #11 from Huxing Zhang <hu...@gmail.com> ---
Created attachment 32927
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32927&action=edit
Back port parallel class loading to tomcat 7.

Hi Mark, Christopher, and Konstantin:

I have back ported the parallel class loading feature to tomcat7. 

Could you please take some time to review this?

The basic idea here is:

1. Keep WebappClassLoader as default which is serial class loading enabled, and
one can configure to use ParallelWebappClassloader by specifying loaderClass in
context.xml (just as in Tomcat8). If user specified to use
ParallelWebappClassloader,  parallel class loading will only be enabled if
tomcat is running on JRE7 or above.
2. Call ClassLoader.registerAsParallelCapable() via reflection, so that jdk7 is
still not required to build tomcat 7 core code.
3. Call ClassLoader.getClassLoadingLock() via reflection to obtain a dedicated
object lock if parallel class loading enabled, or return the WebappClassLoader
object lock if not.
4. Introduce JreCompat.getInstance().isJre7Supported() to determine whether
tomcat is running on JRE7 (or above) or not.
5. Remove StandardClassLoader as well as MBean registration in Bootstrap, since
   1) it is deprecated
   2) it can avoid adding JRECompat to Bootstrap class loader's classpath
6. Add unit test to make sure parallel class loading is working as expected.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #19 from Mark Thomas <ma...@apache.org> ---
(In reply to Huxing Zhang from comment #18)
> Hi Mark,
> 
> Glad to hear the patch has been accepted! Thanks for your hard work!
> BTW, I am interested in becoming a tomcat committer, any advice on that?

Keep contributing patches.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Alex Koturanov <ko...@amazon.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #32554|Patch to work with JDK6     |Patch to work with JDK1.6
        description|                            |

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #12 from Huxing Zhang <hu...@gmail.com> ---
Hi, Any update on this?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
Because we don't have separate Bugzilla entries for exactly the same issue in
different versions of Tomcat.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #17 from Mark Thomas <ma...@apache.org> ---
This has been fixed using a variation of this patch in 7.0.x for 7.0.65
onwards.

Many thanks for the patch.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Huxing Zhang <hu...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |REOPENED

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #9 from Alex Koturanov <ko...@amazon.com> ---
Created attachment 32584
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32584&action=edit
Lock free read for already loaded/cached classes

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #7 from Mark Thomas <ma...@apache.org> ---
This patch is also wrong.

THe correct way to address this is described in bug 56530.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #13 from Huxing Zhang <hu...@gmail.com> ---
Is there anything else I can do to push it forward?
The patch respects the discussion in bug 56530.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #15 from Huxing Zhang <hu...@gmail.com> ---
To make StandardClassLoader parallel capable, we can simply add JRECompact to
the Bootstrap class loader's class path, and then apply the static
initialization of WebappClassLoaderBase's to it.
If we don't want to JreCompat to be in the Bootstrap ClassLoader's class path,
I think adding the following code should work for StandardClassLoader:

public class StandardClassLoader {
    ...
    static {
        try {
            // parallel class loading capable
            final Method registerParallel =
                   
ClassLoader.class.getDeclaredMethod("registerAsParallelCapable");
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                public Object run() {
                    registerParallel.setAccessible(true);
                    return null;
                }
            });
            registerParallel.invoke(null);
        } catch (NoSuchMethodException e) {
            // expect java 6 or lower
        } catch (Exception e) {
            // ignore
        }
    }
    ...
}

If there is anything else I can help, please feel free to let me know.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #5 from Alex Koturanov <ko...@amazon.com> ---
Created attachment 32554
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32554&action=edit
Patch to work with JDK6

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

Alex Koturanov <ko...@amazon.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |koturano@amazon.com
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #6 from Alex Koturanov <ko...@amazon.com> ---
Attachment 'Parallel classloading port from Tc8.0 into Tc7.0' was incomplete
and should not be used, apologies for attaching a wrong diff.

'Patch to work with JDK6' re-implements getClassLoadingLock() in
WebappClassloader and turns serial WebappClassLoader into parallel.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #16 from Mark Thomas <ma...@apache.org> ---
I opted for the simpler replacement of StandardClassLoader with URLClassLoader
wherever the StandardClassLoader was used.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57681] Allow parallel class loading in web application class loader by synchronizing on class specific object

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57681

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
And for the record the patch is nowhere close to correct.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org