Protocol Buffer Anyone?

We often discuss XML and JSON as the data formats for client server computing over the web. Another format – Protocol Buffer (protobuf) – is gaining ground. It is a binary format and the size of messages are much smaller than XML or JSON.

But, things begin to get cloudy. XML and JSON can be compressed in flight. Compressed XML and JSON messages are actually smaller than protobuf.

Even with compressed XML and JSON, benchmarks show that protobuf can be faster. This IBM DeveloperWorks article gets into that. Note: The article does not explicitly say that the performance benchmark was done for compressed XML and JSON. The author has confirmed that in the follow on discussion, seen below the article.

No Comments

Getting Started With Android 2.2

I have often found that Google’s quick start guide for Android development lacks crucial details. Finally, I decided to do something about it. This tutorial should help an absolute new comer to Android programming.

Before you start, make sure that you have these installed:

  • JDK 6. Just JRE is not enough. You will need to install full JDK.
  • Eclipse Galileo

Install Android 2.2 Platform

Download android SDK 2.2 from this link. Unzip the ZIP file under C:\. This should create the C:\android-sdk-windows folder.

Add C:\android-sdk-windows to the PATH environment variable.

Log off and log back in for the change to PATH to take effect.

Now, we will download the Android 2.2 platform.

From the C:\android-sdk-windows\tools folder, run android.bat.


Select Settings on the left hand list.

Check the Force https checkbox as shown above.


Select Available Packages.

On the right hand side, select SDK Platform Android 2.2, API 8, revision 1 as shown above.

Click Install Selected to start installation.


Click Install.


When installation finishes, click on Close.

Install Eclipse Plugin

Make sure that you have added the SDK directory to PATH environment variable.

Launch Eclipse.

Select Help > Install New Software.

Click the Add button to add a new site.


Add the URL as the new site. Click OK.


Expand Developer Tools and check Android Development Tools.

Click Next.


Click Finish.


Click OK.


Click Yes to restart Eclipse.

Create a Virtual Device

An Android Virtual Device (AVD) is a device (phone) emulator. You will use it to test and debug applications.

From Eclipse menubar, select Window > Preferences.


Select Android.

Click Browse button and select the directory where the SDK was installed (C:\android-sdk_r06-windows in our case).

Click OK.

From menubar, select Window > Android SDK and AVD Manager.

Select Virtual Devices on the left.

Click New.


Enter my_avd as the name. Select Android 2.2 as the target.

Click Create AVD.

Close the AVD manager.

Write a Simple Application

We will now develop a basic application to test our development environment.

in Eclipse, select File > New > Project from the menubar.


Expand Android and select Android Project.

Enter the values as shown below.


Click Finish.

Expand the HelloWorld project and then src > com.webage.hello.



Change the onCreate method as follows.

public void onCreate(Bundle savedInstanceState) {
    TextView tv = new TextView(this);
    tv.setText("Hello World!");

Organize imports (Control+Shift+O).

Save changes.

Test the Application

While the editor for is active, from the menubar, select Run > Run.


Select Android Application. Then click OK.

System will start the Android Virtual Device. This can take up to 5 minutes. While the device is booting, the screen will look like this.


Then, you will see the home screen.


Finally, the application will be started.


To exit the application, click the home button.


Congratulations, you have successfully installed the Android development environment and tested your first Android application.


Mobile Computing Stream Launched

At Web Age Solutions, we have discussed offering a curriculum on iPhone/iPod touch/iPad and Android OS for a long time. Our training has been always geared towards the large enterprise type businesses. The timing is just right. While iPhone is not new, the enterprise scale businesses are beginning to get into the platform. Mobile platforms are filling in various gaps left open by a PC and browser based combination. Mobile apps are special purpose. They can offer data and services more efficiently than a browser. I am a huge fan of soccer. I use the ESPN World Cup soccer app for iPod Touch several times a day. It gives me just what I need to know, including video, very quickly. I can be anywhere in the house or out for a walk. In contrast, I have been to the ESPN’s World Cup soccer web site only twice. These apps are excellent for building brand loyalty. They do that by offering valuable information about a company’s products and services within a few taps.

Today, our Mobile Computing stream finally went live. Right now, there is only one course – WA1920 iPhone Application Development Using SDK 4 and 3. It’s a 3 day course right now. The goal is to turn a C++ and Java developer into a full fledged Apple mobile developer within three days. We may add an extra day of Objective-C, if that is what our clients find useful.

Courses on Android are coming soon!

1 Comment

Small Linux Fun

Recently, I had to run a few experiments with Linux. I did not want to boot Linux separately from Windows. A virtual machine was the solution. I just didn’t have the time to download a large virtual image. I was working from my hotel room with despicable Internet speed. Then I hit upon Damn Small Linux (DSL). This thing saved my day. DSL distributes a virtual image along with the Qemu virtual machine.

I download from one of the mirrors. Extracted it in C:\temp\dsl. From there, I simply ran dsl-base.bat. Voila, Linux started to boot.

Why can’t everything be so simple, huh?


Eventually, X Windows with a full desktop started up.


No Comments

Generational GC in IBM JDK

IBM JDK 1.5 introduced the use of generational GC. Prior to that, the whole heap was divided into Large Object Area (LOA) and Small Object Area (SOA). No consideration was given to the age of an object.

Generational GC attempts to minimize the number of objects to be inspected during GC. It takes into account the age of the objects. The mechanism is similar to the generational GC of Sun HotSpot and JRockit. There are slight differences.

Enabling Generational GC

Generational GC is not enabled by default in IBM JDK 1.5. To enable it, use the gencon GC policy. This is done by adding the following command line argument.


Heap Partitions

Partitioning the heap in regions is key to minimizing the number of objects to be inspected during GC. When generational GC is enabled, the heap is divided into two spaces:

  1. The new space.
  2. The tenured space.

The new space is further divided into two zones:

  1. Allocate space.
  2. Survivor space.



Initially, the survivor space is completely empty. A new object is always created in the allocate space.


If when creating a new object an allocation failure takes place in the allocate space, a minor GC called scavenge is started. Scavenge works as follows.


All live objects from the allocate space are moved to the survivor space. The allocate space becomes completely empty of any live objects. The roles of the allocate and survivor spaces are then switched.


New objects are then created in the new allocate space.

If during scavenge, it is detected that a live object to be moved from the allocate space has survived N number of previous scavenge attempts, the object is moved to the tenured space instead. Where N is called the tenure age and is dynamically determined by the JVM.


It is expected that if an object has survived multiple scavenge attempts, it is probably a long lived object. There not much point is inspecting that object during every GC. By moving that object to the tenured space we reduce the number of objects to be inspected during a scavenge.

If after a scavenge and allocation failure continues in the new allocate space, the new area is grown.

If during tenuring, the tenured space has allocation failure a GC of the tenured space will be needed.

Setting Sizes

The –Xms and –Xmx options continue to set the total initial and maximum sizes of the heap.

To set the initial and maximum sizes of the new space, use the –Xmns and –Xmnx options. For example:

-Xms5m  -Xmns2m

The total initial heap size is 5MB. Out of which 2MB will be for new space. The remaining 3MB will be for the old space.

You can also set the initial and maximum size of the tenured (old) space using –Xmos and –Xmox. But, avoid setting both new and tenured space sizes. It is best to set the size of one space and let the system use the remaining heap for the other space.

To view the current sizes of various spaces, use the –verbose:sizes option. For example:

-verbosegc -Xms5m -Xgcpolicy:gencon -verbose:sizes –Xmns2m

This will output:

-Xmca32K        RAM class segment increment  
-Xmco128K       ROM class segment increment
-Xmns2M         initial new space size  
-Xmnx253764K    maximum new space size  
-Xms5M          initial memory size
-Xmos3M         initial old space size
-Xmox1015058K   maximum old space size
-Xmx1015058K    memory maximum
-Xmr16K         remembered set size
-Xmso32K        operating system thread stack size
-Xiss2K         java thread stack initial size
-Xssi16K        java thread stack increment
-Xss256K        java thread stack maximum size 

Understanding Generational Verbose GC Output

When a scavenge is performed, only the new or nursery area is collected. The verbose GC output looks like this.

<af type="nursery" id="1" timestamp="Jun 22 22:46:35 2010" intervalms="0.000"> 
  <minimum requested_bytes="16" />
  <time exclusiveaccessms="0.014" meanexclusiveaccessms="0.014" threads="0" lastthreadtid="0x00172F00" />
  <refs soft="3" weak="6" phantom="1" dynamicSoftReferenceThreshold="32" maxSoftReferenceThreshold="32" />
  <nursery freebytes="0" totalbytes="1048576" percent="0" />
  <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
    <soa freebytes="2871984" totalbytes="2988544" percent="96" />
    <loa freebytes="157184" totalbytes="157184" percent="100" />
  <gc type="scavenger" id="1" totalid="1" intervalms="0.000">
    <flipped objectcount="8514" bytes="467600" />
    <tenured objectcount="0" bytes="0" />
    <finalization objectsqueued="1" />
    <scavenger tiltratio="50" />
    <nursery freebytes="463696" totalbytes="1048576" percent="44" tenureage="10" />
    <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
      <soa freebytes="2871984" totalbytes="2988544" percent="96" />
      <loa freebytes="157184" totalbytes="157184" percent="100" />
    <time totalms="1.962" />
  <nursery freebytes="461648" totalbytes="1048576" percent="44" />
  <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
    <soa freebytes="2871984" totalbytes="2988544" percent="96" />
    <loa freebytes="157184" totalbytes="157184" percent="100" />
  <refs soft="3" weak="2" phantom="1" dynamicSoftReferenceThreshold="32" maxSoftReferenceThreshold="32" /> <time totalms="2.023" />

The af type and gc type clearly shows that it is a scavenge type GC.

The <nursery> element appears in three places. The first one shows to size of the new space and the amount of free space available. The second one shows the same metrics right after scavenge. The third one shows the metrics after the new object has been allocated (the object that could not be allocated earlier that resulted in an allocation failure). The sizes of the tenured space should not change before and after a scavenge.

The -Xtgc:excessiveGC option comes handy to detect any GC related performance problem. This will output the following after every GC.

excessiveGC: gcid="6" intimems="7.014" outtimems="284.637"
 percent="2.40" averagepercent="0.40" 

Here, intimems shows the amount of time spent doing the last GC (with GC id of 9). The outtimems parameter shows the interval between the last two GCs (GC id 8 and 9). The percent and averagepercent parameters show the percentage of the time spent doing GC compared to normal execution of the JVM.

By default, verbose GC output goes to native standard error file. The –Xverbosegclog option allows you to route verbose GC output to a different file. For example: