JDK-8314020 : Print instruction blocks in byte units
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17,21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-08-09
  • Updated: 2023-10-27
  • Resolved: 2023-08-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 21 JDK 22
17.0.9Fixed 21.0.1Fixed 22 b11Fixed
Related Reports
Relates :  
Description
When following up on JVM crashes in the field, we frequently want to disassemble the "Instructions:" block in hs_err. Unfortunately, some architectures print out the instructions in 4-byte chunks, which is affected by platform endianness. The simple scripts would then fail to parse the instruction stream, because they have no assumptions about the endianness. 

For example, here is an attempt to decode a piece of AArch64 "Instructions:" block:

```
% cat asm.txt; xxd -r asm.txt > asm.bin; hexdump -C asm.bin; objdump -D -m aarch64 -b binary asm.bin 
924cfce4g 382268bf 12800000 f9400881 8b020422
924cfcf4g 39000440 17ffffaa 52800002 528000a1


00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
924cfce0  00 00 00 00 38 22 68 bf  12 80 00 00 f9 40 08 81  |....8"h......@..|
924cfcf0  8b 02 04 22 39 00 04 40  17 ff ff aa 52 80 00 02  |..."9..@....R...|
924cfd00  52 80 00 a1                                       |R...|
924cfd04

asm.bin:     file format binary


Disassembly of section .data:

0000000000000000 <.data>:
	...
    924cfce4:	bf682238 	.inst	0xbf682238 ; undefined
    924cfce8:	00008012 	.inst	0x00008012 ; undefined
    924cfcec:	810840f9 	.inst	0x810840f9 ; undefined
    924cfcf0:	2204028b 	.inst	0x2204028b ; undefined
    924cfcf4:	40040039 	.inst	0x40040039 ; undefined
    924cfcf8:	aaffff17 	orn	x23, x24, xzr, ror #63
    924cfcfc:	02008052 	.inst	0x02008052 ; undefined
    924cfd00:	a1008052 	.inst	0xa1008052 ; undefined
```

Note how `382268bf` is written out in the original dump, and that value is big-endian for AArch64. But `xxd` then treats this as just a sequence of bytes, which effectively writes it down to binary file as little-endian, and then the decoding breaks.

Of course, one can convert the endianness, assuming there are 4-byte blocks in instruction stream for AArch64, and then the decoding would work:

```
$ hexdump -v -e '1/4 "%08x"' -e '"\n"' asm.bin | xxd -r -p > asm.reversed.bin
$ objdump -D -m aarch64 -b binary asm.reversed.bin

asm.reversed.bin:     file format binary


Disassembly of section .data:

0000000000000000 <.data>:
	...
    924cfce4:	382268bf 	strb	wzr, [x5, x2]
    924cfce8:	12800000 	mov	w0, #0xffffffff            	// #-1
    924cfcec:	f9400881 	ldr	x1, [x4, #16]
    924cfcf0:	8b020422 	add	x2, x1, x2, lsl #1
    924cfcf4:	39000440 	strb	w0, [x2, #1]
    924cfcf8:	17ffffaa 	b	0x924cfba0
    924cfcfc:	52800002 	mov	w2, #0x0                   	// #0
    924cfd00:	528000a1 	mov	w1, #0x5                   	// #5
```

...but that is rather cumbersome.

It would be easier to dump the "Instructions:" block in byte unit, so that endianness does not even enter the picture here, and the hex dump would just follow the natural order of bytes in the dump.

x86 already does the byte-unit dump, since it has a variable-size encoding. The ease of debugging would be improved for fixed-size encoding here too.
Comments
In case of AArch64, this is a regression as a result of https://bugs.openjdk.org/browse/JDK-8245986.
27-10-2023

Fix Request (17u) Same reason as for 21u. Patch does not apply cleanly due to context differences that are easy to resolve. 17u PR acked by Paul. Tests pass.
28-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1686 Date: 2023-08-23 07:01:44 +0000
23-08-2023

Fix Request (21u) Improves post-mortem diagnostics. Applies cleanly. Builds/tests pass.
21-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/63 Date: 2023-08-16 12:59:18 +0000
16-08-2023

Changeset: a602624e Author: Aleksey Shipilev <shade@openjdk.org> Date: 2023-08-16 07:02:48 +0000 URL: https://git.openjdk.org/jdk/commit/a602624ef46908456052146d50467c60efa636c3
16-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15211 Date: 2023-08-09 17:40:43 +0000
09-08-2023