< prev index next >

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

Print this page

26 #include "oops/oop.inline.hpp"
27 #include "unittest.hpp"
28 
29 // Class to create a "fake" oop with a mark that will
30 // return true for calls to must_be_preserved().
31 class FakeOop {
32   oopDesc _oop;
33 
34 public:
35   FakeOop() : _oop() { _oop.set_mark(originalMark()); }
36 
37   oop get_oop() { return &_oop; }
38   markWord mark() { return _oop.mark(); }
39   void set_mark(markWord m) { _oop.set_mark(m); }
40   void forward_to(oop obj) {
41     markWord m = markWord::encode_pointer_as_mark(obj);
42     _oop.set_mark(m);
43   }
44 
45   static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
46   static markWord changedMark()  { return markWord(0x4711); }
47 };
48 
49 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
50 
51 TEST_VM(PreservedMarks, iterate_and_restore) {
52   PreservedMarks pm;
53   FakeOop o1;
54   FakeOop o2;
55   FakeOop o3;
56   FakeOop o4;
57 
58   // Make sure initial marks are correct.
59   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
60   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
61   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
62   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
63 
64   // Change the marks and verify change.
65   o1.set_mark(FakeOop::changedMark());
66   o2.set_mark(FakeOop::changedMark());

26 #include "oops/oop.inline.hpp"
27 #include "unittest.hpp"
28 
29 // Class to create a "fake" oop with a mark that will
30 // return true for calls to must_be_preserved().
31 class FakeOop {
32   oopDesc _oop;
33 
34 public:
35   FakeOop() : _oop() { _oop.set_mark(originalMark()); }
36 
37   oop get_oop() { return &_oop; }
38   markWord mark() { return _oop.mark(); }
39   void set_mark(markWord m) { _oop.set_mark(m); }
40   void forward_to(oop obj) {
41     markWord m = markWord::encode_pointer_as_mark(obj);
42     _oop.set_mark(m);
43   }
44 
45   static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
46   static markWord changedMark()  { return markWord((uintptr_t)0x4711 << markWord::hash_shift); }
47 };
48 
49 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
50 
51 TEST_VM(PreservedMarks, iterate_and_restore) {
52   PreservedMarks pm;
53   FakeOop o1;
54   FakeOop o2;
55   FakeOop o3;
56   FakeOop o4;
57 
58   // Make sure initial marks are correct.
59   ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
60   ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
61   ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
62   ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
63 
64   // Change the marks and verify change.
65   o1.set_mark(FakeOop::changedMark());
66   o2.set_mark(FakeOop::changedMark());
< prev index next >