This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Interesting paper on Supporting Binary Compatibility with StaticCompilation


Jeff Sturm wrote:
Suppose the compiled class metadata were free of pointers instead.  No
relocations, except lazy function calls.  The metadata could then be
constant and loaded into .rodata.
I think this could be a big win.  We could also at the same time try to
make the metadata more compact: If we use integer offsets instead of
pointers in most cases 16 bits is plenty.

I've attached some notes I made, concentrating on representing fields.
Similar ideas apply to methods, but their representation is more
complex, so I started with fields.
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
struct Class
{
  /** Array of names.
      Initially just a bunch of Utf8Const objects appended in a section.
      Note there is just a single pointer to the entire array.
      The array can be shared between classes, at least within a compilation,
      and potentially within a shared library. */
  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 pointer 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;

  ... methodInfo uperclassInfo etc ...
};

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) field, a variable-width data structure:
  name, as offset into class's 'names' array (normally 16 bits);
  type, as offset of mangling 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 size in fieldInfo is variable size - usually 7 bytes.  No relocations.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]