Skip to content

Commit

Permalink
Tweak prefixAllocator
Browse files Browse the repository at this point in the history
Tweak StrLenTest
  • Loading branch information
mcimadamore committed Oct 29, 2024
1 parent 3b24b9c commit 75394a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ static SegmentAllocator slicingAllocator(MemorySegment segment) {
* @throws IllegalArgumentException if the {@code segment} is
* {@linkplain MemorySegment#isReadOnly() read-only}
*/
static SegmentAllocator prefixAllocator(MemorySegment segment) {
static SegmentAllocator.OfRaw prefixAllocator(MemorySegment segment) {
assertWritable(segment);
return (AbstractMemorySegmentImpl)segment;
}
Expand Down
13 changes: 9 additions & 4 deletions test/micro/org/openjdk/bench/java/lang/foreign/StrLenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static String makeString(int size) {
return lorem.substring(0, size);
}

static class RingAllocator implements SegmentAllocator {
static class RingAllocator implements SegmentAllocator.OfRaw {
final MemorySegment segment;
SegmentAllocator current;
long rem;
Expand All @@ -156,7 +156,7 @@ public RingAllocator(Arena session) {
}

@Override
public MemorySegment allocate(long byteSize, long byteAlignment) {
public MemorySegment allocateRaw(long byteSize, long byteAlignment) {
if (rem < byteSize) {
reset();
}
Expand Down Expand Up @@ -184,16 +184,21 @@ public Arena acquire() {
return new SlicingPoolAllocator();
}

class SlicingPoolAllocator implements Arena {
class SlicingPoolAllocator implements Arena, SegmentAllocator.OfRaw {

final Arena arena = Arena.ofConfined();
final SegmentAllocator slicing = SegmentAllocator.slicingAllocator(pool);

public MemorySegment allocate(long byteSize, long byteAlignment) {
public MemorySegment allocateRaw(long byteSize, long byteAlignment) {
return slicing.allocate(byteSize, byteAlignment)
.reinterpret(arena, null);
}

@Override
public MemorySegment allocate(long byteSize, long byteAlignment) {
return SegmentAllocator.OfRaw.super.allocate(byteSize, byteAlignment);
}

@Override
public Scope scope() {
return arena.scope();
Expand Down

0 comments on commit 75394a9

Please sign in to comment.