diff -r 13e041be4e5c -r de9d23469c68 src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Thu Sep 19 20:26:51 2019 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Thu Sep 19 20:26:52 2019 +0200 @@ -1296,7 +1296,10 @@ ShenandoahHeapIterationRootScanner rp; ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack); - if (unload_classes()) { + // If we are unloading classes right now, we should not touch weak roots, + // on the off-chance we would evacuate them and make them live accidentally. + // In other cases, we have to scan all roots. + if (is_evacuation_in_progress() && unload_classes()) { rp.strong_roots_do(&oops); } else { rp.roots_do(&oops);