Jump to content




JavaL: Java bytecode interpreter

utility java lua

20 replies to this topic

#1 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 01 January 2013 - 03:52 PM

JavaL (instead of LuaJ, you know?)

Basically, sort of like that n00b programming language ComputerCraftFan11 is writing, except instead of parsing Java source code (which would be a pain in the a**), it parses either Java bytecode (directly), or disassembled (through `javap -c`) code.

That way, instead of relying on people to program according to a strict standard supported by the interpreter (durr, you must put one statement on each line and you have to have braces on the same line and no extra whitespace), the interpreter only needs to rely on the (inherently strict) bytecode produced by the Java compiler (or, if you're really desperate, yourself).

That's what I'm working on right now, using Wikipedia and the Java VM Specs as reference.

Feedback?

Screenies!
Spoiler

Edited by pokepal101, 03 January 2013 - 12:32 AM.


#2 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 01 January 2013 - 03:54 PM

Maybe I misunderstood, but since when can you run java code directly through computercraft?

#3 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 01 January 2013 - 05:58 PM

View PostDlcruz129, on 01 January 2013 - 03:54 PM, said:

Maybe I misunderstood, but since when can you run java code directly through computercraft?
Maybe I wasn't clear. I was actually talking about writing a Java VM in Lua (which, of course, CC can run).

On an unrelated note, here's a screenshot of it!
Posted Image

#4 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 01 January 2013 - 06:16 PM

View Postpokepal101, on 01 January 2013 - 05:58 PM, said:

View PostDlcruz129, on 01 January 2013 - 03:54 PM, said:

Maybe I misunderstood, but since when can you run java code directly through computercraft?
Maybe I wasn't clear. I was actually talking about writing a Java VM in Lua (which, of course, CC can run).

On an unrelated note, here's a screenshot of it!
Posted Image

o_O it's done already?

#5 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 January 2013 - 12:24 AM

View PostDlcruz129, on 01 January 2013 - 06:16 PM, said:

View Postpokepal101, on 01 January 2013 - 05:58 PM, said:

* snip *

o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.

#6 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 02 January 2013 - 02:05 AM

View PostOrwell, on 02 January 2013 - 12:24 AM, said:

View PostDlcruz129, on 01 January 2013 - 06:16 PM, said:

View Postpokepal101, on 01 January 2013 - 05:58 PM, said:

* snip *

o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Yes, I've got quite a fair bit to go. (Actually, not that much towards a Hello World compatible JVM) Although, flicking through the JVM specifications, it doesn't look like too big a job. Mainly just keeping everything readable (without having access to OOP) and implementing all those 200 opcodes.........

#7 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 January 2013 - 02:10 AM

View Postpokepal101, on 02 January 2013 - 02:05 AM, said:

View PostOrwell, on 02 January 2013 - 12:24 AM, said:

View PostDlcruz129, on 01 January 2013 - 06:16 PM, said:

View Postpokepal101, on 01 January 2013 - 05:58 PM, said:

* snip *

o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Yes, I've got quite a fair bit to go. (Actually, not that much towards a Hello World compatible JVM) Although, flicking through the JVM specifications, it doesn't look like too big a job. Mainly just keeping everything readable (without having access to OOP) and implementing all those 200 opcodes.........
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P At least if you want it to run at a bearable speed...

#8 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 02 January 2013 - 06:18 AM

View PostOrwell, on 02 January 2013 - 02:10 AM, said:

I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P At least if you want it to run at a bearable speed...
For Redpower 2?! Java emulator! :o

#9 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 January 2013 - 07:01 AM

View Posttiin57, on 02 January 2013 - 06:18 AM, said:

View PostOrwell, on 02 January 2013 - 02:10 AM, said:

I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P At least if you want it to run at a bearable speed...
For Redpower 2?! Java emulator! :o
Not a Java emulator :P A 65EL02 bytecode emulator written in Lua. There will also be a compiler and a way to flash the 65EL02 from CC using bundled cables. :) I could try and port an existing open source Java emulator to the 65EL02.. would be challenging with those specs though.

#10 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 02 January 2013 - 03:28 PM

View PostOrwell, on 02 January 2013 - 02:10 AM, said:

I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P At least if you want it to run at a bearable speed...
I'm not that worried about efficiency :D. It it runs at 1 FLOPS, deal with it. But if I can't find my way around the growing labyrinth of code...

#11 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 January 2013 - 03:42 PM

View Postpokepal101, on 02 January 2013 - 03:28 PM, said:

View PostOrwell, on 02 January 2013 - 02:10 AM, said:

I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P At least if you want it to run at a bearable speed...
I'm not that worried about efficiency :D. It it runs at 1 FLOPS, deal with it. But if I can't find my way around the growing labyrinth of code...
Fair point. :)

#12 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 03 January 2013 - 12:35 AM

View PostOrwell, on 02 January 2013 - 12:24 AM, said:

He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Here's another step! JavaL can now print the disassembled bytecode of a Java program! Almost there!!!
Spoiler


#13 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 03 January 2013 - 12:42 AM

This is exciting..! :D I think that you'll have more work than you expect though. :P I know that I have for my own.

#14 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 03 January 2013 - 01:35 AM

View PostOrwell, on 03 January 2013 - 12:42 AM, said:

This is exciting..! :D/> I think that you'll have more work than you expect though. :P/> I know that I have for my own.
http://en.wikipedia....uction_listings
Push to stack... Pop from stack... Look-up from constant pool... Numerical local variables...
Doesn't look too difficult from here on in.
The lack of OOP in Lua might become a problem later down the track though...

#15 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 03 January 2013 - 01:44 AM

The problems lie more in stuff like unsigned bytes and big endian and other stuff that's non-trivial in Lua... But you'll be ok. Java is designed to be emulated anyway, so that's an advantage. :)

#16 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 03 January 2013 - 01:55 AM

View PostOrwell, on 03 January 2013 - 01:44 AM, said:

The problems lie more in stuff like unsigned bytes and big endian and other stuff that's non-trivial in Lua... But you'll be ok. Java is designed to be emulated anyway, so that's an advantage. :)/>
Unsigned bytes? Just... read a number....... Lua doesn't care.
Big endian? The majority of numbers in class files are 2-bytes long. I couldn't have gotten this far without implementing that!
function readu2()    --Read unsigned 2-byte integer
    bit.blshift(byte1, 8) + byte2
end


#17 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 03 January 2013 - 02:02 AM

I know, those were just examples. About signedness, Lua doesn't care, but the simulated machine does, I'm not sure about the JVM, but I had to implement both explicitly. Well, you can keep on proving how simple it is, I believe you anyway. :) My experience just says that you will hit at least one wall somewhere, but we'll see. :P

I must say, I can see your doing a good job at this. :) And I notice that you have a good understanding of computer systems and architecture. :) I'm rather curious!

#18 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 03 January 2013 - 02:08 AM

View PostOrwell, on 03 January 2013 - 02:02 AM, said:

I notice that you have a good understanding of computer systems and architecture. :)
Really? I honestly don't. I still don't get the difference between 32-bit and 64-bit computers :) I'm just a unix-head who uses C when he has to.

#19 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 03 January 2013 - 02:14 AM

View Postpokepal101, on 03 January 2013 - 02:08 AM, said:

View PostOrwell, on 03 January 2013 - 02:02 AM, said:

I notice that you have a good understanding of computer systems and architecture. :)
Really? I honestly don't. I still don't get the difference between 32-bit and 64-bit computers :) I'm just a unix-head who uses C when he has to.
In that case, I'm even more curious. :P Addressing width might even be something you need to take in consideration (not sure, I'm not that knowledgeable about the JVM).

Btw, I just checked and the JVM is quite chill about signedness. :) Basically it uses unsigned bytes or signed shorts.

Edit: Also, most emulators are written using the procedural paradigm instead of object oriented. It would be quite hard to implement OOP into the design (I have the cpu and ram as the only types, the rest are all helper functions that take the cpu as argument). I'm sure you could do better, though often OOP is traded for efficiency.

#20 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 03 January 2013 - 12:17 PM

If you plan on being able to just run an arbitrary Java program, you then need the entire Java part of the jvm library, which then relies on native libraries that I'm unsure how easily you'll be able to achieve if at all loading of jni native libs.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users