1 /*
2 * Copyright (c) 2000, 2017, 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 *
89 public void printLockInfo(PrintStream tty, int frameCount) {
90 // If this is the first frame and it is java.lang.Object.wait(...)
91 // then print out the receiver. Locals are not always available,
92 // e.g., compiled native frames have no scope so there are no locals.
93 if (frameCount == 0) {
94 if (getMethod().getName().asString().equals("wait") &&
95 getMethod().getMethodHolder().getName().asString().equals("java/lang/Object")) {
96 String waitState = "waiting on"; // assume we are waiting
97 // If earlier in the output we reported java.lang.Thread.State ==
98 // "WAITING (on object monitor)" and now we report "waiting on", then
99 // we are still waiting for notification or timeout. Otherwise if
100 // we earlier reported java.lang.Thread.State == "BLOCKED (on object
101 // monitor)", then we are actually waiting to re-lock the monitor.
102 // At this level we can't distinguish the two cases to report
103 // "waited on" rather than "waiting on" for the second case.
104 StackValueCollection locs = getLocals();
105 if (!locs.isEmpty()) {
106 StackValue sv = locs.get(0);
107 if (sv.getType() == BasicType.getTObject()) {
108 OopHandle o = sv.getObject();
109 printLockedObjectClassName(tty, o, waitState);
110 }
111 } else {
112 tty.println("\t- " + waitState + " <no object reference available>");
113 }
114 } else if (thread.getCurrentParkBlocker() != null) {
115 Oop obj = thread.getCurrentParkBlocker();
116 Klass k = obj.getKlass();
117 tty.format("\t- parking to wait for <" + ADDRESS_FORMAT + "> (a %s)",
118 obj.getHandle().asLongValue(), k.getName().asString());
119 tty.println();
120 }
121 }
122
123 // Print out all monitors that we have locked, or are trying to lock,
124 // including re-locking after being notified or timing out in a wait().
125 List<MonitorInfo> mons = getMonitors();
126 if (!mons.isEmpty()) {
127 boolean foundFirstMonitor = false;
128 for (int index = mons.size() - 1; index >= 0; index--) {
129 MonitorInfo monitor = mons.get(index);
130 if (monitor.eliminated() && isCompiledFrame()) { // Eliminated in compiled code
131 if (monitor.ownerIsScalarReplaced()) {
132 Klass k = Oop.getKlassForOopHandle(monitor.ownerKlass());
133 tty.println("\t- eliminated <owner is scalar replaced> (a " + k.getName().asString() + ")");
134 } else if (monitor.owner() != null) {
135 printLockedObjectClassName(tty, monitor.owner(), "eliminated");
136 }
137 continue;
138 }
139 if (monitor.owner() != null) {
140 // the monitor is associated with an object, i.e., it is locked
141 String lockState = "locked";
142 if (!foundFirstMonitor && frameCount == 0) {
143 // If this is the first frame and we haven't found an owned
144 // monitor before, then we need to see if we have completed
145 // the lock or if we are blocked trying to acquire it. Only
146 // an inflated monitor that is first on the monitor list in
147 // the first frame can block us on a monitor enter.
148 lockState = identifyLockState(monitor, "waiting to lock");
149 } else if (frameCount != 0) {
150 // This is not the first frame so we either own this monitor
151 // or we owned the monitor before and called wait(). Because
152 // wait() could have been called on any monitor in a lower
153 // numbered frame on the stack, we have to check all the
154 // monitors on the list for this frame.
155 lockState = identifyLockState(monitor, "waiting to re-lock in wait()");
156 }
157 printLockedObjectClassName(tty, monitor.owner(), lockState);
158 foundFirstMonitor = true;
159 }
160 }
161 }
162 }
163
164 /** Printing operations */
165
166 //
167 // FIXME: implement visitor pattern for traversing vframe contents?
168 //
169
170 public void print() {
171 printOn(System.out);
172 }
173
174 public void printOn(PrintStream tty) {
175 super.printOn(tty);
|
1 /*
2 * Copyright (c) 2000, 2018, 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 *
89 public void printLockInfo(PrintStream tty, int frameCount) {
90 // If this is the first frame and it is java.lang.Object.wait(...)
91 // then print out the receiver. Locals are not always available,
92 // e.g., compiled native frames have no scope so there are no locals.
93 if (frameCount == 0) {
94 if (getMethod().getName().asString().equals("wait") &&
95 getMethod().getMethodHolder().getName().asString().equals("java/lang/Object")) {
96 String waitState = "waiting on"; // assume we are waiting
97 // If earlier in the output we reported java.lang.Thread.State ==
98 // "WAITING (on object monitor)" and now we report "waiting on", then
99 // we are still waiting for notification or timeout. Otherwise if
100 // we earlier reported java.lang.Thread.State == "BLOCKED (on object
101 // monitor)", then we are actually waiting to re-lock the monitor.
102 // At this level we can't distinguish the two cases to report
103 // "waited on" rather than "waiting on" for the second case.
104 StackValueCollection locs = getLocals();
105 if (!locs.isEmpty()) {
106 StackValue sv = locs.get(0);
107 if (sv.getType() == BasicType.getTObject()) {
108 OopHandle o = sv.getObject();
109 if (OopUtilities.threadOopGetThreadStatus(thread.getThreadObj()) == OopUtilities.THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER) {
110 waitState = "waiting to re-lock in wait()";
111 }
112 printLockedObjectClassName(tty, o, waitState);
113 }
114 } else {
115 tty.println("\t- " + waitState + " <no object reference available>");
116 }
117 } else if (thread.getCurrentParkBlocker() != null) {
118 Oop obj = thread.getCurrentParkBlocker();
119 Klass k = obj.getKlass();
120 tty.format("\t- parking to wait for <" + ADDRESS_FORMAT + "> (a %s)",
121 obj.getHandle().asLongValue(), k.getName().asString());
122 tty.println();
123 }
124 }
125
126 // Print out all monitors that we have locked, or are trying to lock,
127 // including re-locking after being notified or timing out in a wait().
128 List<MonitorInfo> mons = getMonitors();
129 if (!mons.isEmpty()) {
130 boolean foundFirstMonitor = false;
131 for (int index = mons.size() - 1; index >= 0; index--) {
132 MonitorInfo monitor = mons.get(index);
133 if (monitor.eliminated() && isCompiledFrame()) { // Eliminated in compiled code
134 if (monitor.ownerIsScalarReplaced()) {
135 Klass k = Oop.getKlassForOopHandle(monitor.ownerKlass());
136 tty.println("\t- eliminated <owner is scalar replaced> (a " + k.getName().asString() + ")");
137 } else if (monitor.owner() != null) {
138 printLockedObjectClassName(tty, monitor.owner(), "eliminated");
139 }
140 continue;
141 }
142 if (monitor.owner() != null) {
143 // the monitor is associated with an object, i.e., it is locked
144 String lockState = "locked";
145 if (!foundFirstMonitor && frameCount == 0) {
146 // If this is the first frame and we haven't found an owned
147 // monitor before, then we need to see if we have completed
148 // the lock or if we are blocked trying to acquire it. Only
149 // an inflated monitor that is first on the monitor list in
150 // the first frame can block us on a monitor enter.
151 lockState = identifyLockState(monitor, "waiting to lock");
152 }
153 printLockedObjectClassName(tty, monitor.owner(), lockState);
154 foundFirstMonitor = true;
155 }
156 }
157 }
158 }
159
160 /** Printing operations */
161
162 //
163 // FIXME: implement visitor pattern for traversing vframe contents?
164 //
165
166 public void print() {
167 printOn(System.out);
168 }
169
170 public void printOn(PrintStream tty) {
171 super.printOn(tty);
|