[ 
https://issues.apache.org/jira/browse/LOG4J2-1359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15906252#comment-15906252
 ] 

Ralph Goers commented on LOG4J2-1359:
-------------------------------------

Let's see if I can help.  First, I suggest you read 
https://www.sitepoint.com/deep-dive-into-java-9s-stack-walking-api/. Notice 
that when StackWalker::forEach is used to get the StackTraceElement containing 
the file name and line number it is actually slower than walking the Throwable, 
which is in contrast to Reflection.getCallerClass() where we get a performance 
boost. But also notice that the cost decreases with the number of stack frames 
that have to be retrieved. So the openjdk devs recommend using StackWalker's 
getCallerClass method. Of course, the only way to do that is to have the call 
be in the first Log4j method that is called. Then we would have to pass the 
retrieved StackFrame instead of the FQCN. IOW, we would not lazily resolve the 
location information. I have my doubts that can be done without unacceptable 
performance consequences.

Worse, I did some gross testing and it seemed that walking the Throwable was 
slower in Java 9 than in Java 8. However, the openjdk devs believe I did 
something wrong.  The only way to know is to test it.  I plan to do just that 
by starting with https://github.com/pingtimeout/stack-walker-benchmark and then 
creating a Java 8 version and a Java 9 version.

So yes, we can defer walking the stack but the cost of retrieving location 
information will probably be worse than it is pre-Java 9.

For a reference to the core-libs discussion see the thread that starts with 
http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-May/040826.html.

> Add support for Java 9 StackWalker API in ReflectionUtil
> --------------------------------------------------------
>
>                 Key: LOG4J2-1359
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1359
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>         Environment: Java 1.9+
>            Reporter: Matt Sicker
>            Assignee: Ralph Goers
>              Labels: jdk9
>
> [StackWalker|http://download.java.net/jdk9/docs/api/java/lang/StackWalker.html]
> Based on the functional nature of this API, supporting it may require 
> compiling at least one class using javac 1.9 and reflectively loading it in 
> ReflectionUtil similar to how Spring supports newer JDK APIs.
> Without support for StackWalker, ReflectionUtil will fall back to using a 
> slower API in Java 1.9. This is because the Reflection class is a 
> sun-internal class which are no longer exported to non-JDK code without 
> setting special command line flags.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to