Slow performance of StackWalker.getCallerClass() vs Reflection.getCallerClass()

Remi Forax forax at univ-mlv.fr
Tue Jul 2 12:49:59 UTC 2019


Hi Kasper,
did you store the StackWalker instance in a static final field ?

Rémi

----- Mail original -----
> De: "Kasper Nielsen" <kasperni at gmail.com>
> À: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Mardi 2 Juillet 2019 11:09:11
> Objet: Slow performance of StackWalker.getCallerClass() vs Reflection.getCallerClass()

> Hi,
> 
> Are there any security reasons for why StackWalker.getCallerClass()
> cannot be made as performant as Reflection.getCallerClass()?
> StackWalker.getCallerClass() is at least 100 times slower then
> Reflection.getCallerClass() (~1000 ns/op vs ~10 ns/op).
> 
> I'm trying to retrofit some existing APIs where I cannot take a Lookup
> object to do some access control checks.
> But the performance of StackWalker.getCallerClass() is making it impossible.
> 
> Best
>  Kasper


More information about the core-libs-dev mailing list