"Malloc/Free" Callbacks for Dynamic Off-heap MemorySegments
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Apr 19 09:05:42 UTC 2021
On 18/04/2021 20:03, leerho wrote:
> In order for your proposal to work with /allocate/, the Child would
> have to be constructed with /new Child(TrackingAllocator,
> MemorySegment) /in order for it to access/allocate. /This is certainly
> possible, however, what would be nice (and symmetric) would be for the
> child to be able to access /allocate/ via the scope as well. Sort of
> a /scope.addOnAllocate(Runnable) /or perhaps a
> /scope/./addOnTrackingAllocator(interface) /that could handle both/.,
> /But I can see that this is more complex and may not be practical.
I see what you mean - in general I don't think this is feasible, as a
ResourceScope is more general than for just segments - e.g. it can
handle VaList, upcall stubs, etc. So having segment specific stuff in
there might be odd.
Your tracking allocator might also contain a scope (actually we're
investigating if _all_ allocators should have a scope which defines
their lifecycles) - in which case it should be easier to at least just
use the TrackingAllocator always (since from there you can go to the
scope). Just an idea.
My sense here is also that here we're using APIs to intercept calls etc.
- but in reality you need something a little bit deeper: ability to
collect stats on memory allocation/deallocation. Right now the JDK
doesn't give much control over this kind of info, and this is something
that (albeit lower priority) we will need to look into sooner or later.
If you had such an API, I believe you could just use that directly,
instead of trying to recreate it/emulate it from scratch.
Maurizio
More information about the panama-dev
mailing list