From: Christian N. <chr...@em...> - 2003-09-09 10:02:50
|
[Hmm. SourceForge lists seems to have been down. Trying again...] An ICQ discussion with Bill yesterday ended in these conclusions: The Timer and ShutdownHook scenarios can be handled without bytecode manipulation. For the Timer we will check runtime wether the Timer class is available or not. If not available we will use our own timing code. The Timer will only be accessed through reflection so that our source will compile under JDK 1.2. The same strategy will be applied to the ShutdownHook except that we will not offer any alternative implementation for 1.2. We'll simply document that 1.2 users will have to take care of the shutdown expilcitly. The Proxy scenario is a bit more complex. I have evaluated the following libraries in conjuction with this: ASM (http://asm.objectweb.org/) This proved to be a very low level library that requires a good knowledge of the Java byte code instruction set. It is very small and fast, but unless anybody wants to dive into the JVM spec I think its going to be to complex to use. Javassist (http://www.jboss.org/index.html?module=html&op=userdisplay&id=developers/projects/javassist) Unlike ASM this library offers a very high level api for class manipulation. It enables you to create and load classes runtime, and can even compile and add methods to classes from strings containing source code (!). It's a medium size lib (about 350k). It does not come with a ready made Proxy replacement, but we can probably roll our own with a bit of effort. CGLIB (http://cglib.sourceforge.net/) This uses ASM as a backend and comes with a ready made replacement for Proxy. The lib size is (145k). I did a rough benchmark between CGLIB and the JDK Proxy. CGLIB added a slight overhead compared to JDK Proxy calls, but it was very tiny. A million method calls to a simple string getter took about 550 milliseconds using the JDK Proxy, and about 650 milliseconds using CGLIB. I'll do the CGLIB test with 1.2 as well (the test was performed on 1.4.2) to make sure that the overheasd is not significantly larger there. I guess the best solution would be to use a similar approach to that mentioned above: Use Proxy for 1.3+ and CGLIB for 1.2. The problem here is that I have not figured out how to make a class implement the InnvocationHandler *runtime* with CGLIB. This is a simple method call in Javassist. I'll investigate further... Another compelling approach is to simply stop using the JDK Proxy and use the CGLIB Proxy all over. If we go that route we can throw away the 1.2 source tree today... I'll do a bit more investigation and keep you updated. CHR > On Fri, 2003-09-05 at 14:45, Bill Horsman wrote: > > > Hi, > > > > We're looking at replacing our use of JDK 1.3's proxy classes with those > > from http://asm.objectweb.org. The big benefit we get, other than > > possible performance improvements, is independence from using JDK 1.3. > > Our goal is to continue to support JDK 1.2 for a good while yet. > > > > The trouble is that we also make some other references to JDK 1.3+. Namely: > > > > 1) ShutdownHooks. These ensure that Proxool is properly shutdown when > > the JVM dies. It works really well and is much more robust than using > > finalize(). > > > > 2) We use a Timer class to collect statistical information. We can get > > round this with either a thread that sleeps for a while and keeps > > checking the time. Or possibly look around for a third party solution. > > I've been thinking about this. We could use the new proxy to handle both > the Timer and the ShutdownHook too. For instance, for the Timer we write > and interface that Timer is able to implement and then write our own > JDK1.2 implementation. At runtime, we try and load the JDK1.3 Timer and > if that fails, use our own implementation instead. The proxy classes are > used to get JDK1.3's Timer to implement our interface at runtime. I > think that would work. > > Advantages: 1) We get to use the (probably) more efficient JDK1.3 > classes if available. 2) Our code compiles with all JDKs. > > Disadvantages: 1) It might be a bit slower (but this doesn't matter > because both ShutdownHook and Timer are only constructed at startup). > > Christian, if you are working on the proxy stuff over the next few days > then you might want to think about this). > > Cheers, > Bill -- __________________________________________________________ Sign-up for your own personalized E-mail at Mail.com http://www.mail.com/?sr=signup CareerBuilder.com has over 400,000 jobs. Be smarter about your job search http://corp.mail.com/careers |