logo       

RFC: Reflection refactoring: msg#00162

java.classpath.patches

Subject: RFC: Reflection refactoring

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

Attachment: Field.java
Description: Field.java

Attachment: VMField.java
Description: VMField.java

_______________________________________________
Classpath-patches mailing list
Classpath-patches@xxxxxxx
http://lists.gnu.org/mailman/listinfo/classpath-patches
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise