title: How are java interfaces implemented internally? (vtables?)
body: <p>C++ has multiple inheritance. The implementation of multiple inheritance at the assembly level can be quite complicated, but there are good <a href="http://en.wikipedia.org/wiki/Virtual_table" rel="noreferrer">descriptions</a> online on how this is normally done (vtables, pointer fixups, thunks, etc). </p>
  
  <p>Java doesn't have multiple implementation inheritance, but it does have multiple interface inheritance, so I don't think a straight forward implementation with a single vtable per class can implement that. How does java implement interfaces internally? </p>
  
  <p>I realize that contrary to C++, Java is Jit compiled, so different pieces of code might be optimized differently, and different JVMs might do things differently. So, is there some general strategy that many JVMs follow on this, or does anyone know the implementation in a specific JVM? </p>
  
  <p>Also JVMs often devirtualize and inline method calls in which case there are no vtables or equivalent involved at all, so it might not make sense to ask about actual assembly sequences that implement virtual/interface method calls, but I assume that most JVMs still keep some kind of general representation of classes around to use if they haven't been able to devirtualize everything. Is this assumption wrong? Does this representation look in any way like a C++ vtable? If so do interfaces have separate vtables and how are these linked with class vtables? If so can object instances have multiple vtable pointers (to class/interface vtables) like object instances in C++ can? Do references of a class type and an interface type to the same object always have the same binary value or can these differ like in C++ where they require pointer fixups? </p>
  
  <p>(for reference: <a href="https://stackoverflow.com/questions/3262428/how-does-net-clr-implement-an-interface-internally">this question</a> asks something similar about the CLR, and there appears to be a good explanation in <a href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx#S12" rel="noreferrer">this msdn article</a> though that may be outdated by now. I haven't been able to find anything similar for Java.)</p>
  
  <p><strong>Edit:</strong></p>
  
  <ul>
  <li>I mean 'implements' in the sense of "How does the GCC compiler implement integer addition / function calls / etc", not in the sense of "Java class ArrayList implements the List interface". </li>
  <li>I am aware of how this works at the JVM bytecode level, what I want to know is what kind of code and datastructures are generated by the JVM after it is done loading the class files and compiling the bytecode. </li>
  </ul>