Rewriting code after compilation

For a project at my work I needed to replace invocations of methods with my own code and still be able to call the original code in replacement. I couldn’t change the source directly as I wanted the code to be general enough to use it with other projects too.

The goal of my replacement was to add logging code to the application on byecode level. I wrote a class with a static method to do the logging and call the original method. My method had to be static to reduce the changes needed to replace the method onvocations on bytecode level. Then I put this class into my CLASSPATH. To replace the actual method invocations I used ASM. Its pretty easy to change existing class files with ASM. I will blog later about this.

When you replace method invocations like this you have to follow some rules. When the original method is static the new method has to use the same method signature. This means the the same arguments. Thanks to the way non-static methods are called in bytecode level its easy to replace them with a static method too. You just have to add the instance as first argument to the argument list of the new static method. To give you an example: the signature of the old method

(II)V

becomes

(Lfoo.bar.MyClass;II)V

for the new static method.

Inside my own static method I was able to do the logging and call the real method that got replaced. Other possible usages of this would be to change behavior of compiled code.

Posted in General, Uncategorized | Comments Off on Rewriting code after compilation

Reduzing size of GNU classpath’s runtime jar

Late I spoke with Rege Wagner in person about GNU classpath and other free software to run them on some PDA device like the iPaq. We both agreed that the glibj.zip from GNU classpath e.g. used by jamvm is way too big for small devices with 8MB or 16MB of RAM. Now I thought about this a bit and found three possible ways to reduce the size:

1) Removing of unused stuff.
2) Obfuscating/shrinking stuff that is not in the public API.
3) Using a different format to store the classes.

Point 1 is relatively easy to describe: remove all classes from glibj.zip that you don’t need at runtime, e.g. remove javax.swing.* when you don’t wanna run Swing applications. I will try to make this easy with the GNU classpath build system soon. My idea is to use some kind of profiles on what classes should be put into glibj.zip. With these profiles the user then gets only what he asked for. Another approach to this might be to use annotations and process the code with an annotation processing tool. This can reduce the size too and has the net effect that you can remove some stuff from classes instead of using the whole class or removing it completely. We don’t have such a tool yet in out toolchain. Any volunteers?

Point 2 is relatively easy to to. You just call proguard on glibj.zip and tell it what stuff should be obfuscated/shrinked and what not. As I currently use proguard a lot currently at work I know its advantages and disadvantages. I will publish some isntructions in my blog in some time. What this works really well we can adopt this in our build system.

Jar/zip is a really ineffective file format to store stuff inside. There better ways to store files inside a file and load it into memory at runtime. The problem with most formats is that you need some information in memory that are needed for extraction. Better compression algorithms need normally more CPU and/or memory to decompress stuff. We need to investigate this and perhaps support different formats like tar.gz and tar.bz2 to store the class files and resources provided by GNU classpath. Another problem is that our runtimes need to support the formats. I will experiment with jamvm a bit and implement decompression from different formats in it.

Posted in General, Uncategorized | Comments Off on Reduzing size of GNU classpath’s runtime jar

antiauto project started

I decided to start a new project after I got some feedback on my last past. Having some automake integration in Eclipse seems to be really needed. The project is called antiauto and can be found here now.

More feedback is really welcome. The released version is much improved over the version I wrote about earlier.

Posted in General, Uncategorized | Comments Off on antiauto project started

Automake based projects in Eclipse

Currently automake based projects are not very well supported in Eclipse. On the other side ant based projects are really well supported in Eclipse.

To close this gap until one writes a plugin that does it for real I wrote a small build.xml template
for ant that calls configure and make. It allows to generate the auto* files, runs configure with the needed flags and can call the most common targets of Makefiles. It just needs to be placed in the root of an automake based project with the filename build.xml. Eclipse recognizes this as ant build file automatically then and you can easily runnin its targets.

Please test it and give feedback. More ideas and patches are welcome.

Posted in General, Uncategorized | Comments Off on Automake based projects in Eclipse

GNU classpath in the press (update)

Mark Wielaard just sent me a mail telling me that the article is online now. Unfortunatly it is german only. I will write another update when I find an english version.

Posted in General, Uncategorized | Comments Off on GNU classpath in the press (update)

GNU classpath in the press

Yesterday I looked into the new edition of the monthly german Linux Magazine. I was very glad when I read the Brave GNU World column by Georg C. Greve, president of FSF Europe. It was mainly about Java and Free Software. A big part of it described GNU classpath. Its good to see that some people not directly involved use it and actually do something to make it more popular. Unfortunately I can’t find an online version of this article yet but I’m sure there will be soon together with translations to other languages like english.

Posted in General, Uncategorized | Comments Off on GNU classpath in the press

gcjwebplugin 0.3.1

Today I released a new version of gcjwebplugin. This release now startes the appletviewer process when it is actually needed. This means when it has to show an applet inside the web browser. Some other minor fixes are done too.

To implement this feature I need to use GDK mutexes. Its the first time I used them. What I found on google I have mixed feelings about them. Some people seem to have problems with them. I hope I use them the right way. The patch that introduced them was pretty small and all look okay.

Posted in General, Uncategorized | Comments Off on gcjwebplugin 0.3.1

Swing When You’re Winning

I had some free time while I did a bootstrap of new GCC including the BC branch merge. My Computer is not very fast. It needs over two hours for a full bootstrap. So I decided to hack a little bit on javax.swing. I looked into the japi results for the javax.swing package and saw many methods for JList, JTable and JTree missing that should be fairly easy to implement. I added them to one of my GNU classpath trees where I use the very fast jikes compiler to build. I added 72 missing methods and fixed some others while the GCC bootstrap was lasting. And I compiled GNU classpath several times in that time too. So all methods I added are actually okay. And they are all pretty obvious. Mostly missing property accessor methods or to simplify access to associated classes. Very productive after all.

Posted in General, Uncategorized | Comments Off on Swing When You’re Winning

Resistance is futile

Locale informations in GNU classpath are very buggy currently. They miss much informations, others are partly wong, some locales are completely missing. A good is the missing support for the Euro currency. ‘m currently working on this problem. Some localizations but in our bug tracker. If you are aware of one not listed there or you can provide additional informations please put them into the bug tracker, post them to GNU classpath mailing list or to me personally. My plan is to get rid of them all as soon as possible.

This weekend I attended at an indoor cycling (spinning) event. It was a 10 hours marathon. The instuctors very motivating and the music pretty good. This time the food was good too, unlike my last event. We did mountain climbing most of the time, my preferred technique. Its all about your will pushing your body to do it when you higher the resistance the bike gives you. When the exercise is finished you really feel great afterwords. I recommend everyone to try out this sport too.

Posted in General, Uncategorized | Comments Off on Resistance is futile

Indoor cyling

Yesterday I attended on an indoor cycling marathon event. Eight hours of cycling with a different instuctor every hour. It was an event to get money of the German Children Cancer Help organization. All starting charges were for them. This way I had twice as much fun as normally: I had fun cyling with over 100 other mad people while listening to cool music and I did something good.

The service there was good too. There were some people there only bringing drinks and fruits to the bikers.After cyling was finished we all got a big meal (pasta, yum yum …) and a live-band played and some people started dancing. All in all it was a very good event.

For all of you who think people doing indoor cycling are mad: I first thought the same. These people must be crazy. I will never do this. Then I tried it and I got addicted to it. It does much fun and you are doing something good for your body (most doctors say: better then jogging). Try it yourself.

Posted in General, Uncategorized | Comments Off on Indoor cyling