title: Java call stack inspection and manipulation
body: <p><strong>My question is</strong>: is it possible (in ANY way) to analyze and modify call stack (both content of frames and stack content) in runtime?</p>
  
  <p>I'm looking for any possibility - low-level, unsafe or internal API, possibility to write C extension, etc. Only constraint: it should be usable in standard runtime, without debugging or profiling mode. This is the point where I'm doing research "is it possible at all?", not "is it good idea?".</p>
  
  <p>I'd like to gather all local data from a frame, store it somewhere, and then remove that frame from stack, with possibility of restoring it later. Effectively that gives us continuations in JVM, and they will allow fast async frameworks (like gevents from python) and generator constructs (like those from python) to come up.</p>
  
  <p>This may look like repeated question, but I've only found questions that were answered with "use <code>Thread.currentThread().getStackTrace()</code>" or "that should be done with debugging tools". There was <a href="https://stackoverflow.com/questions/17975897/set-java-call-stack">similiar question to mine</a>, but it was only answered in context of what asking guy wanted to do (work on async computations), while I need more general (java-stack oriented) answer. <a href="https://stackoverflow.com/questions/27230992/jvm-is-it-possible-to-manipulate-frame-stack">This question</a> is similiar too, but as before, it is focused on parallelization, and answers are focused on that too.</p>
  
  <p>I repeat: this is research step in process of coming up with new language feature proposal. I don't wanna risk corrupting anything in JVM - I'm looking for possibility, then I'm gonna analyse possible risks and look out for them. I know that manipulating stack by hand is ugly, but so is creating instances with ommiting consrtuctor - and it is basis for objenesis. Dirty hacks may be dirty, but they may help introducing something cool.</p>
  
  <p>PS. I know that <a href="http://docs.paralleluniverse.co/quasar/" rel="nofollow noreferrer">Quasar</a> and <a href="http://lightwolf.sourceforge.net/index.html" rel="nofollow noreferrer">Lightwolf</a> exist, but, as above, those are concurrency-focused frameworks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Little clarification: I'm looking for something that will be compatible with future JVM and libraries versions. Preferably we're talking about something that is considered stable public API, but if the solution lies in something internal, yet almost standard or becoming standard after being internal (like sun.misc.Unsafe) - that will do too. If it is doable by C-extension using only C JVM API - that's ok. If that is doable with bytecode manipulation - that's ok too (I think that MAY be possible with ASM).</p>