Monday, November 24, 2008

Can AOP be some sort of elegant workaround?

In the pursuit of problem solving (or at least trying to) in my research, I guess I am taking AOP as a strategy to give me what I don't have. Maybe I am becoming too addicted to pointcuts...

I have used Aspect Oriented Programming for intercepting method calls to the OSGi framework and for adding my "concerns". These interceptions allowed me to, mainly, add hooks to service registration and retrieval. I think the good thing is that the solution was elegant enough and enabled portability accross different OSGi implementations, since the aspects targeted the API. The bad thing is that it does not rely in a standard mechanism supported by the platform, and it needs an additional building step (i.e. weaving the framework).

After taking a look at the draft OSGi spec 4.2, I've checked the Service Registry Hooks with the hope that my weaved hooks could be replaced by a standard mechanism. They have exactly proposed the hooks I wanted but sadly that alternative solution had been rejected. The hooks they will provide still do not allow me to do what I need. I'll still be doing the AOP trick...

I just can think of more pointcuts to add to my future solutions/attempts in order to have other types of hooks. As I said previously, this approach is useful to avoid changing the source code of a chosen OSGi implementation. There are lots of people in the research area who usually customize an OSGi impl to their needs (I still see recent articles talking about customizations of OSCAR). One disadvantage is that if you touch the source code directly, you're stuck with a given version which makes it difficult to follow the evolution of the chosen impl. (either Equinox, KF or Felix). You would need constant effort for merging/synchronization your branch with the current version. I believe they could avoid that by doing the AOP trick as well. However, sometimes (like while writing this) I am not sure if this a true elegant solution or if I've just found a nice and powerful workaround for adding my hooks to the OSGi core.

Thursday, September 18, 2008

How to open source an OSGi targeted tool?

I was working on a tool (with a funny name, or a ridiculous name if you will) for the diagnosis of stale references in the OSGi platform. It was part of my master thesis at Grenoble 1 university. The tool has been presented in an OSGi event in june, and in an academic conference in the beginning of this month. Among our “future plans” is to open source this tool. I am starting the PhD in the same university, and this tool will not be my main activity. I will have plenty of other things to do also. However we would like to continue evolving it.

But, I have several questions for all this process of releasing such a thing as open source. Maybe an inner self crisis!

1. Is this tool useful to anyone?

This tool is no rocket science and it does not cure problems, it only points a few of them.

My first thought is that the thing is useless, because I will always have the thought that what I’ve coded sucks and I could have done better…

But, if we do not make it available for the developer community it will surely be useless, since it would not be accessible to others. We never know if any a brave (and maybe a little insane) person would like to help evolving that.

2. How (and where) to do open source it?

Initially I may think to put it in sourceforge or google code. But my thesis advisor says it would be useless and without a good visibility for the target audience: developers of OSGi based applications. I agree. I’ve made available a small “useless” scripting console at google code, but the download count is insignificant, thus nobody is using it. We can imagine that a more specific project would fall into oblivion.

So, my thesis advisor, who is a committer in an Open Source OSGi implementation, has contacted its project leader. The guy said ok, but no more open source progress for our tool after that. I am not sure if : 1- he was just being polite and said ok; or 2- he is so busy that he can’t get into too much details on all mail that he receives. We also have not insisted since other stuff came up.

3. What if the code is not ready yet?

I am sure it is not ready. I feel like I’m leaving my house and while I'm not there people come in and see all the mess: dirt dishes, laundry, underwear in the floor. I would need to polish it. And after that, the project will no longer be “my house”, since it would belong to the community. Then the dirty laundry will be everyone's business.

But, that leads to another question: when would it be ready for that? I guess the polishing is just removing the really ugly hardcoded stuff, a few bad practices (did I just said that?). The GUI is complicated for the end user to understand it. It would definitely need some good work. I confess that in a 5 month project, with a bunch of articles to read, and also the master’s thesis to write I’ve neglected in some software engineering and also human interaction practices. If anybody has never done that before, cast the first stone.
Ah! Mavenization also. That's part of the polishing. For simplicity, I’ve used ant. Decent projects these days at least use maven for managing dependencies.

4. What if they find bugs in my code?

Normal. Just open an issue. I am far away from being a bug free coder and I guess 99% of the developers out there are not bug free either.

5. When to do the open sourcing?

Good question. I guess ASAP before I have even less time for polishing the code.

6. Volunteers for continuing the tool development?
I believe we have at least one: me :)

Well, these are basically my doubts that I share here in this post based on the little spark of dellusion that my master thesis result would be useful to someone.

Friday, September 5, 2008

Exclusive OSGi session at Euromicro SEAA

I was at the 34th Euromicro conference on Software Engineering and Advanced Applications (SEAA) to present an article about the tool that we have developed for detecting stale references in OSGi applications.
The conference had a session dedicated to OSGi in the Component-Based Software Engineering Track. Somehow it shows the industry/academia recognition of the important role that OSGi plays in the development of component-based appplications.

There were three articles presented in that session:
  • "Enhanced OSGi Bundle Updates to Prevent Runtime Exceptions"
    Premysl Brada
  • "Method for resource monitoring of OSGi-based software components"
    Tuukka Miettinen, Daniel Pakkala, Mika Hongisto
  • "Service Coroner: A Diagnostic Tool for locating OSGi Stale References"
    Kiev Gama, Didier Donsez
The other two presentations were pretty interesting. Each one of us showed little "hacks" for addressing some issues in the OSGi platform :)

Sunday, August 10, 2008

Benchmarking the cost of dynamic proxies

I needed to quickly compare the cost of dynamic proxies versus direct access to objects, and also position it in relation to RMI. In theory we know that they add overhead, but how much? I just wanted more precise arguments to reinforce a rather obvious statement: “Dynamic proxies are not that bad. Take RMI for example...” :)

I could not find exact and up to date info saying that RMI is X times slower than direct method calls, nor dynamic proxies. In this link they’ve said that RMI is at least 1000 times slower than local calls. Since that appears to be some info from 2001, I imagine that we’ve had some nice optimizations in JVMs in the last 7 years.

I’ve changed a benchmark code that has been used in my lab, so I could have an approximate value of each method call in different approaches. This post (which actually points to here) that I’ve just read this Sunday helped me a lot in adapting the code.

My benchmark consisted of calling a million times a method in a given object which implements the tested "dummy" interface. The method was void with no parameters, and the implementation had just one line of code assigning an integer variable. The idea was to get the closest possible to the actual invocation time, with the minimum possible for method execution time.

I’ve executed the benchmark a few times and I’ve always got the same minimum values for direct calls and dynamic proxy, respectively. However the minimum time for RMI calls varied a lot.

Dynamic proxies: 1.63 times slower than direct calls, which is not bad.
RMI calls: At least 200 times slower.

For info, here is my not so performing platform:
JVM: Sun Hotspot/JRE 1.6.0 07.
OS: Windows XP SP2.
Hardware: Pentium 1.7 GHz 1GB RAM

The cost of dynamic proxies surprised me. This article from developerWorks shows similar conclusions. I thought they would be more expensive. However, we are talking about a minimal overhead level here, as in actual usages of proxies we usually add more code for decoration, verifications, etc which would obviously lead to more than the 1.63 times that I’ve measured. Well, this info provided here cannot considered sufficient as more tests would need to be performed in order to be more precise.

Sunday, July 20, 2008

JSR 296 in coma ?

I’ve been checking the upcoming features of Java 7 and found a cool detailed list here. Also, some Java One 2008 slides from Danny Coward’s presentation show a little on that too.

Among the JSRs mentioned in the first link, I already had checked some stuff from JSRs 277, 294, concerning Java Modules, JSR 284, concerning resource consumption and JSRs 295, 296 and 303 concerning Swing.

I’ve known these swing-related JSRs since, more or less, they became available as JSRs. I had special interest on them at the time because I was working in a project where we needed a product built on top of a Rich Client Platform, to enable the development of plugins from third parties. The idea was to have a simple and pluggable structure.

For us, Eclipse RCP was overkill so was the Netbeans platform. Spring RCP was in its initial stages. We’ve decided to go from scratch, using OSGi as the base for a pluggable architecture, and build our own straightforward RCP. The JSR 296 (Swing Application Framework) proposes most of what we needed (and developed) as a Swing foundation for our RCP:

  • Resource management for i18n
  • Task services/monitoring
  • Storage for session state
  • Events/actions framework
  • Managed application exiting (exit listeners), startup, shutdown

I can't say that this is a PCP (Poor Client Platorm). Maybe an ARCP (Almost Rich Client Platform). But, as I said, it does most of what we needed at that time. And I believe there are hundreds or thousands of other applications that don't need all the heavy richness provided by the RCPs.

So I decided to take a look at JSR 296 (Swing Application Framework) to see what they have for us so far. I’ve downloaded it from the project site. (You should also need to download the SwingWorker since they do not use the SwingWorker delivered with Java 6)

This tutorial has good examples concerning the features of the JSR 296, like the magic stuff for saving session state (components dimensioning, positioning, etc):

//The non-qualified getters below are inherited from the SingleFrameApplication class
//
//Saving session State
getContext().getSessionStorage().save(getMainFrame(), sessionFile);
...
//Restoring session State
getContext().getSessionStorage().restore(getMainFrame(), sessionFile);

Lots of weeks of modelling and coding can be saved by using that framework.

There was a weird thing about the last available version: it was from November 2007. It seems that it is not evolving anymore. I’ve read a few months ago in blogs that I don’t recall, that some senior engineers from the Swing team were leaving Sun Microsystems. I could find this blog entry mentioning some of them.

The guys that took care of JSR 296 (Hans Muller) and 295 (Scott Violet) are gone. However, I think that there are no worries with JSR 295 and 303 which are just “standardizing” the concepts used in JGoodies by Karsten Lentz, who is a member of both expert groups. But the JSR 296 is apparently a home grown implementation from Sun. The guy that was handling that is gone, and there are no new versions for 8 months.

Weird… It appears that the project is in some sort of "coma".

Don’t know if it will make it until Java 7

Sunday, July 6, 2008

Heap snapshot analysis and objects with different class versions

I’ve been working lately on the detection of a particular problem, called stale references, that may happen on OSGi based applications. It is a consequence of bad OSGi programming practices that may lead to memory retention and the utilization of inconsistent objects.

As a part of the diagnosis process I need to analyze heap snapshots to find the referrers of services that have been unregistered. I’ve found some interesting stuff (at least for me) concerning memory inspection and classloading. Each module (bundle) in OSGi is provided with its own class loader instance. If you replace (update) a module during runtime, it will basically stop, refresh and restart; and get a new class loader. Objects and classes from the previous class loader must not be referenced anymore, and that previous CL is supposed to be “discarded” and GC’d.

In our custom tool I was seeing that objects from “discarded” class loaders were still being referenced by other modules. However, when I used JHat (either embedded or standalone) to inspect the heap snapshots by performing queries like “select x from com.foo.TheClassOfTheReferencedObject” the result set listed only one object instance (from the running module) when I was supposed to get two instances (one loaded by the old class loader and other by the new one).

I thought my tracking code was falsely accusing the service object from the old bundle version. After patiently and manually (maybe “stupidly”) verifying each class loader instance, I found the two different class loaders that referred to the same bundle ID, and could also found the “lost” object.

After a few weeks I’ve tried to track the same problem with the heap inspection provided in the VisualVM. It worked like a charm! I could see all object instances of the same class name, no matter what class loader provided the object class. It does not have advanced queries like JHat, but in this case I only needed a filter to find the class instances that interest me.

It’s a pity. JHat has powerful queries to analyze heap snapshots, but it can’t deal clearly with the same class names loaded by different class loaders (i.e. different versions of the same class). VisualVM has much more limited power that JHat, but allows to see attribute values, referrers and referring trees just like JHat. In addition, VisualVM deals with no problem with classes carrying the same name but loaded by different class loaders, and that what’s more interesting for me, at least for now.

Monday, June 16, 2008

How can we developers (not the companies) do off-shore jobs ?

Recently (actually just 40 minutes ago) I got an “almost certain” temporary home-office contract refused because I am overseas.
Huh ?

I’ll explain it… But skip to (2) if you’re in a hurry…

(1) The company is located in Brazil, and some people who know my job (and apparently trust on it) wanted to hire me for a temporary home-office job in that company. No development services with them so far, but as a freelance trainer last year I’ve even taught Java classes in this company which is also a faculty and tech training school, so I’m not a complete stranger for them.

I've quit my job 10 months ago and came to France to enroll in a computer science master’s degree. Ok so far. That's my choice. After knowing that some friends had done home-office for them, and since I was about to take summer vacations I’ve contacted them one month ago and said “hey if you need somebody for home-office development I’m here”.

Before leaving I left a legal representative in Brazil who can sign papers in my name, open bank accounts, etc. I’ve informed the company that I was going to be able to give legal receipts, invoices or whatever, which was what they have asked for.

But their legal department said NO…

(2) To make this story shorter:

  • The receipt/invoice would be issued by the town hall of my home city in Brazil (this is the type of receipt they asked for)
  • The money would be deposited in my bank account in Brazil
  • The job was going to be performed by a brazilian citizen with brazilian documents who would sign a contract with them, but with a TEMPORARY address in France and a PERMANENT address in Brazil.

However, as I am not residing in the country, the legal department refused to issue the temporary contract.

I have no clue how to deal with such situation. Neither these guys who contacted me have. They had good intention but the big guys said no…

My question is: how to deal with such issues related to off-shore jobs? Usually companies are hired to do off-shore. But what about people? Developers like me, like you.
Does anybody have ever faced similar situations?