Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8010831

Save 3 bytes per instance of Symbol

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • hs25
    • None
    • hotspot

      (Issue A) -- 2 byte reduction: change _refcount from 4 bytes to 2 bytes. It's extremely unlikely that the reference count would be as high as 32767.

      class Symbol : public MetaspaceObj {
       private:
        volatile int _refcount;
        int _identity_hash;
        unsigned short _length; // number of UTF8 characters in the symbol
        jbyte _body[1];

      (Issue B) -- 1 byte reduction: size(int) function is incorrect. It assumes (pessimistically) that sizeof(Symbol) is 11, but in fact with most compilers sizeof(Symbol) is 12.

        static int size(int length) {
          size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0));
          return align_object_size(sz);
        }


      The fix for issue B is to split Symbol into two parts:

      class SymbolBase {
          // all fields except _body[];
      };

      class Symbol: private SymbolBase {
          jbyte _body[1];

        static int size(int length) {
          size_t sz = heap_word_size(sizeof(SymbolBase) + (length > 0 ? length : 0));
          return align_object_size(sz);
        }

      };


            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: