I've added two new methods to CodeGenerator:
void method_switch(Method[] methods, ObjectSwitchCallback callback);
void constructor_switch(Constructor[] methods, ObjectSwitchCallback callback);
"method_switch" assumes the name of the method and a Class[] of
parameter types have been pushed onto the stack. "constructor_switch"
only needs the parameter types.
The basic idea is to do a series of nested switches:
a) on method name (if applicable)
b) on the size of the parameter type array
c) on the name of the class in the nth index of the parameter type array,
where n is chosen to minimize the number of switches
d) repeat (c) ad nauseum, until each method/constructor is uniquely
identified
This may seem like a lot of work, but it is actually less than the
current situation of ClassKey creation + HashMap lookup.
Having constructor_switch now removes the need to have a Map of
ConstructorProxy objects in each Enhanced class. Instead, optimized
lookup code is generated that enables the new_instance code to be
inlined into the Factory.newInstance(Class[], Object[], Callbacks)
method.
I plan to use both method_switch and constructor_switch in an improved
MetaClass, to provide optimized versions of Method.invoke, i.e.:
Object value = metaClass.invoke(methodName, parameterTypes, arguments);
MetaClass will then become a true replacement for all types of
reflection.
Chris
|