11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "gc/shared/preservedMarks.inline.hpp"
26 #include "gc/shared/fullGCForwarding.inline.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "unittest.hpp"
29
30 static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
31 static markWord changedMark() { return markWord(0x4711); }
32
33 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
34
35 TEST_VM(PreservedMarks, iterate_and_restore) {
36 PreservedMarks pm;
37
38 HeapWord fakeheap[32] = { nullptr };
39 HeapWord* heap = align_up(fakeheap, 8 * sizeof(HeapWord));
40 FullGCForwarding::initialize(MemRegion(&heap[0], &heap[16]));
41
42 oop o1 = cast_to_oop(&heap[0]); o1->set_mark(originalMark());
43 oop o2 = cast_to_oop(&heap[2]); o2->set_mark(originalMark());
44 oop o3 = cast_to_oop(&heap[4]); o3->set_mark(originalMark());
45 oop o4 = cast_to_oop(&heap[6]); o4->set_mark(originalMark());
46
47 // Make sure initial marks are correct.
48 ASSERT_MARK_WORD_EQ(o1->mark(), originalMark());
49 ASSERT_MARK_WORD_EQ(o2->mark(), originalMark());
50 ASSERT_MARK_WORD_EQ(o3->mark(), originalMark());
51 ASSERT_MARK_WORD_EQ(o4->mark(), originalMark());
52
53 // Change the marks and verify change.
54 o1->set_mark(changedMark());
55 o2->set_mark(changedMark());
56 ASSERT_MARK_WORD_EQ(o1->mark(), changedMark());
57 ASSERT_MARK_WORD_EQ(o2->mark(), changedMark());
58
59 // Push o1 and o2 to have their marks preserved.
60 pm.push_if_necessary(o1, o1->mark());
61 pm.push_if_necessary(o2, o2->mark());
62
63 // Fake a move from o1->o3 and o2->o4.
64 FullGCForwarding::forward_to(o1, o3);
65 FullGCForwarding::forward_to(o2, o4);
66 ASSERT_EQ(FullGCForwarding::forwardee(o1), o3);
67 ASSERT_EQ(FullGCForwarding::forwardee(o2), o4);
68 // Adjust will update the PreservedMarks stack to
69 // make sure the mark is updated at the new location.
70 pm.adjust_during_full_gc();
71
72 // Restore all preserved and verify that the changed
73 // mark is now present at o3 and o4.
74 pm.restore();
75 ASSERT_MARK_WORD_EQ(o3->mark(), changedMark());
76 ASSERT_MARK_WORD_EQ(o4->mark(), changedMark());
77 }
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "gc/shared/preservedMarks.inline.hpp"
26 #include "gc/shared/fullGCForwarding.inline.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "unittest.hpp"
29
30 static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
31 static markWord changedMark() { return markWord(0x4712); }
32
33 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
34
35 TEST_VM(PreservedMarks, iterate_and_restore) {
36 PreservedMarks pm;
37
38 HeapWord fakeheap[32] = { nullptr };
39 HeapWord* heap = align_up(fakeheap, 8 * sizeof(HeapWord));
40 FullGCForwarding::initialize(MemRegion(&heap[0], &heap[16]));
41
42 oop o1 = cast_to_oop(&heap[0]); o1->set_mark(originalMark());
43 oop o2 = cast_to_oop(&heap[2]); o2->set_mark(originalMark());
44 oop o3 = cast_to_oop(&heap[4]); o3->set_mark(originalMark());
45 oop o4 = cast_to_oop(&heap[6]); o4->set_mark(originalMark());
46
47 // Make sure initial marks are correct.
48 ASSERT_MARK_WORD_EQ(o1->mark(), originalMark());
49 ASSERT_MARK_WORD_EQ(o2->mark(), originalMark());
50 ASSERT_MARK_WORD_EQ(o3->mark(), originalMark());
51 ASSERT_MARK_WORD_EQ(o4->mark(), originalMark());
52
53 // Change the marks and verify change.
54 o1->set_mark(changedMark());
55 o2->set_mark(changedMark());
56 ASSERT_MARK_WORD_EQ(o1->mark(), changedMark());
57 ASSERT_MARK_WORD_EQ(o2->mark(), changedMark());
58
59 FullGCForwarding::begin();
60
61 // Push o1 and o2 to have their marks preserved.
62 pm.push_if_necessary(o1, o1->mark());
63 pm.push_if_necessary(o2, o2->mark());
64
65 // Fake a move from o1->o3 and o2->o4.
66 FullGCForwarding::forward_to(o1, o3);
67 FullGCForwarding::forward_to(o2, o4);
68 ASSERT_EQ(FullGCForwarding::forwardee(o1), o3);
69 ASSERT_EQ(FullGCForwarding::forwardee(o2), o4);
70 // Adjust will update the PreservedMarks stack to
71 // make sure the mark is updated at the new location.
72 pm.adjust_during_full_gc();
73
74 // Restore all preserved and verify that the changed
75 // mark is now present at o3 and o4.
76 pm.restore();
77 ASSERT_MARK_WORD_EQ(o3->mark(), changedMark());
78 ASSERT_MARK_WORD_EQ(o4->mark(), changedMark());
79
80 FullGCForwarding::end();
81 }
|