8265759: Shenandoah: Avoid race for referent in assert

Reviewed-by: shade, zgu
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
index 7877748..c9065f3 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
@@ -386,8 +386,11 @@
 oop ShenandoahReferenceProcessor::drop(oop reference, ReferenceType type) {
   log_trace(gc, ref)("Dropped Reference: " PTR_FORMAT " (%s)", p2i(reference), reference_type_name(type));
 
-  assert(reference_referent<T>(reference) == NULL ||
-         ShenandoahHeap::heap()->marking_context()->is_marked(reference_referent<T>(reference)), "only drop references with alive referents");
+#ifdef ASSERT
+  oop referent = reference_referent<T>(reference);
+  assert(referent == NULL || ShenandoahHeap::heap()->marking_context()->is_marked(referent),
+         "only drop references with alive referents");
+#endif
 
   // Unlink and return next in list
   oop next = reference_discovered<T>(reference);