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

后端 未结 5 1094
独厮守ぢ
独厮守ぢ 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:39

    Living Java objects will always be part of the GC life cycle. Or said another way, marking an object to be non-gc is the same order of overhead than having your object referenced by a root reference (a static final map for instance).

    But thinking a bit further, data put in a cache are most likely to be temporary, and would eventually be evicted. At that point you will start again to like the JVM and the GC. If you have 100's of GBs of permanent data, you may want to rethink the architecture of your application, and try to shard and distribute your data (horizontally scalability).

    Last but not least, lots of work has been done around serialization, and the overhead of serialization (I'm not speaking about the poor reputation of ObjectInputStream and ObjectOutputStream) is not that big. More than that, if your data is mainly composed of primitive types (including bytes array), there is efficient way to readInt() or readBytes() from off heap buffers (for instannce netty.io's ChannelBuffer). This could be a way to go.

提交回复
热议问题