RFR: JDK-8314890: Reduce number of loads for Klass decoding in static code [v12]

Thomas Stuefe stuefe at openjdk.org
Wed Jan 17 12:37:56 UTC 2024


On Thu, 11 Jan 2024 19:43:17 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

>> Thomas Stuefe has updated the pull request incrementally with three additional commits since the last revision:
>> 
>>  - Update src/hotspot/share/oops/compressedKlass.cpp
>>    
>>    Co-authored-by: Aleksey Shipilëv <shipilev at amazon.de>
>>  - Update src/hotspot/share/oops/compressedKlass.cpp
>>    
>>    Co-authored-by: Aleksey Shipilëv <shipilev at amazon.de>
>>  - Update src/hotspot/share/oops/compressedKlass.hpp
>>    
>>    Co-authored-by: Aleksey Shipilëv <shipilev at amazon.de>
>
> Looks good to me! Thank you!
> (And regarding the bitfield discussion - I *would* like to handle object header fields as bitfield, eventually. Not sure if it makes sense though or if we ever get there...)

> > @rkennke
> > > (And regarding the bitfield discussion - I would like to handle object header fields as bitfield, eventually. Not sure if it makes sense though or if we ever get there...)
> > 
> > 
> > Yes. I wonder whether this would result in better code generated by the C++ compiler,
> 
> I doubt it very much. FYI, I believe that every compiler recognizes the canonical bitfield extract `(x << n) >> m` and some e.g. AArch64 have a single-instruction for that.

That's not what I meant. I meant that if the compiler recognizes that the extracted data is word-sized and resides at a word boundary, it could use a word-sized load instead of loading a 64-bit value and then shifting or bitfield-extracting.

But it seems to do that already. I tried three variants in godbolt and all give me the same word-sized loads (GCC ARM64):


struct MarkWord_1 {
    unsigned long long value;
    unsigned get_hash() const { return value >> 32; }
};

struct MarkWord_2 {
    unsigned other_stuff;
    unsigned hash;
    unsigned get_hash() const { return hash; }
};

struct MarkWord_3 {
        unsigned other_stuff: 32; 
        unsigned hash: 32; 
};

unsigned get_hash_1(struct MarkWord_1* p) {
    return p->get_hash();
}

unsigned get_hash_2(struct MarkWord_2* p) {
    return p->get_hash();
}

unsigned get_hash_3(struct MarkWord_3* p) {
    return p->hash;
}

results in 


get_hash_1(MarkWord_1*):
 ldr	w0, [x0, #4]
 ret
get_hash_2(MarkWord_2*):
 ldr	w0, [x0, #4]
 ret
get_hash_3(MarkWord_3*):
 ldr	w0, [x0, #4]
 ret

So, bitfields are good for code readability but probably won't improve code quality.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15389#issuecomment-1895721227


More information about the hotspot-dev mailing list