接口的使用
java.lang.foreign.MemorySegment
使用 MemorySegment 的包PREVIEW
包
描述
提供对 Java 运行时之外的内存和函数的低级访问。
定义通道,它表示与能够执行 I/O 操作的实体的连接,例如文件和套接字;定义选择器,用于多路复用、非阻塞 I/O 操作。
孵化功能。 将在未来的版本中删除。
-
MemorySegment 的用法PREVIEW 在java.lang.foreign
修饰符和类型方法描述default MemorySegmentPREVIEWArena.allocate(long byteSize, long byteAlignment) 返回具有给定大小(以字节为单位)和对齐约束(以字节为单位)的本机内存段。default MemorySegmentPREVIEWSegmentAllocator.allocate(long byteSize) 分配给定大小的内存段。SegmentAllocator.allocate(long byteSize, long byteAlignment) 分配具有给定大小和对齐约束的内存段。default MemorySegmentPREVIEWSegmentAllocator.allocate(MemoryLayoutPREVIEW layout) 分配具有给定布局的内存段。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfAddressPREVIEW layout, MemorySegmentPREVIEW value) 分配具有给定布局的内存段,并使用给定的地址值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfBytePREVIEW layout, byte value) 分配具有给定布局的内存段,并使用给定的字节值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfCharPREVIEW layout, char value) 分配具有给定布局的内存段并使用给定的 char 值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfDoublePREVIEW layout, double value) 分配具有给定布局的内存段,并使用给定的双精度值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfFloatPREVIEW layout, float value) 分配具有给定布局的内存段,并使用给定的浮点值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfIntPREVIEW layout, int value) 分配具有给定布局的内存段,并使用给定的 int 值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfLongPREVIEW layout, long value) 分配具有给定布局的内存段并使用给定的 long 值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfShortPREVIEW layout, short value) 分配具有给定布局的内存段并使用给定的短值对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(MemoryLayoutPREVIEW elementLayout, long count) 分配具有给定元素布局和大小的内存段。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfBytePREVIEW elementLayout, byte... elements) 分配具有给定布局的内存段,并使用给定的字节元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfCharPREVIEW elementLayout, char... elements) 分配具有给定布局的内存段并使用给定的 char 元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfDoublePREVIEW elementLayout, double... elements) 分配具有给定布局的内存段,并使用给定的双精度元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfFloatPREVIEW elementLayout, float... elements) 分配具有给定布局的内存段,并使用给定的浮点元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfIntPREVIEW elementLayout, int... elements) 分配具有给定布局的内存段,并使用给定的 int 元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfLongPREVIEW elementLayout, long... elements) 分配具有给定布局的内存段,并使用给定的 long 元素对其进行初始化。default MemorySegmentPREVIEWSegmentAllocator.allocateArray(ValueLayout.OfShortPREVIEW elementLayout, short... elements) 分配具有给定布局的内存段,并使用给定的短元素对其进行初始化。static MemorySegmentPREVIEWMemorySegment.allocateNative(long byteSize, long byteAlignment, SegmentScopePREVIEW scope) 创建具有给定大小(以字节为单位)、对齐方式(以字节为单位)和范围的本机段。static MemorySegmentPREVIEWMemorySegment.allocateNative(long byteSize, SegmentScopePREVIEW scope) 创建具有给定大小(以字节为单位)和范围的本机段。static MemorySegmentPREVIEWMemorySegment.allocateNative(MemoryLayoutPREVIEW layout, SegmentScopePREVIEW scope) 创建具有给定布局和范围的本机段。default MemorySegmentPREVIEWSegmentAllocator.allocateUtf8String(String str) 将 Java 字符串转换为 UTF-8 编码、以 null 结尾的 C 字符串,并将结果存储到内存段中。MemorySegment.asReadOnly()返回此段的只读视图。default MemorySegmentPREVIEWMemorySegment.asSlice(long offset) 在给定的偏移量处返回此内存段的一片。MemorySegment.asSlice(long offset, long newSize) 在给定的偏移量处返回此内存段的一片。default MemorySegmentPREVIEWMemorySegment.copyFrom(MemorySegmentPREVIEW src) 执行从给定源段到此段的批量复制。MemorySegment.fill(byte value) 将值填充到此内存段中。default MemorySegmentPREVIEWMemorySegment.get(ValueLayout.OfAddressPREVIEW layout, long offset) 以给定的偏移量和给定的布局从该段中读取一个地址。default MemorySegmentPREVIEWMemorySegment.getAtIndex(ValueLayout.OfAddressPREVIEW layout, long index) 从给定索引处的给定段读取地址,按给定布局大小缩放。VaList.nextVarg(GroupLayoutPREVIEW layout, SegmentAllocatorPREVIEW allocator) 将下一个复合值读入新的MemorySegment,使用提供的分配器分配,并推进此可变参数列表的位置。VaList.nextVarg(ValueLayout.OfAddressPREVIEW layout) 读取下一个地址值,将其包装到本机段中,并推进此可变参数列表的位置。static MemorySegmentPREVIEWMemorySegment.ofAddress(long address) static MemorySegmentPREVIEWMemorySegment.ofAddress(long address, long byteSize) static MemorySegmentPREVIEWMemorySegment.ofAddress(long address, long byteSize, SegmentScopePREVIEW scope) 创建具有给定大小、地址和范围的本机段。static MemorySegmentPREVIEWMemorySegment.ofAddress(long address, long byteSize, SegmentScopePREVIEW scope, Runnable cleanupAction) 创建具有给定大小、地址和范围的本机段。static MemorySegmentPREVIEWMemorySegment.ofArray(byte[] byteArray) 创建由保存给定字节数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(char[] charArray) 创建一个由保存给定 char 数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(double[] doubleArray) 创建由保存给定双精度数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(float[] floatArray) 创建一个由保存给定浮点数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(int[] intArray) 创建由保存给定 int 数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(long[] longArray) 创建一个由保存给定长数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEWMemorySegment.ofArray(short[] shortArray) 创建一个由保存给定短数组的堆上内存区域支持的堆段。static MemorySegmentPREVIEW创建一个内存段,该内存段由支持给定Buffer实例的同一内存区域支持。VaList.segment()Linker.upcallStub(MethodHandle target, FunctionDescriptorPREVIEW function, SegmentScopePREVIEW scope) 创建一个存根,它可以作为函数指针传递给其他外部函数,与给定范围相关联。返回类型中包含 MemorySegment 类型参数的 java.lang.foreign 中的方法PREVIEW修饰符和类型方法描述MemorySegment.asOverlappingSlice(MemorySegmentPREVIEW other) 返回此片段的一部分,该片段是此片段与提供的片段之间的重叠部分。MemorySegment.elements(MemoryLayoutPREVIEW elementLayout) 返回此段中不相交切片(其大小与指定布局的大小匹配)的顺序Stream。返回具有给定名称的符号的地址。MemorySegment.spliterator(MemoryLayoutPREVIEW elementLayout) 返回此内存段的拆分器。java.lang.foreign 中的方法,参数类型为 MemorySegmentPREVIEW修饰符和类型方法描述VaList.Builder.addVarg(GroupLayoutPREVIEW layout, MemorySegmentPREVIEW value) 将具有给定布局的MemorySegment写入正在构造的可变参数列表。VaList.Builder.addVarg(ValueLayout.OfAddressPREVIEW layout, MemorySegmentPREVIEW segment) default MemorySegmentPREVIEWSegmentAllocator.allocate(ValueLayout.OfAddressPREVIEW layout, MemorySegmentPREVIEW value) 分配具有给定布局的内存段,并使用给定的地址值对其进行初始化。MemorySegment.asOverlappingSlice(MemorySegmentPREVIEW other) 返回此片段的一部分,该片段是此片段与提供的片段之间的重叠部分。static voidMemorySegment.copy(MemorySegmentPREVIEW srcSegment, long srcOffset, MemorySegmentPREVIEW dstSegment, long dstOffset, long bytes) 执行从源段到目标段的批量复制。static voidMemorySegment.copy(MemorySegmentPREVIEW srcSegment, ValueLayoutPREVIEW srcElementLayout, long srcOffset, MemorySegmentPREVIEW dstSegment, ValueLayoutPREVIEW dstElementLayout, long dstOffset, long elementCount) 执行从源段到目标段的批量复制。static voidMemorySegment.copy(MemorySegmentPREVIEW srcSegment, ValueLayoutPREVIEW srcLayout, long srcOffset, Object dstArray, int dstIndex, int elementCount) 将多个元素从源内存段复制到目标数组。static voidMemorySegment.copy(Object srcArray, int srcIndex, MemorySegmentPREVIEW dstSegment, ValueLayoutPREVIEW dstLayout, long dstOffset, int elementCount) 将多个元素从源数组复制到目标内存段。default MemorySegmentPREVIEWMemorySegment.copyFrom(MemorySegmentPREVIEW src) 执行从给定源段到此段的批量复制。default MethodHandleLinker.downcallHandle(MemorySegmentPREVIEW symbol, FunctionDescriptorPREVIEW function, Linker.OptionPREVIEW... options) 创建一个方法句柄,可用于调用具有给定签名和地址的外部函数。default longMemorySegment.mismatch(MemorySegmentPREVIEW other) 查找并返回此段与给定其他段之间第一个不匹配的偏移量(以字节为单位)。static longMemorySegment.mismatch(MemorySegmentPREVIEW srcSegment, long srcFromOffset, long srcToOffset, MemorySegmentPREVIEW dstSegment, long dstFromOffset, long dstToOffset) 查找并返回源段和目标段之间第一个不匹配的相对偏移量(以字节为单位)。static SegmentAllocatorPREVIEWSegmentAllocator.prefixAllocator(MemorySegmentPREVIEW segment) 返回一个段分配器,它通过回收单个段来响应分配请求。longMemorySegment.segmentOffset(MemorySegmentPREVIEW other) 返回提供的段相对于此段的偏移量(以字节为单位)。default voidMemorySegment.set(ValueLayout.OfAddressPREVIEW layout, long offset, MemorySegmentPREVIEW value) 使用给定的布局在给定的偏移量处将地址写入此段。default voidMemorySegment.setAtIndex(ValueLayout.OfAddressPREVIEW layout, long index, MemorySegmentPREVIEW value) 在给定索引处将地址写入此段,按给定布局大小缩放。static SegmentAllocatorPREVIEWSegmentAllocator.slicingAllocator(MemorySegmentPREVIEW segment) 返回一个段分配器,它通过返回从提供的段中获得的连续切片来响应分配请求。 -
MemorySegment 的用法PREVIEW 在java.nio.channels
修饰符和类型方法描述FileChannel.map(FileChannel.MapMode mode, long offset, long size, SegmentScopePREVIEW session) 预览。将此通道文件的一个区域映射到一个新的映射内存段,具有给定的偏移量、大小和内存会话。 -
MemorySegment 的用法PREVIEW 在jdk.incubator.vector
jdk.incubator.vector 中的方法,参数类型为 MemorySegmentPREVIEW修饰符和类型方法描述static ByteVectorByteVector.fromMemorySegment(VectorSpecies<Byte> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static ByteVectorByteVector.fromMemorySegment(VectorSpecies<Byte> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Byte> m) static DoubleVectorDoubleVector.fromMemorySegment(VectorSpecies<Double> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static DoubleVectorDoubleVector.fromMemorySegment(VectorSpecies<Double> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Double> m) static FloatVectorFloatVector.fromMemorySegment(VectorSpecies<Float> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static FloatVectorFloatVector.fromMemorySegment(VectorSpecies<Float> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Float> m) static IntVectorIntVector.fromMemorySegment(VectorSpecies<Integer> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static IntVectorIntVector.fromMemorySegment(VectorSpecies<Integer> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Integer> m) static LongVectorLongVector.fromMemorySegment(VectorSpecies<Long> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static LongVectorLongVector.fromMemorySegment(VectorSpecies<Long> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Long> m) static ShortVectorShortVector.fromMemorySegment(VectorSpecies<Short> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo) static ShortVectorShortVector.fromMemorySegment(VectorSpecies<Short> species, MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Short> m) VectorSpecies.fromMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidByteVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidByteVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Byte> m) final voidDoubleVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidDoubleVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Double> m) final voidFloatVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidFloatVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Float> m) final voidIntVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidIntVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Integer> m) final voidLongVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidLongVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Long> m) final voidShortVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) final voidShortVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<Short> m) abstract voidVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo) abstract voidVector.intoMemorySegment(MemorySegmentPREVIEW ms, long offset, ByteOrder bo, VectorMask<E> m)