Creating a high level Pointer API

Ty Young youngty1997 at gmail.com
Thu Jan 9 12:02:33 UTC 2020


Hi,


After the confirmation that Pointer is being axed, I've started to 
create my own high level Pointer abstraction called Crosspoint[1]. 
Corsspoint's goal is to (as seamlessly as possible) smooth over the 
rough edges of using the raw Memory Access API and mimic the old Pointer 
API.


In short, it:


1. Provides seamless interoperability with lower Memory Access APIs by 
directly extending Memory Access's interfaces(Pointer interfaces extends 
MemoryAddress interface, for example).


2. Does not hide any lower level details. In other words, you can go top 
down(by Pointer.ofJavaByte()) static method or bottom up(by 
Pointer.fromAddress()) which takes lower level Memory Access objects as 
paramaters.


3. Allows the explicit creation of platform specific Pointers. Example:


Pointer<? super Number> longPointer = 
Pointer.ofPlatformLong(Platform.WINDOWS);


where ofPlatformLong can either return a Pointer of Pointer<Integer>(as 
above on Windows) or as Pointer<Long>(for everything else).


4. provides a way to read, write, and work with referenced memory, just 
like the old Pointer API(with different method naming, anyway):


long longNumber = 1;

longPointer.setValue(longNumber);

System.out.println(longPointer.getValue());


5. Constant Null Pointer:


Pointer<?> nullPointer = Pointer.ofNull();


6. Planned ability to "home" a Pointer that is based on a non native 
ValueLayout to the equivalent native layout as well as a quick boolean 
check utility function to check if it isn't.


(probably more than I'm forgetting)


It isn't much yet - only Byte, Integer, and Long are implemented(no 
Array or anything like that yet either) but so far it seems to be even 
more user friendly than the older Pointer API. That's mostly just down 
to Scope's no longer being in the way.


Anyway, what I'm sending this for is to ask for memory access API 
enhancements so that I can add 6(referring to above). Right now -unless 
I'm blind- there is no way to determine the current runtime ABI and I 
need that to determine which ABI to "home" the pointer to. Could this be 
added if it isn't or can anyone point me to where I can find it? I'd 
also need the ValueLayout to expose the Platform(perhaps by enums?) in 
which they belong to. Right now AFAIK they don't. Could all that be added?


While I'm at it, could the documentation for var handles be simplified 
at all? I spent way longer than I'd like to admit trying to figure out 
how to actually read data from the Var Handle and ended up just 
referencing the jextract clang code that was linked on this list before. 
I know working with memory is complicated but when you're met with a 
method that accepts an ambiguous array of objects and a long, 
(seemingly) complicated docs it kinda throws you off a bit.


If there is any observations on the code itself or advice that can be 
given for making a higher level abstraction then I'd appreciate it as 
well. Keep in mind that the goal isn't to support every use case, but 
only to cover what the old Pointer API(collectively) could/did do.


[1] https://github.com/BlueGoliath/Crosspoint



More information about the panama-dev mailing list