The development of a Java VM for .NET
Suppose you have the following Managed C++ class:
__gc
[...] void foo(int32 i) [...][...] void foo(int32 modopt([Microsoft.VisualC]Microsoft.VisualC.IsLongModifier) l) [...]
The long parameter is annotated with the optional modifier Microsoft.VisualC.IsLongModifier. Modifiers are part of the signature, so it is legal to have signatures that differ only by modifier.
Now, suppose IKVM.NET is compiling the following Java class:
class Foo { Bar foo(Bar o) {} Baz foo(Baz o) {}}
Also suppose that Bar and Baz are not yet available when the class is compiled. For the types that are not available, java.lang.Object is substituted, so now we again have two methods with the same signature. It would have been nice to use a custom modifier to resolve this, but this isn't possible for two reasons:
The solution is to use method name mangling. The next problem is that we need a place to store the name of the class that the arguments and return value actually are. The most obvious way to do this is custom attributes. Method arguments (parameters) can be annotated with custom attributes using MethodBuilder.DefineParameter(...). Parameters are indexed starting at one, this (and the ilasm syntax) suggests that zero refers to the return type, unfortunately DefineParameter throws an exception when it is called with zero. This bug also exists in both .NET 1.0 and 1.1. Again the work around is easy, just emit a method attribute and put the real return type class in there.
Remember Me
I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.
Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)