A question in ZGC

Stefan Karlsson stefan.karlsson at oracle.com
Thu Dec 3 10:07:21 UTC 2020


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.

StefanK

> 
> Thanks,
> Liang
> 


More information about the zgc-dev mailing list