< prev index next >

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

Print this page

 32   ScopedDisabledBiasedLocking() : _orig(UseBiasedLocking) { UseBiasedLocking = false; }
 33   ~ScopedDisabledBiasedLocking() { UseBiasedLocking = _orig; }
 34 };
 35 
 36 // Class to create a "fake" oop with a mark that will
 37 // return true for calls to must_be_preserved().
 38 class FakeOop {
 39   oopDesc _oop;
 40 
 41 public:
 42   FakeOop() : _oop() { _oop.set_mark(originalMark()); }
 43 
 44   oop get_oop() { return &_oop; }
 45   markWord mark() { return _oop.mark(); }
 46   void set_mark(markWord m) { _oop.set_mark(m); }
 47   void forward_to(oop obj) {
 48     markWord m = markWord::encode_pointer_as_mark(obj);
 49     _oop.set_mark(m);
 50   }
 51 
 52   static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
 53   static markWord changedMark()  { return markWord(0x4711); }
 54 };
 55 
 56 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
 57 
 58 TEST_VM(PreservedMarks, iterate_and_restore) {
 59   // Need to disable biased locking to easily
 60   // create oops that "must_be_preseved"
 61   ScopedDisabledBiasedLocking dbl;
 62 
 63   PreservedMarks pm;
 64   FakeOop o1;
 65   FakeOop o2;
 66   FakeOop o3;
 67   FakeOop o4;
 68 
 69   // Make sure initial marks are correct.
 70   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
 71   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
 72   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
 73   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
 74 
 75   // Change the marks and verify change.
 76   o1.set_mark(FakeOop::changedMark());
 77   o2.set_mark(FakeOop::changedMark());
 78   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
 79   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
 80 
 81   // Push o1 and o2 to have their marks preserved.
 82   pm.push(o1.get_oop(), o1.mark());
 83   pm.push(o2.get_oop(), o2.mark());
 84 
 85   // Fake a move from o1->o3 and o2->o4.
 86   o1.forward_to(o3.get_oop());
 87   o2.forward_to(o4.get_oop());
 88   ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
 89   ASSERT_EQ(o2.get_oop()->forwardee(), o4.get_oop());
 90   // Adjust will update the PreservedMarks stack to
 91   // make sure the mark is updated at the new location.



 92   pm.adjust_during_full_gc();
 93 
 94   // Restore all preserved and verify that the changed
 95   // mark is now present at o3 and o4.
 96   pm.restore();
 97   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::changedMark());
 98   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::changedMark());
 99 }

 32   ScopedDisabledBiasedLocking() : _orig(UseBiasedLocking) { UseBiasedLocking = false; }
 33   ~ScopedDisabledBiasedLocking() { UseBiasedLocking = _orig; }
 34 };
 35 
 36 // Class to create a "fake" oop with a mark that will
 37 // return true for calls to must_be_preserved().
 38 class FakeOop {
 39   oopDesc _oop;
 40 
 41 public:
 42   FakeOop() : _oop() { _oop.set_mark(originalMark()); }
 43 
 44   oop get_oop() { return &_oop; }
 45   markWord mark() { return _oop.mark(); }
 46   void set_mark(markWord m) { _oop.set_mark(m); }
 47   void forward_to(oop obj) {
 48     markWord m = markWord::encode_pointer_as_mark(obj);
 49     _oop.set_mark(m);
 50   }
 51 
 52   static markWord originalMark() { return markWord(markWord::unlocked_value); }
 53   static markWord changedMark()  { return markWord(0x4711); }
 54 };
 55 
 56 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
 57 
 58 TEST_VM(PreservedMarks, iterate_and_restore) {
 59   // Need to disable biased locking to easily
 60   // create oops that "must_be_preseved"
 61   ScopedDisabledBiasedLocking dbl;
 62 
 63   PreservedMarks pm;
 64   FakeOop o1;
 65   FakeOop o2;
 66   FakeOop o3;
 67   FakeOop o4;
 68 
 69   // Make sure initial marks are correct.
 70   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
 71   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
 72   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
 73   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
 74 
 75   // Change the marks and verify change.
 76   o1.set_mark(FakeOop::changedMark());
 77   o2.set_mark(FakeOop::changedMark());
 78   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
 79   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
 80 
 81   // Push o1 and o2 to have their marks preserved.
 82   pm.push(o1.get_oop(), o1.mark());
 83   pm.push(o2.get_oop(), o2.mark());
 84 
 85   // Fake a move from o1->o3 and o2->o4.
 86   o1.forward_to(o3.get_oop());
 87   o2.forward_to(o4.get_oop());
 88   ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
 89   ASSERT_EQ(o2.get_oop()->forwardee(), o4.get_oop());
 90   // Adjust will update the PreservedMarks stack to
 91   // make sure the mark is updated at the new location.
 92   // TODO: This is the only use of PM::adjust_during_full_gc().
 93   // GCs use the variant with a forwarding structure here,
 94   // test that variant, and remove the method.
 95   pm.adjust_during_full_gc();
 96 
 97   // Restore all preserved and verify that the changed
 98   // mark is now present at o3 and o4.
 99   pm.restore();
100   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::changedMark());
101   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::changedMark());
102 }
< prev index next >