diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 965fd5603ba..9b2d59f9412 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -942,6 +942,7 @@ ATTRIBUTE_NO_ASAN static bool read_safely_from(intptr_t* p, intptr_t* result) { } static void print_hex_location(outputStream* st, address p, int unitsize) { + assert(is_aligned(p, unitsize), "Unaligned"); address pa = align_down(p, sizeof(intptr_t)); #ifndef _LP64 // Special handling for printing qwords on 32-bit platforms @@ -961,10 +962,14 @@ static void print_hex_location(outputStream* st, address p, int unitsize) { #endif // 32-bit, qwords intptr_t i = 0; if (read_safely_from((intptr_t*)pa, &i)) { + // bytes: CA FE BA BE DE AD C0 DE + // bytoff: 0 1 2 3 4 5 6 7 + // LE bits: 0 8 16 24 32 40 48 56 + // BE bits: 56 48 40 32 24 16 8 0 const int offset = (int)(p - (address)pa); const int bitoffset = LITTLE_ENDIAN_ONLY(offset * BitsPerByte) - BIG_ENDIAN_ONLY((int)(sizeof(intptr_t) - 1 - offset) * BitsPerByte); + BIG_ENDIAN_ONLY((int)((sizeof(intptr_t) - unitsize - offset) * BitsPerByte)); const int bitfieldsize = unitsize * BitsPerByte; intptr_t value = bitfield(i, bitoffset, bitfieldsize); switch (unitsize) {