This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ds84182's profile picture

JVML - Java Virtual Machine emulation in ComputerCraft

Started by ds84182, 13 February 2014 - 08:17 AM
ds84182 #1
Posted 13 February 2014 - 09:17 AM
Last weekend, I started a project to port the Java Virtual Machine to ComputerCraft. Although I rage quitted the project (Alot :P/>), I now have a somewhat working version, running on a ComputerCraft computer! Currently I have 132 instructions, not including the instructions that I have created so that the example demo would work.

Currently, my only problem is porting rt.jar from the real java. I cannot just use the jar as is, because rt.jar exists to wrap around several native methods (like the System class). Fortunately, I am making a library to interface with the computers and turtles, I might even support peripherals in the near future!

As of now, I can run this program on the computer. This is what it outputs:

FAQ Time!:
  • Q: Can I run Minecraft in ComputerCraft?
  • A: Technically, yes, but you would have to make a LWJGL port to CCLights2 in order to see anything!
  • Q: Can I run a Minecraft Server in ComputerCraft?
  • A: Yes, you can, given that you have a socket peripheral to allow connections from a Minecraft client.
  • Q: Can I run LuaJ in ComputerCraft?
  • A: Yes, you can run LuaJ in ComputerCraft, although you might want to do a little porting magic.
  • Q: Can I run __________ in ComputerCraft?
  • A: Sure.
  • Q: How fast is it?
  • A: I haven't tested how fast JVML is, but there is room for lots of optimizations!
  • Q: Why haven't you ported rt.jar entirely?
  • A: Because rt.jar is a flustercuck of classes, and all of them including their methods have to be ported to Lua.
Github: https://github.com/ds84182/JVML
Edited on 10 March 2014 - 10:33 PM
TechMasterGeneral #2
Posted 13 February 2014 - 09:34 AM
Interesting…
awsmazinggenius #3
Posted 13 February 2014 - 09:43 AM
Nice job there :)/>
nutcase84 #4
Posted 13 February 2014 - 10:38 AM
MC in MC in MC in

XD looks amazing, I can host a MC server! In a MC server! In a MC Server!
Alice #5
Posted 13 February 2014 - 10:50 AM
Somehow I have the feeling I will be using this in the near future.
xBlizzDevious #6
Posted 13 February 2014 - 11:11 AM
This is… This is beyond amazing. I…. I don't know what to say, but eh, nice work! I may have to test this one day and just for the sake of it, play Minecraft, within Minecraft, within Minecraft… On a Minecraft server that's inside a Minecraft server that's inside a Minecraft server. I am curious, though; it should run reasonably well, I'm sure, running just one Minecraft inside Minecraft, but what happens if you start doing Minecraft inside Minecraft inside Minecraft? Will it start to become beyond laggy?
6677 #7
Posted 13 February 2014 - 11:32 AM
This is… This is beyond amazing. I…. I don't know what to say, but eh, nice work! I may have to test this one day and just for the sake of it, play Minecraft, within Minecraft, within Minecraft… On a Minecraft server that's inside a Minecraft server that's inside a Minecraft server. I am curious, though; it should run reasonably well, I'm sure, running just one Minecraft inside Minecraft, but what happens if you start doing Minecraft inside Minecraft inside Minecraft? Will it start to become beyond laggy?
Actually 1 minecraft inside 1 minecraft would already be unusably slow
Alice #8
Posted 13 February 2014 - 11:34 AM
This is… This is beyond amazing. I…. I don't know what to say, but eh, nice work! I may have to test this one day and just for the sake of it, play Minecraft, within Minecraft, within Minecraft… On a Minecraft server that's inside a Minecraft server that's inside a Minecraft server. I am curious, though; it should run reasonably well, I'm sure, running just one Minecraft inside Minecraft, but what happens if you start doing Minecraft inside Minecraft inside Minecraft? Will it start to become beyond laggy?
Actually 1 minecraft inside 1 minecraft would already be unusably slow
It's Minecraft in ComputerCraft in Minecraft, so most likely it will be.
Playing it on a server would be suicide.
Yevano #9
Posted 13 February 2014 - 06:26 PM
That's really cool! Have you been able to port anything interesting to it yet? You should write a JIT compiler for it which targets Lua bytecode, lol.
Csstform #10
Posted 17 February 2014 - 01:05 PM
Can I SEE minecraft in minecraft? :3
Thib0704 #11
Posted 17 February 2014 - 04:26 PM
One word: AMAZING!!!!!
ElvishJerricco #12
Posted 18 February 2014 - 08:55 AM
I'd be very interested in working with this. I think it'd be fun to try to JIT the java bytecode to lua bytecode and to work with the natives structure java uses to create adapter classes for CC APIs.
Mads #13
Posted 22 February 2014 - 12:00 PM
My gut tells me that you're just using something like
str:gsub("System.out.println", "print")
, since you write "instructions". Of course you can't write a JVM emulator in CC(it'd be slow as hell and very limited), let alone in the time that has passed since last weekend.

Of course, you could also mean instructions as in the ones in bytecode, and if so, I applaud you.
Edited on 22 February 2014 - 11:01 AM
Alekso56 #14
Posted 22 February 2014 - 01:02 PM
look guyze i found dis randomly on ds's github!+1
https://github.com/ds84182/JVML
Symmetryc #15
Posted 22 February 2014 - 02:40 PM
My gut tells me that you're just using something like
str:gsub("System.out.println", "print")
, since you write "instructions". Of course you can't write a JVM emulator in CC(it'd be slow as hell and very limited), let alone in the time that has passed since last weekend.

Of course, you could also mean instructions as in the ones in bytecode, and if so, I applaud you.
It doesn't run java code, it interprets the .class files (compiled java).
ElvishJerricco #16
Posted 01 March 2014 - 10:04 AM
look guyze i found dis randomly on ds's github!+1
https://github.com/ds84182/JVML

I'm having waaaay too much fun with a fork of this…
Edited on 01 March 2014 - 09:11 AM
Yevano #17
Posted 16 March 2014 - 02:48 AM
If anyone's interested, I've been working on JIT for this for over a week now. It has been loads of fun. Not everything works yet, and even simple things can break it, but I wanted to go ahead and commit it for those interested in this sort of thing. Maybe I can even get some help. :)/>

https://github.com/Yevano/JVML-JIT

Edit: Originally this was a fork, but I felt it diverged too much from the original code and was too experimental for it to make sense to merge it to the main repo. It does change the entire execution scheme, after all. For these reasons, I pushed all my history to a new repo and deleted my original fork.
Edited on 16 March 2014 - 02:54 AM
apemanzilla #18
Posted 18 March 2014 - 03:45 PM
Soo

JVM inside a Lua emulator inside JVM?!?

What about… Cc-emu? CC-emu in a JVM in a Lua emulator in minecraft in JVM?
gamemanj #19
Posted 17 August 2014 - 04:34 PM
A JVM in Lua,by itself,without needing ComputerCraft integration,is amazing.
I wonder how much more useful ComputerCraft will be-
Especially since as far as I can tell CPU emulator writers avoid Lua like the plague for some reason…
(Edit:Just looked at the rt.jar implementation.Advice for anyone who wants to use this:1.Keep JDK 8 on hand,2.Yevano's fork reimplementation's rt.jar replacement seems to at least keep the String class as a real class,so you might want to edit JVML itself so that you can do the same,and 3.Again,keep JDK 8 on hand!)
Edited on 17 August 2014 - 07:19 PM
0099 #20
Posted 23 August 2014 - 02:30 PM
Take Minecraft server in Minecraft, add a couple (thousands) of command blocks with computers as controllers and comparator feedback - and you can build Matrix in Minecraft!
zekesonxx #21
Posted 25 August 2014 - 07:27 PM
Shouldn't this suffer from incorrect math due to Lua number rounding?
Wiiplay123 #22
Posted 13 September 2014 - 06:09 PM
So can it run .jar files yet?
MKlegoman357 #23
Posted 13 September 2014 - 07:11 PM
So can it run .jar files yet?

Latest commit was 6 months ago, I don't think it had changed. But, Yevano did something similar to this, maybe even better. He made a JVML-JIT which can convert Java programs/code/bytecode (I don't remember which) to Lua bytecode, thus making your Java programs run pretty fast and smooth.
ElvishJerricco #24
Posted 17 September 2014 - 11:55 AM
So can it run .jar files yet?

Latest commit was 6 months ago, I don't think it had changed. But, Yevano did something similar to this, maybe even better. He made a JVML-JIT which can convert Java programs/code/bytecode (I don't remember which) to Lua bytecode, thus making your Java programs run pretty fast and smooth.

Yevano and I have been working on and off on JVML-JIT for a while now. It's tough stuff, but yea the goal is to JIT java class files to Lua for some pretty fast Java in CC. Any help is welcome in a pull request!
RoD #25
Posted 30 September 2014 - 07:57 PM
Exciting!
RoD #26
Posted 30 September 2014 - 08:18 PM
Quick noob question: how am i supoused to run a program?
ElvishJerricco #27
Posted 01 October 2014 - 08:26 AM
Quick noob question: how am i supoused to run a program?

So this thread is old and outdated. Yevano and I have been working on JVML-JIT for a while now and it's going well, but we haven't felt confident enough to release it to the forums yet. I suppose until then this thread can act as a discussion thread of sorts…

Anyway to install, you need to run the installer from pastebin (pastebin run NzNwtBQy). Or if you want access to the test suit and a lot of files that are unnecessary to end users and don't care about not being able to install it through a simple pastebin command, then you can just clone the github repo.

The main program you'll use is bin/jvml (I suggest you add the bin folder to your shell's path). The usage is jvml <class name>, or jvml -jar <jar name> if you have an executable jar.

Compiling against CCLib instead of your local java development kit is also important. You'll want to compile your java programs with the bootclasspath argument specified. e.g. javac -bootclasspath CCLib/jar/cc_rt.jar MyProgram.java. You might not run into problems if you don't do this, but doing this guarantees you won't run into those problems.