>
> Hi Kasper,
>
> sorry to jump in here as an uninvolved onlooker, but I can't resist.
> I really don't see why this should matter. Getting the caller class is a
> rare edge case that you just do in exceptional situations; most often
> it's more for debugging or something.
>
> What users really are interested in is high performance for standard
> cases. Implementing a specific optimization into Hotspot to gain few
> milliseconds is the least thing I expect from the JVM developers.
>
> I also don't understand why someone should instantiate a logger during
> performance critical procedures. In more than 20 years of Java
> development, I've never seen the need to create a logger on the fly.
> They are *always* assigned to final static variables, or at least to
> predefined pools. Everything else would be just wrong: To instantiate a
> logger, you have to fetch at least the log level definition from some
> configuration source, and this can never be fast. At least not that
> we're talking about nanoseconds here.
>
> All logging implementations I know of (and all that make sense) are
> highly optimized on log throughput; this can only be achieved by
> preprocessing during initialization, why this is slow. But that doesn't
> matter, because, as said, you should anyway create logger instances
> beforehand.
>
> Sorry for the rant, but I really don't see the use case here.
>

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());

You can implement something similar with StackWalker but it just adds a bit
of
non-negligible overhead to every invocation of the method.

I'm pretty sure there must be other valid use cases out there
where performance
is important. After all, the StackWalker API was created because existing
solutions
such as Thread::getStackTrace weren't performant enough.

/Kasper

Reply via email to