I'm writing my own toy Dalvik VM, and I can't seem to figure out how dalvik handles inherited static fields.
Consider the following java code:
class Parent { static int parent_int = 10; }
class MyCode extends Parent {
public static void main(String[] args){
System.out.println(parent_int + 1);
}
}
When compiled and run with javac and java it prints 11 to the console, as one would expect. However, when this is compiled to dalvik, the parent_int value is turned into an sget statement to get field@0000, whilst in the <clinit> method of Parent the field id of parent_int is field@0001.
In my implementation of the Dalvik VM this becomes a problem, since field@0000 is not initialized, even though the Parent class and field@0001 has been.
How does the Dalvik VM handle this? How does it know that they are related, and should be considered the same? And why have they been turned into two different fields in the first place, when they could just as well be one?
from How come the same static field has two different ids in dalvik?
No comments:
Post a Comment