test/hotspot/gtest/gc/shared/test_preservedMarks.cpp
author stefank
Tue, 06 Aug 2019 10:48:21 +0200
changeset 57777 90ead0febf56
parent 49722 a47d1e21b3f1
permissions -rw-r--r--
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier Reviewed-by: rkennke, coleenp, kbarrett, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     1
/*
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47885
diff changeset
     2
 * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     4
 *
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     8
 *
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    13
 * accompanied this code).
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    14
 *
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    18
 *
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    21
 * questions.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    22
 */
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    23
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    24
#include "precompiled.hpp"
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    25
#include "gc/shared/preservedMarks.inline.hpp"
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47885
diff changeset
    26
#include "oops/oop.inline.hpp"
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    27
#include "unittest.hpp"
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    28
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    29
class ScopedDisabledBiasedLocking {
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    30
  bool _orig;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    31
public:
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    32
  ScopedDisabledBiasedLocking() : _orig(UseBiasedLocking) { UseBiasedLocking = false; }
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    33
  ~ScopedDisabledBiasedLocking() { UseBiasedLocking = _orig; }
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    34
};
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    35
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    36
// Class to create a "fake" oop with a mark that will
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    37
// return true for calls to must_be_preserved().
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    38
class FakeOop {
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    39
  oopDesc _oop;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    40
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    41
public:
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47885
diff changeset
    42
  FakeOop() : _oop() { _oop.set_mark_raw(originalMark()); }
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    43
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    44
  oop get_oop() { return &_oop; }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    45
  markWord mark() { return _oop.mark_raw(); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    46
  void set_mark(markWord m) { _oop.set_mark_raw(m); }
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    47
  void forward_to(oop obj) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    48
    markWord m = markWord::encode_pointer_as_mark(obj);
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47885
diff changeset
    49
    _oop.set_mark_raw(m);
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    50
  }
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    51
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    52
  static markWord originalMark() { return markWord(markWord::lock_mask_in_place); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    53
  static markWord changedMark()  { return markWord(0x4711); }
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    54
};
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    55
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    56
#define ASSERT_MARK_WORD_EQ(a, b) ASSERT_EQ((a).value(), (b).value())
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    57
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    58
TEST_VM(PreservedMarks, iterate_and_restore) {
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    59
  // Need to disable biased locking to easily
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    60
  // create oops that "must_be_preseved"
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    61
  ScopedDisabledBiasedLocking dbl;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    62
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    63
  PreservedMarks pm;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    64
  FakeOop o1;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    65
  FakeOop o2;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    66
  FakeOop o3;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    67
  FakeOop o4;
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    68
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    69
  // Make sure initial marks are correct.
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    70
  ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::originalMark());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    71
  ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::originalMark());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    72
  ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::originalMark());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    73
  ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::originalMark());
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    74
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    75
  // Change the marks and verify change.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    76
  o1.set_mark(FakeOop::changedMark());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    77
  o2.set_mark(FakeOop::changedMark());
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    78
  ASSERT_MARK_WORD_EQ(o1.mark(), FakeOop::changedMark());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    79
  ASSERT_MARK_WORD_EQ(o2.mark(), FakeOop::changedMark());
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    80
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    81
  // Push o1 and o2 to have their marks preserved.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    82
  pm.push(o1.get_oop(), o1.mark());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    83
  pm.push(o2.get_oop(), o2.mark());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    84
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    85
  // Fake a move from o1->o3 and o2->o4.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    86
  o1.forward_to(o3.get_oop());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    87
  o2.forward_to(o4.get_oop());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    88
  ASSERT_EQ(o1.get_oop()->forwardee(), o3.get_oop());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    89
  ASSERT_EQ(o2.get_oop()->forwardee(), o4.get_oop());
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    90
  // Adjust will update the PreservedMarks stack to
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    91
  // make sure the mark is updated at the new location.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    92
  pm.adjust_during_full_gc();
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    93
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    94
  // Restore all preserved and verify that the changed
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    95
  // mark is now present at o3 and o4.
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    96
  pm.restore();
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    97
  ASSERT_MARK_WORD_EQ(o3.mark(), FakeOop::changedMark());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 49722
diff changeset
    98
  ASSERT_MARK_WORD_EQ(o4.mark(), FakeOop::changedMark());
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents:
diff changeset
    99
}