How does StackWalker.Option SHOW_HIDDEN_FRAMES work in Java 9

Viewed 248

I've been exploring the StackWalking API introduced in jdk9. I couldn't see any difference in the output with or without the option StackWalker.Option.SHOW_HIDDEN_FRAMES.

As per the API documentation:

A Java Virtual Machine implementation may hide implementation specific frames in addition to reflection frames. A StackWalker with this SHOW_HIDDEN_FRAMES option will show all hidden frames (including reflection frames)

Can anyone please help me understand which exact frames could the JVM hide in addition to the reflection frames? What is the exact use of this option?

This is my demo code:

class DemoClass {

    public static void a() {
        b();
    }

    static void b() {
        c();
    }

    static void c() {
        d();
    }

    static void d() {
        StackWalker sw = StackWalker.getInstance(Set.of(StackWalker.Option.RETAIN_CLASS_REFERENCE, StackWalker.Option.SHOW_HIDDEN_FRAMES));
        sw.forEach(System.out::println);
    }
}

public class StackWalkerAPI {

    public static void main(String[] args) {
        try {
            Method methodA = Class.forName("DemoClass").getMethod("a");
            methodA.invoke(null, (Object[]) null);
        } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            Logger.getLogger(StackWalkerAPI.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
1 Answers
Related