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

David Holmes dholmes at openjdk.org
Sun Apr 2 23:01:18 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

Seems correct - just one minor request below. Thanks.

src/hotspot/share/cds/filemap.cpp line 1767:

> 1765: void FileMapInfo::write_bytes(const void* buffer, size_t nbytes) {
> 1766:   assert(_file_open, "must be");
> 1767:   ssize_t size = (ssize_t)nbytes;

I'm very confused as to how the underlying OS `write` can take in an unsigned count of bytes to write, yet the actual count of what was written is signed and so cannot reflect the true count for large values! Can we at least assert here that size is > 0 ?

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

Marked as reviewed by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/13188#pullrequestreview-1368153519
PR Review Comment: https://git.openjdk.org/jdk/pull/13188#discussion_r1155388070


More information about the hotspot-runtime-dev mailing list