10.26.05

Java Bytecode BCEL vs ASM

Posted in PL Research at 3:25 pm by site admin

My research on the NextGen Generic Java Compiler has progressed on to supporting mixins. A Mixin is a parametric class that extends its parametric type parameter, for example “Mixin extends T”. One advantage of Mixins is that they provide an abstract mechanism to specifiy uniform class extensions. For example I can define a class TimeStamped<T> that can extend any given class, provide additional functionality, but still preserve the same functionality as its parent.

One of the most interesting issues with Mixins in Java concerns what kind of mechanism is used to instantiate Mixins. In Java, there is no uniform way to instantaniate classes. As a result, it is not straightfoward to create a Mixin that satisfies all the possible constructor types in its super class. In otherwords, the set of constructors must be determined based on its parent class.

Now with that basic introduction, I would like to discuss how I create a Mixin instantiation. Basically, I take a Mixin template and instantiate with respect to its parent class. Wihle this process is a straightfoward “fill-in the holes”, the main difficulty I have encountered is preserving the constructor methods. What I needed to do was create a constructor in the sub class for each constructor in the parent. In addition to “bridging”, the constructor must initialize any additional state from the template. Now to do this I would normally use BCEL. However, I know development on BCEL has waned. So I did some research and discovered that it is kind of in maintence mode. In the mailing list I found a Comparison between ASM and BCEL, as well as a few other comparisons between ASM, BCEL, JavaAssist, etc. On the ASM homepage, they boast a 700% performance gain over BCEL. This seemed too good to be true, so I decided to test the performance of ASM vs BCEL in my task of creating Mixins. I am providing a copy of my source asm_vs_bcel.tgz.

Now my simple test shows that ASM is about 350% faster than BCEl. My test does the following:
1. read both the Mixin template and the new super class (used for the mixin)
2. Parse out the available constructors in the parent
3. Use the init method found in the mixin as a template to generate the appropriate ‘bridge’ constructors found in 3. After each super call, I then append all the remaining initialization necessary for the mixin (found in the mixin’s init method)
4. Write out the newly instantiated class.

The bcel code follows a very procedural methodology. While there are some annoyances resulting from using JavaClass vs ClassGen and Method vs MethodGen, a top-down read can easily explain the method.

Now the ASM code is different. At first the ASM Tutorial did not seem to stick. It is however, very correct. The two intersting points of ASM are:

* ASM works through a series of visitors.
* ASM follows a SAX model for traversing a java class.

So a ClassVisitor works through a series of sequential calls:

visit [ visitSource ] [ visitOuterClass ] ( visitAnnotation | visitAttribute )* (visitInnerClass | visitField | visitMethod )* visitEnd.

Thus to perform any code manipulation, it is necessary to define a new ClassVisitor (and probably MethodVisitor). The ASM developers have conviently provided a ClassAdapter and MethodAdapter to faciliate development. Now the use of Visitors in Java is not very new. What is kinda weird is how the SAX-ish design of ASM plays in to everything. For example, to parse a class, the class reader must accept a subclass a ClassVisitor, namely ClassNode. ClassNode represents a class tree in ASM. Naturally, ClassNode also has an __visit__ method for ClassVisitors.


ClassReader super_cr = new ClassReader(super_class);
ClassNode cn = new ClassNode();
super_cr.accept(cn, true);

And then to add a method to parsed tree, I follow a similiar pattern:

newMethod.accept (cn);

Check out the provided source code if you are interested in how ASM code and BCEL code compare, or simply need an example how to write a small class transformation using either of these two languages. For my purposes, ASM is faster and smaller and thus is my choice for the job. I will however, be performing future metrics comparing ASM, BCEl, and also down and dirty manual byte hacking for the purpose of changing the Constant Pool. The issue of course, is that ASM does not provide direct access to the constant pool. The ASM SAX model seems cumbersome, and unintuitive, in this case. I leave this task for another day.

10.19.05

Climate Model says US in trouble.

Posted in Environment at 9:50 am by site admin

Ack! Just when you thought it couldn’t get any worse. A new climate model predictsextreme weather changes in the US. Expect warmer weather everywhere. If it rains where you live, expect more rain and heavier rain.

Time to start being environment friendly. Where is my bicycle?

10.17.05

Gobal Warming and Droughts

Posted in Environment at 9:57 am by site admin

Scientific American has an article about how Warmer Climate Produces Less Rain. Although global warming increases the amount of water vapor in the air, it also increases the air’s ability to retain this moisture. As a result we have less rain in many terrestial areas.

On a positive note, there is an increases rainfall in tropical regions. I think this may explain why 16 tropical storms developed last year in the Atlantic ocean. This year, we are currently on Tropical Storm #21, Wilma in the Atlantic Ocean. And we still have roughly 6 more weeks of the tropical storm season left. Hopefully we can outdo the record holding year of 1933 with 21 tropical storms. I’m just itching to see “Tropical Storm Alpha”

Canada sure does look like a great place to live right now.. ;)

10.14.05

Om the Sacred Sound

Posted in Buddhism, Religion/Philosophy at 6:03 pm by site admin

I have been reading Siddhartha by Hermann Hesse with Elisa. Near the middle of the book Siddhartha foresakes his life as a merchant and returns to his life as an ascetic. Eventually he reaches a river and debates on killing himself. As he questions his life, he hears a voice speak the mystical word ‘Om’.

So the question I had is why is Om a special word. For many Hindus and Buddhists, Om represents creation. It signifies God and and the one-ness of everything. According to ancient Hindu beliefs, God first created sound, and these sounds manifested themselves into the phenomenal world. While many years ago this belief sounded unscientific, more modern research in physics has shown that energy and matter are connect (e.g. E=mc^2).

So why does Om mean what it means?

By examining the Sanskrit we can see that ‘Om’ actually contains 3 sounds. First the diphthong ‘o’ which actually consits of two simplier vowels ‘a’ (short a, as in the english word ‘but’) and ‘u’ (short u as in the english word ‘put’). The final sound is the ‘m’ sound produced when your lips get closed.

Now the ‘a’ sound is a pure sonant (sound produced with the vocal cords). It is the simpliest sound one can produce using the vocal cords. Consequently, it should come as no suprise why ‘a’ is considered a primal sound present throughout all of the worlds languages. Since the ‘a’ sound is produced with an open mouth it can tangibly represent creation. Now the ‘u’ sound occurs when you begin to close your mouth. The point of vibration thus shifts from solely the throat to the mouth. And then finally when ‘m’ is produced, the point of vibration shifts to the now closed lips. Thus ‘m’ signifies destruction and the end of the cycle. ‘Om’ (or Aum) represents the holy trinity of Brahma, Vishnu and Shiva. When one utters ‘Om’ successively, the trinity of creation, preservation, and destruction presents itself in a continuous cycle.

Now there is considerable analysis of the written form of ‘Om’ and its various symbolic meanings. If you are interested in such manifestations of the way, check out http://om.exoticindiaart.com/, http://www.omsakthi.org/worship/mantra.html, and http://hinduism.about.com/library/weekly/aa022200.htm. Remember though, an oral languages preceeds its written form.

10.13.05

Fish in Water

Posted in Daoism, Religion/Philosophy at 12:23 pm by James

Its easy to loose sight of where we are and where we are going. Sometimes we move around aimlessly throughout our day like a zombie raised from the dead. We confuse ourselves with our deeds; we confuse ourselves with our pains; and we confuse ourselves with our pleasures. This is dwelling. To live we must be aware in our presence and intent in our future. But what is the future? Well, what is the meaning of life? Is it the epicurian persuit of pleasure, the attainment of fame and riches, or the accumulation of power? No its not. To think so is a delusion. Is it the opposite: an austere and simple existence devoid of life? That doesn’t feel right either. There is nothing wrong with enjoying yourself, having money, fame or power. What matters is what you do with it. Life centers on learning and evolution. For intelligent life this translates into understanding, awareness, and intent. To live well, we must understand the dao. Its important to realize the amazing, creative force of life. Natural change will always occur, the depth of its energies is bottomless. To resist means death- if not physically, then mentally and spirtually. Shit happens- It’s the nature of the beast. Life goes on. Why waste time moping, arguing, or fighting? Does it really solve anything? Does it change anything? Be active and make your point. Then move on. Life is short. How unfortunate would it be to die a momment too soon, to miss out on quality time with our family and friends? You can always buy a new bike, watch the rerun of your favorite tv show, or catch a late lunch. Whatever you do, where ever you go, make sure you apply this understanding. Understanding is nothing unless you use it. In otherwords, Education is what you remember after you have forgotten everything you’ve learned. Only through continuous application do we transition from the named principle to the unnamed way. The trick is to be aware of where you and what you are doing at that very moment. Don’t be preocupied by your thoughts and let what could be slip through your fingers. Being happy is just like being sad. Its a flip of the switch. It boils down to seeing a glass half empty or half full. The true nature of man is enlightenment. Only by realizing the fog of ego can one find everlasting peace. This doesnt mean nothing in this world matters. There is a journey both in life and in death. Action today sowes the seeds of tomorrow. So be earnest in all that you do.

How to prevent loosing your buddy list

Posted in internet at 9:13 am by site admin

Is surpising how many comments I get on my original post about how I lost my AIM buddy list. Unfortuantely, once its gone, its gone. The hopeful solution is that all your good friends will IM you again. If you do log all your conversations, it is possible to filter through your log files fetching out all the distinct buddies. The only guaranteed way is to actually backup your AIM buddy list. I believe its the “Save Buddy List” in the file menu. However, like all things in life precautions just take time and are a nuisance. Its far better to have some type of failsafe. Perhaps the AIM creators can have backup your buddy list automatically.

On the bright side, loosing my buddy list was actually kinda nice. It cleared up the clutter of names. Some of the people were old friends or acquatences that I did not talk to much anymore. With a clear buddy list I was able to “move on” so to speak. And now a days, sometimes I stay off AIM all together. IM is cool and convient, but sometimes it can feel like a chain that fixes me to the computer. Socializing with people via phone or in person is a far more humanly experience. Dont get me wrong, I still use AIM to kill some time at work, fill in idle periods on the computer, and to coordinate outings.

10.08.05

Subversion RC

Posted in internet, linux at 8:34 pm by James

I’ve had a few brief encounters with CVS, but it never really got my interest. I’ve been neglecting the issue of revision control for a while. Recently I’ve been having to maintain 2-3 different sets of tools in maybe 5 disjoint machines. So I’ve decided to try to consolidate my efforts and minimize repetition. For now, I have opted to use subversion

To setup up svn on the server:
$ svnadmin create –fs-type fsfs /path/to/repos

Originally I created the svn as a berkley db, but changed it b/c the db requires a posix compliant file system. So it won’t work over nfs. Here is some propaganda for fsfs. To convert the db type after the fact:

svnadmin dump /path/to/old/repos > repos.dmp
svnadmin load /path/to/new/repos < repos.dmp

Other commands I used to get started using svn over ssh:

#check out the new repository
svn checkout svn+ssh://me@myserver.com/path/to/repos/trunk .
#import local files into the repository
svn import /local/path svn+ssh://me@myserver.com/path/to/repos/trunk
#directly create a directory on the svn server
svn mkdir svn+ssh://me@myserver.com/path/to/repos/trunk/new_directory

svn does solve a number of short comming of cvs. However, it still follows the same centralized server model and thus is hard to manage on networks with poor network connectivity. Currently I am waiting to see what direction Linus takes the Linux kernal development (which inherenttly involves distributed repository client model).

A second concern of mine is how subversion supports binaries. By their very nature, binary files are not easily monitored into revision control. Typically though, binary files are not changed very often. If they are, I probably would not care for the older versions. For these files, I have been looking for more of a file repository than a revision control source.

Another useful tool is the distributed file synchronization tool Unison.

Houston sushi

Posted in Restaurants at 8:16 pm by site admin

It seems like Japanese sushi restaurants are popping up everywhere in houston. Every other day I see a new one. Some of them have good names and character, some of them are just another wannabe place. The last couple I have seen that have stuck in my mind are:

1. Sushi King. What a name. I went in briefly and I saw a really fancy place with over priced sushi. It just seemed they were just another one of those places. I didnt eat there, and I probably wont. AND they didnt have ramen.

2. Sakana. I just heard about this place. I hear its traditional and maybe worth visiting sometime in the near future.

3. Sage 400 Japanese Cuisine (which is suprisingly located on 2800 Sage #A-400). [713-961-9566]. This place opened about 4 weeks ago so I’m sure they havent worked out all the kinks. I went there about a week ago and had a poor dining experience. While the food was reasonably good, it was not worth the wait or the price. The restaurant had 7 people at the sushi bar and 4-5 tables occupied. Our food took around 45 minutes to get to us. After everything was said and done, we ended up going to Teppay for a followup. It was awesome. While their menu is very small, we were able to order several dishes off the menu. The restaurant was not packed at all, and the service was excellent. Our meal ended with a small dish of freshly cut mangoes, asian pears, and grapes.

We also made a trip to the Cafe Japon on Kirby on Friday night. Sadly, the dumpster for the Taco Cabana is 5 meters from the front door. The smell of rotting mexican food fills the air in front of the place. Even at 9pm on a friday the place was packed. We got gawking stares all the way to our table. After a quick look at the menu, we decided to leave for a place with a better ambiance.