Skip to content

Commit 7764742

Browse files
committed
8348909: [BACKOUT] Implement a better allocator for downcalls
Reviewed-by: shade, liach
1 parent fcd5ebc commit 7764742

File tree

7 files changed

+20
-474
lines changed

7 files changed

+20
-474
lines changed

src/java.base/share/classes/jdk/internal/foreign/SlicingAllocator.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, 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
@@ -38,22 +38,6 @@ public SlicingAllocator(MemorySegment segment) {
3838
this.segment = segment;
3939
}
4040

41-
public long currentOffset() {
42-
return sp;
43-
}
44-
45-
public void resetTo(long offset) {
46-
if (offset < 0 || offset > sp)
47-
throw new IllegalArgumentException(String.format("offset %d should be in [0, %d] ", offset, sp));
48-
this.sp = offset;
49-
}
50-
51-
public boolean canAllocate(long byteSize, long byteAlignment) {
52-
long min = segment.address();
53-
long start = Utils.alignUp(min + sp, byteAlignment) - min;
54-
return start + byteSize <= segment.byteSize();
55-
}
56-
5741
MemorySegment trySlice(long byteSize, long byteAlignment) {
5842
long min = segment.address();
5943
long start = Utils.alignUp(min + sp, byteAlignment) - min;

src/java.base/share/classes/jdk/internal/foreign/abi/BufferStack.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,26 @@ static long pickChunkOffset(long chunkOffset, long byteWidth, int chunkWidth) {
382382
: chunkOffset;
383383
}
384384

385-
private static final int LINKER_STACK_SIZE = Integer.getInteger("jdk.internal.foreign.LINKER_STACK_SIZE", 256);
386-
private static final BufferStack LINKER_STACK = new BufferStack(LINKER_STACK_SIZE);
387-
388-
@ForceInline
389385
public static Arena newBoundedArena(long size) {
390-
return LINKER_STACK.pushFrame(size, 8);
386+
return new Arena() {
387+
final Arena arena = Arena.ofConfined();
388+
final SegmentAllocator slicingAllocator = SegmentAllocator.slicingAllocator(arena.allocate(size));
389+
390+
@Override
391+
public Scope scope() {
392+
return arena.scope();
393+
}
394+
395+
@Override
396+
public void close() {
397+
arena.close();
398+
}
399+
400+
@Override
401+
public MemorySegment allocate(long byteSize, long byteAlignment) {
402+
return slicingAllocator.allocate(byteSize, byteAlignment);
403+
}
404+
};
391405
}
392406

393407
public static Arena newEmptyArena() {

test/jdk/java/foreign/TestBufferStack.java

Lines changed: 0 additions & 157 deletions
This file was deleted.

test/jdk/java/foreign/libTestBufferStack.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)