Stack frame annotation

4

There has been an interesting thread lately in the jvm-languages Google group that I thought was worth bringing up. The thread concerns finding a better solution to artifical call frames, such as perhaps stack frame annotations. The idea is that many dynamic languages must introduce artificial call frames, purely to be able to recover the dynamic language’s stack trace. The thread was started by Charles Nutter based on JRuby, but it seems that this is a common issue from the discussion.

The solution discussed in thread concerns the ability to annotate both threads and stack frames with additional metadata. Doing so would allow the artificial call frame to go away and be replaced by metadata attached to the thread and/or stack frame, just riding along on the normal Java stack frame. It seems from the discussion that a number of JVM languages could benefit from this improvement.

Kelly Nawrocke mentioned that there is a similar proposal in the works for EcmaScript 4 based on the thesis by John Clements. This inspection allows inspection of all frames of the stack and the modification of annotations for any frame in the stack.

It appears that one of the key considerations is being able to maintain proper tail call optimization (something Java doesn’t have now, but which is being considered as a possibility via JSR 292 in Java 7). In the case of tail call optimization, it is necessary to reuse stack frames, so the key is to do something useful in this case. Read the links for more info.

I’m pretty sure that there are some interesting optimizations we could make in Terracotta based on this capability as well. For example, we must maintain some per-lock information for each nested lock and currently this gets pushed into some ThreadLocal stack data structures, but the information may fit more naturally as stack frame annotations where locks are acquired as you walk down the frame.

What would you do with the power of stack frame annotation?

Comments

4 Responses to “Stack frame annotation”
  1. This seems similar to how we have approached runtime request and state diagnostics in JXInsight.

    Introduction to Diagnostics API
    http://blog.jinspired.com/?p=35

    Diagnostics API
    http://www.jinspired.com/products/jxinsight/api/com/jinspired/jxinsight/diagnostics/Diagnostics.html

    We can transparently weave this capability into the runtime via our AspectJ extensions.
    http://blog.jinspired.com/?p=62

    William

  2. Daniel Yokomizo says:

    An interesting idea is to add debugging capabilities to local variables and parameters, so as an exception unwinds the stack the variable values are bound to the stack frame they’re part of and can be printed, inspected or whatever.

  3. Fred says:

    Security system based on ThreadLocal are also a nightmare. Someone thought about using this for security?

Trackbacks

Check out what others are saying about this post...
  1. [...] Alex Miller has posted a blog entry referencing an interesting thread discussing artificial stack frames and as well as the ability to annotate frames with meta data including local stack variables. This all looks very familiar – JXInsight Diagnostics (@see Open API). [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!