// immutable, has strong refs // Do not run in a synchronized block - it goes wrong in the presence // of elaborate classloaders (like in Gazelle BEA) // see #1102990 and #1102991 final sclass _MethodCache { final Class c; final HashMap> cache = new HashMap; *(Class *c) { _init(); } void _init() { Class _c = c; while (_c != null) { for (Method m : _c.getDeclaredMethods()) if (!isAbstract(m) && !reflection_isForbiddenMethod(m)) multiMapPut(cache, m.getName(), makeAccessible(m)); _c = _c.getSuperclass(); } // add default methods - this might lead to a duplication // because the overridden method is also added, but it's not // a problem except for minimal performance loss. for (Class intf : allInterfacesImplementedBy(c)) for (Method m : intf.getDeclaredMethods()) if (m.isDefault() && !reflection_isForbiddenMethod(m)) multiMapPut(cache, m.getName(), makeAccessible(m)); ifdef _MethodCache_debug print("MethodCache " + this + ": " + className(c) + " => " + keys(cache)); endifdef } // Returns only matching methods Method findMethod(S method, O[] args) ctex { L m = cache.get(method); ifdef _MethodCache_debug print("findMethod " + this + ": " + className(c) + "/" + method + " => " + m); endifdef if (m == null) null; int n = m.size(); for i to n: { Method me = m.get(i); if (call_checkArgs(me, args, false)) ret me; } null; } Method findStaticMethod(S method, O[] args) ctex { L m = cache.get(method); if (m == null) null; int n = m.size(); for i to n: { Method me = m.get(i); if (isStaticMethod(me) && call_checkArgs(me, args, false)) ret me; } null; } }