Emma Code Coverage Tool Fixed 64 Bit Support (2.1.5320)

So I’ve been spending my time trying to come up with a fix for 64bit JVM support in EMMA for some tools I’ve been building. Unfortunately active development on EMMA has died, and although there have been talks about forking the project nothing has really happened with this project since 2005. EMMA 2.1 is really neat because it comes with some tools that allow you to do instrumentation on the fly, while applications remain running.

This can allow you to do coverage of your apps against live automation tests instead of just JUnit test cases. If you’ve ever tried to run EMMA in a 64bit JVM you’ll know that you get a wonderful ArrayIndexOutOfBounds Exception the second you try to instrument the code. This issue is known and there is a bug filled in the bug tracker for EMMA but since no one is actively maintaining it nothing has really been done to fix it.

If you checkout the bug tracker (here) a nice fellow by the name of Lukas has generated a patch to fix this issue, and even provided a patched version of emma.jar on his blog. Unfortunately this patch and the patched emma.jar are for 2.0.5312 which does not have support for the CTL tool. This is the tool that allows you to do instrumentation on the fly without relying on a JVM shutdown to write coverage information.

With all this information in hand I decided that I would patch the latest 2.1.5320 code line in order to bring 64bit support to the Emma 2.1 branch. This was a little more difficult then I originally thought, but luckily I wound up getting everything working in the end.

I am providing here a copy of the patched emma.jar (version 2.1.5320 fixed) in hopes that it may help some people out and perhaps spur some people to fork EMMA and get development started again on this project. I’d definitely be more than willing to help get something like that started.

Please see the EMMA license for distribution. Please note I do not plan to release newer versions of Emma.

Fixed version of Emma 2.1.5320: emma jar updated

Reversing a String in Scala

So I’ve been reading “Programming in Scala” by Martin Odersky, Lex Spoon and Bill Venners and I’ve been coming up with ways to get myself thinking and programming more in Scala. Since I spent a better part of my week interviewing people I thought I’d take some time to write the famous “Reverse a String” interview question. This is a pretty straight forward thing to do and thought it would be fun to experiment with some of Scala’s other cool features to get my feet wet.

On my first attempt I wound up with my usual tail-recursive implementation that makes use of an accumulator.

This seemed pretty standard to me. It doesn’t differ much from the Java implementation I’ve written a hundred times, nor is it really all that interesting. I decided to jump ahead a few chapters in the book to see what I could accomplish using a left fold. For those unfamiliar with what a fold left operation is I point you to the Wikipedia entry on it here. The basic idea as stated in the book “Programming in Scala” is this: “A fold left operation (z /: xs) (op) involves three objects: a start value z, a list xs, and a binary operation op. The result of the fold is op applied between successive elements of the list prefixed by z.”

Ok that seems like it applies very well to what we are trying to accomplish. Rewriting the above methods into one clean line of Scala code yielded the following

Pretty beautiful isn’t it? It’s amazingly simple and achieves the same thing as the tail-recursive implementation. I can’t express how excited I am to get through this book and really start doing real programming with Scala.

So I guess the next time you go for an interview try and remember this for the answer and see how the interviewers faces light up, either with glee or rage that you didn’t solve it using the standard recursive implementation :)

Until next time …

Really Funny XKCD Comic

A co-worker sent this to me yesterday and I definitely had a good laugh since for many years I’ve joked about calling my kid “URL”, pronounced EAARRLLL. I definitely think this name is a better though and could definitely lead to some very comical situations.

XKCD A Webcomic SQL
XKCD A Webcomic

I hope you all enjoy this, now back to work!

Ext-JS Tasks & Progressbars a match made in heaven

I’ve been working on some stuff that requires me to execute some long running tasks on a server from a web based client. I really wanted to a way to let the user know what was going on, and I figured a progress bar would be the best way to let them know what was going on and how much longer it was going to be before the task was complete.

Using Ext-JS this task was actually a lot easier then I had originally thought. Ext has these two great classes called TaskRunner and TaskManager. These classes basically allow you to create a task for execution in a multithreaded manner (we all know that JavaScript is only single threaded so this definitely will never be executed in parallel but we can all dream). Here’s an example from the Ext API on how to setup a task to run a simple clock that updates every second.

In my case I wanted to setup a task that would execute every 10 seconds and ask the server what the progress of my long running task was. I then used the information returned from the server to update the progress bar on page.

Now I’ve let some code out here for handling the failure case of the Ajax request and a couple of other functions for handling what I’m actually doing on the server but you can start to see that with the combination of the TaskRunner and the ProgressBar adding “background” worker threads to your interface becomes a lot easier.

Unfortunately this solution is not necessarily optimal since the client will constantly be polling the server asking what’s going on. A much better solution to this would be to implement a comet based service that allowed the server to merely report to the user its status and when it was complete.

Currently Ext does not have any comet handling functionality, but if you watch for my next post I’ll show how you can implement a comet based Servlet in Tomcat 6 and create a client that will listen for updates from the server.

Tail Recursive Algorithms In Scala

After the NFJS conference this weekend I have been spending more and more time working in Scala and trying to learn the ins-and-outs of the language. One of the neat things I came across was tail recursive algorithm optimization within the language itself.

When writing in a functional language like Scala you rely heavily on recursive algorithms to do your work, instead of iterative algorithms more present in OO languages like Java. This leads to an interesting problem with running functional languages within the JVM.

The Java Virtual Machine does not have support for tail-recursive algorithm optimizations. What does that mean? Basically the JVM cannot spot when to optimize calls stacks for recursive algorithms. Well who cares right? If you’re writing in Java this issue doesn’t usually come up since most of us simply write our loops and are happy with the performance the JVM offers us.

However, when you are writing a lot of recursive algorithms you quickly start to see how tail-recursive algorithms help makes your code more efficient.

For those of you who don’t remember what a tail-recursive algorithm is, here is a short little explanation:

A Tail-recursive function is a function that ends in a recursive call to itself (effectively not building up any deferred operations). Tail recursive functions have the ability to re-use the same stack frame over and over and therefore are not bound by the number of available stack frames. Many people have written the simple factorial function recursively, but many have noticed that if you pass it a value of N that is large enough you will see a dreaded Out of Memory exception.

The reason for this is due to the factorial functions deferred operation statement that comes at the end of the method. Let’s look at the simple factorial algorithm

You can see that at then end of the algorithm we have a deferred operation of multiplying n with the next value computed from factorial, this goes on and on until we finally hit a factorial function that returns one, at which point the stack is popped and everything returns nicely. However we are now bound by the available stack frames in terms of computing n (Also by the max size of an int, but that’s beside the point).

In a tail-recursive algorithm you do not see this deferred execution, and therefore the same stack frame can be reused over and over again. Here is the same algorithm rewritten using a tail-recursive algorithm.

As you can see there are no deferred operations in this example we have effectively gotten rid of having to use n number of stack frames. Each call to fact_support brings with it the current accumulated sum, and thus does not need to wait to pop the stack and rely on the stack pop to accumulate the sum of the factorials.

As you can see tail-recursive optimizations are very important to languages where recursion is relied on heavily. Without this type of optimization many of the recursive algorithms are now bound by the number of available stack frames.

So that can’t be so hard right? Why not just write all your algorithms to use tail-recursion? Well for one it’s not always possible to do this, but also it puts a lot of work in the hands of the developer. We have this beautiful thing called the JVM that should be able to spot cases where optimization can occur.

Unfortunately the JVM doesn’t know how to spot this optimization, therefore the Scala compiler must look at ways of optimizing your code. Even more unfortunate the Scala documentation explicitly states that you should not rely on the Scala compiler making this optimization.

It may optimize your code, but it may not as well, so really the only way to be sure is to write your algorithms guaranteeing that tail-recursion is being utilized from the get-go.

It would be really nice to see the JVM improved to allow for this type of optimization to be done in the Hotspot, and there has been talk about improving the JVM to support functional languages, but I guess time will only tell.

No Fluff Just Stuff Boston 2008 Overall Review

I’ve spent my weekend in Boston at the local No Fluff Just Stuff conference and I figured I’d write a little summary of what I observed and learnt over the weekend.

To start this was my first conference that I’ve attended besides some small ones while in College and University, and I have to say that it was both exciting and disappointing.

Heading into the weekend I was very excited to hear Brian Goetz and Ted Neward give talks about cool things like Java Concurrency, The Java Memory Model, Hacking the JDK, Scala etc, and I expected most people at the conference to be of the same mind set.

I found through talking with many attendees that most people seemed to share a different set of values as to what was important to them. I found this to be very interesting as it really showed me the difference between people who are developing for the Enterprise or big business and people like me who develop more for a technology based company.

When I heard people talking about Groovy and Grails I couldn’t understand why anyone would be so interested in a language that performed as poorly as Groovy (Yes I know it’s been getting better but when you start from incredibly slow, and move to just being a little less incredibly slow I hardly see this as an improvement) I started to see that there really is a difference between the enterprise developer and the developer.

I think this was an amazing aspect of this conference is that it really opened my eyes to the other side of the coin, to the developers that work hard to create the applications that we use every single day from our Banks, Insurance companies etc and the different set of requirements that their applications have to deal with then what I’m used to.

I also have to say that after this weekend I am VERY VERY glad to be working where I am. Some of the horror stories I heard from people as to how they have to work, the lack of tools support that they face, and an overall management’s lack of letting things change made me cringe in pain and a few times I just wanted to give them a hug to tell them that it would all be OK (Yes sometimes it really was that bad like the guy who told me they were still using Java 1.4.2 because his boss thought if it works don’t fix it!)

So after sitting back over the weekend and getting over the initial culture shock that I faced meeting a lot of these developers, I have to say that this conference helped me in a way I never thought it would.

Sure I learnt all about the Java Memory Model, and how I can modify byte code on the fly with tools like BCEL, but more importantly I learnt what other developers have to go through on a daily basis and what it’s like to be an Enterprise developer in the real world.

All I have to say to that is, thank god I don’t have to deal with that shit every day. Overall though I definitely would recommend this conference to someone working in the Enterprise world, I definitely got value out of it though with my talks with Brian and Ted and I have to say that if they weren’t there this show definitely would of been a wash for me. So thanks Brian and Ted for really opening my mind and eyes to some cool new ways of doing things.

Picked up some new books

Last week I finished the book “Prelude to Foundations” by Isaac Asimov. It was recommended to me by my boss, and I have to say it was one of the better books I have read in a while. I usually try to switch up reading technical books with non-technical books, and since I haven’t read any new technical books I decided to head over to chapters and pickup some new books.

I have head great things about both Java Concurrency by Brian Goetz, and Effective Java 2nd Edition by Joshua Bloch. The real problem with both these books is they are hard to find in store. I happened to come across both of them at my local Chapters, and quickly snatched them up.

I have been reading Java Concurrency over the past couple of days and I have to say this is one of the best Java books I’ve read in a while. Brian Goetz has a way of writing that really helps bring complex problems into perspective.

One of my initial gripes about this book was the lack of exercises at the end of the Chapters, however now that I’m a little ways into the book I’ve noticed that the examples chosen for each Chapter progress almost as a set of exercises in themselves. Not to mention that Brian picks examples that relate well to the real world, instead of most of the silly easy examples found in other books I’ve read.

I would definitely recommend this book to anyone looking to delve into the world of Java Concurrency, or even someone looking to freshen up on the latest stuff available in JDK 1.5 in terms of threading. This book has really helped me in my pet projects and in my day-to-day work so I would definitely recommend getting it and keeping it close by.

I’ve yet to really get into Effective Java, but the little bits I’ve read here and there have really shown me that this this book lives up to all the hype about it. Joshua is a smart man, and this book definitely reflects his intelligence. It is well organized and shows you things about Java that you never thought even existed. I’m really excited to delve deeper into this one.

I’ll write a more thorough review once I’m finished with it. Anyway until next time …

Finally a new PC!

Well I finally broke down and decided it was time to upgrade my old PC.  To be honest I couldn’t of asked for a better computer, I’ve had it since 2004 and it’s cost me nothing but a new hard drive once.  To me this is prove of why I always tell people the best computer money can buy is the one you build yourself.

Sure you can walk into your local Futureshop or PC Shop and get a pre manufactured/assembled PC, but you have zero guarantee as to what is inside of that PC.  In most cases large manufacturers use subpar components in order to keep prices competitive.  Small PC Shops are notorious for advertising certain components but giving you low cost alternatives in the final product, not to mention that their computers are usually more expensive then just buying the parts yourself.

As I’ve always built my own computer, this time was really no different.  I had been toying around with the idea of buying a Mac Pro, but I just couldn’t justify the cost, not to mention that I’ve been successfully running OSx86 for months on my PC.  In order to continue doing so I had a couple of requirements for my new PC which seems to be a theme of mine as of late.

First my new PC had to be power efficient.  I find myself becoming a lot more eco-friendly, and I feel that having a PC that is efficient can really help to reduce everyones carbon foot print.  This leads to my second requirement, which was my number one requirement in my previous PC, the computer had to be QUIET.

If there’s one thing I hate more then anything else, it’s having to listen to the hum of 5 fans churning away inside someone’s PC.  I don’t understand how people live with this.  I spend a good amount of time next to my computer, and the last thing I want is to have to listen to fans.

My previous PC utilized a lot of power efficient components that I could passively cool, in order to minimize noise.  I also made use of one of my favourite cases the Antec Sonata II this quiet case included a lot of ducting to help air flow and minimize the number of fans needed to cool your components.  It also came with hard drive shock absorber mounts, and a heavy aluminium construction to eliminiate vibration noise. Unfortunately the interior ducting was also the most annoying part of this case, adding new components was a pain, and tucking wires became an issue as the ducting really got in the way.

My third requirement was that my new PC be built with components that I knew would last for at least the next couple of years.  I’m a firm believer of paying money up front on solid top of the line components that I know will not be obsolete in a few months, and that are well manufactured.

With these three requirements in place I spent some time wrestling with what components I wanted to include, and where I was going to get the best price for these components.

One of my first problems was whether or not to splurge on a quad core cpu. I had really considered the Intel Quad Core Q6600, but after doing some reading (Especially this article over at Coding Horror) I really came to the conclusion that the Quard Cores would probably go to waste on me. Not to mention that the Quad Core uses a 65nm process, and definitely violates my power efficiency requirement.

After eliminating the quad core from my list of potential CPUs I had to decide what dual core processor I wanted and to be honest this wasn’t a difficult pick for me.  The new Wolfdale based Core2Duo processors from Intel are power efficient and use a 45nm design which allows them to be overclocked to insane levels.  These CPUs are only marginally more expensive then their 65nm counterparts, and since my local PC shop was having a sale on the Core 2 Duo 8400 I decided to pick it up for $190.

My next problem was choosing a suitable video card.  I knew first that I had to choose something from Nvidia, as driver support for ATI based cards is abysmal in Linux, and OSx86.  This somewhat limited my choices, and with so many high end gamer cards made me wonder if I’d ever find something to suit my needs.  I really wanted something that was passively cooled, since in most PCs the bulk of noise originates from the Video Cards cheap fan.  After doing some thinking and reading I decided that the highend 8800 series was out as it was difficult to passively cool and definitely violated my power efficiency requirement.

My next card was the 9600GT which I really did consider thoroughly.  Gigabyte has a new passively cooled version of the 9600GT that I thought would make a perfect fit, however I couldn’t justify the $200 it was going to cost me.  I am not an avid gamer, in fact that last game I ever played on my PC was Command and Conquer Tiberium Wars, not the most graphic intensive video game.

With these cards eliminated I stumbled across an ASUSTek Silent 8600GT, which seemed to fit my needs quite well.  This card is passively cooled and does not require and extra power connection.  This card was also on sale at my local PC shop, so I managed to score it for $75.

I now had to find a suitable motherboard to connect all this stuff too.  I’ve always been fond of Asus motherboards and have been using them exclusively in my personal computers since 1998.  I’ve yet to really ever have an issue with them, so it was obvious to me that I would be putting one in my new computer as well.  My first job though was to verify what Asus boards worked best with OSx86.  After doing some hunting around the web I found that the P5k-E series of motherboards had good compatability with OSx86, and were solid performing motherboards based on Intel’s P35 architecture.   I found a P5K-E on sale at my local pc shop for $160.00.

Asus P5K-E

Having my main components in hand, I decided that I’d have to get a new case to house my new components. I decided on the Antec P182.  This case was designed with the help of SilentPCReview there are tons of reviews of this case on the net, so I won’t go into full details as to why I chose the case, but it definitely fit my needs, and fit my budget as well.  I fitted the P182 with an Enermax Modu+82 525w powersupply.  Unforutnately I couldn’t find a lower wattage powersupply.  I would of prefered the 425W Modu+ 82, but things don’t always work out for the best.  I’ll be keeping my eye out for something a little lighter in the future and will probably make the switch.  I do have to say though, this power supply is incredibly quiet.  Usually power supplies are always humming along, but with this one I barely even notice when the fan kicks in.

I filled the rest of my PC build up with the usual components, 4gb of ram (A definite requirement for anyone who does any type of software development), a DVDRW drive, and a Seagate NCQ 500GB hard drive.

Overall the new PC is everything I dreamed it to be.  Finally my PC isn’t struggling to run Tomcat, MySQL, and Eclipse at the same time, finally Itunes loads in a reasonable amount of time, and most of all finally it doesn’t take me hours on end to Rip a DVD.

Here’s a final spec list for the build including prices for all the items

Bringing the grand total to $873.96!!!!

When you consider that the same PC from Dell or HP would cost you a lot more then that, it’s pretty satisfying to know that not only did you save yourself money, but you enjoyed yourself while doing it.

Back from New York

Well this post is probably a little late, but I recently took a trip with some friends to New York City. This was my first time in the big apple and I have to say that I fell in love with the place, like so many do. This city has everything anyone could ever want and then some. I was only there for a short period, but in that short period I got the feeling like New York was the type of place I could see myself living, if only for a little bit.

My favourite part of the trip had to be the when my friends and I ventured down to Canal St, and China town. I have never experienced anything like that in my life, the amount of people and little shops on the street selling knock off everything was unbelievable. Looking for a follex? perhaps some Gucci sunglasses, they have it all and are willing to negotiate on price 😉 We happened to be in New York around the same time as Chinese New Year so the streets of China town were packed full of people celebrating and dancing around. At every corner there were people dressed as ritualistic dragons dancing and store owners presenting offerings for prosperous New Years.

Our best meal of the trip in my opinion was at this little Vegetarian Dim Sum place, where I got to sample of Simulated Shark Fin, Spinach, and Simulated Shrimp Dumplings which were all very yummy. We got the “real” tour of China Town thanks to my friends friend who actually lives in New York and worked for a long time as a designer in the China Town area. It was great because he knew all the cool places to checkout, and even took us on a little tour of Little Italy. Little Italy was great as well, but by that point the sun had set and I was beginning to freeze, so I have to say I probably didn’t enjoy it as much as I normally would.

My friends and I decided to get a NY Pass which got us into so many places for free and with line bypass. Our first use of this pass was a trip up the Empire State Building. It’s funny for such an amazing building the inside has to be thoroughly disappointing. Except for the main lobby where the architecture is breathetaking, the rest of the building is either falling apart or currently under “remodeling”. Once you get up to the top though, everything about the interior is forgotten. You are presented with a birds eye view of the entire city, and you really get a feeling for how big New York City is, and at the same time how small it is considering how many people actually live there. We were lucky since the day we went was a clear sunny day that allowed us to see the entire city.

Our pass also got us into all of the amazing museums in New York. We took our second day to tour around MOMA, Natural Science Museum, and the Guggenheim. I’m usually not a huge fan of Museums but I really did enjoy all of these, except for the Natural Science museum which I found somewhat boring. My favourite of the bunch was definitely the Guggenheim, it is a beautifully designed building and the exhibits were different from anything I had seen before. On display was a famous Chinese artist you used gun powder to create absolutely amazing “paintings”.

We also spent a lot of time walking around Central park as we made our way to the different museums, and I have to say I’ve never experienced something of that scale before in such a densely populated area. It was amazing to see all the beautiful apartments looking into Central Park, but even more amazing was that I felt like I wasn’t in the city anymore. It was like being transported into a beautiful natural wooded area, while still being steps away from the core of New York City. It really was quite an amazing feeling and I could definitely see why many New Yorkers spend so much time walking around Central Park.

I could go on and on about all the things we did and saw but I’d quickly fill up my entire blog, not to mention I just don’t have the patience to retell the entire story here.

I have to say that New York gave me this feeling that no other city has managed to give me. I felt like the city was alive, it gave me this energy that no other city has ever given me. There’s always something going on in New York, always places to go and see. Not to mention the history that engulfs the entire city. I loved the fact that you could just walk anywhere you wanted to go, there was no need to worry about getting into your car, just throw your favourite pair of shoes on and walk. Nothing was really that far and if it was it was only a short subway ride to get you there.

I really have to thank my friends for planning such an amazing trip, I really did enjoy myself and I can’t wait to go back. Hopefully next time I go it will be the summer time so I can enjoy more of the city without having to worry about freezing my butt off. I have also included the pictures from our trip.

Diebold Fixing The Election Already?

I don’t know how many of you guys are following the primaries going on in the US but I have been watching it closely over the past couple of weeks, and came across some interesting information regarding the New Hampshire primaries that were held last night.

It seems as though Diebold, you know the guys who make the electronic voting machines that even a child could hack, has been tinkering with some of the polling stations throughout New Hampshire in order to give Hilary Clinton a little boost in the polls.  Although the data is not 100% conclusive it does offer some interesting looks into what may be happening in the upcoming election.

Anyway this is a good read for anyone following what’s going on in Politics in the states or who generally follows Politics.

Diebold and New Hampshire

The Contrarian

Also I found these rather humorous images about Diebold.

Diebold Fixation Images

This is definitely my favourite