www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - From the Department of Insane Ideas: D on the JVM

reply Gregor Richards <Richards codu.org> writes:
No, I'm not saying somebody should do it, I'm saying I've done it.

http://www.codu.org/nestedvm-gdc/

Using NestedVM, a tool that lets you compile anything GCC supports to 
Java bytecode, I've made a modified copy of GDC that can produce native 
Java .class files from D source.

What's the use? I don't know, I only did it to have a bit of perverse fun.

Sockets and threads don't work yet, and it's not extensively tested, but 
it works enough to get a simple Hello, World! compiled.

I'll put up full documentation on using it later, just thought the NG 
might be interested in knowing it exists.

  - Gregor Richards
Dec 12 2006
next sibling parent bobef <be lessequal_dontspam.com> writes:
LOL! Let me give you an idea if you like doing stuff like that. Can't 
you make PySWT work with D? Or something similar with GCJ?


Gregor Richards wrote:
 No, I'm not saying somebody should do it, I'm saying I've done it.
 
 http://www.codu.org/nestedvm-gdc/
 
 Using NestedVM, a tool that lets you compile anything GCC supports to 
 Java bytecode, I've made a modified copy of GDC that can produce native 
 Java .class files from D source.
 
 What's the use? I don't know, I only did it to have a bit of perverse fun.
 
 Sockets and threads don't work yet, and it's not extensively tested, but 
 it works enough to get a simple Hello, World! compiled.
 
 I'll put up full documentation on using it later, just thought the NG 
 might be interested in knowing it exists.
 
  - Gregor Richards

Dec 13 2006
prev sibling next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Gregor Richards wrote:

 Using NestedVM, a tool that lets you compile anything GCC supports to 
 Java bytecode, I've made a modified copy of GDC that can produce native 
 Java .class files from D source.
 
 What's the use? I don't know, I only did it to have a bit of perverse fun.
 Sockets and threads don't work yet, and it's not extensively tested,
 but it works enough to get a simple Hello, World! compiled.

Excellent hack! Will give it a try on Mac OS X, might even be useful. :) "NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file." "Entire virtual memory space mapped to a giant int[][] array indexed by page, then address. Breaking memory up by pages allows memory to be dynamically allocated." "Applications interact with the Operating System via the SYSCALL instruction. ... The syscall instruction is simply mapped to the syscall() method of the Runtime class." So it seems the only thing GDC needs is a "nestedvm" OS and "MIPS" CPU ? --anders PS. Quotes from http://www.zentus.com/nestedvm/ and their NestedVM.pdf
Dec 13 2006
parent reply Gregor Richards <Richards codu.org> writes:
Anders F Björklund wrote:
 Gregor Richards wrote:
 
 Using NestedVM, a tool that lets you compile anything GCC supports to 
 Java bytecode, I've made a modified copy of GDC that can produce 
 native Java .class files from D source.

 What's the use? I don't know, I only did it to have a bit of perverse 
 fun.
 Sockets and threads don't work yet, and it's not extensively tested,
 but it works enough to get a simple Hello, World! compiled.

Excellent hack! Will give it a try on Mac OS X, might even be useful. :) "NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file." "Entire virtual memory space mapped to a giant int[][] array indexed by page, then address. Breaking memory up by pages allows memory to be dynamically allocated." "Applications interact with the Operating System via the SYSCALL instruction. ... The syscall instruction is simply mapped to the syscall() method of the Runtime class." So it seems the only thing GDC needs is a "nestedvm" OS and "MIPS" CPU ? --anders PS. Quotes from http://www.zentus.com/nestedvm/ and their NestedVM.pdf

First off, for the skeptical: While all those quotes are true, it isn't as bad as it seems. It compiles the actual code to Java bytecodes, so it's not a virtual /execution/ environment, just virtual memory and a virtual syscall handler. OK, now on to what you actually asked: I'll be documenting how to get it all compiled soon. It's unfortunately a bit of a pain in the arse. Basically, you need to compile NestedVM (with GCC <4), then compile a newer GCC with GDC and my patch, with the same configure flags as those used for NestedVM. G'luck if you want to try it before I put up a doc :) - Gregor Richards
Dec 13 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Gregor Richards wrote:

 PS. Quotes from http://www.zentus.com/nestedvm/ and their NestedVM.pdf

First off, for the skeptical: While all those quotes are true, it isn't as bad as it seems. It compiles the actual code to Java bytecodes, so it's not a virtual /execution/ environment, just virtual memory and a virtual syscall handler.

I actually thought "was that all there was to it" and that it sounded easy, sorry if it sounded bad in any way. Patches to GDC were minimal*. I thought the virtual execution environment of the JVM was a feature :-) Somehow the idea of running a virtual OS in a virtual VM is hilarious. Running through your installation, just installing darcs and ghc first. (not sure if it's needed but seemed to be, so I use MacPorts to install) --anders * it probably could be cut down a bit, once the autoconf stuff is fixed.
Dec 13 2006
prev sibling next sibling parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Gregor Richards wrote:

 No, I'm not saying somebody should do it, I'm saying I've done it.
 
 http://www.codu.org/nestedvm-gdc/
 
 Using NestedVM, a tool that lets you compile anything GCC supports to
 Java bytecode, I've made a modified copy of GDC that can produce native
 Java .class files from D source.
 
 What's the use? I don't know, I only did it to have a bit of perverse fun.
 
 Sockets and threads don't work yet, and it's not extensively tested, but
 it works enough to get a simple Hello, World! compiled.
 
 I'll put up full documentation on using it later, just thought the NG
 might be interested in knowing it exists.
 
   - Gregor Richards

I suppose the most important question would be how to interface between Java and D. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Dec 13 2006
next sibling parent reply Gregor Richards <Richards codu.org> writes:
Lars Ivar Igesund wrote:
 Gregor Richards wrote:
 
 No, I'm not saying somebody should do it, I'm saying I've done it.

 http://www.codu.org/nestedvm-gdc/

 Using NestedVM, a tool that lets you compile anything GCC supports to
 Java bytecode, I've made a modified copy of GDC that can produce native
 Java .class files from D source.

 What's the use? I don't know, I only did it to have a bit of perverse fun.

 Sockets and threads don't work yet, and it's not extensively tested, but
 it works enough to get a simple Hello, World! compiled.

 I'll put up full documentation on using it later, just thought the NG
 might be interested in knowing it exists.

   - Gregor Richards

I suppose the most important question would be how to interface between Java and D.

Actually it's fairly simple. NestedVM provides a virtual syscall "CallJava" that allows you to send a few ints out, you catch that with a Java function that gets strings or whatnot, and then it goes out to the Java world. It also provides you with .call(), which allows you to call any extern (C) function in D from Java. - Gregor Richards
Dec 13 2006
parent reply Alexander Panek <a.panek brainsware.org> writes:
 Actually it's fairly simple. NestedVM provides a virtual syscall 
 "CallJava" that allows you to send a few ints out, you catch that with a 
 Java function that gets strings or whatnot, and then it goes out to the 
 Java world. It also provides you with .call(), which allows you to call 
 any extern (C) function in D from Java.

World impacts! I mean, wow. That sounds like a *very* useful feature, actually. You could use advantages of three languages. Pretty impressive.
 
  - Gregor Richards

Dec 13 2006
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Alexander Panek wrote:
 
 Actually it's fairly simple. NestedVM provides a virtual syscall 
 "CallJava" that allows you to send a few ints out, you catch that with 
 a Java function that gets strings or whatnot, and then it goes out to 
 the Java world. It also provides you with .call(), which allows you to 
 call any extern (C) function in D from Java.

World impacts! I mean, wow. That sounds like a *very* useful feature, actually. You could use advantages of three languages. Pretty impressive.
  - Gregor Richards


It IS impressive... although it starts sounding like possible early thoughts of those who went on to create .NET/Mono and SunONE, which also attempt to marry languages after a fashion. I'm keeping my eye on this "insane" project. -- Chris Nicholson-Sauls
Dec 13 2006
prev sibling parent reply renoX <renosky free.fr> writes:
 I suppose the most important question would be how to interface
 between Java and D.

To stay in the insane possibilities: D using Java's GC! renoX
Dec 13 2006
parent Gregor Richards <Richards codu.org> writes:
renoX wrote:
I suppose the most important question would be how to interface
between Java and D.

To stay in the insane possibilities: D using Java's GC! renoX

Unfortunately, I think this one is one step beyond insane to im{probable,possible}. - Gregor Richards
Dec 13 2006
prev sibling next sibling parent reply Alexander Panek <a.panek brainsware.org> writes:
What the... X_X

You seem to be pretty much bored, don't ya? :O

Apart from that, good work. Should be an argument against people 
shouting out loud about D not being capable of running inside a VM. ;)

Kind regards,
Alex
Dec 13 2006
parent reply Gregor Richards <Richards codu.org> writes:
Alexander Panek wrote:
 What the... X_X
 
 You seem to be pretty much bored, don't ya? :O
 
 Apart from that, good work. Should be an argument against people 
 shouting out loud about D not being capable of running inside a VM. ;)
 
 Kind regards,
 Alex

Bored? Nah, I just have a perverse sense of humor ;) It actually only took me a few hours to get this working. That's a good point - it may not be particularly useful, but for people in love with VMs ... who knows. - Gregor Richards
Dec 13 2006
parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Gregor Richards wrote:

 Alexander Panek wrote:
 What the... X_X
 
 You seem to be pretty much bored, don't ya? :O
 
 Apart from that, good work. Should be an argument against people
 shouting out loud about D not being capable of running inside a VM. ;)
 
 Kind regards,
 Alex

Bored? Nah, I just have a perverse sense of humor ;) It actually only took me a few hours to get this working. That's a good point - it may not be particularly useful, but for people in love with VMs ... who knows. - Gregor Richards

Or who are otherwise contracted to use Java/JVM at work ... -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Dec 13 2006
parent reply Alexander Panek <a.panek brainsware.org> writes:
Well, another thing would be reflection. Afaik, runtime reflection gets 
much easier when run in a VM, thus D could have reflection libraries 
just like Java - once being able to be run in a VM, that is.
Dec 13 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Panek schrieb am 2006-12-13:
 Well, another thing would be reflection. Afaik, runtime reflection gets 
 much easier when run in a VM, thus D could have reflection libraries 
 just like Java - once being able to be run in a VM, that is.

There is no need for VMs to do runtime reflection in D. Granted, Flectioned[1] currently only allows instanciating classes and structs and isn't yet a replacement for java.lang.reflect.*. But it is never the less interesting to see how the seperation between VM and non-VM capabilities isn't as clear as many would think. Thomas [1] http://svn.dsource.org/projects/flectioned/downloads/flectioned.zip -----BEGIN PGP SIGNATURE----- iD8DBQFFgQ0oLK5blCcjpWoRAlQ9AKCbfN/7a+AndVXVTZ51Y2p9R5cb9QCeKefF lg7B7mAtsB/twSCS3FS72jU= =29Wr -----END PGP SIGNATURE-----
Dec 13 2006
parent Alexander Panek <a.panek brainsware.org> writes:
I didn't mind to put your work down, of course not! I just wanted to 
point out, that there *are* Java reflection libraries with a pretty 
great approach (what I've heard from a Java programmer.. I didn't use 
them). And, again, I didn't want to put your work down. :)

Kind regards,
Alex
Dec 14 2006
prev sibling parent Gregor Richards <Richards codu.org> writes:
Gregor Richards wrote:
 No, I'm not saying somebody should do it, I'm saying I've done it.
 
 http://www.codu.org/nestedvm-gdc/
 
 Using NestedVM, a tool that lets you compile anything GCC supports to 
 Java bytecode, I've made a modified copy of GDC that can produce native 
 Java .class files from D source.
 
 What's the use? I don't know, I only did it to have a bit of perverse fun.
 
 Sockets and threads don't work yet, and it's not extensively tested, but 
 it works enough to get a simple Hello, World! compiled.
 
 I'll put up full documentation on using it later, just thought the NG 
 might be interested in knowing it exists.
 
  - Gregor Richards

I've added some basic documentation on compiling and installing nestedvm-gdc, as well as a nifty script 'gdcj' that does compilation and generation of .jar files for you :) http://www.codu.org/nestedvm-gdc/ - Gregor Richards
Dec 13 2006