RFR: 8321467: MemorySegment.setString(long, String, Charset) throws IAE(Misaligned access) [v2]

Per Minborg pminborg at openjdk.org
Thu Dec 7 07:48:34 UTC 2023


On Wed, 6 Dec 2023 17:03:08 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR fixes a couple of aligned accesses when reading/writing strings. Such aligned accesses crept in when we optimized string read/write operations to work in bulk. As a result, depending on the maximum alignment constraints supported by the heap segment, some string operations might fail.
>> 
>> I've added some tests to make sure that all operations work as expected with unaligned semantics.
>> 
>> Note: I've considered inferring an alignment constraint from the provided charset, and then use aligned operations (and document that behavior), but I found that to be unsatisfactory: memory operations typically accept a layout, which allow clients to opt out from alignment checks if needed. But if we always infer an alignment constraint from the provided charset, clients would find themselves w/o an escape hatch. For this reason, I think the best way to fix this is to use unaligned operations when reading/writing the string.
>
> Maurizio Cimadamore has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Make test more robust
>  - Simplify test

LGTM. Testing looks solid.

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

Marked as reviewed by pminborg (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/16999#pullrequestreview-1769404275


More information about the core-libs-dev mailing list