Is Java GC Deterministic

梦想的初衷 提交于 2020-01-02 05:13:47

问题


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?


回答1:


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.




回答2:


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.




回答3:


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:

  • Metronome GC (IBM VM)
  • BEA JRockit
  • Azul's Pauseless Garbage Collector
  • FijiVM and its Schism: Fragmentation-Tolerant Real-Time Garbage Collection


来源:https://stackoverflow.com/questions/16608120/is-java-gc-deterministic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!