RFR: 8303942: FileMapInfo::write_bytes aborts on a short os::write
David Holmes
dholmes at openjdk.org
Mon Apr 3 09:18:43 UTC 2023
On Mon, 3 Apr 2023 00:46:36 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> `os::write` is called in a loop until all the requested size is written. The number of bytes parameter(`size_t nbytes`) is casted to `ssize_t size` to be able to check `> 0` condition. To enable pointer arithmetic, the `const void *` is casted to `const char *` for addition and then recasted back.
>>
>> ### Test
>> local: hotspot:tier1
>> mach5 tier1-5
>
> We have other cases that assumes that `os::write` writes all the requested bytes:
>
> https://github.com/openjdk/jdk/blob/aa762102e9328ca76663b56b3be6f6141b044744/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L379-L389
>
> Writing a loop for each case will be messy and buggy. It's better to get rid of `os::write()` and replace it with `os::write_fully()`.
>
>
> size_t bytes_written = os::write_fully(fd, buffer, bytes_requested);
> if (bytes_written != bytes_requested) {
> // report error ....
> }
>
>
> and I can't understand why `os::write` takes an `unsigned int`!
>
> https://github.com/openjdk/jdk/blob/aa762102e9328ca76663b56b3be6f6141b044744/src/hotspot/os/posix/os_posix.cpp#L774-L778
@iklam the JFR code you linked already handles the short write case. I only found two cases where it was not handled and bugs were filed for each - this is one of them. See JDK-8303937 for links.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13188#issuecomment-1493939865
More information about the hotspot-runtime-dev
mailing list