Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Sunday, March 16, 2014

Building Avian Java Virtual Machine

 

What is Avian?

Avian is an open-source, lightweight Java virtual machine (JVM) and class library designed to provide a useful subset of Java's features, suitable for building self-contained applications.

The VM is implemented from scratch and designed to be small and fast, featuring:

  • Just-in-time compilation for fast program execution
  • Generational, copying garbage collection to ensure short pause times and good spatial locality
  • Thread-local heaps providing O(1) memory allocation with no synchronization overhead
  • Null pointer dereferencing and arithmetic errors handled via operating system signals to avoid unnecessary branches
  • Proper tail calls and continuations

& Best of it is

The virtual machine is designed to be embedded along with application classes into a single executable file, which can be run on systems where the Oracle Java platform isn't installed.

Supported OS: Windows, OSX, iOS, Linux, FreeBSD

Platform: ARM, IA-32, x86-64 & PowerPC

Let’s Build it for Windows.

What is needed?

1. MinGW or TDM GCC

2. MSYS

3. JDK 7 ( skip if already installed )

4. zlib

5. Go to Avian’s Github repository & download Avian’s source code in zip.

Avian_github

Introduction about Tools:

MinGW & TDM GCC provides gcc for windows (i.e. Windows port of GCC)

MSYS provides *nix environment on Windows like Bash shell, GNU Core Utilities...

Steps:

1. Start MSYS either by shortcut or go to MSYS install folder & execute MSYS.bat

2. Now you will see nice Bash shell console window.

3. Now set JAVA_HOME environmental variable to JDK directory & do not include bin directory. ( including bin generates build error )

E.g. export JAVA_HOME="C:\Program Files (x86)\Java\jdk1.7.0_21"

4. Now first we need to build zlib, Extract zlib, cd to Zlib directory

5. Execute “make -f win32/Makefile.gcc BINARY_PATH=C:\TDM-GCC-32\bin INCLUDE_PATH=C:\TDM-GCC-32\include LIBRARY_PATH=C:\TDM-GCC-32\lib install”

Here replace C:\TDM-GCC-32\ with your Mingw or TDM install directory

6. Now we have everything to build Avian. Extract Avian to folder & cd to Avian’s directory.

7. Execute “make bootimage=true” & press enter.

8. Now if everything works fine then Avian is built under “build” folder

9. cd to Avian’s “build” folder, cd to “windows-i386-bootimage” , create your java program here

10. Now compile it with “javac -bootclasspath classpath <name>.java”

11. Copy “classpath.jar” from host to its parent directory means “windows-i386-bootimage”.

12. Now execute “jar u0f classpath.jar Hello.class” ( This will add your .class file to classpath.jar )

13. Now copy “classpath.jar” to embed directory.

14. Rename classpath.jar to boot.jar ( You can optionally see with archive manager that your .class file is added or not )

15. Execute “embed.exe output.exe boot.jar [package.]<classname>” ( [] optional part )

E.g. embed.exe hello.exe boot.jar Hello

Avian_output

Avian creates much smaller executables than GJC but supports limited API