< prev index next >

test/hotspot/gtest/gc/shared/test_preservedMarks.cpp

Print this page
*** 21,68 ***
   * questions.
   */
  
  #include "precompiled.hpp"
  #include "gc/shared/preservedMarks.inline.hpp"
  #include "oops/oop.inline.hpp"
  #include "unittest.hpp"
  
! // Class to create a "fake" oop with a mark that will
! // return true for calls to must_be_preserved().
- class FakeOop {
-   oopDesc _oop;
- 
- public:
-   FakeOop() : _oop() { _oop.set_mark(originalMark()); }
- 
-   oop get_oop() { return &_oop; }
-   markWord mark() { return _oop.mark(); }
-   void set_mark(markWord m) { _oop.set_mark(m); }
-   void forward_to(oop obj) {
-     markWord m = markWord::encode_pointer_as_mark(obj);
-     _oop.set_mark(m);
-   }
- 
-   static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
-   static markWord changedMark()  { return markWord(0x4711); }
- };
  
  #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
  
  TEST_VM(PreservedMarks, iterate_and_restore) {
    PreservedMarks pm;
!   FakeOop o1;
!   FakeOop o2;
!   FakeOop o3;
!   FakeOop o4;
  
    // Make sure initial marks are correct.
!   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
!   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
!   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
!   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
  
    // Change the marks and verify change.
!   o1.set_mark(FakeOop::changedMark());
!   o2.set_mark(FakeOop::changedMark());
!   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
!   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
  
    // Push o1 and o2 to have their marks preserved.
!   pm.push_if_necessary(o1.get_oop(), o1.mark());
!   pm.push_if_necessary(o2.get_oop(), o2.mark());
  
    // Fake a move from o1->o3 and o2->o4.
!   o1.forward_to(o3.get_oop());
!   o2.forward_to(o4.get_oop());
!   ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
!   ASSERT_EQ(o2.get_oop()->forwardee(), o4.get_oop());
    // Adjust will update the PreservedMarks stack to
    // make sure the mark is updated at the new location.
    pm.adjust_during_full_gc();
  
    // Restore all preserved and verify that the changed
    // mark is now present at o3 and o4.
    pm.restore();
!   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::changedMark());
!   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::changedMark());
  }
--- 21,60 ---
   * questions.
   */
  
  #include "precompiled.hpp"
  #include "gc/shared/preservedMarks.inline.hpp"
+ #include "gc/shared/slidingForwarding.inline.hpp"
  #include "oops/oop.inline.hpp"
  #include "unittest.hpp"
  
! static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
! static markWord changedMark()  { return markWord(0x4711); }
  
  #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
  
  TEST_VM(PreservedMarks, iterate_and_restore) {
    PreservedMarks pm;
! 
!   HeapWord fakeheap[32] = { nullptr };
!   HeapWord* heap = align_up(fakeheap, 8 * sizeof(HeapWord));
!   SlidingForwarding::initialize(MemRegion(&heap[0], &heap[16]), 8);
+ 
+   oop o1 = cast_to_oop(&heap[0]); o1->set_mark(originalMark());
+   oop o2 = cast_to_oop(&heap[2]); o2->set_mark(originalMark());
+   oop o3 = cast_to_oop(&heap[4]); o3->set_mark(originalMark());
+   oop o4 = cast_to_oop(&heap[6]); o4->set_mark(originalMark());
  
    // Make sure initial marks are correct.
!   ASSERT_MARK_WORD_EQ(o1->mark(), originalMark());
!   ASSERT_MARK_WORD_EQ(o2->mark(), originalMark());
!   ASSERT_MARK_WORD_EQ(o3->mark(), originalMark());
!   ASSERT_MARK_WORD_EQ(o4->mark(), originalMark());
  
    // Change the marks and verify change.
!   o1->set_mark(changedMark());
!   o2->set_mark(changedMark());
!   ASSERT_MARK_WORD_EQ(o1->mark(), changedMark());
!   ASSERT_MARK_WORD_EQ(o2->mark(), changedMark());
+ 
+   SlidingForwarding::begin();
  
    // Push o1 and o2 to have their marks preserved.
!   pm.push_if_necessary(o1, o1->mark());
!   pm.push_if_necessary(o2, o2->mark());
  
    // Fake a move from o1->o3 and o2->o4.
!   SlidingForwarding::forward_to(o1, o3);
!   SlidingForwarding::forward_to(o2, o4);
!   ASSERT_EQ(SlidingForwarding::forwardee(o1), o3);
!   ASSERT_EQ(SlidingForwarding::forwardee(o2), o4);
    // Adjust will update the PreservedMarks stack to
    // make sure the mark is updated at the new location.
    pm.adjust_during_full_gc();
  
    // Restore all preserved and verify that the changed
    // mark is now present at o3 and o4.
    pm.restore();
!   ASSERT_MARK_WORD_EQ(o3->mark(), changedMark());
!   ASSERT_MARK_WORD_EQ(o4->mark(), changedMark());
+   SlidingForwarding::end();
  }
< prev index next >