Path: blob/master/test/hotspot/gtest/gc/shared/test_preservedMarks.cpp
41152 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/shared/preservedMarks.inline.hpp"25#include "oops/oop.inline.hpp"26#include "unittest.hpp"2728class ScopedDisabledBiasedLocking {29bool _orig;30public:31ScopedDisabledBiasedLocking() : _orig(UseBiasedLocking) { UseBiasedLocking = false; }32~ScopedDisabledBiasedLocking() { UseBiasedLocking = _orig; }33};3435// Class to create a "fake" oop with a mark that will36// return true for calls to must_be_preserved().37class FakeOop {38oopDesc _oop;3940public:41FakeOop() : _oop() { _oop.set_mark(originalMark()); }4243oop get_oop() { return &_oop; }44markWord mark() { return _oop.mark(); }45void set_mark(markWord m) { _oop.set_mark(m); }46void forward_to(oop obj) {47markWord m = markWord::encode_pointer_as_mark(obj);48_oop.set_mark(m);49}5051static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }52static markWord changedMark() { return markWord(0x4711); }53};5455#define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())5657TEST_VM(PreservedMarks, iterate_and_restore) {58// Need to disable biased locking to easily59// create oops that "must_be_preseved"60ScopedDisabledBiasedLocking dbl;6162PreservedMarks pm;63FakeOop o1;64FakeOop o2;65FakeOop o3;66FakeOop o4;6768// Make sure initial marks are correct.69ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());70ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());71ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());72ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());7374// Change the marks and verify change.75o1.set_mark(FakeOop::changedMark());76o2.set_mark(FakeOop::changedMark());77ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());78ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());7980// Push o1 and o2 to have their marks preserved.81pm.push(o1.get_oop(), o1.mark());82pm.push(o2.get_oop(), o2.mark());8384// Fake a move from o1->o3 and o2->o4.85o1.forward_to(o3.get_oop());86o2.forward_to(o4.get_oop());87ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());88ASSERT_EQ(o2.get_oop()->forwardee(), o4.get_oop());89// Adjust will update the PreservedMarks stack to90// make sure the mark is updated at the new location.91pm.adjust_during_full_gc();9293// Restore all preserved and verify that the changed94// mark is now present at o3 and o4.95pm.restore();96ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::changedMark());97ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::changedMark());98}99100101