Tagged: jvm

Send code, not data

There are times when it is more appropriate to send a chunk of code to another machine rather than receive a large amount of data. One would think this would be more practical with portable languages running on the CLR or JVM. One should be able to serialize a method, then regenerate the method on another machine. Fortunately, this post describes how to generate a DynamicMethod from a MethodInfo in .NET. The next step is to serialize the MethodInfo instance, which looks a bit tricky. I’m still looking into that.

Compiler generator using method inlining

It should be possible to write a language interpreter on top of Java or .NET and rely on method inlining to instantly get compiled code. Implement most of your interpreter opcodes as small static methods: Add, Subtract, LessThan, etc. Translate your language into Java/C# methods that call these opcodes. When the JIT sees all these small static methods, it should inline and optimize them. Presto! You’ve just written a compiler. It’s a bit like using partial evaluation to generate a compiler from an interpreter. I think Peter Sestof did this the hard way a long time ago.