[foreign-memaccess+abi] RFR: 8313238: Improve the performance of strlen for null-terminated strings [v3]
ExE Boss
duke at openjdk.org
Wed Aug 9 21:53:34 UTC 2023
On Mon, 7 Aug 2023 10:48:24 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> This PR proposes to use native calls for determining the string length for C-type strings.
>>
>> Smaller segments (<1024 bytes) is using a trivial call whereas all other segments are using a normal call. We might consider always using regular calls if we think most segments are unbound anyhow.
>>
>> The PR also contains a number of new tests, one of which requires a large heap size to run. It is likely that this latter test will not run in most test environments. In such cases, it is silently ignored.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>
> Break out native invocations in separate methods
Changes requested by ExE-Boss at github.com (no known OpenJDK username).
src/java.base/share/classes/jdk/internal/foreign/StringSupport.java line 192:
> 190: // iterate until overflow (String can only hold a byte[], whose length can be expressed as an int)
> 191: for (int offset = 0; offset >= 0; offset += 2) {
> 192: short curr = segment.get(JAVA_SHORT, offset);
The old version intentionally used `JAVA_BYTE` here, as `strlen` and `strnlen` is for byte‑encoded strings (e.g.: **UTF‑8**):
Suggestion:
for (int offset = 0; offset >= 0; offset++) {
short curr = segment.get(JAVA_BYTE, offset);
-------------
PR Review: https://git.openjdk.org/panama-foreign/pull/857#pullrequestreview-1570598897
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/857#discussion_r1289226078
More information about the panama-dev
mailing list