RFR (S) JDK-8009575 - Reduce Symbol::_refcount from 4 bytes to 2 bytes
Ioi Lam
ioi.lam at oracle.com
Tue Mar 26 14:03:28 PDT 2013
Please review:
http://cr.openjdk.java.net/~iklam/8009575/symbol_refcount_001/
<http://cr.openjdk.java.net/%7Eiklam/8009575/symbol_refcount_001/>
Bug: Reduce Symbol::_refcount from 4 bytes to 2 bytes
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8009575
https://jbs.oracle.com/bugs/browse/JDK-8009575
Summary of fix:
(1) Symbol::_refcount has been changed to a short.
Note that _refcount needs to be incremented atomically using
Atom::add, which requires a 32-bit word in memory. So I glue the
_refcount and _length fields together using union and ENDIAN
tricks, which is kind of ugly but faster.
The prettier alternative would be to use shift and masking to
access the _refcount and _length components, but performance
would be slightly slower.
If anyone has a more elegant solution, please let me know.
#------------------------------------------------------
union {
volatile int _refcount_and_length;
struct {
#ifdef VM_LITTLE_ENDIAN
unsigned short _length; // number of UTF8 characters in the
symbol
volatile short _refcount;
#else
volatile short _refcount;
unsigned short _length; // number of UTF8 characters in the
symbol
#endif
} s;
} u;
void Symbol::increment_refcount() {
if (u.s._refcount >= 0) {
// Adding 0x10000 to _refcount_and_length is equivalent to
adding 0x1 to
// _refcount (w.r.t overflow/underflow).
(void)Atomic::add(0x10000, &u._refcount_and_length);
....
}
#------------------------------------------------------
(2) Symbol::size(int) was wasting one byte per Symbol instance. I fixed
it by
splitting part of the fields from Symbol into SymbolBase.
Footprint result:
The theoretical reduction is 3 bytes per symbol -- 2 bytes
from _refcount, and 1 byte from the fixed Symbol::size(int)
function.
In actual measurement, CDS image (about 3000 classes, with about
50000 symbols) is reduced by about 140KB, or about 2.8 bytes per
Symbol, or about 0.6% of the whole CDS image.
Testing:
* UTE (vm.runtime.testlist, vm.quick.testlist
vm.parallel_class_loading.testlist)
Thanks,
Ioi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/attachments/20130326/02d64784/attachment-0001.html
More information about the hotspot-runtime-dev
mailing list