Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Scipi on January 31, 2012, 09:47:51 pm

Title: nJava - Nspire JVM
Post by: Scipi on January 31, 2012, 09:47:51 pm
Hello.

As you can guess my the title, I am starting a project to port a Java Virtual Machine to the Nspire.

So far I have found an open sourced JMV here

http://jamvm.sourceforge.net/ (http://jamvm.sourceforge.net/)

That I believe can be ported to the Nspire. It is also written almost entirely in C so I think that'll help.

What I want to do is basically be able to take any Java byte code, and be able to run it on the Nspire. (Possible Minecraft, anyone?) :P

However, I don't know where to start with this project. I downloaded the source for the JVM and found the main file, however I do not know what I need to do to port it to the Nspire.

I hope that this can become a community project where anyone can contribute, because if it were only myself, it might never come to fruition, which would be a shame.

So, first question, where do I start? ExtendeD suggested to me earlier to try to compile the project as is using the Ndless SDK to see what dependencies aren't supported, although I don't know what I should make for a makefile to do that.

Thanks!
Title: Re: nJava - Nspire JVM
Post by: Juju on January 31, 2012, 09:49:42 pm
That might be pretty awesome. Good luck on the project! :D
Title: Re: nJava - Nspire JVM
Post by: hellninjas on January 31, 2012, 09:50:50 pm
:O This makes me want to leanr Java!!! DO NOW !! lol
Now if only this could be done with C++ D:
Title: Re: nJava - Nspire JVM
Post by: jwalker on January 31, 2012, 10:18:30 pm
i might be interested. also did you try what extended suggested, thats how i would do it, get one bug out at a time
Title: Re: nJava - Nspire JVM
Post by: Scipi on January 31, 2012, 10:23:48 pm
i might be interested. also did you try what extended suggested, thats how i would do it, get one bug out at a time

Well, I'm trying to figure out how to try what Extended suggested. I don't exactly know what I need to do with make, includes, etc.
Title: Re: nJava - Nspire JVM
Post by: jwalker on January 31, 2012, 10:26:11 pm
how many includes and files are there??
im sick so i have plenty of time on my hands...
i think i will be home tomorrow too
Title: Re: nJava - Nspire JVM
Post by: Scipi on January 31, 2012, 10:30:49 pm
A ton. I count at least 47 files. D:

I have some time on my hands. Mainly on the Weekends though.

Title: Re: nJava - Nspire JVM
Post by: jwalker on January 31, 2012, 10:36:57 pm
i got it unzipped and everything, and there are alot... i'll take a better look at it in the morning
Title: Re: nJava - Nspire JVM
Post by: Scipi on January 31, 2012, 10:46:17 pm
Yeah, once this gets started I'll start a sourceforge project for it, or perhaps a DropBox Shared Folder.

Something for multiple people to collaborate on the project.
Title: Re: nJava - Nspire JVM
Post by: AzNg0d1030 on January 31, 2012, 10:52:13 pm
See, now is the part where I wish I didn't stop learning Java
Title: Re: nJava - Nspire JVM
Post by: willrandship on February 01, 2012, 01:24:44 am
You won't see minecraft. It uses a few native code libs which will be worse to port than the whole JVM, like LWJGL.

Not to say you shouldn't do it! There's plenty of stuff (games) that run with pure java libs.
Title: Re: nJava - Nspire JVM
Post by: Reo on February 01, 2012, 01:36:21 am
Is there any way that we would be able to use the Jazelle (http://en.wikipedia.org/wiki/Jazelle) instruction set that the Nspire's ARM processor apparently supports?
Title: Re: nJava - Nspire JVM
Post by: Lionel Debroux on February 01, 2012, 02:06:20 am
First of all: such projects are interesting because they can indeed help filling in the blanks of the Ndless infrastructure, and therefore help other projects, which is a good reason to pursue them - not to mention that they can be a good learning experience :)

But if the port of JamVM and its dependencies (GNU Classpath...) is completed, people should not set their hopes too high about its speed, for the practical purposes of, say, running Java games on the Nspire. Not to say that it shouldn't be done, but here are several facts:
* JamVM's performance is better than that of a number of other JVMs, but it's not the most optimized JVM for ARM platforms. The one in OpenJDK / IcedTea (well, Sun/Oracle's code) is, but chances are that it's harder to compile than JamVM is, and it definitely has a much larger fooprint;
* GNU Classpath (which is what released versions of JamVM use) is missing lots of classes and methods, and it's unmaintained; OpenJDK's class library is not necessarily very easy to compile either, and it has a larger footprint than GNU Classpath has, because it's more complete.

I'm speaking out of my recent professional experience with Java (precisely JamVM, GNU Classpath, OpenJDK) and native code on recent ARM platforms, and I don't mean to bash Java ;)
The platforms I've used / I'm using have superscalar Cortex-A8/A9 processors (i.e. more advanced than the ARM9 in Nspires), clocked at much higher frequencies (4x-8x), and they have much more RAM (512 MB or 1 GB), than Nspires... and yet, on such platforms, CPU-intensive native code is more or less an order of magnitude slower than on modern x86_64 cores. What performance can interpreted languages achieve on platforms which are nearly an order of magnitude less powerful than those ? Yeah, probably not much better than TI's proprietary, non-standard Lua, or a third-party port of LuaJIT ;)


Reo: well, open source software is unlikely to use Jazelle, read more thoroughly the page you've pointed ;)


Again, there are plenty of valid reasons for working on such a project, some of them are mentioned in the first paragraph. But speed for practical matters is unlikely to be one of them.
Title: Re: nJava - Nspire JVM
Post by: Jim Bauwens on February 01, 2012, 02:17:47 am
Maybe you should take a look at Java ME (phoneME). Its specifically made for (simple) mobile phones, so I assume it will have a lighter footprint.
There are a ton of games that work on it, and its open source :)
Title: Re: nJava - Nspire JVM
Post by: Reo on February 01, 2012, 02:19:03 am
Reo: well, open source software is unlikely to use Jazelle, read more thoroughly the page you've pointed ;)
Obviously a non-ARM specific virtual machine wouldn't use Jazelle, we'd have to find a way to implement it ourselves.
Title: Re: nJava - Nspire JVM
Post by: Jim Bauwens on February 01, 2012, 02:21:05 am
I think the point is that its very badly documented, making it much harder to do something with it :)
Title: Re: nJava - Nspire JVM
Post by: Lionel Debroux on February 01, 2012, 02:24:04 am
Exactly: hardly anybody uses Jazelle because it's badly documented :)

Java ME can be unpleasant to use: lots of Java 1.4, 5, 6 and 7 goodies (both in terms of language features and in terms of class library), which people have enjoyed for years on Java SE, are not available.
Title: Re: nJava - Nspire JVM
Post by: calc84maniac on February 01, 2012, 02:30:58 am
/me points at http://ourl.ca/8791 (http://ourl.ca/8791)
Title: Re: nJava - Nspire JVM
Post by: Lionel Debroux on February 01, 2012, 02:45:37 am
Oh yeah, forgot about that topic :)
Title: Re: nJava - Nspire JVM
Post by: DJ Omnimaga on February 01, 2012, 02:48:22 am
Java would be nice on the Nspire since a bunch of people know this language and this might increase the Nspire programmer audience considerably, although of course it won't be even close to Ndless (and maybe Lua?) performance.
Title: Re: nJava - Nspire JVM
Post by: jwalker on February 01, 2012, 08:04:46 am
thats my only real worry
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 01, 2012, 09:24:52 am
Hopefully the performance won't be too insufferable. As of right now, I just want Java to be an option one can choose for making programs and apps for the Nspire. Once that's accomplished we can work on optimizing and speeding up the JVM.
Title: Re: nJava - Nspire JVM
Post by: Goplat on February 01, 2012, 03:04:00 pm
Java would be nice on the Nspire since a bunch of people know this language and this might increase the Nspire programmer audience considerably, although of course it won't be even close to Ndless (and maybe Lua?) performance.
Running Java code is generally faster than running Lua code, because of the type information available to the JVM. Take object field accesses for example - in Java, if you have a variable "Rectangle r", the JVM knows at class-loading time that it points to a Rectangle object, and therefore can determine in advance what location within the object will be accessed in an expression like "r.width". In an untyped language like Lua, on the other hand, fields have to be looked up by name at run-time every time they're accessed, which is much slower.

The main problem with Java isn't its execution speed, it's its size. JamVM brags about its executable being only 200KB, but how much memory does it use, and how big is the required class library? Porting the class library could also be a lot of work. I was considering porting the CLDC reference implementation (a Java environment with a much smaller class library) a while ago, after I had found out about Jazelle, but never did anything substantial to that end.
Title: Re: nJava - Nspire JVM
Post by: Lionel Debroux on February 01, 2012, 03:54:53 pm
IIRC, the significantly incomplete GNU Classpath library is megabytes large, and the standard (OpenJDK) classpath, which JamVM is not supposed to support, is of course much worse.
CLDC, and J2ME are much smaller in general indeed... but also quite a bit less fun to program.
Title: Re: nJava - Nspire JVM
Post by: willrandship on February 04, 2012, 04:49:25 am
A good analogy of what you could expect for performance would be:
For 84+, BASIC < Hybrid BASIC/BBC < Axe < Asm
For Nspire, BASIC < Lua < Java < C

(Java's limitations compared to C are different than Axe's compared to Asm, but they basically come to the same concept: Lower level programming is faster. Higher Level programs add bulk and slow stuff down. It's the ever-present trade-off in tech of work vs performance, but Java gains cross-compatibility as a bonus)

After all, that lua interpreter was written by TI. If anything it would be worse than the standard implementation, making it a wider gap.
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 04, 2012, 11:41:15 am
I'm also hoping that coding in Java will be easier than C for the Nspire. (I don't know why, but C with the Nspire SDK seems confusing... Perhaps it's just me though) :P

Hopefully standard Java will be supported and even games already written can be run.
Title: Re: nJava - Nspire JVM
Post by: ExtendeD on February 04, 2012, 11:51:30 am
If anything can be done to improve the native SDK, I'm open to your suggestions.
Title: Re: nJava - Nspire JVM
Post by: Jim Bauwens on February 04, 2012, 02:56:56 pm
After all, that lua interpreter was written by TI. If anything it would be worse than the standard implementation, making it a wider gap.
The interpreter itself is not written by TI, they just added some modules and made it event based (Not hard to do that at all).
They implemented it as many other games/programs do.
Title: Re: nJava - Nspire JVM
Post by: AngelFish on February 04, 2012, 06:43:53 pm
Hello.

As you can guess my the title, I am starting a project to port a Java Virtual Machine to the Nspire.

So far I have found an open sourced JMV here

http://jamvm.sourceforge.net/ (http://jamvm.sourceforge.net/)

That I believe can be ported to the Nspire. It is also written almost entirely in C so I think that'll help.

What I want to do is basically be able to take any Java byte code, and be able to run it on the Nspire. (Possible Minecraft, anyone?) :P

However, I don't know where to start with this project. I downloaded the source for the JVM and found the main file, however I do not know what I need to do to port it to the Nspire.

I hope that this can become a community project where anyone can contribute, because if it were only myself, it might never come to fruition, which would be a shame.

So, first question, where do I start? ExtendeD suggested to me earlier to try to compile the project as is using the Ndless SDK to see what dependencies aren't supported, although I don't know what I should make for a makefile to do that.

First, understand precisely what a JVM is and how it works.
That means you need to read the Sun Spec for the Java VM. It will be invaluable for understanding the logic behind some of the superficially "WTF?" decisions that appear in the VM. Also, try to get your hands on the book "Inside the Java Virtual Machine." It's not quite as useful as the spec itself, but the depth it goes into can occasionally be helpful and it explains some of the algorithms used in the sun implementation, something the spec deliberately avoids doing.

Also, get comfortable with optimization and low level programming. They're the heart of a good VM.

Perhaps most importantly, understand the code you're trying to use as if you had written it yourself. If you're going to be maintaining it, then you'll quickly see why that's such a good idea.

So, long story short: Writing/porting a JVM is a very good way to learn precisely how much you don't know. You'll come out of it a better programmer either way and I highly recommend attempting it for the learning experience, even if you never manage to fully port it. If you do manage to fully port it, then I love you :D
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 04, 2012, 06:46:47 pm
Ok, thanks. I'll definitely do that then. If all else fails, I can probably get quite a bit of help from my College professors as well if any of them are interested in assisting me. :D
Title: Re: nJava - Nspire JVM
Post by: jwalker on February 04, 2012, 07:27:24 pm
have you tried to compile the files as is yet, i would but i still dont understand the makefiles very well, although i might almost have it figured it out :)
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 04, 2012, 07:53:52 pm
I tried compiling with a standard makefile used in compiling other Nspire programs, however some files seem to be missing, such as config.h, and arch.h.

(I saw a config.h.in, however)
Title: Re: nJava - Nspire JVM
Post by: annoyingcalc on February 04, 2012, 07:59:55 pm
Wow I can't believe I missed this topic, I think this is a great idea and (when libraries are implemented Minecraft might be possible)
Title: Re: nJava - Nspire JVM
Post by: Deep Toaster on February 05, 2012, 12:12:28 am
Wow, I came late x.x
* JamVM's performance is better than that of a number of other JVMs, but it's not the most optimized JVM for ARM platforms. The one in OpenJDK / IcedTea (well, Sun/Oracle's code) is, but chances are that it's harder to compile than JamVM is, and it definitely has a much larger fooprint;
That's too bad... I'd still love to see Java on the Nspire though.
Wow I can't believe I missed this topic, I think this is a great idea and (when libraries are implemented Minecraft might be possible)
willrandship already said here (http://omniurl.tk/12484/228308/) that Minecraft won't be possible. There are more Java games than that, though :D
Title: Re: nJava - Nspire JVM
Post by: jwalker on February 05, 2012, 09:35:08 am
I tried compiling with a standard makefile used in compiling other Nspire programs, however some files seem to be missing, such as config.h, and arch.h.

(I saw a config.h.in, however)
hmm i wonder where those are...
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 05, 2012, 10:37:05 am
It might be a part of an library it needs. (I have not installed ClassPath as of yet, perhaps that's what I'm doing wrong)

It might also be that those files are created while compiling.
Title: Re: nJava - Nspire JVM
Post by: hellninjas on February 06, 2012, 12:28:08 am
Well if minecraft is not possible than I promise that when I finally learn Java I will remake minecraft into OMNIcraft!!
Title: Re: nJava - Nspire JVM
Post by: annoyingcalc on February 06, 2012, 02:05:01 am
Great!
Title: Re: nJava - Nspire JVM
Post by: AzNg0d1030 on February 07, 2012, 09:02:24 pm
Well if minecraft is not possible than I promise that when I finally learn Java I will remake minecraft into OMNIcraft!!
:O Can we have our character be a calculator with a digital face and the monsters be lobsters and stuff?
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 07, 2012, 09:04:21 pm
Well, if minecraft ever could be ported, we could potentially be able to use any mod that works with regular minecraft. ;)
Title: Re: nJava - Nspire JVM
Post by: willrandship on February 15, 2012, 02:37:56 am
Err, there's a reason it won't happen as a direct result of a java port, mostly involving 3D graphics hardware and native libraries.

I'm afraid pretty much none of the mods will run on a port, since a port would have to have a very specialized rendering engine and a far more limited map system. (Read: Total rewrite)

Keep in mind, you don't just have to port the jvm, you have to port every single library MC uses, including LWJGL, which requires 3D acceleration.

Am I saying it's impossible to make a minecraft-like game, survival and all? No way. (I lost all faith in my ability to judge programming capability for the 83+ when I saw nostromo (http://benryves.com/journal/3739423)) I'm just saying that minecraft in its current state will never run on the nspire. Not even slowly. Especially if the 3D rendering gets offloaded to the CPU (That alone would max the nspire, let alone gameplay)

Minicraft, though......Not so sure there. It's a lot more possible, I'll acknowledge that.
Title: Re: nJava - Nspire JVM
Post by: Scipi on February 15, 2012, 09:38:38 am
Yeah, I don't doubt maps would have to be very, very small.

That's something in the far future, however. First we have to port the JVM and get it running. :P
Title: Re: nJava - Nspire JVM
Post by: hellninjas on May 03, 2012, 11:51:51 pm
Hey HOMER, hows the progress going for this?
Title: Re: nJava - Nspire JVM
Post by: Scipi on May 04, 2012, 08:13:24 am
No progress at all. I'm not too inclined to continue the project in the near future, but I might when I have more knowledge of the JVM.
Title: Re: nJava - Nspire JVM
Post by: hellninjas on May 04, 2012, 12:01:49 pm
Darn, maybe you could get others to help you out?
I'm sure there are many members on omni with knowledge of JVM :D
Title: Re: nJava - Nspire JVM
Post by: Jim Bauwens on May 04, 2012, 12:05:03 pm
Fishbot maybe, with his work on Khavi.
But I suppose the has enough stuff to do..
Title: Re: nJava - Nspire JVM
Post by: DJ Omnimaga on May 04, 2012, 06:05:17 pm
I hope eventually both projects come to fruition, although I understand this might be hard to get java stuff to run at a decent speed considering on modern PCs, some stuff like Minecraft (even in single player mode) have lag sometimes.
Title: Re: nJava - Nspire JVM
Post by: Scipi on May 04, 2012, 07:28:27 pm
If I learn more about programming C on the Nspire, then I'll revive the project. Or if I find someone who can help who has the knowledge.

Else, I'm going to try working on my game projects over the summer.