|
RFC: Reflection refactoring: msg#00162java.classpath.patches
Hi, I would like to add an indirection layer to reflection (attached is java.lang.reflect.Field, but I also want to do this for Method and Constructor). By doing this, we can start caching these objects in Class and have a Classpath common reflection caching mechanism. To give an idea of how that would look, here's a rough example: public class Class { private SoftReference reflectionCache; static class ReflectionCache { Constructor defaultConstructor; VMMethod[] methods; VMField[] fields; } private ReflectionCache getReflectionCache() { ReflectionCache rc; if(reflectionCache == null) { rc = new ReflectionCache(); reflectionCache = new SoftReference(rc); return rc; } rc = reflectionCache.get(); if(rc == null) { rc = new ReflectionCache(); reflectionCache = new SoftReference(rc); } return rc; } public Field getDeclaredField(String name) throws NoSuchFieldException { memberAccessCheck(Member.DECLARED); VMField[] field = internalGetDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(name)) return fields[i].newField(); } throw new NoSuchFieldException(); } private VMField[] internalGetDeclaredFields() { ReflectionCache rc = getReflectionCache(); if(rc.fields == null) { rc.fields = VMClass.getDeclaredFields(this); } return rc.fields; } } Regards, Jeroen
Classpath-patches mailing list Classpath-patches@xxxxxxx http://lists.gnu.org/mailman/listinfo/classpath-patches
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [generics] FYI: Minor fixes to java.lang, Andrew John Hughes |
|---|---|
| Next by Date: | Re: RFC: Reflection refactoring, Archie Cobbs |
| Previous by Thread: | FYI: gnu.classpath.SystemProperties.java, Sven de Marothy |
| Next by Thread: | Re: RFC: Reflection refactoring, Archie Cobbs |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |