Re: A question in ZGC

Liang Mao at
Thu Dec 3 12:12:53 UTC 2020

Hi Stefan,

Thanks very much for your explanation!


From:Stefan Karlsson <stefan.karlsson at>
Send Time:2020 Dec. 3 (Thu.) 18:07
To:"MAO, Liang" < at>; zgc-dev <zgc-dev at>
Subject:Re: A question in ZGC

Hi Liang,

On 2020-12-03 11:02, Liang Mao wrote:
> Dear ZGC developers,
> May I ask a detailed question about the following code?
> void ZMark::follow_array_object(objArrayOop obj, bool finalizable) {
>    if (finalizable) {
>      ZMarkBarrierOopClosure<true /* finalizable */> cl;
>      cl.do_klass(obj->klass());
>    } else {
>      ZMarkBarrierOopClosure<false /* finalizable */> cl;
>      cl.do_klass(obj->klass());
>    }
> I'm confused with this. Why do we need to specificaly visit the object array's
>   klass(actually the class load data) when we are marking the object array?
>   It comes from JDK12:8214897: ZGC: Concurrent Class Unloading.

This is done to keep the class of the object array alive. We do the same 
for other GCs as well, but through a different code path. See:

template <typename T, typename OopClosureType>
void ObjArrayKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {
   assert (obj->is_array(), "obj must be array");
   objArrayOop a = objArrayOop(obj);

   if (Devirtualizer::do_metadata(closure)) {
     Devirtualizer::do_klass(closure, obj->klass());

   oop_oop_iterate_elements<T>(a, closure);

Where we visit the klass and all its normal object pointers.


> Thanks,
> Liang

More information about the zgc-dev mailing list