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

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Dec 6 17:03:08 UTC 2023


> 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

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/16999/files
  - new: https://git.openjdk.org/jdk/pull/16999/files/856d3e14..12cf9e3a

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=16999&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=16999&range=00-01

  Stats: 51 lines in 1 file changed: 0 ins; 26 del; 25 mod
  Patch: https://git.openjdk.org/jdk/pull/16999.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16999/head:pull/16999

PR: https://git.openjdk.org/jdk/pull/16999


More information about the core-libs-dev mailing list