Lazy memory initialization for Unsafe (calloc vs. malloc)
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Jan 25 17:49:59 UTC 2019
On 25/01/2019 17:29, mail.openjdk.java.net at lemmster.de wrote:
> On 16.01.19 04:07, Maurizio Cimadamore wrote:
>> * while adding a new method to Unsafe seems like the most natural path,
>> please be aware that we have committed to reduce the footprint of that
>> API over time; your proposal goes in the opposite direction. That said,
>> we could still have some internal functionality for performing calloc
>> that is only used internally by the Panama offheap API
>>
>> * I'm not an expert in the area, but I'm wondering whether the lazy
>> zeroing scheme is truly cross-platform as opposed to being just a Linux
>> optimization; of course adding a new functionality that adds benefit on
>> a single platform has a different cost compared to adding something that
>> provides advantages across the board
>
> Hi Maurizio,
>
> I'd argue that the functionality of allocating initialized/zeroed memory
> (calloc as opposed to malloc) offers advantages that are orthogonal to
> the optimistic memory allocation strategy provided by the OS. That
> said, I checked with a colleague who is intimately familiar with Windows
> memory management. The Win32 API comes with VirtualAlloc* [1] which
> supports a similar optimistic allocation strategy to what I described
> for Linux.
> I haven't tried implementing a prototype on Windows yet, but let me know
> if it makes sense at this point. Please also advise how to move the API
> out of Unsafe into Panama.
Hi Markus,
I think that, as an experiment you could try adding that functionality
as a native method in the Panama internal ScopeImpl class, and have
Scope use that for allocating memory, rather than Unsafe.
Regarding platforms, it would be nice to know what is the performance
cost for going with this option (which I agree would be desirable from
an usability perspective), possibly on all the three supported platforms
(Mac x64, Linux x64 and Windows x64).
Cheers
Maurizio
>
> I'd have to do more research to find out what's possible on macOS.
>
> Thanks
> Markus
>
> [1]
> https://msdn.microsoft.com/en-us/library/windows/desktop/aa366890(v=vs.85).aspx
More information about the panama-dev
mailing list