Is it possible to mark java objects non-collectable from gc perspective to save on gc-sweep time?

后端 未结 5 1139
独厮守ぢ
独厮守ぢ 2021-01-04 21:26

Is it possible to mark java objects non-collectable from gc perspective to save on gc-sweep time?

Something along the lines of http://wwwasd.web.cern.ch/wwwasd/lhc++

5条回答
  •  情书的邮戳
    2021-01-04 21:40

    The recommended approaches would be to use either a commerical RTSJ implementation to avoid GC, or to use off heap memory. One could also look into soft references for caches as well (they do get collected).

    This is not recommended: If for some reason you do not believe these options are sufficient, you could look into direct memory access which is UNSAFE (part of sun.misc.Unsafe). You can use the 'theUnsafe' field to get the 'Unsafe' instance. Unsafe allows to allocation/deallocate memory via 'allocateMemory' and 'freeMemory'. This is not under GC control nor limited by JVM heap size. The impact on GC/application, once you go down this route, is not guaranteed - which is why using byte buffers might be the way to go (if you're not using a RTSJ like implementation).

    Hope this helps.

提交回复
热议问题