Is there any way to view the thread stack values (i.e.) how to see that, what does the thread stack contains while execution?
I came to know that object values are stored in heap memory but the each thread creates its own reference to that and stores it inside the stack.
I want to confirm that. Is there any other way to do that?
Asked
Active
Viewed 69 times
1

c0der
- 18,467
- 6
- 33
- 65

Sabareesh Muralidharan
- 636
- 4
- 11
-
Not directly, no. Apart from (I guess) using `gdb` debug a running JVM. See https://neugens.wordpress.com/2015/02/26/debugging-the-jdk-with-gdb/ – Stephen C Sep 26 '18 at 11:05
-
1You could use the debugger API (or just use the debugger) to see that information. – Peter Lawrey Sep 26 '18 at 11:17
-
1@PeterLawrey .... I avoided saying that because the Java debugger / API works at too high a level of abstraction. I think. It won't let you see the values at specific memory addresses, which is what the OP needs to "confirm" the kind of thing he is interested in. (Not that I think it is either an easy or worthwhile thing to do. I mean, a physics student doesn't actually *need* to use a particle accelerator to validate what his text books tell him.) – Stephen C Sep 26 '18 at 11:52
-
1Are you asking how to do that in a debugger? or are you asking how the program can _[reflect](https://en.wikipedia.org/wiki/Reflection_(computer_programming))_ on its own stacks? Last time I looked, a program could construct a `Throwable`, and then call its `getStackTrace()` method, but that only gives you the names of the function calls on the stack. It doesn't give you any information about the local variables. – Solomon Slow Sep 26 '18 at 12:29
-
in Java9, you can use StackFrame and StackWalker: https://stackoverflow.com/a/42518450/1206301 – Alexei Kaigorodov Sep 26 '18 at 15:49