Skip to content

Commit 7c22b81

Browse files
author
Vladimir Ivanov
committed
8350811: [JMH] test foreign.StrLenTest failed with StringIndexOutOfBoundsException for size=451
Reviewed-by: jbhateja, vpaprotski, mcimadamore
1 parent 54fe643 commit 7c22b81

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

test/micro/org/openjdk/bench/java/lang/foreign/StrLenTest.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,10 +54,10 @@ public class StrLenTest extends CLayouts {
5454
Arena arena = Arena.ofConfined();
5555

5656
SegmentAllocator segmentAllocator;
57-
SegmentAllocator arenaAllocator = new RingAllocator(arena);
58-
SlicingPool pool = new SlicingPool();
57+
SegmentAllocator arenaAllocator;
58+
SlicingPool pool;
5959

60-
@Param({"5", "20", "100"})
60+
@Param({"5", "20", "100", "451"})
6161
public int size;
6262
public String str;
6363

@@ -76,6 +76,8 @@ public class StrLenTest extends CLayouts {
7676
@Setup
7777
public void setup() {
7878
str = makeString(size);
79+
arenaAllocator = new RingAllocator(arena, size + 1);
80+
pool = new SlicingPool(size + 1);
7981
segmentAllocator = SegmentAllocator.prefixAllocator(arena.allocate(size + 1, 1));
8082
}
8183

@@ -142,6 +144,9 @@ static String makeString(int size) {
142144
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
143145
mollit anim id est laborum.
144146
""";
147+
while (lorem.length() < size) {
148+
lorem += lorem;
149+
}
145150
return lorem.substring(0, size);
146151
}
147152

@@ -150,8 +155,8 @@ static class RingAllocator implements SegmentAllocator {
150155
SegmentAllocator current;
151156
long rem;
152157

153-
public RingAllocator(Arena session) {
154-
this.segment = session.allocate(1024, 1);
158+
public RingAllocator(Arena session, int size) {
159+
this.segment = session.allocate(size, 1);
155160
reset();
156161
}
157162

@@ -173,9 +178,13 @@ void reset() {
173178
}
174179

175180
static class SlicingPool {
176-
final MemorySegment pool = Arena.ofAuto().allocate(1024);
181+
final MemorySegment pool;
177182
boolean isAcquired = false;
178183

184+
public SlicingPool(int size) {
185+
this.pool = Arena.ofAuto().allocate(size);
186+
}
187+
179188
public Arena acquire() {
180189
if (isAcquired) {
181190
throw new IllegalStateException("An allocator is already in use");

test/micro/org/openjdk/bench/java/lang/foreign/ToCStringTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,7 +54,7 @@
5454
@Fork(value = 3, jvmArgs = { "--enable-native-access=ALL-UNNAMED", "-Djava.library.path=micro/native" })
5555
public class ToCStringTest extends CLayouts {
5656

57-
@Param({"5", "20", "100", "200"})
57+
@Param({"5", "20", "100", "200", "451"})
5858
public int size;
5959
public String str;
6060

@@ -97,6 +97,9 @@ static String makeString(int size) {
9797
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
9898
mollit anim id est laborum.
9999
""";
100+
while (lorem.length() < size) {
101+
lorem += lorem;
102+
}
100103
return lorem.substring(0, size);
101104
}
102105
}

test/micro/org/openjdk/bench/java/lang/foreign/ToJavaStringTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@ public class ToJavaStringTest {
4848

4949
private MemorySegment strSegment;
5050

51-
@Param({"5", "20", "100", "200"})
51+
@Param({"5", "20", "100", "200", "451"})
5252
int size;
5353

5454
static {
@@ -58,6 +58,9 @@ public class ToJavaStringTest {
5858
@Setup
5959
public void setup() {
6060
var arena = Arena.ofAuto();
61+
while (LOREM.length() < size) {
62+
LOREM += LOREM;
63+
}
6164
strSegment = arena.allocateFrom(LOREM.substring(0, size));
6265
}
6366

0 commit comments

Comments
 (0)