1 /*
 2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 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 
25 #include "precompiled.hpp"
26 #include "oops/compressedOops.inline.hpp"
27 #include "oops/markWord.hpp"
28 #include "runtime/thread.inline.hpp"
29 #include "runtime/objectMonitor.inline.hpp"
30 #include "utilities/ostream.hpp"
31 
32 markWord markWord::displaced_mark_helper() const {
33   assert(has_displaced_mark_helper(), "check");
34   if (has_monitor()) {
35     // Has an inflated monitor. Must be checked before has_locker().
36     ObjectMonitor* monitor = this->monitor();
37     return monitor->header();
38   }
39   if (has_locker()) {  // has a stack lock
40     BasicLock* locker = this->locker();
41     return locker->displaced_header();
42   }
43   // This should never happen:
44   fatal("bad header=" INTPTR_FORMAT, value());
45   return markWord(value());
46 }
47 
48 void markWord::set_displaced_mark_helper(markWord m) const {
49   assert(has_displaced_mark_helper(), "check");
50   if (has_monitor()) {
51     // Has an inflated monitor. Must be checked before has_locker().
52     ObjectMonitor* monitor = this->monitor();
53     monitor->set_header(m);
54     return;
55   }
56   if (has_locker()) {  // has a stack lock
57     BasicLock* locker = this->locker();
58     locker->set_displaced_header(m);
59     return;
60   }
61   // This should never happen:
62   fatal("bad header=" INTPTR_FORMAT, value());
63 }
64 
65 void markWord::print_on(outputStream* st, bool print_monitor_info) const {
66   if (is_marked()) {  // last bits = 11
67     st->print(" marked(" INTPTR_FORMAT ")", value());
68   } else if (has_monitor()) {  // last bits = 10
69     // have to check has_monitor() before is_locked()
70     st->print(" monitor(" INTPTR_FORMAT ")=", value());
71     if (print_monitor_info) {
72       ObjectMonitor* mon = monitor();
73       if (mon == NULL) {
74         st->print("NULL (this should never be seen!)");
75       } else {
76         mon->print_on(st);
77       }
78     }
79   } else if (is_locked()) {  // last bits != 01 => 00
80     // thin locked
81     st->print(" locked(" INTPTR_FORMAT ")", value());
82   } else {
83     st->print(" mark(");
84     if (is_neutral()) {   // last bits = 01
85       st->print("is_neutral");
86       if (has_no_hash()) {
87         st->print(" no_hash");
88       } else {
89         st->print(" hash=" INTPTR_FORMAT, hash());
90       }
91     } else {
92       st->print("??");
93     }
94     st->print(" age=%d)", age());
95   }
96 }