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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 05:01:38

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!