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