Set the declaring class of obsolete ArtMethods during redefinition

During structureal redefinition, we create a new class with a new set of
methods and fields and replace all old classes and their instances with
new class and newly created instances. We also retain the old class to
let any old methods that were still on stack during redefinition to
finish their execution. When replacing the old classes with new class we
should take care that the old method's declaring class isn't replaced.
It is very hard to ensure this since when walking the objects / roots
it is hard to check if the current reference is actually a declaring
class. We had this logic earlier but is a little brittle with addition
of any new roots.

This CL actually adds the logic so we can just replace all old class
reference with new class and we undo the changes for the old class's
methods and fields.

Bug: 206029744
Test: art/test.py
Change-Id: I96c5509f07562910cb1883cb5bf1236d01048213
1 file changed