Results 1 to 4 of 4

Thread: Distribution of the Java memory

  1. #1
    Join Date
    Aug 2009
    Posts
    124

    Distribution of the Java memory

    I'm trying to understand how memory is incorporated in a Java process. What I understood is that there is the heap (controlled by -Xmx and -Xms), the perm space (controlled -XX:MaxPermSize and -XX:PermSize), the code cache (controlled-XX:ReservedCodeCacheSize and -XX:InitialCodeCacheSize) and the stack per thread (controlled by -Xss and -XX:ThreadStackSize).

    From there, I'd imagine that adding all this, I had to get very nearly the size of memory allocated to the process. Well no! I have two examples, both web applications under Tomcat 6 with JDK 6. Both in the first case, I've never been alerted, as in the second case, the difference is significant and can cause me problems.

    First case:
    Under Linux 64bits : heap + perm + code cache=4096 MB, StackSize=1MB with 21 threads
    If I add up everything, I get 837 MB, while my process uses 873 MB.

    Second case:
    Under Linux 64bits : heap + perm + code cache=4096 MB, StackSize=1MB with 250 threads => 4350 MB, and my process uses 1500 MB more!

    Which side should I look to find what occupies my 1500 MB?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Distribution of the Java memory

    The JVM allocates memory in advance, so the process takes more space than it actually uses. You can see the difference with a tool such jvisualvm (included with the JDK since version 1.6b10) which allows you to view memory.

  3. #3
    Join Date
    Aug 2009
    Posts
    124

    Re: Distribution of the Java memory

    Maybe I missed something with jVisualVM, but I do not see how to explore something other than the heap. But I have no problem with the heap.

    Can you tell me how I should proceed to explore what is neither in the heap nor in the perm space or in the stacks? I assume that what remains is the responsibility of native libraries and buffers with the OS, but how to learn more?

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: Distribution of the Java memory

    Have you checked the memory actually used with

    cat /proc/<pid>/status

    VIRT column in top is that information on the address space used by the application, it has nothing to do with the memory it has reserved and is not an indication of needs memory in your application. If I create a C application that is able to work with 100k of memory but that is a 5 -mmap file 100G, I have a VIRT Alegre exceeding 500G.

    It 'just' what have 1 page of data mapped in the area of addressing 16G, for example, with a big hole of 15.99 billion between it and the base of your program, so that the column of VIRT 16G gives your process.

    I manage, no problem here, to push the VIRT a JVM (ok, I push the cap but good) to 2.5 tera memory, yet as great, the JVM throws out of memory exceptions when j 'reaches the 512M authorized by their orders without really require from system memory.

    In short, the VIRT column is certainly not to be taken into account when measuring the need for an application (or java or any other). The most similar is in the area [-RES SHR, RES] when you did not swap.

    And unlike VIRT / RES is absolutely not related to the difference permsize / MaxPermSize, HEAPSIZE / maxheapsize because this management is unknown to the bone, which is the jvm or not allocate memory segment based on supported via calls realloc ()

    There are plenty of things that can increase the address space in an application without requiring the RAM because full operating system are based on page address (access to the device, access to flat files, access to shared resources, inter-process communication, etc.).

Similar Threads

  1. Replies: 4
    Last Post: 30-01-2012, 06:12 PM
  2. Detect memory leak in java
    By Isabella in forum Software Development
    Replies: 8
    Last Post: 14-11-2011, 11:56 AM
  3. java- store a web page in memory
    By arvindikchari in forum Software Development
    Replies: 1
    Last Post: 15-06-2011, 12:19 AM
  4. Memory error in java
    By Maya Angelou in forum Software Development
    Replies: 5
    Last Post: 10-03-2010, 01:34 PM
  5. Access memory address in java
    By Kingfisher in forum Software Development
    Replies: 5
    Last Post: 15-01-2010, 02:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,661,592.72277 seconds with 16 queries