Return-Path: Delivered-To: apmail-incubator-geronimo-dev-archive@incubator.apache.org Received: (qmail 39945 invoked by uid 500); 22 Aug 2003 18:41:12 -0000 Mailing-List: contact geronimo-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: geronimo-dev@incubator.apache.org Delivered-To: mailing list geronimo-dev@incubator.apache.org Received: (qmail 39843 invoked from network); 22 Aug 2003 18:41:10 -0000 Received: from adsl-209-233-18-245.dsl.snfc21.pacbell.net (HELO public.coredevelopers.net) (209.233.18.245) by daedalus.apache.org with SMTP; 22 Aug 2003 18:41:10 -0000 Received: from coredevelopers.net (dsundstrom-host236.dsl.visi.com [208.42.65.236]) (using TLSv1 with cipher DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by public.coredevelopers.net (Postfix on SuSE Linux 8.0 (i386)) with ESMTP id 6CFEDDEB1 for ; Fri, 22 Aug 2003 08:05:12 -0700 (PDT) Date: Fri, 22 Aug 2003 10:11:33 -0500 Mime-Version: 1.0 (Apple Message framework v552) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: [bcel] Is anyone a BCEL expert? From: Dain Sundstrom To: geronimo-dev@incubator.apache.org Content-Transfer-Encoding: 7bit Message-Id: X-Mailer: Apple Mail (2.552) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N We are going to need some BCEL code which varies from simple to quite complex. If you are an expert or eager to learn, here is what we need (from simple to complex): Interface proxy generator -- This is a copy of java.reflection.Proxy. Why do we need a copy? Well I think it is a good starting point for the rest of the stuff, and I know we can do it better. I would like the proxy generator to be able to generate class names that have some meaning other then Proxy$24, and I think we can write code that this faster. Dynamic instance factory -- One slow thing we will run into with the proxy generator above is normally the core of the generator looks like this: Object getProxy(Class[] interfaces) { Class clazz = getProxyClass(interfaces); Constructor constructor = clazz.getConstructor(null); constructor.newInstance(null); } Jeremy and I did some benchmarks the other day and the call to newInstance on constructor is surprisingly expensive (the rest can be optimized out). The fastest way we found to create a class was to generate the byte code for an instance factory. The factory would be the equivalent of this Java code: public class MyProxyInstanceFactory implements InstanceFactory { public Object newInstance() { return new MyProxy(); } } So the line newInstance line becomes: InstanceFactory factory = getInstanceFactory(clazz); return factory.newInstance(); Notice this is not using a reflection call, it would raw byte code to create a new instance the normal java way and has the exact same cost as calling an interface method (duh, it is a call on an interface method). This is another flexibility versus speed trade off. To keep the factory simple, it can only create classes with no arguments. I used beclifier to do this, but I really don't understand BECL, so I would not want to commit it. Abstract class proxy generator -- We need this for the CMP 2.x implementation. In CMP 2.x the bean provider writes an abstract class and we generate a concrete sub class. I think the best way to implement this, is to extend the interface proxy generator above, to allow one of the specified interfaces to be a class. When it detects a real class, the proxy generator would generate a subclass of the class and implement any abstract methods by delegating them to an InvocationHandler. Field interception -- This will make CMP 1.x much easier to implement. In CMP 1.x, the bean provider writes a concrete class where the persistent fields are simple public fields of the class. If we can replace all byte code that access these fields with a call to the InvocationHandler, it will make CMP 1.x look like CMP 2.x. This technique is also used by JDO so it will make our JDO implementation (when we get to that) easier. This should be a very fun project. I'd do it myself, but I've got too many other things on my plate right now. -dain /************************* * Dain Sundstrom * Partner * Core Developers Network *************************/