Request for review: 7102776 Pack instanceKlass boolean fields into single u1 field

Paul Hohensee paul.hohensee at oracle.com
Thu Nov 10 12:05:15 PST 2011


Actually, the C/C++ standards do guarantee dense bit packing in bitfields,
because they were originally intended to be used to access device registers.

The type of the bitfield determines how much space the underlying integral
type occupies.  E.g.,

unsigned char bit1:1, bit2:1, bit3:1;

occupies the "first" 3 bits of a one-byte class data member, while

unsigned int bit1:1, bit2:1, bit3:1;

occupies the "first" 3 bits of a 4-byte class data member.

Note that "first" means that bitfields are allocated starting from the 
lowest addressed
byte in the bitfield type.  That means that on big-endian machines, the 
first allocated
bit in an unsigned int bitfield will be the msb, while on little-endian 
machines
it'll be the lsb.  If you want a bitfield that's endian-independent, you 
have to
use the masking technique in the webrev: e.g., if you want to pass a 
bitfield to Java
code, which has no concept of endianness.

Paul

On 11/10/11 2:32 PM, Jiangli Zhou wrote:
> Hi Chris,
>
> Thanks for the review. Comments below.
>
> On 11/10/2011 03:11 AM, Christian Thalinger wrote:
>> On Nov 10, 2011, at 12:02 PM, David Holmes wrote:
>>
>>> Hi Chris,
>>>
>>> On 10/11/2011 7:26 PM, Christian Thalinger wrote:
>>>> What about:
>>>>
>>>> -  bool            _is_marked_dependent:1;  // used for marking 
>>>> during flushing and deoptimization
>>>> -  bool            _rewritten:1;            // methods rewritten.
>>>> -  bool            _has_nonstatic_fields:1; // for sizing with 
>>>> UseCompressedOops
>>>> -  bool            _should_verify_class:1;  // allow caching of 
>>>> preverification
>>>>
>>>> Wouldn't that be much easier?  And we already have code like that 
>>>> in e.g. nmethod.hpp.
>>> I'm not familiar with this particular notation but I assume it is 
>>> similar to using bitfields.
>> Correct.
>>
>>> This had been discussed internally but unfortunately the SA code 
>>> needs to access the "is-marked-dependent" bit and as there's no 
>>> guarantee as to the order in which bitfields are packed, the SA 
>>> would not know how to extract that bit.
>> Good point.  Bitfields won't work then.
>
> Besides the bit addressing issue, it cannot guarantee that the bit 
> fields are always packed into the smallest size by all compilers.
>
> Thanks,
> Jiangli
>
>> -- Chris
>>
>>> David
>>> -----
>>>
>>>> -- Chris
>>>>
>>>> On Nov 9, 2011, at 6:47 PM, Jiangli Zhou wrote:
>>>>
>>>>> Compact following 4 instanceKlass boolean fields into a signal u1 
>>>>> field. Each flag now uses 1-bit. The new field is placed after the 
>>>>> _idnum_allocated_count field to utilize the unused 2-byte after 
>>>>> _idnum_allocated_count. Compacting these fields saves 4-bytes for 
>>>>> each loaded classes.
>>>>>
>>>>>   bool _is_marked_dependent; // used for marking during flushing and
>>>>>   deoptimization
>>>>>   bool _rewritten; // methods rewritten.
>>>>>   bool _has_nonstatic_fields; // for sizing with UseCompressedOops
>>>>>   bool _should_verify_class; // allow caching of preverification
>>>>>
>>>>> http://cr.openjdk.java.net/~bobv/7102776/webrev.00/
>>>>>
>>>>> Tested with runThese on ubuntu. Ran JPRT.
>>>>>
>>>>> Thanks,
>>>>> Jiangli
>


More information about the hotspot-runtime-dev mailing list