JDK-8288850 : SegmentAllocator:allocate() can return null some cases
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-21
  • Updated: 2022-07-27
  • Resolved: 2022-07-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19 JDK 20
19 b31Fixed 20Fixed
Related Reports
Relates :  
Description
Observed that allocate(bytesSize) and allocate(bytesSize, alignment) might throw OutOfMemoryError when bytesSize is too long.

IMO, this can be stated in spec.

And also observed that allocate(bytesSize, alignment) can return null, with  
====
 SegmentAllocator segmentAllocator = SegmentAllocator.newNativeArena(MemorySession.openConfined());
        MemorySegment memorySegment = segmentAllocator.allocate(Long.MAX_VALUE, 2);
        System.out.println(" The memorySegment is " + memorySegment);
====

If this is a valid case Spec can be enhanced for this.

Comments
Changeset: 2baf526f Author: Maurizio Cimadamore <mcimadamore@openjdk.org> Date: 2022-07-12 14:14:46 +0000 URL: https://git.openjdk.org/jdk19/commit/2baf526fcec3ecd8e306fd9bd483ab5ed4ec8afe
12-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19/pull/133 Date: 2022-07-11 15:05:34 +0000
11-07-2022

The lack of OutOfMemoryError is not an issue - this dynamic exception is not specified in other methods as well (see MemorySegment::allocateNative). Other API methods such as ByteBuffer::allocateDirect similarly do not specify this. But the `null` result is something bad which should be fixed.
11-07-2022