On Thu, 24 Jul 2025 14:38:13 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> I recall runtime requires UTF16 byte array and char array have exactly the 
>> same layout - would be nice if we keep this in the design notes for the 
>> string implementation classes, such as on the class header.
>> 
>> (Useful notes could include that indices are char-based, UTF16 byte[] and 
>> char[] has identical layout, etc.)
>
> The StringUTF16.getChar and putChar methods are carefully written to use the 
> platform endianness to compose and decompose char values from and to byte[] 
> in terms of shifts of the lower and upper bytes.
> The mapping of that into other apis that try to optimize between char[] and 
> the compact string byte[] are less well documented.

I've found the code that imposes this requirement:

https://github.com/openjdk/jdk/blob/7bf4c608e7b23398ea89cf0a592e9554af98144e/src/hotspot/share/opto/library_call.cpp#L1713-L1718

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2236359828

Reply via email to