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

Reduce Symbol::_refcount from 4 bytes to 2 bytes

XMLWordPrintable

    • b39

        Reported by Chris P:

        If you make Symbol._refcount a short rather than an int, and co-locate with _length, then we can save 4 bytes per Symbol:

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

        I don't think it would be very common for the _refcount to overflow (> 32767) , and we already handle that by just pinning the refcount and keeping it live.

        However, _refcount needs to be updated atomically, and I don't think there is any way of doing this with a 16-bit value other than to use locking rather than Atomic::inc/dec. CVM uses 8 bits for the refcount, and all type system APIs are protected with a lightweight lock. More expensive, but less footprint, and in the end does not affect application throughput (but may impact startup). It might be worth measuing the vmRSS footprint savings with this change. If it seems worth doing, use a lock to protect _refcount. If there is a performance concern, maybe we could make lock vs atomic a buildtime option, and use the lock for embedded. Actually it could easily be a runtime option instead of buildtime.

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

                Created:
                Updated:
                Resolved: