Pacerier
Pacerier

Reputation: 89613

How do we get memory information regarding the stack space and the PermGen space?

Hi all I was wondering how do we get the size of the memory allocated per stack (e.g. -Xss512k),

and the size of the memory allocated to the PermGen space (e.g. XX:MaxPermSize=256m) ?

I've looked into

  1. java.lang.Runtime.totalMemory

  2. java.lang.Runtime.freeMemory

  3. java.lang.Runtime.maxMemory

but the functions only return information about the heap space.

How do we query information about the stack space and the PermGen space?

Upvotes: 3

Views: 174

Answers (1)

alf
alf

Reputation: 8513

Your journey starts at MemoryManagerMXBean where you can find all the memory pools; after that, ask MemoryPoolMXBean to find out details about a given pool.

The simplest way would be,

List<MemoryPoolMXBean> memoryPoolMXBeans = 
                                       ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool: memoryPoolMXBeans) {
    out.println("pool: " + pool.getName());
    out.println("    type: " + pool.getType());
    out.println("    usage: " + pool.getUsage());
    out.println();
}

Also, take a look at How to determine the maximum stack size limit? — they have a way to get the parameters passed to JVM.

Upvotes: 3

Related Questions