Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the local variables in Heap file

I have a j2ee application and monitoring it by visualVM.

Lets say that I have a method like this:

public void doStuff(int param) {
    String s = getStringVariable(param);
    StringBuilder sb = new StringBuilder();
    //Do stuff with sb object
}

From the thread tap, I can see that some of my threads stuck in the above method. So I have generated a heap dump file to figure out what is s and sb contains.

But how can I do that? I am using Eclipse Memory Analyzer.

like image 221
Sam Avatar asked Mar 18 '14 21:03

Sam


People also ask

Is local variable stored in heap?

Whenever an object is created, it's always stored in the Heap space and stack memory contains the reference to it. Stack memory only contains local primitive variables and reference variables to objects in heap space.

Where are local variables found?

In most languages, local variables are automatic variables stored on the call stack directly. This means that when a recursive function calls itself, local variables in each instance of the function are given distinct addresses.

Where are local variables stored in memory?

Local variables are stored in memory area of the corresponding function. Scope of a variable is a program part, in which a variable can be referred to. Variables declared inside a block (at the internal level), have the block as their scope.

Where are local variables stored in JVM?

Stack in java is a section of memory which contains methods, local variables, and reference variables. Stack memory is always referenced in Last-In-First-Out order. Local variables are created in the stack.


1 Answers

you can get the local variable's from your thread, because if a local variable is a currently a live, then that means the only reference for that variable is its own thread.

So first you need to list your current threads, and you can do that by:

  1. Click on the objects options button from the actions bar [].
  2. Select Java Basics -> Threads Overview and Stacks.

Then to list the object for a specific Thread:

  • Right Click -> List Object -> OutGoing references

Then Search for your local variable with in a tag <Java Local>

like image 162
Salah Avatar answered Sep 28 '22 11:09

Salah