Jeu George’s Weblog

Life in the fast lane

Archive for June, 2006

Son of a Bug

Posted by Jeu George on 16th June 2006

This was one of the earliest and probably one of the more frustating bugs I worked on. It was my first job and probably around six months into it. printf was still my favorite debugging tool, and was still getting the hang of  debuggers. My task was to improve the performance of Connection pool manager in the JDBC driver I was working on at the time. A section of this code implemented the singleton pattern, and one of the taskitems was to change the regular implementation to the Double Checked Locking Mechanism. I thought this was a pretty clever idea, but it kept breaking and I couldn’t figure out the reason for the longest time. The funny thing was that I couldn’t reproduce this under the debugger and neither were my printf’s (System.Writeline) or colleagues of any help and that made it even more frustating.

I eventually decided not to go ahead with this obviously, but I was glad to know the reason(s) when I finally knew it.

One of the explanations attributed it to a bug in the Java Memory Model (Out of memory writes).

1: public static Singleton getInstance()
2: {
3:   if (instance == null)
4:  {
5:    synchronized(Singleton.class) { 
6:      if (instance == null)         
7:        instance = new Singleton();
8:     }
9:   }
10:   return instance;
11: }

You would expect Line 7 to be atomic, but in fact you can break this up into

7.1 mem = allocateMemory();       //Allocate memory for Singleton object.
7.2 instance = mem;               //Note that instance is now non-null, but has not been initialized.
7.3 ctorSingleton(instance);      //Invoke constructor for Singleton passing instance.

In a multithread environment, you can guess what would happen after one thread loses its time slice after executing Line 7.2

 The other explanation that I heard was that the compiler would get ’smart’ and realize that there was nothing really useful between Lines 3 and 6 and nothing changed the value of the instance variable in between, and so it would ‘optimize’ the code by taking out Line 6 and combining it with Line 3. In Debug mode, it wouldn’t ‘optimize’ this and it worked like a charm.

There have been a ton of discussion around this, a good amount of which is captured here.

Sources for sources: http://www-128.ibm.com/developerworks/java/library/j-dcl.html

Posted in Technology | No Comments »

Bugs UnPlugged

Posted by Jeu George on 8th June 2006

How long can a bug go undetected, especially when it’s in a place that is widely used. How about 9 years? This one in the standard binary search in JDK was caused by the infamous overflow error. When the code was originally written, testing something like this was probably infeasible.

That brings up an interesting question, Should you keep testing even after you ship?

Posted in Technology, Trivia | 1 Comment »

On Top of the World

Posted by Jeu George on 5th June 2006

Well, not exactly on Mt Everest. But we won our ARCL cricket division finals for the second consecutive time this season. Unlike last time, this season’s performance in the round robin league wasn’t all that great, but we managed to qualify for the knockout stage and made it to an enthralling final yesterday.

 

We won the toss and elected to bat, history suggests it’s always good to bat first in a pressure match like this one. It was another ordinary batting performance yesterday, with just 28 in the first 10, at the cost of 4 wickets. A good partnership between Vijay and Ram helped us reach 63 in 16, just enough for us to fight back and stay in the game.

 

But an excellent display of fast bowling by Ram, and some spectacular catching (something like this and this) lead us to a comprehensive victory, bowling a strong opposition out for just 28. The match was won in the first 3 overs. With 3 wickets and just around 5 runs on the board, we had to commit harakiri to throw the match away.

 

Go Daemons Go!!

 

Update: Check out some of the pictures http://spaces.msn.com/durbha/

Posted in Cricket | 1 Comment »

New technology incubation centre opens in Bangalore

Posted by Jeu George on 3rd June 2006

This is a good move by the Karnataka government and should help budding entrepreneurs realize their dreams. All the big successful software companies in India have their business models centered around servicing. Yes, it does bring in a lot of revenue, creates jobs, improves the economy, but eventually the fruits are harvested in other places. This needs to change and moves like this will take us one step closer.

There have been programs like this by other state governments, but IMO their objective is to attract more people and help improve the state economy. But something like this, in a place like Bangalore, India’s Silicon Valley, is certainly a move in the right direction. Although, it is to be seen what kind of benefits will be made available to get more people to adapt this program.

There will be a day when we will have more production units, than servicing centers.

Posted in Technology, Current Affairs | 1 Comment »

The Ultimate PC or whatever you want to call it

Posted by Jeu George on 1st June 2006

Computers have evolved over the years, from the Antikythera used by the ancient Greeks to study planetary movements, to good old Abacus’, use of punch cards to ENIAC’s, micro computers and main frames to the modern PC that we use today including the various variants like handhelds, laptops, tablets, video game consoles and not to forget the super computers.

It’s been quite a journey, but what will it look like a few thousand or maybe just a hundred years down the lane, long after we are all gone. This is what I envision how my life might look like. There is this device called “brain wave codec”, which I always carry with me. Authentication is through a combination of my DNA (saliva) and a password that I just have to think. I can command the device through thought. The brain waves (electrical signals emitted from the brain) are decoded to analyze my thoughts and convert them into a universal intermediate language which every other device can understand. I wake up in the morning and I need to know what’s happening in the world, maybe catch up with the daily headlines and check out how India did in yesterday’s cricket match, So I just think about it, the codec converts my thoughts and sends the commands out to the web (yeah, its all wireless duh..). The web returns back a bunch of stuff that I am interested in, Its been studying my interests for a while now. The codec then converts it back to something my senses could use, like voice or text or just feed it directly to my brain so I just know what happened. Based on my mood, the kitchen is sent commands to prepare whatever breakfast I want. At work, I will be writing cool user friendly software that shows and analyze users thinking patterns that could be used by businesses to build wonderful applications. During weekends, I would want to go shopping with wife to this new mall, Yeah, I don’t think this will change in a thousand years. So, we sit in our car, the car now already knows about this and it would take us to this new place. We shop around for stuff and pick my things from the shop and just walk out. The checkout system knows who we are and so it just deducts what it needs from my bank balance. We decide to have dinner outside in a Thai restaurant. I think about what the best Thai restaurants are around this new place, I immediately get results from the web and decide to go to one in the list, my car then just drives me there. On the way we pull up the menu and place an order, all through thought. Yeah, even though we can telepathy, we usually just talk. The table and food are ready when we reach there, so we have a good time and leave the place and head back home, a few dollars less.

Posted in Technology, History | No Comments »