Extend instanceOop and Klass

Tom Rodriguez tom.rodriguez at oracle.com
Tue Apr 6 15:13:01 PDT 2010


You can add fields to Klass without any problems.  If you add fields to instanceOopDesc then you need to modify instanceOopDesc::base_offset_in_bytes to always return sizeof(instanceOopDesc) otherwise those extra fields won't exist in the compressed oops vm.

tom

On Apr 5, 2010, at 9:42 PM, Peng Du wrote:

> Hello,
> 
> 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 {
> private:
>  void*     _some_ptr;
>  jlong     _some_int;
> 
>  ...
> };
> 
> class Klass : public Klass_vtbl {
>  friend class VMStructs;
> protected:
>  enum { _primary_super_limit = 8 };
>  ...
>  // The oop block.
>  ...
>  jint _biased_lock_revocation_count;
> 
>  bool _flag_1;
>  bool _flag_2;
> 
>  ...
> };
> 
> 
> Thanks
> 
> 



More information about the hotspot-dev mailing list