Reputation: 51
I am running multiple runs of the same scenario on a Java product with same JVM arguments. Every run gives a different GC behavior both in terms of its duration and its 'start time'. Is this expected?
Upvotes: 4
Views: 1787
Reputation: 9028
Java Hotspot VM does not implement a deterministic GC algorithm.
In general, deterministic GC algorithms do exist for Java. For example in the following JVMs:
Upvotes: 1
Reputation: 14930
The Java VM specifications do not specify how garbage collection should be implemented. So you cannot assume any deterministic behavior.
From: The Java® Virtual Machine Specification, Java SE 7 Edition: 2.5.3. Heap
The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java Virtual Machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements. The heap may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger heap becomes unnecessary. The memory for the heap does not need to be contiguous.
Summarizing: yes the behavior you are observing is normal and expectable.
Upvotes: 2
Reputation: 5866
Are you manually running System.gc()
? Becuase that's not guaranteed to actually do the garbage collection immediately (or even at all).
For automatic garbage collection, I'd assume it's the same where the JVM determines a good time to do the garbage collection.
Upvotes: 2