[foreign-memaccess+abi] RFR: 8268230: Foreign Linker API & Windows user32/kernel32: String conversion seems broken
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Jun 10 12:36:31 UTC 2021
On Thu, 10 Jun 2021 12:03:59 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> The problem is that we only add a single 0 byte as a null terminator, regardless of the charset used. For wider char sets, more 0 bytes need to be added. For instance, for UTF_16LE two 0 bytes need to be added.
>
> This patch fixes the issue by adding the null terminator to the Java string, and only then encoding it as a `byte[]`.
Good catch - I think the fix can be made slightly more efficient
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/CLinker.java line 302:
> 300: }
> 301:
> 302: private static String addNullTerminator(String str) {
This is gonna allocate another string in an already allocation-heavy code. Wouldn't it be better to just add the correct termination sequence in the segment? I suggest running StrLen benchmark before/after to make sure string conversion performance isn't negatively impacted.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/554
More information about the panama-dev
mailing list