Stack allocation API
Jorn Vernee
jorn.vernee at oracle.com
Thu Feb 17 13:21:11 UTC 2022
> However I think that everyone (or at least me) think about something like this:
> https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/stackalloc
This seems to be using the underlying OS thread stack to allocate things? Note that we can not do the same in Java. We want Java thread stacks to be freely copyable for Loom, which means we can't have pointers into the thread's native stack.
A solution to this problems would be for instance to have a dedicated thread-local side stack for the native allocations, which is not moved around. This is essentially what the LWJGL MemoryStack does. I believe Loom's ScopeLocals could help to make the thread-local access part faster in the future as well.
Jorn
On 17/02/2022 00:33, Radosław Smogura wrote:
> Hi,
>
> My understanding is that scope local is like parameter you can pass to function (but it’s passed like a global reference), and enforces closure (Autoclosable can’t enforce value to be put in try-with-resources, so stack can be incorrect if exceptions are not properly handled).
>
> However I think that everyone (or at least me) think about something like this:
>
> https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/stackalloc
>
> Kind regards,
> Rado
> On Feb 16, 2022, at 10:40 PM, Remi Forax <forax at univ-mlv.fr> wrote:
>
> ----- Original Message -----
> From: "Ioannis Tsakpinis" <iotsakp at gmail.com>
> To: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> Cc: "Felix Cravic" <themode at outlook.fr>, "panama-dev at openjdk.java.net'" <panama-dev at openjdk.java.net>
> Sent: Wednesday, February 16, 2022 9:56:43 PM
> Subject: Re: Stack allocation API
>
>
> ...
>
> An issue with LWJGL's approach is the thread-local access to grab the
> current thread's MemoryStack. The thread-local lookup itself is not
> terribly expensive (but not free either), however it does become a problem
> in hot code. Hotspot cannot hoist it out of loops and this has unfortunate
> consequences for the surrounding code.
>
> I wonder how the ScopeLocal of loom behave compared to ThreadLocal.
> https://download.java.net/java/early_access/loom/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/ScopeLocal.html
>
>
> - Ioannis
>
> Rémi
More information about the panama-dev
mailing list