Tuesday, August 12, 2008

Providing synchronization support in Jato

When I started to work on monitorenter and monitorexit, I thought it would be quite easy. Get the reference, call the lock/unlock function, done. But, soon after beginning, I was chanting "nothing-is-what-it-seems" mantra.

For monitorenter and monitorexit, it is necessary to provide support for goto and athrow bytecode instructions. Here is why.

Providing support for athrow instruction was easy. As Jato still does not support exception handling, actually nothing but function for bytecode consuming and dummy instruction selection rule was necessary.

But, for goto, I ran into a bug in control flow analyzer. So, after few hours of debugging, did fix that bug. And every thing was easy there after.

Then sent flood of patches! YAY !

( I made some nasty formatting horrors, which were fixed by Pekka. Thanks Pekka. )

Monday, July 28, 2008

The 64 Bit and premature optimaization anomaly !

I am currently working to improve my undergrad research on Neural Network (which has been accepted in Fifth International Symposium On Neural Networks ).We have done a lot of brain storming in last few months. And then I was selected to translate the whole idea to code ! Having the sole responsibility for developing the whole idea does involve twist and turns, but it is fun too ! After finishing developing , I have a feeling that it is gonna be a good work.

And last night, my research partner informed me that , result has improved for every case but for benchmark heart attack problem. For this data set the program falls into an infinite loop.

In constructing neural network, instead of maintaining a explicit relationship of which node connected to which one, I have packed the connection information in unsigned integer. So storing and retrieving the connection information is easy, just a few left or right shift and masking .

As a matter of fact, this optimization is not very necessary here, because

1) Storing and retrieving connection information do not occur that much.

2) As it is a research on how neural network can predict result more accurately , result is of more concern not the speed.


But now, as heart attack benchmark problem has 35 input nodes, way more than other benchmark problems, I am left shifting an unsigned integer by 35 bits !. Phew ! Guess what Donald. E. Knuth has told us

"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." (Knuth, Donald. Structured Programming with go to Statements, ACM Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268.)


But as changing it would cause an avalanche of more changes, I did the obvious, changed the data type from unsigned integer to unsigned long long. And the result is same, trapped in the infinite loop.

So after more debugging for 2 hours, when I am cursing under my breath, the following line just hit me

connection_matrix_value+=1<<(edge->get_forward_node()->get_node_id()+

shifting_value_for_forward_node);

Here, 1 is of type int having length 32 bits, so shifting it by 32 or more bits, nothing retains, the net result is a big fat 0 !. So what i need to do is making 1 as unsigned long long type ( 1ULL ).

And, YAY ! everything works !

Friday, July 25, 2008

Update On Jato

Well , everything seems little scattered.

<*>store and <*>load is almost done , but cant check whether it actually works or not because of its dependency on register allocation.

instanceof is done but a little code re-structuring is needed.


For monitorenter and monitorexit , parsing and code generation is done, but need to handle athrow as well.


Haven't looked into checkcast yet.

And the deadline is August 18. Gotta run !.

Wednesday, June 25, 2008

multianewarray byte instruction in Jato

I think, multianewarray instruction was the most tough one that I have confronted so far while working on Jato. But with the help of Pekka Enberg, finally I was able to creep out of the abyss.

Initially , I assumed (very naively) that the counts for multianewarray instruction would be pushed in expression stack as EXPR_VALUE expressions. But then, Pekka pointed out that it does not work for every situation. For example, it will break in the following code :
   public int[][] newArray(int x, int y) {
return new int[x][y];
}

The better way would be, as Pekka suggested, to 'abuse' the EXPR_ARG. That is , converting each count expression to argument expression, so that instruction selector can automatically push appropriate values on the stack.

So in multianewarrray byte code handler, what I do is, after popping dimension values from the expression stack, wrap each expression into EXPR_ARGS. Then, in instruction selection and code emission phase, as all the count values are already pushed on stack, all I need to do is, make a call to array allocation function in jamvm.

Easy as pie , when you are in right track !

Monday, June 16, 2008

SynchMaster 920nw in My Fedora

Just got a SyncMaster 920nw 19" wide screen . A very nice monitor to have , bright clear distinct view all the times. But after plugging it to my computer , it shows a black area on my left ,as if it starts rendering from some (x,0) pixel.

So , I started to look into X configuration , and after a lot of head scratching , when I set the refresh rate to 75
Hz , it started to work perfectly . Weird !

Thursday, June 5, 2008

Debugging Jato

In last few weeks , while working on arraylength bytecode instruction , I had to debug Jato . But instruction provided in readme file is rather obsolete . So I had to go through the run-suite.sh and ''reinvent the wheel" .

To debug , you have to point gnu.classpath.boot.library.path to <gnu_classpath_root>/lib/classpath and bootclasspath should contain <gnu_classpath_root>/share/classpath/glibj.zip and <jato_root>/lib/classes.zip.

The easiest way to do so is , setting the following values



GNU_CLASSPATH_ROOT=`<JATO_ROOT>/tools/classpath-config`

GLIBJ=$GNU_CLASSPATH_ROOT/share/classpath/glibj.zip

BOOTCLASSPATH=<JATO_ROOT>/lib/classes.zip:$GLIBJ


then applying usual gdb command ,i.e.,



gdb --args <JATO_ROOT>/java \
-Dgnu.classpath.boot.library.path=:$GNU_CLASSPATH_ROOT/lib/classpath \
-Xbootclasspath:$BOOTCLASSPATH -cp <JATO_ROOT>/regression class_file_name_to_debug



will launch it in debug mode. You can additionally pass any other command line option ( -Xint , -Xtrace:jit ... ) also.

Tuesday, April 8, 2008

Jato , The First Look

Usually looking into any OpenSource project is rather intimidating. But ,Jato, at the first look, did not seem that scary to me. The code base is not that large and I was somehow familiar with the field (at least I thought that !). And particularly the project owner was very nice to work with.

So , armed with git , I downloaded the source code , and started to hack on it (Who wants to go to the beach in a sunny day , when you can code ;) ) So far I have submitted patch for anewarray .

Initially ,it took times to grasp the idea . But thanks to Pekka Enberg , with his help , the ride so far is fun.

Thursday, February 14, 2008

Setting Java plugin for Firefox

If you have JDK or JRE installed, enabling java in Firefox is easy.
Just make a symbolic link of libjavaplugin_oji.so resided in your JRE to your Firefox-Plugin directory.

In short ,
ln -s $JAVA_HOME/jre/plugin/i386/ns7-gcc29/libjavaplugin_oji.so /usr/lib/firefox-2.0.0.3/plugins/

will enable java in your Firefox.

Wednesday, February 13, 2008

Setting Java Path

To set Java path for all user, it is needed to edit /etc/profile

Assuming that you have installed Java at /usr/java/jdk1.6.0_02
append the following lines at /etc/profile


export JAVA_HOME=/usr/java/jdk1.6.0_02
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib

You can also edit .bashrc to provide user specific Java path setup.

Wednesday, January 23, 2008

J2ME

We've released new LivTv version last week. Encountering J2ME technology for the first time was fun ( I mean it ). But device dependency was the real pain in the ass.Here are some learned-in-hard-way facts for the newbies in the brave new world of J2ME.

  • Never ever believe your emulator . Build incrementally and run the program in the widest number of devices possible.

  • If any program runs smoothly in other devices but seems to hang in Nokia N70, check if there is any UnsupportedOperationException(default action in newly created functions in NetBeans) anywhere . NokiaN70 stalls at the very sight of UnsupportedOperationException even if it has not been thrown during runtime.


  • Do not calculate the height or width of the canvas in the constructor of any class derived from abstract Canvas class. Some phones returns wrong result when Canvas.getHeight() or Canvas.getWidth() is called in the constructor .

  • Never ever draw anything using absolute pixel distance . It is destined to make a mess for phones having different resolutions. Instead make it as general as possible . For example if you are drawing a string surrounded by a rectangle , then use stringWidth() or getHeight() methods declared in Font class to calculate the height and width of surrounding rectangle. Remember the first law, Do not believe the emulator.

  • Trying to access camera in a Samsung device by using J2ME API may turn out as a waste of time.

  • Some Samsung devices place icons and other informations at the top of the canvas. So dont just start to draw from (0,0), make it dynamical too.

  • J2ME threads are somehow different than Java threads. In J2ME , one thread can not stop, pause or resume another thread, keeping that in mind during design may save from lot of head scratching later.

  • Adding multiple commands in an alert may cause weird behavior in NokiaN90.

  • If URL contains "|" ( pipe symbol ) , NokiaN95 fails to open that Http Connection . One way around it is using Base64 encoder and decoder .

Hope, this helps.