On Fri, 8 Apr 2022 at 06:57, Michael Kuhlmann <j...@fiolino.de> wrote:

> Good morning!
>
> On 4/7/22 23:59, Kasper Nielsen wrote:
> > Hi Michael,
> >
> > I don't really have an opinion on how you obtain a logger. But one
> > particular
> > use-case I've had was that I would like to perform some access checks
> based
> > on the module of the caller. Something similar to how Panama checks for
> > native access:
> >
> > Reflection.ensureNativeAccess(Reflection.getCallerClass());
>
> Hmh, but wouldn't it be sufficient to perform these checks at
> initialization time?
>

There might not be an initialization time. Take, for example, this
piece of code from jdk.incubator.foreign.CLinker:

static void freeMemory(MemoryAddress addr) {
        Reflection.ensureNativeAccess(Reflection.getCallerClass());
        SharedUtils.checkAddress(addr);
        SharedUtils.freeMemoryInternal(addr);
 }


> That I totally agree! Having the exact line number in the log statement
> would be a huge win.
>
> But to be honest, Reflection::getCallerClass wouldn't help either.
>

Getting the caller class is the fastest operation of StackWalker.
Getting something like line numbers from the top stack frame is
somewhat slower.

Again for many use cases, the performance of StackWalker is fine.
But if you like Ceki is looking for information about stack frames
and only have 100 ns to spend then there aren't really any APIs
you can use.

/Kasper

Reply via email to