XMLVM.org Main Page Overview Documentation Stories Download Contribute Contact Check out our tutorials
Header

Overview: Frontend

At the core of XMLVM is an XML-representation of byte code programs. Such programs are typically executed by a virtual machine. Two prominent virtual machines are Sun Microsystem's Java Virtual Machine (JVM) and Microsoft's Common Language Runtime (CLR) that is part of the .NET framework. Both these virtual machines implement stack-based operations; i.e., byte code instructions retrieve and store their arguments via a stack.

The front-end of the XMLVM toolchain translates byte code programs to XML. Currently XMLVM supports Java VM and CLR instructions. A Java or a .NET program are first compiled by a native compiler. The result is a Java class file or a .NET executable respectively. The XMLVM front-end takes these binary files as input and generates an XML document. We make use of XML-namespaces to represent byte code instructions from different virtual machines.

XMLVM Frontend

In the following we demonstrate this translation process for the Java and C# version of the familiar "Hello World" program. Consider the "Hello World" program in Java:

public class HelloWorld
{
  static public void main(String[] args)
  {
    System.out.println("Hello World");
  }
}

This Java program is first compiled to a Java class file and then translated by XMLVM to the following XML-document:

<vm:xmlvm xmlns:vm="http://xmlvm.org" xmlns:jvm="http://xmlvm.org/jvm">
  <vm:class name="HelloWorld" extends="java.lang.Object">
    <vm:method name="main" isPublic="true" isStatic="true" stack="2" locals="1">
      <vm:signature>
        <vm:return type="void" />
        <vm:parameter type="java.lang.String[]" />
      </vm:signature>
      <vm:code>
        <jvm:var name="args" id="0" type="java.lang.String[]" />
        <jvm:getstatic class-type="java.lang.System" type="java.io.PrintStream" field="out" />
        <jvm:ldc type="java.lang.String" value="Hello World" />
        <jvm:invokevirtual class-type="java.io.PrintStream" method="println">
          <vm:signature>
            <vm:return type="void" />
            <vm:parameter type="java.lang.String" />
          </vm:signature>
        </jvm:invokevirtual>
        <jvm:return />
      </vm:code>
    </vm:method>
  </vm:class>
</vm:xmlvm>

We refer to this document XMLVMJVM since it features byte code instructions from the Java virtual machine. It contains the same information that is present in HelloWorld.class. The <vm:class> tag describes the details of the Java class HelloWorld and the <vm:method> tag the details of the method main. The attributes locals and stack denote the number of local variables and number of stack elements respectively needed for this method. The <vm:code> tag finally contains the the byte code instructions that reflect the implementation of the main-method. The <jvm:getstatic> tag pushes the object reference stored in the static member System.out onto the stack. <jvm:ldc> (load constant) pushes the string "Hello World" onto the string. The <jvm:invokevirtual> instruction finally calls method println of the object pointed to by the previously pushed reference with "Hello World" as the actual parameter. <jvm:return> finally leaves the scope of the main-method.

A .NET program can be translated to XMLVMCLR analogously. The following is the C# version of "Hello World":

using System;
class HelloWorld {
  public static void Main()
  {
    Console.WriteLine("Hello World");
  }
}

This C# program is first compiled to a .NET executable and then fed into our toolchain to yield the following XMLVMCLR:

<vm:xmlvm xmlns:vm="http://xmlvm.org" xmlns:clr="http://xmlvm.org/clr">
  <vm:class name="HelloWorld" extends="System.Object">
    <vm:method name="Main" isStatic="true" isPublic="true" stack="8" locals="0">
      <vm:signature>
        <vm:return type="void" />
      </vm:signature>
      <vm:code>
        <clr:ldc type="System.String" value="Hello World" />
        <clr:call has-this="false" class-type="System.Console" method="WriteLine">
          <vm:signature>
            <vm:return type="void" />
            <vm:parameter type="System.String" />
          </vm:signature>
        </clr:call>
        <clr:return />
      </vm:code>
    </vm:method>
  </vm:class>
</vm:xmlvm>

The general structure of XMLVMCLR is identical to XMLVMJVM. The main difference is that XMLVMCLR features byte code instructions supported by the .NET virtual machine. The <clr:ldc> instruction pushes the string "Hello World" onto the stack. The <clr:call> instruction calls the static method System.Console.WriteLine with the string "Hello World" as the actual parameter.

SourceForge.net Logo