What is the difference between Java Non Heap Memory and Stack Memory? Are they Same if not what is the difference between them?

40,145

Solution 1

There are essentially three categories of storage in all C-based languages (and most other languages):

  1. Heap
  2. Stack
  3. Static (with several variations)

Heap you're familiar with.

Stack you're also familiar with, but you just don't know it. When you have a method with "local" variables, those variables are allocated in a "invocation frame". The "invocation frame" is allocated when you call the method and deleted when you return from the method, and hence it's most efficiently implemented using a "stack" that grows with call and shrinks with return.

Static is stuff that you don't explicitly allocate and essentially exists from the time program execution begins.

The space required for stack is generally fairly small and is lumped in with "Non Heap Memory" in the categories above.

Solution 2

Non-heap memory is all the memory the JVM allocated for purposes other than the heap. This includes:

  • the call stacks (as you noted);
  • memory allocated by native code (e.g. for off-heap caching);
  • in HotSpot 8, the Metaspace (replacement for the Permanent Generation);
  • memory used by the JIT compiler (compiled native code).

In your list, "CMS Old Gen", "Par Eden Space", "Par Survivor Space", and "CMS Perm Gen", all refer to various sections of the heap.

Solution 3

Please follow the links http://www.yourkit.com/docs/kb/sizes.jsp and http://publib.boulder.ibm.com/infocenter/javasdk/v5r0/index.jsp?topic=%2Fcom.ibm.java.doc.diagnostics.50%2Fdiag%2Fproblem_determination%2Faix_mem_heaps.html

Non-Heap Also, the JVM has memory other than the heap, referred to as non-heap memory. It is created at the JVM startup and stores per-class structures such as runtime constant pool, field and method data, and the code for methods and constructors, as well as interned Strings.

Unfortunately, the only information JVM provides on non-heap memory is its overall size. No detailed information on non-heap memory content is available.

The abnormal growth of non-heap memory size may indicate a potential problem, in this case you may check up the following:

If there are class loading issues such as leaked loaders. In this case, the problem may be solved with the help of Class loaders view. If there are strings being massively interned. For detection of such problem, Object allocation recording may be used.

Share:
40,145
user2885295
Author by

user2885295

Updated on September 17, 2020

Comments

  • user2885295
    user2885295 over 3 years

    I am using Jconsole for monitoring a Java Application. The memory tab shows different Heap and Non Heap memories like

    1. Heap Memory Usage
    2. Non Heap Memory Usage
    3. Memory Pool "CMS Old Gen"
    4. Memory Pool "Par Eden Space"
    5. Memory Pool "Par Survivor Space"
    6. Memory Pool "Code Cache"
    7. Memory Pool "CMS Perm Gen"

    What is the difference between these terms. Also please provide some information regarding - how to find anomalies in the application behavior by monitoring these parameters.

  • PeterToTheThird
    PeterToTheThird over 7 years
    It's preferred to not link to external sites as pages are often moved or deleted and the links become broken.
  • user64141
    user64141 almost 7 years
    "Heap you're familiar with." -- I am?
  • Hot Licks
    Hot Licks almost 7 years
    @user64141 -- Any time you use new you're using heap.