[foreign-memaccess+abi] RFR: 8291639: Improve the ability to visualize a MemorySegment in human readable forms [v2]
Glavo
duke at openjdk.org
Fri May 26 19:33:12 UTC 2023
On Fri, 26 May 2023 16:08:53 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> And, in many cases, the Linker will have to bulk-copy the struct or union somewhere else (e.g. in the stack).
Because I only want to map the struct value to the record local variable, I don't really want to allocate a record object unless it escapes. So, I don't think this will cause any trouble on this issue.
Well, specifically...Okay, let's use this PR as an example.
I don't want to map a `struct Point *` to `Point[]`. What I want is:
private static final ValueLayout.OfRecord<Point> POINT_LAYOUT = MemoryLayout.structLayout(
JAVA_INT.withName("x"),
JAVA_INT.withName("y"))
.withCarrier(Point.class);
MemorySegment segment = MemorySegment.ofArray(new int[]{3, 4});
Point p = segment.get(POINT_LAYOUT, 0); // Point[x=3, y=4]
segment.set(POINT_LAYOUT, 0, new Point(5, 6));
I prefer this kind of thing to this PR.
Similar to the example I wrote earlier that called the C function, all records are only used locally in the method. I hope the JIT compiler can think that passing a record to an foreign MethodHandle is not an escape, and store the record object freely on the stack, passing it through registers to the C function, thereby avoiding additional overhead.
-------------
PR Comment: https://git.openjdk.org/panama-foreign/pull/833#issuecomment-1564836555
More information about the panama-dev
mailing list