5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 "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());
67 ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
68 ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
69
70 // Push o1 and o2 to have their marks preserved.
71 pm.push_if_necessary(o1.get_oop(), o1.mark());
72 pm.push_if_necessary(o2.get_oop(), o2.mark());
73
74 // Fake a move from o1->o3 and o2->o4.
75 o1.forward_to(o3.get_oop());
76 o2.forward_to(o4.get_oop());
77 ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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/gc_globals.hpp"
26 #include "gc/shared/preservedMarks.inline.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "unittest.hpp"
29
30 // Class to create a "fake" oop with a mark that will
31 // return true for calls to must_be_preserved().
32 class FakeOop {
33 oopDesc _oop;
34
35 public:
36 FakeOop() : _oop() { _oop.set_mark(originalMark()); }
37
38 oop get_oop() { return &_oop; }
39 markWord mark() { return _oop.mark(); }
40 void set_mark(markWord m) { _oop.set_mark(m); }
41 void forward_to(oop obj) {
42 markWord m = markWord::encode_pointer_as_mark(obj);
43 _oop.set_mark(m);
44 }
45
46 static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
47 static markWord changedMark() { return markWord(0x4711); }
48 };
49
50 #define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
51
52 TEST_VM(PreservedMarks, iterate_and_restore) {
53 PreservedMarks pm;
54 FakeOop o1;
55 FakeOop o2;
56 FakeOop o3;
57 FakeOop o4;
58
59 FlagSetting fs(UseAltGCForwarding, false);
60
61 // Make sure initial marks are correct.
62 ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
63 ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
64 ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
65 ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
66
67 // Change the marks and verify change.
68 o1.set_mark(FakeOop::changedMark());
69 o2.set_mark(FakeOop::changedMark());
70 ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
71 ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
72
73 // Push o1 and o2 to have their marks preserved.
74 pm.push_if_necessary(o1.get_oop(), o1.mark());
75 pm.push_if_necessary(o2.get_oop(), o2.mark());
76
77 // Fake a move from o1->o3 and o2->o4.
78 o1.forward_to(o3.get_oop());
79 o2.forward_to(o4.get_oop());
80 ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
|