[jvm-l] Improving the performance of stacktrace generation

John Rose john.r.rose at oracle.com
Thu Apr 11 16:07:25 PDT 2013


On Apr 11, 2013, at 10:12 AM, Charles Oliver Nutter <headius at headius.com> wrote:

> Unfortunately there's no API to get just a partial stack trace, via
> JVMTI or otherwise. The relevant code in Hotspot itself is rather
> simple; I started prototyping a JNI call that would allow getting a
> partial trace. Perhaps something like:
> 
> thread.getStackTrace(depth)

You may have looked at the internal API used by LogRecord.inferCaller.

Reference:  http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/file/tip/src/share/classes/java/util/logging/LogRecord.java

When a Throwable calls fillInStackTrace, the entire stack is walked (eagerly!) and an initial internal chunked array is filled with metadata.

Later on, native methods getStackTraceDepth() and getStackTraceElement(int) unpack that stuff into StackTraceElement fields.

It would be reasonable to add entry points which would instantiate only requested segments of the data (e.g., 0..9, 0..99) created by fillInStackTrace, like your method above, except on Throwable.  Then the getStackTraceElement stuff could be used to fetch the data that is there.  (If you asked for elements that hadn't been filled in yet, you could be hit with an index exception.)

— John

> ...and something equivalent for JVMTI.
> 
> John agreed that this would be a worthwhile feature for a JEP, and I'd
> certainly like to see it trickle into a standard API too.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20130411/210caf24/attachment.html 


More information about the mlvm-dev mailing list