Java breaking minimum and maximum heap contract if both are set to same value of 2 mb in java 7 -
i testing gc out of memory simulation after setting min , max heap value equal 2.(-xmx2m -xms2m)
the java program should take max memory value 2 mb . seen in logs , heap dump analyzer showing program has taken memory till 4 mb.
why taking 4 mb instead of 2mb?
code :
vm flag used : -xmx2m -xms2m -xx:+printgcdetails -xx:+printgcdatestamps -xx:+heapdumponoutofmemoryerror
public class gcflags { public static void main(string[] args) { list<humanbeing> humanbeings = new arraylist<humanbeing>(); system.out.println("avaliable memory before while loop :" + runtime.getruntime().freememory() / 1024); humanbeing anjelinajolie = null; humanbeing bradpitt = null; while (true) { anjelinajolie = new humanbeing("anjelina jolie"); bradpitt = new humanbeing("brad pitt"); humanbeings.add(anjelinajolie); humanbeings.add(bradpitt); } } } public class humanbeing { private static string description = "human being on earth"; private string name; public humanbeing(string name) { super(); this.name = name; } /** * @return returns name. */ public string getname() { return name; } /** * @param name * name set. */ public void setname(string name) { this.name = name; } /** * @return description */ public string getdescription() { return description; } }
console logs:
avaliable memory before while loop :1709 2016-09-22t18:54:34.844+0500: [gc2016-09-22t18:54:34.844+0500: [defnew: 845k->64k(960k), 0.0038254 secs] 845k->569k(1984k), 0.0039363 secs] [times: user=0.00 sys=0.00, real=0.00 secs] 2016-09-22t18:54:34.852+0500: [gc2016-09-22t18:54:34.852+0500: [defnew: 802k->63k(960k), 0.0037686 secs]2016-09-22t18:54:34.856+0500: [tenured: 1102k->1081k(1152k), 0.0122294 secs] 1307k->1081k(2112k), [perm : 143k->143k(12288k)], 0.0160887 secs] [times: user=0.02 sys=0.00, real=0.02 secs] 2016-09-22t18:54:34.876+0500: [gc2016-09-22t18:54:34.876+0500: [defnew: 652k->64k(960k), 0.0026151 secs] 1733k->1730k(2764k), 0.0026988 secs] [times: user=0.00 sys=0.00, real=0.00 secs] 2016-09-22t18:54:34.881+0500: [gc2016-09-22t18:54:34.881+0500: [defnew: 960k->64k(960k), 0.0035680 secs]2016-09-22t18:54:34.885+0500: [tenured: 2561k->2162k(2608k), 0.0159277 secs] 2626k->2162k(3568k), [perm : 143k->143k(12288k)], 0.0196062 secs] [times: user=0.02 sys=0.00, real=0.02 secs] 2016-09-22t18:54:34.907+0500: [gc2016-09-22t18:54:34.907+0500: [defnew: 1539k->128k(1728k), 0.0057813 secs] 3702k->3698k(5332k), 0.0058662 secs] [times: user=0.00 sys=0.00, real=0.00 secs] 2016-09-22t18:54:34.916+0500: [gc2016-09-22t18:54:34.916+0500: [defnew: 1728k->1728k(1728k), 0.0000470 secs]2016-09-22t18:54:34.917+0500: [tenured: 3570k->3604k(3604k), 0.0257361 secs] 5298k->4255k(5332k), [perm : 143k->143k(12288k)], 0.0259492 secs] [times: user=0.02 sys=0.00, real=0.03 secs] 2016-09-22t18:54:34.944+0500: [full gc2016-09-22t18:54:34.944+0500: [tenured: 3604k->4096k(4096k), 0.0281657 secs] **4854k->4844k(5952k),** [perm : 143k->143k(12288k)], 0.0282632 secs] [times: user=0.02 sys=0.00, real=0.03 secs] 2016-09-22t18:54:34.972+0500: [full gc2016-09-22t18:54:34.972+0500: **[tenured: 4096k->4095k(4096k), 0.0311708 secs]** 4844k->4834k(5952k), [perm : 143k->143k(12288k)], 0.0312679 secs] [times: user=0.03 sys=0.00, real=0.03 secs] java.lang.outofmemoryerror: java heap space dumping heap java_pid7888.hprof ... heap dump file created [9852670 bytes in 0.315 secs] heap def new generation total 1856k, used 788k [0x34000000, 0x34200000, 0x34200000) eden space 1664k, 47% used [0x34000000, 0x340c52b0, 0x341a0000) space 192k, 0% used [0x341a0000, 0x341a0000, 0x341d0000) space 192k, 0% used [0x341d0000, 0x341d0000, 0x34200000) tenured generation total 4096k, used 4095k [0x34200000, 0x34600000, 0x34600000) space 4096k, 99% usedexception in thread "main" [0x34200000, 0x345ffff8, 0x34600000, 0x34600000) compacting perm gen total 12288k, used 146k [0x34600000, 0x35200000, 0x38600000)
Comments
Post a Comment