Saturday, April 7, 2012

Build a java virtual machine that is actually readable/modifiable for Win32

Is it possible to build a Java virtual machine for Win32 in an sort of understandable way?  It is mostly impossible.  The OpenJDK build will take hours just to build and will take a day to prepare your environment.   If you aren't a core JVM developer, who actually is going to take several days to prep their environment so that they can hack OpenJDK.  The jikes RVM may work with cygwin/win32 but it is mostly designed for linux or some other open platform.  You are really only left with JamVM.  I was actually able to install all of the dependencies with cygwin and perform a build in 15 minutes.  And then actually edit the C source, add a log statement, rebuild and run against a bytecode class file.  JamVM is the only JVM project that is understandable (20-30 core C files) and the build actually works with a modern version of cygwin.

I will go through some of the setup.  It helps to actually install JamVM through cygwin.  Full install.

1. Run cygstart and use cygports as your cygwin repository.  Cygports allows you access to more software packages.

cygstart -- /cygdrive/c/Users/bbrown/Downloads/setup.exe -K

2. Select 'jamvm' and run through the installer.

I am installed 'jamvm-1.5.3-5'

3. Run cygstart -- /cygdrive/c/Users/bbrown/Downloads/setup.exe -K
Again but this time select 'jamvm' source install.  Double click on the text 'Keep' near jamvm.

4.  Change your directory to /usr/src.  The source for jamvm is located in the src directory.

5.  Install jamvm-1.5.3-5 based on the source:

Run cygport ./jamvm-1.5.3-5.cygport all

6.  Then run  cygport ./jamvm-1.5.3-5.cygport prep

7.  Then run  cygport ./jamvm-1.5.3-5.cygport compile

8. Enter '/jamvm-1.5.3-5/build/src'
9. Type 'make' and edit a C source file.

10. javac -source 1.5 -target 1.5
11. Run jamvm.exe Test



Some of the dependencies established through jamvm install:

ecj (3.5.2-1)
gnome-icon-theme (
java-classpath (0.98-2)
java-ecj (3.5.2-1)
libgtk2.0_0 (2.24.10-1)
libjbig2 (2.0-11)
libjpeg8 (8b-1)
libpango1.0_0 (1.29.4-2)
libpng14 (1.4.8-1)
libtiff5 (3.9.4-1)
libXext6 (1.3.0-1)
shared-mime-info (1.0-1)
xcursor-themes (1.0.3-1)


[2]  (1.5.3)

Sunday, April 1, 2012

Code snippet of the day: Haskell for the dumb idiot lazy programmers

The euler project problem reads as such, "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000."
Here is one of many implementations in Haskell.  I used a verbose recursive approach, iterate up to 1000 and then build a list with the items of interest.  In this case, 'multiples of 3 or 5'.  The first implementation contains a logging utility for writing a string at each iteration.

Figure 1: Euler Problem1 in Haskell

Here is the second source snippet, I just wanted to provide something more practical, a log parsing example that you can run against your web log files.

Figure 2: Applied Haskell, simply read each line of a file, find a term and output the results to another file.