title: Generating Java source code and jumps
body: <p>I am generating Java code on the fly which will then be compiled and loaded back in. My issues is that I essentially need jumps because when I return from the function I wish to continue execution from the point in the loop from where I have exited. Hopefully, the code here illustrates my desire. Although the actual code will have some ifs as well and be much deeper.</p>
  
  <pre><code>MyIter a,b,c;
  
  boolean func() {
   jump to correct state here
  
   state0:
  
   a = ...;
   while (a.next()) {
     state1: while (b.next()) {
       return true; // start again at state1
     }
     b = ...;
   }
  
   c = ...;
   state2:
   while (c.next()) {
     return true; // start again at state2
   }
   return false;
  }
  </code></pre>
  
  <p>In C I would probably use a jump table and state variable. Performance is the key here and the code interacts with the Java application. </p>
  
  <p>My best guesses so far have been:</p>
  
  <ul>
  <li>Flipping the nesting of loops and the logic. That became too cumbersome and problematic.</li>
  <li>Adding logic to allow the flow to get back to where it was but this may be messy.</li>
  <li>I assume the bytecode can jump so I could generate the bytecode myself but that doesn't seem ideal (is there any good libraries for this?)</li>
  <li>Continuation passing style to avoid returning but that would involve major restructuring, although currently the likely way to go.</li>
  </ul>
  
  <p>I was wondering if anyone had any thoughts?</p>