Extend instanceOop and Klass

Peng Du imdupeng at gmail.com
Mon Apr 5 21:42:02 PDT 2010


I am writing some code in HotSpot that needs per-object, per-klass
information. I figured I could add some extra fields directly to the
oop classes, i.e. instanceOopDesc and Klass to carry the
information. I followed some basic rules, e.g. instanceOopDesc should
be HeapWord aligned and the "oop block" in Klass should be kept intact.

My code kinda worked for some small programs that I tried. But it would
fail for bigger programs that incurs GC. The errors are different
depending on whether UseCompressedOops is turned on or off. After
reading related bug reports and the HotSpot internal wiki, I
suspect the extra C++ fields I added to the oop classes must have
messed up the object layout.

Can someone point out what is the right way to add custom data to
oop classes, like instanceOopDesc and klassOopDesc? What methods
should also be updated to reflect the new layout?

For example,
class instanceOopDesc : public oopDesc {
   void*     _some_ptr;
   jlong     _some_int;


class Klass : public Klass_vtbl {
   friend class VMStructs;
   enum { _primary_super_limit = 8 };
   // The oop block.
   jint _biased_lock_revocation_count;

   bool _flag_1;
   bool _flag_2;



More information about the hotspot-dev mailing list