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