GCJ information
Per Bothner
per@bothner.com
Wed Dec 12 11:33:00 GMT 2001
Tom Tromey wrote:
> If you're concerned about size, I think there are two really
> worthwhile things to do that nobody has tried yet:
>
> 1. Change the representation of metadata. For instance, it could be
> stored compressed and then decompressed during class initialization.
> Done properly this could also reduce startup time when libgcj is
> dynamic, by reducing the number of relocs required. There have been a
> few discussions of this and related ideas on this list.
I've done a little thinking about this. I suggest *not* decompressing
during initialization, but deferring it until we actually need it,
for reflection, JNI, or serialization. The other idea is
typedef java::lang::reflect::Field _Jv_Field;
typedef java::lang::reflect::Method _Jv_Method.
That way we don't need duplicate data structures.
Here are soem notes about field representation (under the assumption
that we "fix" fields first and methods after that):
struct Class
{
/** Array of names.
* Initially just a bunch of Utf8Const objects appended in a
s * section. */
unsigned char *names;
/** A compact encoding of refletive information for fields.
* The encoding should be read-only and pointer-free, so we can put
* in the text segment and not use relocations.
* The first part of this array is a sub-array contining the offsets
* of the instance pointer fields. This is needed by GC.
* The rest is a compressed. */
unsigned char *fieldInfo;
/** Array of pointers to (non-inherited) static fields. */
unsigned void* staticFields;
/** Initially null, only allocated if reflection or JNI or
* serialization.
* Contains pointers to java.lang.reflect.Field objects.
* The getDeclaredField and getFields methods allocate a new
* Field array, but they don't allocate new Field objects -
* they just use the ones in the fields array. */
_Jv_Field *fields;
};
typedef java::lang::reflect::Field _Jv_Field;
Suggested (preliminary) encoding of the 'fieldInfo' data:
/* Used by GC. */
_Jv_ushort number of pointer fields (including inherited ones);
for each pointer field:
_Jv_ushort offset of pointer field.
for each (non-inherited) fields:
name, as offset into class's 'names' array (normally 16 bits);
type, of offset of encoding in class's 'names' array (normally 16 bits);
offset: if static, index in staticFields array (normally 8 bits);
if non-static, offset from start of object (normally 8 bits);
(offset could be implied - just count from start)
access_flags (8 bits)
class java::lang::reflect::Field
{
jclass class;
jstring name;
jclass type;
/** 24 bits of offset plus 8 bits of modifier flags */
jint offset_flags;
}
Old (current) sizeof(_Jv_Field) is 3*sizeof(void*)+2 = 16 bytes if
32-bit ptrs.
New sizeof(_Jv_Field) is variable size - typically 7 bytes.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
More information about the Java
mailing list