RFR: 8295537: Debug tracing for resolved java.lang.invoke.CallSite [v2]
Jorn Vernee
jvernee at openjdk.org
Tue Oct 25 19:46:15 UTC 2022
On Tue, 25 Oct 2022 19:37:06 GMT, Ioi Lam <iklam at openjdk.org> wrote:
> Is it possible to use filter/findfirst without using lambdas? I want to avoid recursion inside the tracing code.
You could do this I believe (if I've eye-balled that correctly :)):
Suggestion:
String callerName = caller.getName();
String callerInfo = StackWalker.getInstance().walk(new Function<Stream<StackWalker.StackFrame>, String>() {
// We use inner classes (instead of stream/lambda) to avoid triggering
// further invokedynamic resolution, which would cause infinite recursion.
// It's OK to use + for string concat, because java.base is compiled without
// the use of indy string concat.
@Override
public String apply(Stream<StackWalker.StackFrame> s) {
return s.filter(new Predicate<StackWalker.StackFrame>() {
@Override
public boolean test(StackWalker.StackFrame f) {
return callerName.equals(f.getClassName());
}
}).findFirst().get().toStackTraceElement().toString();
}
});
> I am not sure about dumping the call stack. It seems an overkill and not useful in most cases. It’s easier to rebuild the JDK and add Thread.dumpStack() in the rare occasion that you need to do this.
Fair enough.
-------------
PR: https://git.openjdk.org/jdk/pull/10842
More information about the core-libs-dev
mailing list