RFR (S) JDK-8009575 - Reduce Symbol::_refcount from 4 bytes to 2 bytes
David Holmes
david.holmes at oracle.com
Wed Mar 27 02:30:21 PDT 2013
On 27/03/2013 3:05 PM, Ioi Lam wrote:
> On 03/26/2013 09:24 PM, David Holmes wrote:
>>> (2) Symbol::size(int) was wasting one byte per Symbol instance. I fixed
>>> it by
>>> splitting part of the fields from Symbol into SymbolBase.
>>
>> I don't understand this part. What were we wasting? And given
>> alignment constraints did we in fact waste it?
>>
> The old code was
>
> class Symbol : public MetaspaceObj {
> int _refcount;
> int _identity_hash;
> unsigned short _length;
> jbyte _body[1];
>
> static int size(int length) {
> size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length -
> 1 : 0));
> return align_object_size(sz);
> }
>
> It assumes that sizeof(Symbol) is 11 bytes (2 ints + 1 short + 1 byte),
> hence the "length - 1". I.e., if length == 2, size() => 11 + 2 - 1 = 12.
That is not the way I read it. I assumed the _body[] was one of those
variables we would manually extend. If the length argument to size was 2
then it says "I want space for two bytes" - but we already allocated one
of them for _body, hence we use length-1 added to sizeof(Symbol).
Now as you point out we may over allocate because of alignment. BUt I
didn't see that directly connected to the use of "length-1".
David
-----
> However, on most platforms, sizeof(Symbol) == 12, so we get (12 + 2 - 1)
> = 13 bytes.
>
> Hence, while a 2-byte symbol could be stored in 12 bytes, we would
> allocate 13 bytes (rounded up to 16) for the Symbol.
>
> On average, we would waste one byte per symbol -- we have a more-or-less
> even distribution of (length % 4).
>>> 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.
>>
>> I'm not sure that makes sense. I would expect you to save 0 bytes or 4
>> bytes depending on alignment (assuming the Symbol is 32-bit aligned to
>> start with).
>
> You're correct that sometimes you save 4 bytes, sometimes none. Due to
> the even distribution of (length % 4), on average you save ~ 3 bytes per
> Symbol.
>
> Thanks
> - Ioi
>
>>
>>
>> Thanks,
>> David
>>
>>>
>>> Testing:
>>>
>>> * UTE (vm.runtime.testlist, vm.quick.testlist
>>> vm.parallel_class_loading.testlist)
>>>
>>> Thanks,
>>> Ioi
>>>
>
More information about the hotspot-runtime-dev
mailing list