RFR: 8303942: FileMapInfo::write_bytes aborts on a short os::write

Ioi Lam iklam at openjdk.org
Mon Apr 3 00:49:19 UTC 2023


On Mon, 27 Mar 2023 08:04:23 GMT, Afshin Zafari <duke 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

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

PR Comment: https://git.openjdk.org/jdk/pull/13188#issuecomment-1493491094


More information about the hotspot-runtime-dev mailing list