Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Odd memory consumption between x32 and x64

I've been profiling the x64 version of my application as the memory usage has been outrageously high, all of it seems to be coming from the JavaFX MediaPlayer, i'm correctly releasing listeners and eventhandlers.

Here is the stark contrast.

The x32 version at start

enter image description here

And now the x64 version at start

enter image description here

The x32 version stays below 256mb while the x64 will shoot over a gig; this is while both are left to play through their playlist.

All the code is the same.

JDK: jdk1.8.0_20

JRE: jre1.8.0_20

VM arguments on both

-XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70 -Xms3670k -Xmx256m -Dsun.java2d.noddraw=true -XX:+UseParallelGC

Same issue occurring on another x64 Java application

enter image description here

Is this a bug or am I overlooking something?

like image 347
user3037561 Avatar asked Sep 30 '14 22:09

user3037561


People also ask

What is the difference between 32-bit and 64-bit Java?

Because the size of the OOP (Ordinary Object Pointer) has increased from 32 to 64 bits, the same Java application will use more memory in the 64-bit JVM than in the 32-bit JVM. You can get away with it if you use the JVM option -XXCompressedOOP, which tells JVM to use 32-bit pointers.

What is the 64-bit JVM and why is it useful?

The 64-bit JVM is especially useful for Java applications with large heaps, such as those that use more than 100 GB of memory as a maximum.

How to download 64-bit Java on Windows?

64-bit Java is presented as a download option automatically for 64-bit Internet Explorer and 64-bit Firefox. Switch to the 64-bit browser to access the 64-bit download. Users should download 32-bit Java software, if they are using 32-bit browser on their 64-bit Windows.

How much memory does a 32 bit operating system have?

As you may be aware of that in any 32-bit operating system, you are limited to 4096 MB (4 GB) of RAM. It is simple because the size of a 32-bit value will not allow any more references in memory. 2 32 = 4,294,967,296 i.e. roughly 4.29 GB


1 Answers

What you are seeing is the memory usage of the entire JVM running your process. The -Xmx256m setting only limits the maximum heap space available for your application to allocate (and the JVM would enforce that). Outside of heap space, the JVM can use additional memory for a host of other purposes (I am sure I will miss a few in the list below):

  • PermGen, which has now be replaced by the Metaspace. According to the documentation, there is no default limit for this:

    -XX:MaxMetaspaceSize=size
    Sets the maximum amount of native memory that can be allocated for class metadata. By default, the size is not limited. The amount of metadata for an application depends on the application itself, other running applications, and the amount of memory available on the system.
    
  • Stack space (memory used = (number of threads) * stack size. You can control this with the -Xss parameter

  • Off-heap space (either use of ByteBuffers in your code, or use of third pary libraries like EHCache which would in turn use off-heap memory)

  • JNI code

  • GC (garbage collectors need their own memory, which is again not part of the heap and can vary greatly depending on the collector used and the application memory usage)

In your case, you are seeing the "almost doubling" of memory use, plus probably a more relax Metaspace allocation when you move from a 32bit to a 64bit JVM. Using -XX:MaxMetaspaceSize=128m will probably bring the memory usage down to under 512MB for the 64bit JVM.

like image 115
xpa1492 Avatar answered Oct 16 '22 18:10

xpa1492