What is large object for JVM GC

2019-02-24 10:09发布

Charlie Hunt says that large object is bad for JVM GC in his presentation. Because:

  1. Large objects are expensive to allocate and initialize.

  2. Large objects of different sizes can cause Java heap fregmentation.

How to define large object? How can I know if the object is large object? Thanks

3条回答
叼着烟拽天下
2楼-- · 2019-02-24 10:35

There is no theoretical definition on its size but this will depend upon your JVM configuration for example if young generation is small then even small classes will be causing too many swaps (GC). If your objects are big enough w.r.t your JVM heap then GC will have to do more work to allocate and claim them from heap. This will lead to "stop the world" problem more often.

查看更多
不美不萌又怎样
3楼-- · 2019-02-24 10:50

The definition depends on the platform, JVM and JVM configuration. For instance, here is as excerpt from How Garbage Collection differs in the three big JVMs blog post by Michael Kopp:

Large and small objects

The JRockit differentiates between large and small objects during allocation. The limit for when an object is considered large depends on the JVM version, the heap size, the garbage collection strategy and the platform used. (italics mine - DL.) It is usually somewhere between 2 and 128 KB. Large objects are allocated outside thread local area in in case of a generational heap directly in the old generation. This makes a lot of sense when you start thinking about it. The young generation uses a copy ccollection. At some point copying an object becomes more expensive than traversing it in ever garbage collection.

To your second question, I am not sure how to obtain that threshold, but specifically in HotSpot you can set it:

-XX:PretenureSizeThreshold=2m

Refer to the HotSpot JVM garbage collection options cheat sheet by Alexey Ragozin for details on this and many many other -XX options.

查看更多
做个烂人
4楼-- · 2019-02-24 10:54

Large Objects in general from GC point of view means :

  • Objects which are expensive to allocate
  • Objects which are expensive to initialize

Eg: arraylist of size 10000.

查看更多
登录 后发表回答