title: Reference vs. Precise Reference in Dalvik Verifier
body: <p>I am writing instrumentation on Dalvik bytecode which performs some logging for various method call entries. Specifically, at various method call sites, I will insert a set of instructions which collects up the parameters, puts them in an <code>Object[]</code> array, and then passes that to a logging function.</p>
  
  <p>This is all fine and well, I have implemented and gotten past all of the kludges for most apps. But I'm encountering one particularly impenetrable Dalvik verifier error:</p>
  
  <pre><code>java.lang.VerifyError: Verifier rejected class io.a.a.g: void io.a.a.g.r() 
  failed to verify: void io.a.a.g.r(): [0x570] register v5 has type Reference: 
  java.lang.Object but expected Precise Reference: java.lang.String
  </code></pre>
  
  <p>I looked at the code that is being generated by my instrumentation, and all I'm doing is putting register v5 in an array of objects.</p>
  
  <p>I have a few questions here:</p>
  
  <ul>
  <li>What is a <em>precise</em> reference, and why is it incompatible with references?</li>
  <li>What does the offset here mean? <code>[0x570]</code> points into the middle of a bytecode instruction, so it doesn't clearly map to any instructions: the instructions around there don't involve <code>v5</code>.</li>
  <li>How would I go about debugging this? Ideally, I'd like to know what the verifier thinks should be happening and fix that.</li>
  </ul>
  
  <p>EDIT: </p>
  
  <p>Here's a dump of the bytecode of the method I'm speaking about. <a href="https://gist.github.com/kmicinski/c8382f0521b19643bb24379d91c47d36" rel="noreferrer">https://gist.github.com/kmicinski/c8382f0521b19643bb24379d91c47d36</a> As you can see, 0x570 isn't the beginning of an instruction, and (as far as I can tell) there isn't any place where r5 conflicts with a String where it should be an object.</p>