title: What would be the best way to instrument Java classes in order to create a reverse Java debugger?
body: <p>I'd like to create a reverse debugger (a debugger where it is possible to go backwards in program execution) for Java and for this I need to store variable data alongside program execution. I will use a global cache for this and a static method which updates the cache.</p>
  
  <p>I'd like to instrument loaded classes in such a way that after each field/variable modification, my static method will be called: e.g:</p>
  
  <pre><code>public static void updateCache(String fullVarName, Object value){...}
  </code></pre>
  
  <p>What I observed is that when a field is updated, a <code>putfield</code> instruction is executed. When a local variable is updated, an <code>(I)STORE</code> instruction is used. So I thought of instrumenting the classes and whenever such an opcode is found, I simply insert another <code>getfield</code> or <code>ILOAD</code> after, to get the value of the updated field/variable and then I use an <code>invokestatic</code> to call my static method with all the necessary information.  </p>
  
  <p>The problem is that there are other use cases where variables are collections or arrays and they are updated with specific methods like when updating a <code>HashMap</code> with <code>map.put(key, value)</code>. So I need to intercept these calls as well, but there are a high number of such methods and I need to find and hardcode them all...<br>
  Is there a workaround? Or maybe I am missing something and there is a simpler solution.</p>
  
  <p>Edit: I've also looked into JVMTI before and ran some benchmarks. It seemed that it is too slow for my use case e.g. adds an 7-100x slowdown to my program.....</p>