# Thursday, 20 June 2002
« Download | Main | No Title »
No Title

Sam Ruby: I<<K.VM.NET is a Java byte code to CIL converter (some prefer to call it MSIL, but not me).  My guess is that Jeroen is using the same hooks that CLAW does to modify the byte codes immediately prior to JIT, but in this case the translation is a wee bit more involved.

I'm not using the same hooks as CLAW, I'm using the AppDomain.TypeResolve event. This works very well together with Reflection.Emit, because it allows me to lazily emit a type whenever the CLR needs it. The one downside of it is that it doesn't provide the assembly where it thinks the type lives, so when I'm going to implement multiple classloader support I will need to mangle the classnames.

If all goes well, one should be able to simply put JAR files in a CLASSPATH and transparently call Java code from C#.

That's exactly the idea. My starter executable (the equivalent of jre.exe) looks like this:

public class Starter
 static void Main(string[] args)
  string[] vmargs = new string[args.Length - 1];
  for(int i = 1; i < args.Length; i++)
   vmargs[i - 1] = args[i];
  Type type = Type.GetType(args[0], true);
  MethodInfo main = type.GetMethod("main");
  main.Invoke(null, new object[] { vmargs });

I suspect the hardest part will be handling the class libraries - in particular three classes: Object, String, and Exception.

Exactly. Mapping java.lang.Object to System.Object turns out to be easy, they have the exact same virtual methods, but in order for this to work java.lang.String also has to be mapped to System.String, since string is final, not much to worry about (methods can be redirected to static helpers), except for one thing: interfaces. If java.lang.String implements an interface, System.String should implement the equivalent interfaces. In JDK 1.4 java.lang.String implements: Serializable, Comparable and CharSequence. Serializable has no methods, so it's not a big deal. Comparable maps nicely to System.IComparable, so that's easy, but CharSequence is a problem, System.String doesn't have that, so that interface will probably have to be emulated via some reflection hack. Of course, at the moment I'm aiming for JDK 1.1 compatibility, so it's not really an issue yet :-)

Thursday, 20 June 2002 10:36:27 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
Home page

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)

Comment (HTML not allowed)  

Live Comment Preview