4

If I have a smaller-ram machine and a larger-ram machine. I run the same java code on them. Will jvm do garbage collection more lazily on the machine with larger ram?

The problem I am trying to solve is an out of memory issue. People reported that they have Out of memory issue on small ram machine. I want to test that but the only machine I have now has a much larger ram than theirs. I am wondering if I do the test on this larger-ram machine and keep track of the memory usage, will the memory usage be the same on a smaller-ram machine or it will use even less memory?

Thanks! Erben

Erben Mo
  • 3,528
  • 3
  • 19
  • 32
  • 2
    To model it accurately, you could start a dummy program eating the excess memory. Note that you must really access the memory, otherwise it does get only "virtually allocated". Also switch swapping off. That said, I believe that using `-Xmx` suffices. – maaartinus Jan 27 '14 at 07:55

3 Answers3

6

You need to take a look at the JVM memory parameters. actually you can set the as much memory as you want to your JVM :

-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory

so in your case you can set the much memory as in the another machine. so you machine will not take more RAM than the Xmx value

and you may want to check this parameters also.

-XX:MaxNewSize=  -> this need to be 40% from your Xmx value
-XX:NewSize=614m -> this need to be 40% from your Xmx value

also you may tell you JVM what type of GC to use like :

-XX:+UseConcMarkSweepGC

SO if you set this parameters in the both machines, you will get the same results and the same GC activity most likely.

Salah
  • 8,567
  • 3
  • 26
  • 43
  • This doesn't answer the question. OP is asking if the JVM naturally does less garbage collection and in turn uses more ram when more is available (on default settings I presume) – George Jan 27 '14 at 07:45
  • @George could you please check the question and my answer carefully. thanks. – Salah Jan 27 '14 at 07:50
  • 2
    I've looked at it carefully. Your response might fix the OP's problem, but it doesn't answer this question posed by OP: `Will jvm do garbage collection more lazily on the machine with larger ram?` Which, personally, I'm quite curious about myself :) – George Jan 27 '14 at 07:54
  • `Will jvm do garbage collection more lazily on the machine with larger ram?` as i have said it will not if you set the same parameters on the both machines, because the 2 JVM allocates the same amount of the machine resources, anyway, @George if you know that this is not the right answer then i suppose that you know the right answer, so why don't you answer it instead of keep saying to peoples that they answers is not the right answers!!, try to be positive son!! – Salah Jan 27 '14 at 08:01
  • 1
    No need to get hostile, I didn't down-vote your answer. Your answer might very well solve the OP's problem, but it doesn't address the question about standard garbage collection behavior of the JVM under normal/standard conditions. I hope someone comes by to this question and addresses it, because I really am curious. – George Jan 27 '14 at 08:11
3

Yes it will. This depends on the default maximum heap size. You can check your current maximum heap size using this command:

java -XshowSettings:vm

On my wife's laptop (Windows 8.1, 4 GB RAM, 32-Bit-Java-Runtime) it is 247.5 MB, while on my laptop (Windows 7, 8 GB RAM, 64-Bit-Java-Runtime) it is 903.12 MB.

This is determined by Java (see https://stackoverflow.com/a/4667635/3236102, though the values shown there are for server-class-machines, they might be different from normal machines).

If you want your vm to simulate a low-RAM-machine just use the -Xmx flag to limit your machine to less RAM (e.g. -Xmx128m for 128 MB RAM allocation).

The best thing might be to ask the users that encounter the Out Of Memory-issues to check their maximum heap size (using the command above) and set your machine to the same maximum heap size, so you have the same conditions as they have.

Community
  • 1
  • 1
Dakkaron
  • 5,930
  • 2
  • 36
  • 51
2

The issue can be reproduced with larger RAM.

First you need to get the heap size configuration from the people who reported the issue. Use the same heap size to reproduce the issue.

Use below jvm params for heap settings.

-Xmx512m   Max heap memory that is used to store objects
-XX:MaxPermSize=64m   Max perm gen size. This space is used to store meta info like loaded classes etc