develooper Front page | perl.perl6.internals | Postings from May 2002

jvm.ops

Thread Next
From:
Leon Brocard
Date:
May 1, 2002 01:51
Subject:
jvm.ops
Message ID:
20020501085217.GA487@ns0
Over the weekend I've been thinking about Targeting Parrot. My
thoughts went something like this: Parrot is a register machine. The
Java virtual machine is a stack machine. Parrot is also a stack
machine. Instead of converting Java bytecode to Parrot bytecode, I can
make Parrot into a JVM. And lo, so I did (for a small number of opcodes):

This is Java source code:

public static void spin() {
  int i;
  for(i = 0, i < 12345678; i++);
  System.out.print(i);
}

which turns into the following Java bytecode:

   0 iconst_0
   1 istore_0
   2 goto 8
   5 iinc 0 1
   8 iload_0
   9 sipush 1000
  12 if_icmplt 5
  15 getstatic #3 <Field java.io.PrintStream out>
  18 iload_0
  19 invokevirtual #4 <Method void print(int)>
  22 return

On a different VM, not so far away:

# This is Parrot assembler:
      iconst_0
      istore_0
      goto	IN
REDO: iinc      0, 1
IN:   iload_0
      sipush    12345678
      if_icmplt REDO
      iload_0
      jvm_print
      end

Cute, huh? Of course, Java interpreters are very optimised (and
non-dynamic) and without JITs doing it in Parrot is about 6 times
slower, but it's interesting nevertheless. Is this the kind of thing I
should be doing? I've attached a fledgling jvm.ops. Does my C code
look ok?

Leon
-- 
Leon Brocard.............................http://www.astray.com/
Nanoware...............................http://www.nanoware.org/

.... (c) The Intergalactic Thought Association


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About