You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2006/02/12 23:24:01 UTC

DO NOT REPLY [Bug 38626] New: - LogFactory#getLogFactory should not look for method every time

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626

           Summary: LogFactory#getLogFactory should not look for method
                    every time
           Product: Commons
           Version: 1.0.4
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Logging
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: matthias.ernst@coremedia.com


LogFactory checks for the existence of Thread#getContextClassLoader every time
#getLogFactory is invoked and does a reflective invocation. This is
unnecessarily expensive if many Log objects are created. An easy patch is to
remember the Method object; the lookup happens only once and it will massively
profit from reflection optimizations after a number of calls (a Java code stub
is generated by the reflection package).

Patch:

419a420,426
>     private static Method GET_CONTEXT_CLASS_LOADER = null;
>     static {
>       try {
>         GET_CONTEXT_CLASS_LOADER = Thread.class.getMethod("getContextClassLoad
er", null);
>       } catch (NoSuchMethodException e) {
>       }
>     }
436,439c443
<         try {
<             // Are we running on a JDK 1.2 or later system?
<             Method method = Thread.class.getMethod("getContextClassLoader", nu
ll);
<
---
>         if(GET_CONTEXT_CLASS_LOADER != null) {
442c446
<                 classLoader = (ClassLoader)method.invoke(Thread.currentThread(
), null);
---
>                 classLoader = (ClassLoader)GET_CONTEXT_CLASS_LOADER.invoke(Thr
ead.currentThread(), null);
472c476
<         } catch (NoSuchMethodException e) {
---
>         } else {

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38626] - [logging] LogFactory#getLogFactory should not look for method every time

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626


ebourg@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|LogFactory#getLogFactory    |[logging]
                   |should not look for method  |LogFactory#getLogFactory
                   |every time                  |should not look for method
                   |                            |every time




-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38626] - LogFactory#getLogFactory should not look for method every time

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626





------- Additional Comments From matthias.ernst@coremedia.com  2006-02-12 23:25 -------

> >     private static Method GET_CONTEXT_CLASS_LOADER = null;

Add a "final" there.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38626] - [logging] LogFactory#getLogFactory should not look for method every time

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626


rdonkin@apache.org changed:

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




------- Additional Comments From rdonkin@apache.org  2006-02-16 21:47 -------
After consideration, I'm not happy addressing this for this release.

I would consider a performance patch with either extensive unit tests
(preferrably with security managers) or demonstration code (if it's not feasible
to easily codify into tests) once this release is out. If anyone feels like
contributing one, please attach to this bugzilla and reopen

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38626] - LogFactory#getLogFactory should not look for method every time

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626





------- Additional Comments From skitching@apache.org  2006-02-13 02:31 -------
Nice idea, but unfortunately it's not quite that simple.

The code
  Thread.class.getMethod
is currently in method directGetContextClassLoader that is invoked from method
getContextClassLoader via AccessController.doPrivileged.

The use of SecurityController is for the case where the commons-logging.jar file
is signed and trusted to use reflection but the calling code is not.

What happens if we move this call into a static initialisation block of the
LogFactory class?

Is there any security on this call, or is the current use of AccessController
really just meant to wrap the Method.invoke call?

If we perform this operation from the static initialisation block of the
LogFactory class, what are the security manager implications? I would *guess*
that such an operation would be performed with the privileges of the class being
loaded, ie would be ok WITHOUT using an AccessController. However I don't know a
whole lot about this area..

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38626] - LogFactory#getLogFactory should not look for method every time

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38626>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38626





------- Additional Comments From matthias.ernst@coremedia.com  2006-02-13 08:06 -------
That is a valid concern that I didn't think about. I checked the specification
for #getMethod which would throw a SecurityException in two cases:
if a security manager would deny 

* member access to Thread.class with scope PUBLIC
* package access to java.lang

I would suggest this would be a dysfunctional setup anyway. If you're really
concerned, wouldn't it be possible to wrap the Method lookup in a privileged
block as well?


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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