What is large object for JVM GC

前端 未结 3 933
我在风中等你
我在风中等你 2021-01-19 07:47

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

  1. Large objects are expensive to allocate and initialize.

相关标签:
3条回答
  • 2021-01-19 08:09

    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.

    0 讨论(0)
  • 2021-01-19 08:14

    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.

    0 讨论(0)
  • 2021-01-19 08:17

    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.

    0 讨论(0)
提交回复
热议问题