mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
Merge
This commit is contained in:
commit
2bf5c9a687
31 changed files with 260 additions and 166 deletions
|
@ -883,9 +883,7 @@ public sealed interface MemorySegment extends Addressable permits AbstractMemory
|
|||
Reflection.ensureNativeAccess(Reflection.getCallerClass(), MemorySegment.class, "ofAddress");
|
||||
Objects.requireNonNull(address);
|
||||
Objects.requireNonNull(session);
|
||||
if (bytesSize < 0) {
|
||||
throw new IllegalArgumentException("Invalid size : " + bytesSize);
|
||||
}
|
||||
Utils.checkAllocationSizeAndAlign(bytesSize, 1);
|
||||
return NativeMemorySegmentImpl.makeNativeSegmentUnchecked(address, bytesSize, session);
|
||||
}
|
||||
|
||||
|
@ -957,15 +955,7 @@ public sealed interface MemorySegment extends Addressable permits AbstractMemory
|
|||
*/
|
||||
static MemorySegment allocateNative(long bytesSize, long alignmentBytes, MemorySession session) {
|
||||
Objects.requireNonNull(session);
|
||||
if (bytesSize < 0) {
|
||||
throw new IllegalArgumentException("Invalid allocation size : " + bytesSize);
|
||||
}
|
||||
|
||||
if (alignmentBytes <= 0 ||
|
||||
((alignmentBytes & (alignmentBytes - 1)) != 0L)) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint : " + alignmentBytes);
|
||||
}
|
||||
|
||||
Utils.checkAllocationSizeAndAlign(bytesSize, alignmentBytes);
|
||||
return NativeMemorySegmentImpl.makeNativeSegment(bytesSize, alignmentBytes, session);
|
||||
}
|
||||
|
||||
|
|
|
@ -153,10 +153,7 @@ public abstract non-sealed class AbstractMemorySegmentImpl implements MemorySegm
|
|||
|
||||
@Override
|
||||
public MemorySegment allocate(long bytesSize, long bytesAlignment) {
|
||||
if (bytesAlignment <= 0 ||
|
||||
((bytesAlignment & (bytesAlignment - 1)) != 0L)) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint : " + bytesAlignment);
|
||||
}
|
||||
Utils.checkAllocationSizeAndAlign(bytesSize, bytesAlignment);
|
||||
return asSlice(0, bytesSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ public final class ArenaAllocator implements SegmentAllocator {
|
|||
|
||||
@Override
|
||||
public MemorySegment allocate(long bytesSize, long bytesAlignment) {
|
||||
Utils.checkAllocationSizeAndAlign(bytesSize, bytesAlignment);
|
||||
// try to slice from current segment first...
|
||||
MemorySegment slice = trySlice(bytesSize, bytesAlignment);
|
||||
if (slice != null) {
|
||||
|
|
|
@ -162,4 +162,17 @@ public final class Utils {
|
|||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAllocationSizeAndAlign(long bytesSize, long alignmentBytes) {
|
||||
// size should be >= 0
|
||||
if (bytesSize < 0) {
|
||||
throw new IllegalArgumentException("Invalid allocation size : " + bytesSize);
|
||||
}
|
||||
|
||||
// alignment should be > 0, and power of two
|
||||
if (alignmentBytes <= 0 ||
|
||||
((alignmentBytes & (alignmentBytes - 1)) != 0L)) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint : " + alignmentBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue