On Apr 11, 2013, at 10:12 AM, Charles Oliver Nutter <head...@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.

_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to