Object-Oriented Virtual Machines


The Java Virtual Machine and the .NET Common Language Runtime have enough in common that, for the purposes of this Scheme compiler, they can be described together. Both are designed to support the efficient execution of a statically typed, object-oriented, byte-code language. Although Java and C# are the preferred programming languages for both runtimes , they are really compiled to a high-level, stack-based, byte-code language. For the most part, both byte-code languages are similar enough that little extra work was needed to support both VMs as back ends for the Hotdog Scheme compiler.

Both VMs execute the byte-code instructions at runtime. The byte code is first verified to confirm that it complies with the type and safety protocols of the virtual machine. Although some VMs interpret the instructions, the fastest VMs dynamically compile the instructions into native machine code with a just-in-time (JIT) compiler. All virtual machines support garbage collection, but it is tuned for the allocation patterns of typical object-oriented programs. Finally, the type system, instruction set, and runtime system offer explicit support for object-oriented programs: classes with methods and fields, virtual method dispatch on a single receiver object, single inheritance, reflection, and so on. Although these features are crucial to supporting Java and C#, they complicate the compilation of fundamentally different languages.

For many languages, including Scheme, a significant difference between the CLR and JVM runtimes is the JVM's failure to support proper tail recursion. Briefly, tail recursion is when the last instruction in a routine is a method call. Because the stack frame of the calling routine is no longer required ”after all, it will simply return the value it receives ”it should be removed. Functional languages often express loops as recursive function calls, which allow for more powerful constructs than the primitive "do-while" statements in imperative languages. Without proper tail recursion, however, this style will consume all the provided stack space and raise an exception. Although tail calls can be faked on the JVM, this process exacts an enormous performance penalty.



Programming in the .NET Environment
Programming in the .NET Environment
ISBN: 0201770180
EAN: 2147483647
Year: 2002
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net