-
Notifications
You must be signed in to change notification settings - Fork 0
Dynamic loading for Java #38
Comments
Yes. It is the "proper" way in Mu. The Alternatively Java can be implemented in "the Python way" where dictionary look-ups happen everywhere at run time, but that would be terribly inefficient. p.s. Previously I proposed not letting the Mu type system have Here is how I think vtable can be implemented: We can implement the vtable as an array (or hybrid) of function pointers, but each pointer points to a function of a generic signature (like We can define the vtable as this:
Assume there is a virtual call in class A {
void foo() {
B b = ...;
Object rv = b.bar(arg1, arg2, arg3);
}
}
class B {
public Object bar(int a, double b, String c) {...}
} And assume we loaded A, but know nothing about class B at this moment. The .class file of class A contains a method descriptor which has the signature of the callee
Here we use We must have created a vtable for class B even though class B has not been loaded yet. We must assign a slot in the vtable for the method Then the virtual call mentioned above can be translated as:
When B is actually loaded, if Some other problems: this does not work around field accesses. If field accesses are implemented as struct member access, then the layout of the class must be known when compiling the methods that access its fields. |
So Adam and I have run into an interesting question about how to do dynamic loading for Java. The thing is, one does not know all the details of a class in advance. Therefore, it is hard to give things signatures. Consider, for example, the vtable. We need to have Mu types for all the classes mentioned in all the methods -- the vtable will be a struct of function pointers, each pointer specifically typed. But that would force eager loading of the entire universe to figure out the types!
The only alternative seems to be to refcast all over the place at run time. Is that the intent? (Coming from Java I had a (mistaken) bias that this involves a cost, but I see on referring to the spec that refcast does not involve any run-time work.)
The text was updated successfully, but these errors were encountered: