8350811: [JMH] test foreign.StrLenTest failed with StringIndexOutOfBoundsException for size=451

Reviewed-by: jbhateja, vpaprotski, mcimadamore
This commit is contained in:
Vladimir Ivanov 2025-03-07 16:12:55 +00:00
parent 54fe643e78
commit 7c22b814d6
3 changed files with 26 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,10 +54,10 @@ public class StrLenTest extends CLayouts {
Arena arena = Arena.ofConfined();
SegmentAllocator segmentAllocator;
SegmentAllocator arenaAllocator = new RingAllocator(arena);
SlicingPool pool = new SlicingPool();
SegmentAllocator arenaAllocator;
SlicingPool pool;
@Param({"5", "20", "100"})
@Param({"5", "20", "100", "451"})
public int size;
public String str;
@ -76,6 +76,8 @@ public class StrLenTest extends CLayouts {
@Setup
public void setup() {
str = makeString(size);
arenaAllocator = new RingAllocator(arena, size + 1);
pool = new SlicingPool(size + 1);
segmentAllocator = SegmentAllocator.prefixAllocator(arena.allocate(size + 1, 1));
}
@ -142,6 +144,9 @@ public class StrLenTest extends CLayouts {
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
""";
while (lorem.length() < size) {
lorem += lorem;
}
return lorem.substring(0, size);
}
@ -150,8 +155,8 @@ public class StrLenTest extends CLayouts {
SegmentAllocator current;
long rem;
public RingAllocator(Arena session) {
this.segment = session.allocate(1024, 1);
public RingAllocator(Arena session, int size) {
this.segment = session.allocate(size, 1);
reset();
}
@ -173,9 +178,13 @@ public class StrLenTest extends CLayouts {
}
static class SlicingPool {
final MemorySegment pool = Arena.ofAuto().allocate(1024);
final MemorySegment pool;
boolean isAcquired = false;
public SlicingPool(int size) {
this.pool = Arena.ofAuto().allocate(size);
}
public Arena acquire() {
if (isAcquired) {
throw new IllegalStateException("An allocator is already in use");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,7 +54,7 @@ import static java.lang.foreign.ValueLayout.JAVA_BYTE;
@Fork(value = 3, jvmArgs = { "--enable-native-access=ALL-UNNAMED", "-Djava.library.path=micro/native" })
public class ToCStringTest extends CLayouts {
@Param({"5", "20", "100", "200"})
@Param({"5", "20", "100", "200", "451"})
public int size;
public String str;
@ -97,6 +97,9 @@ public class ToCStringTest extends CLayouts {
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
""";
while (lorem.length() < size) {
lorem += lorem;
}
return lorem.substring(0, size);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -48,7 +48,7 @@ public class ToJavaStringTest {
private MemorySegment strSegment;
@Param({"5", "20", "100", "200"})
@Param({"5", "20", "100", "200", "451"})
int size;
static {
@ -58,6 +58,9 @@ public class ToJavaStringTest {
@Setup
public void setup() {
var arena = Arena.ofAuto();
while (LOREM.length() < size) {
LOREM += LOREM;
}
strSegment = arena.allocateFrom(LOREM.substring(0, size));
}