10

Is there any tool to know how many native memory has been used from my java application ? I've experienced outofmemory from my application : Current setting is : -Xmx900m

Computer, Windows 2003 Server 32bit, RAM 4GB.

Also is changing boot.ini to /3GB on windows, will make any difference? If is set Xmx900m, how much max native memory can be allocated for this process ? is it 1100m ?

NoodleX
  • 709
  • 1
  • 7
  • 21

5 Answers5

19

(in my case I use java 8)

add to command line: -XX:NativeMemoryTracking=summary

then launch jcmd <PID> VM.native_memory

You should get something like this:

Total: reserved=3863657KB, committed=1679977KB
-                 Java Heap (reserved=1843200KB, committed=824320KB)
                            (mmap: reserved=1843200KB, committed=824320KB) 

-                     Class (reserved=1311974KB, committed=298726KB)
                            (classes #52579)
                            (malloc=5350KB #76340) 
                            (mmap: reserved=1306624KB, committed=293376KB) 

-                    Thread (reserved=263278KB, committed=263278KB)
                            (thread #256)
                            (stack: reserved=262140KB, committed=262140KB)
                            (malloc=839KB #1280) 
                            (arena=299KB #510)

-                      Code (reserved=278521KB, committed=164773KB)
                            (malloc=28921KB #37983) 
                            (mmap: reserved=249600KB, committed=135852KB) 

-                        GC (reserved=114897KB, committed=77093KB)
                            (malloc=13729KB #67925) 
                            (mmap: reserved=101168KB, committed=63364KB) 

-                  Compiler (reserved=461KB, committed=461KB)
                            (malloc=330KB #1138) 
                            (arena=131KB #3)

-                  Internal (reserved=13877KB, committed=13877KB)
                            (malloc=13845KB #72978) 
                            (mmap: reserved=32KB, committed=32KB) 

-                    Symbol (reserved=28871KB, committed=28871KB)
                            (malloc=24740KB #275452) 
                            (arena=4131KB #1)

-    Native Memory Tracking (reserved=8393KB, committed=8393KB)
                            (malloc=45KB #523) 
                            (tracking overhead=8348KB)

-               Arena Chunk (reserved=184KB, committed=184KB)
                            (malloc=184KB) 

For more information see https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html

Eugene To
  • 1,890
  • 2
  • 19
  • 30
1

For those that come after, VMMap will give you your answer. It will show native memory allocations. In my experience, the -Xss is ignored at minimum amount of 124K I believe within the OS allocation chunks. The OS allocations come in ever doubling chunks until it gets to 1GB(and then you're done.) If you can't reduce your threads, then try reducing your max heap and max permgen settings or try the /3GB switch.

dmalechek
  • 133
  • 1
  • 8
0

The free process space is a bit smaller than 2GB - Xmx. (assuming Sun JVM) You have to add your permgen space to Xmx, and then subtract around 150-200MB or so for the OS's Kernel stuff. If the real problem is a genuine lack of memory, the 3GB switch or reducing your Xmx and PermGen space should alleviate it. Sometimes, at least on Windows, the OS just takes longer than the JVM is willing to wait to allocate a thread and the problem is more that you're spamming thread spawns than running out of memory. You should have memory space for a few thousand threads. How many do you have before it gives up?

There's also a -Xss switch to control how big a thread stack the JVM asks for. YMMV if changing it actually does anything on Windows or not.

Affe
  • 47,174
  • 11
  • 83
  • 83
  • So you are saying to know maximum native memory space is : 2GB - Xmx - Xmx permgen space = Max native memory space. Is changing to 3GB will expand native memory space also? so it become : 3GB - Xmx - Xmx permgen space = Max native memory space. Is there any tool to monitor this realtime, afaik i can't find this figure in jconsole/jvisualvm. many thanks. – NoodleX May 03 '10 at 09:26
  • Process explorer will give you some fairly detailed information: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx The deep internals of windows memory management are complicated. I don't know if there even exists a simple formula for getting an 'exact' number for how much space you really have free at any given time. Basically you put the app server under production load and tune down the heap until you find the spot where you get neither No Native Threads nor Out of Heap Space. – Affe May 03 '10 at 18:49
0

Native Memory is an area which is usually used by the JVM for it’s internal operations and to execute the JNI codes. The JVM Uses Native Memory for Code Optimization and for loading the classes and libraries along with the intermediate code generation. The Size of the Native Memory depends on the Architecture of the Operating System and the amount of memory which is already commited to the Java Heap. Native memory is an Process Area where the JNI codes gets loaded or JVM Libraries gets loaded or the native Performance packs and the Proxy Modules gets loaded. There is no JVM Option available to size the Native Area. but we can calculate it approximately using the following formula:

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

Found this at devopsconsole

-2

If you use for example jvisualvm ( it's shipped with jdk ) you can see how much memory your application is using, you can also profile it more detailously.

Mirek Pluta
  • 7,883
  • 1
  • 32
  • 23
  • hi Luno, jvisualvm only provide me free and used heap memory, what i need is free native memory. I'm running out of native memory. – NoodleX May 03 '10 at 08:15
  • Yeah, @Mirek Pluta I have tons of free heap memory usage according to jvisualvm, but I'm getting the "out of native memory" error as well. – 11101101b Oct 24 '13 at 16:38