From fc855b8ef1862144827199a06d0bb13ddf696dd9 Mon Sep 17 00:00:00 2001
Date: Thu, 21 Sep 2023 16:43:49 +0800
Subject: add 8271579-G1-Move-copy-before-CAS-in-do_copy

---
 src/hotspot/share/gc/g1/g1ParScanThreadState.cpp | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp
index 896c891ae..49d627205 100644
--- a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp
+++ b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp
@@ -459,11 +459,11 @@ oop G1ParScanThreadState::do_copy_to_survivor_space(G1HeapRegionAttr const regio
 
   // We're going to allocate linearly, so might as well prefetch ahead.
   Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes);
+  Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(old), obj_ptr, word_sz);
 
   const oop obj = cast_to_oop(obj_ptr);
   const oop forward_ptr = old->forward_to_atomic(obj, old_mark, memory_order_relaxed);
   if (forward_ptr == NULL) {
-    Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(old), obj_ptr, word_sz);
 
     {
       const uint young_index = from_region->young_index_in_cset();
@@ -475,19 +475,9 @@ oop G1ParScanThreadState::do_copy_to_survivor_space(G1HeapRegionAttr const regio
     if (dest_attr.is_young()) {
       if (age < markWord::max_age) {
         age++;
-      }
-      if (old_mark.has_displaced_mark_helper()) {
-        // In this case, we have to install the old mark word containing the
-        // displacement tag, and update the age in the displaced mark word.
-        markWord new_mark = old_mark.displaced_mark_helper().set_age(age);
-        old_mark.set_displaced_mark_helper(new_mark);
-        obj->set_mark(old_mark);
-      } else {
-        obj->set_mark(old_mark.set_age(age));
+        obj->incr_age();
       }
       _age_table.add(age, word_sz);
-    } else {
-      obj->set_mark(old_mark);
     }
 
     // Most objects are not arrays, so do one array check rather than
-- 
2.22.0

