From: Ken A. <kan...@bb...> - 2004-11-03 23:16:40
|
Joe, Your talk made me want to look at code i haven't looked at for a long while - how Java methods are invoked. They are like Common Lisp generic functions, the right method is looked up at runtime based on the types of all aguments. There is not "type widening". There is no MOP, like you may have. For a Java class i was teaching i put all constructor/method/field invocation into a class Invoke, which was easily separated from JScheme, though we didn't advertise that. Basically an application of an instance method does a cache lookup on (list isStatic methodName ClassName canAccessPrivateData) The comments below shows the calling sequence for a JavaMethod. We do nothing fancy for method lookup except if there is only one, a common case, we invoke it and hope for the best. Instance methods do a lookup on isStatic, and methodName which we should memoize in the JavaMethod. It looks like we should specialize JavaMethod into JavaStaticMethod JavaInstanceMethod and JavaSpecifiedMethod (where both the class and name are specified) . It may be that HotSpot does some or most of that for us. public Object apply(Object[] args) { if (!(isSpecific)) return Invoke.invokeInstance (args[0], this.name, (Object[]) args[1], canAccessPrivateData); /** What goes on from here? invokeMethod(target.getClass(), target, name, args, false, canAccessPrivateData); methodTable(c, name, isStatic,canAccessPrivateData); ! methodTable0(c, name, isStatic,canAccessPrivateData); ! string cons if # ! getCachedMethodTable(c, internalName, isStatic); ! getMethodCache(isStatic) ! getNameTable(getMethodCache(isStatic), name) .get(c)); ! table.get(name)); .get(c) findMethod(ms, args) findMethodNoOpt(methods,args); loop over methods isApplicable loop over parameter types isArgApplicable isAssignableFrom moreApplicable isAssignableFrom invokeRawMethod((Method) findMethod(ms, args), target, args); invoke(target, args); **/ |