Nested VM is an excellent tool to convert a C application to a Java
interpreted program or can also be used to convert a C program to a
Java Class. There are a few white papers available about the details,
but a summary of the process is:
1. Build the c application for a mips based target (Mips, maps well
to Java bytecode)
2. Use either the Nested VM mips interpreter class or generate a java
class from the mips output
Here's my environment:
1. Windows XP machine
2. Cygwin installed (www.cygwin.com)
3. Eclipse installed (www.eclipse.org)
How to get started:
1. Download nested vm from http://nestedvm.ibex.org/
2. Untar it (use tar xzvf nestedvm-year-month-day.tgz)
3. Get darcs
a. you may also need darcs, if so then download it from here:
http://darcs.net/DarcsWiki/CategoryBinaries
b. unzip it (usually bunzip2 -d *.bz2 and then untar it)
c. I personally just copied over the files in to the /usr/bin/
directory for darcs
4. Make sure the cygwin shell has the path to the java sdk bin
directory
a. In my case it was export PATH=$PATH:/c/Program\ Files/Java/
jdk1.5.0_06/bin/
5. run make in the nestedvm directory (Get a cup of coffee as it
takes awhile)
a. It is building the gcc and binutils for the mips cross
compilier as well as the nested vm classgen classes
b. These files are located in the ./upstream/build area
6. Now take a look at the test files in nestedvm/src/tests
directory
a. In here are test.c files and java files
b. Build one of the .c files with the cross compilier (hello.c)
and name it hello.mips
i. Example: /c/temp/nestedvm/nestedvm-2007-01-12/upstream/
build/gcc-obj/gcc/gcc-cross.exe -EB -O1 -Wall -c hello.c -o hello.o
/c/temp/nestedvm/nestedvm-2007-01-12/upstream/build/gcc-obj/gcc/gcc-
cross.exe -EB -O1 hello.o -o hello.mips
c. NOTE!!!! Things break if you get to crazy with the -O flag -
O3 failed badly for me.
d. Also, use the -EB as -EL does not work on windows or just
leave it off entirely
7. You now have a mips based binary you can use with Nested VM:)
Note, it will NOT run on windows's cygwin if you did it right:) Now
let's integrate it with NestedVM!!!
a. Use this simple java hello test to help you run your
hello.mips
package tests;
//Include the nestedvm.Runtime
import org.ibex.nestedvm.Runtime;
public class hello {
public static void main(String[] args) {
//Place holder for command line arguments
String[] appArgs = new String[args.length + 1];
try {
//Application nmae
appArgs[0] = "./hello.mips";
//Fill in the rest of the command line arguments
for(int i=0;i<args.length;i++) appArgs[i+1] = args[i];
//Make a Runtime instantiation
final Runtime rt;
//Make a new mips interpreter
rt = new org.ibex.nestedvm.Interpreter("./hello.mips");
//Let er rip!
System.exit(rt.run(appArgs));
} catch(Exception e) {
System.err.println(e);
}
}
}
b. Open up eclipse
i. Make a new java project
ii. Point it to the nestedvm/src path (Copy over the nestedvm/
upstream/build/classgen to the nestedvm/build to facilitate path
locations)
iii. Put the above hello.java in the nestedvm/src/tests
directory
iv. Put the hello.mips in the nestedvm/src directory
1. Running out of eclipse defaults to the project main
path, not the location of the java file you're testing that's why
hello.mips not in the .../tests directory
v. Right click on the hello.java in your new project and
select run
vi. TADA!!!
8. For those who wish to hava a java class generated rather than use
an interpreter try this from Brian's quickstart:
http://wiki.brianweb.net/NestedVM/QuickStartGuide
a. java org.ibex.nestedvm.Compiler -outfile helloc.class Hello
hello.mips
Enjoy! I know I have:)
http://wiki.brianweb.net/NestedVM/CygwinBuildingGuide
I just had a few questions/comments...
On Sun, May 20, 2007 at 05:44:11PM -0000, David Aubin wrote:
> i. Example: /c/temp/nestedvm/nestedvm-2007-01-12/upstream/
> build/gcc-obj/gcc/gcc-cross.exe -EB -O1 -Wall -c hello.c -o hello.o
> /c/temp/nestedvm/nestedvm-2007-01-12/upstream/build/gcc-obj/gcc/gcc-
> cross.exe -EB -O1 hello.o -o hello.mips
Any particular reason why you're pulling things out of the gcc build
dir? We actually install a local copy of the cross compiler toolchain
under upstream/install/ so the "right" way to run it is
upstream/install/bin/mips-unknown-elf-gcc
> c. NOTE!!!! Things break if you get to crazy with the -O flag -
> O3 failed badly for me.
This definitely shouldn't happen. We actually build all the libraries
with -O3. The set of CFLAGS we use can be found in env.sh.
What happened when you used -O3? Are you sure it didn't have something
to do with -EL? (below)
> d. Also, use the -EB as -EL does not work on windows or just
> leave it off entirely
Better just leave it off entirely. -EL actually won't work anywhere as
nestedvm has big endian assumptions pretty deeply wired into it.
> public class hello {
> public static void main(String[] args) {
Just for the record. org.ibex.nestedvm.Interpreter has a main() very
similar to this. And when you build a classfile it will generate an
appropriate main(). This certainly helps clarify what is happening
under the hood though.
Thanks again for writing this,
-Brian
Please see my response below:
On May 20, 2:39 pm, Brian Alliet <b...@brianweb.net> wrote:
> Thanks a lot for this David. Hope you don't mind that I reformatted it
> a little and put it on the Wiki.
>
Awesome:)
> http://wiki.brianweb.net/NestedVM/CygwinBuildingGuide
>
> I just had a few questions/comments...
>
> On Sun, May 20, 2007 at 05:44:11PM -0000, David Aubin wrote:
> > i. Example: /c/temp/nestedvm/nestedvm-2007-01-12/upstream/
> > build/gcc-obj/gcc/gcc-cross.exe -EB -O1 -Wall -c hello.c -o hello.o
> > /c/temp/nestedvm/nestedvm-2007-01-12/upstream/build/gcc-obj/gcc/gcc-
> > cross.exe -EB -O1 hello.o -o hello.mips
>
> Any particular reason why you're pulling things out of the gcc build
> dir? We actually install a local copy of the cross compiler toolchain
> under upstream/install/ so the "right" way to run it is
> upstream/install/bin/mips-unknown-elf-gcc
Reason? Ignorance;) I didn't know it existed.
>
> > c. NOTE!!!! Things break if you get to crazy with the -O flag -
> > O3 failed badly for me.
>
> This definitely shouldn't happen. We actually build all the libraries
> with -O3. The set of CFLAGS we use can be found in env.sh.
>
> What happened when you used -O3? Are you sure it didn't have something
> to do with -EL? (below)
I'll retest. I'd love to build with -O3:) And yes it is highly
suspect as
it was at the time I was playing with the compile switches.
>
> > d. Also, use the -EB as -EL does not work on windows or just
> > leave it off entirely
>
> Better just leave it off entirely. -EL actually won't work anywhere as
> nestedvm has big endian assumptions pretty deeply wired into it.
>
> > public class hello {
> > public static void main(String[] args) {
>
> Just for the record. org.ibex.nestedvm.Interpreter has a main() very
> similar to this. And when you build a classfile it will generate an
> appropriate main(). This certainly helps clarify what is happening
> under the hood though.
Cool:)
>
> Thanks again for writing this,
>
> -Brian
Thanks again for making this:)
Dave:)
It made a HUGE performance difference too. My app used to take 85
seconds to run and then with it, it now takes 9 seconds!!!! BOOYA!!!
I LOVE THIS TOOL!!!!
Thanks,
Dave:)
"make env.sh" should generate it for you. It is dependent on where the
build tree is located on your system so we can't include a prebuilt
version.
-Brian