-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
None
As described in https://github.com/openjdk/jdk/pull/19124, when creating a nested memory access var handle, we ensure that the segment is accessed at the correct alignment for the root layout being accessed. But we do not ensure that the segment has at least the size of the accessed root layout. If we verified that, it would be possible for nested var handles to just piggy back on the root layout size check (since a nested var handle is guaranteed, by construction, to only access parts of the root layout). This could improve usability, as certain errors will currently go undetected. Consider a layout like this:
```
MemoryLayout LAYOUT = sequenceLayout(2, structLayout(JAVA_INT.withName("x"), JAVA_INT.withName("y")));
VarHandle X_HANDLE = LAYOUT.varHandle(PathElement.sequenceElement(), PathElement.groupElement("x"));
```
If I have a memory segment whose size is 12, I can successfully call X_HANDLE on it with index 1, like so:
```
MemorySegment segment = Arena.ofAuto().allocate(12);
int x = (int)X_HANDLE.get(segment, 0, 1);
```
This seems incorrect: after all, the provided segment doesn't have enough space to fit _two_ elements of the nested structs.
```
MemoryLayout LAYOUT = sequenceLayout(2, structLayout(JAVA_INT.withName("x"), JAVA_INT.withName("y")));
VarHandle X_HANDLE = LAYOUT.varHandle(PathElement.sequenceElement(), PathElement.groupElement("x"));
```
If I have a memory segment whose size is 12, I can successfully call X_HANDLE on it with index 1, like so:
```
MemorySegment segment = Arena.ofAuto().allocate(12);
int x = (int)X_HANDLE.get(segment, 0, 1);
```
This seems incorrect: after all, the provided segment doesn't have enough space to fit _two_ elements of the nested structs.
- csr for
-
JDK-8332685 Consolidate size and alignment checks in LayoutPath
- Closed
- relates to
-
JDK-8341127 Extra call to MethodHandle::asType from memory segment var handles fails to inline
- Resolved