© Kishori Sharan 2017

Kishori Sharan, Java 9 Revealed, 10.1007/978-1-4842-2592-9_16

16. Stack Walking

Kishori Sharan

(1)Montgomery, Alabama, USA

In this chapter, you will learn:

  • What stacks and stack frames are

  • How to traverse a thread’s stack before JDK 9

  • How to traverse a thread’s stack in JDK 9 using the StackWalker API

  • How to get the caller’s class in JDK 9

What Is a Stack ?

Each thread in a JVM has a private JVM stack that is created at the same time the thread is created. The stack is a List-In-First-Out (LIFO) data structure. A stack stores frames. A new frame is created and pushed to the top of the stack each time a method is invoked. A frame is destroyed (popped out of stack) when the method invocation completes. Each frame on a stack contains ...

Get Java 9 Revealed: For Early Adoption and Migration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.