21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/debugInfoRec.hpp"
31 #include "code/nmethod.hpp"
32 #include "code/pcDesc.hpp"
33 #include "code/scopeDesc.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/oopMapCache.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/frame.inline.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/objectMonitor.hpp"
42 #include "runtime/objectMonitor.inline.hpp"
43 #include "runtime/signature.hpp"
44 #include "runtime/stubRoutines.hpp"
45 #include "runtime/synchronizer.hpp"
46 #include "runtime/thread.inline.hpp"
47 #include "runtime/vframe.inline.hpp"
48 #include "runtime/vframeArray.hpp"
49 #include "runtime/vframe_hp.hpp"
50
51 vframe::vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread)
52 : _reg_map(reg_map), _thread(thread) {
53 assert(fr != NULL, "must have frame");
54 _fr = *fr;
55 }
56
57 vframe::vframe(const frame* fr, JavaThread* thread)
58 : _reg_map(thread), _thread(thread) {
59 assert(fr != NULL, "must have frame");
60 _fr = *fr;
119
120 GrowableArray<MonitorInfo*>* mons = monitors();
121 GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length());
122 if (mons->is_empty()) return result;
123
124 bool found_first_monitor = false;
125 // The ObjectMonitor* can't be async deflated since we are either
126 // at a safepoint or the calling thread is operating on itself so
127 // it cannot exit the ObjectMonitor so it remains busy.
128 ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor();
129 ObjectMonitor *pending_monitor = NULL;
130 if (waiting_monitor == NULL) {
131 pending_monitor = thread()->current_pending_monitor();
132 }
133 oop pending_obj = (pending_monitor != NULL ? (oop) pending_monitor->object() : (oop) NULL);
134 oop waiting_obj = (waiting_monitor != NULL ? (oop) waiting_monitor->object() : (oop) NULL);
135
136 for (int index = (mons->length()-1); index >= 0; index--) {
137 MonitorInfo* monitor = mons->at(index);
138 if (monitor->eliminated() && is_compiled_frame()) continue; // skip eliminated monitor
139 oop obj = monitor->owner();
140 if (obj == NULL) continue; // skip unowned monitor
141 //
142 // Skip the monitor that the thread is blocked to enter or waiting on
143 //
144 if (!found_first_monitor && (obj == pending_obj || obj == waiting_obj)) {
145 continue;
146 }
147 found_first_monitor = true;
148 result->append(monitor);
149 }
150 return result;
151 }
152
153 void javaVFrame::print_locked_object_class_name(outputStream* st, Handle obj, const char* lock_state) {
154 if (obj.not_null()) {
155 st->print("\t- %s <" INTPTR_FORMAT "> ", lock_state, p2i(obj()));
156 if (obj->klass() == SystemDictionary::Class_klass()) {
157 st->print_cr("(a java.lang.Class for %s)", java_lang_Class::as_external_name(obj()));
158 } else {
159 Klass* k = obj->klass();
160 st->print_cr("(a %s)", k->external_name());
161 }
162 }
163 }
164
165 void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
166 Thread* THREAD = Thread::current();
167 ResourceMark rm(THREAD);
168
169 // If this is the first frame and it is java.lang.Object.wait(...)
170 // then print out the receiver. Locals are not always available,
171 // e.g., compiled native frames have no scope so there are no locals.
172 if (frame_count == 0) {
173 if (method()->name() == vmSymbols::wait_name() &&
174 method()->method_holder()->name() == vmSymbols::java_lang_Object()) {
175 const char *wait_state = "waiting on"; // assume we are waiting
176 // If earlier in the output we reported java.lang.Thread.State ==
177 // "WAITING (on object monitor)" and now we report "waiting on", then
178 // we are still waiting for notification or timeout. Otherwise if
179 // we earlier reported java.lang.Thread.State == "BLOCKED (on object
180 // monitor)", then we are actually waiting to re-lock the monitor.
181 StackValueCollection* locs = locals();
182 if (!locs->is_empty()) {
183 StackValue* sv = locs->at(0);
184 if (sv->type() == T_OBJECT) {
185 Handle o = locs->at(0)->get_obj();
186 if (java_lang_Thread::get_thread_status(thread()->threadObj()) ==
187 java_lang_Thread::BLOCKED_ON_MONITOR_ENTER) {
202 // top-frame, so we should be waiting on a Class initialization monitor.
203 InstanceKlass* k = thread()->class_to_be_initialized();
204 if (k != NULL) {
205 st->print_cr("\t- waiting on the Class initialization monitor for %s", k->external_name());
206 }
207 }
208 }
209
210 // Print out all monitors that we have locked, or are trying to lock,
211 // including re-locking after being notified or timing out in a wait().
212 GrowableArray<MonitorInfo*>* mons = monitors();
213 if (!mons->is_empty()) {
214 bool found_first_monitor = false;
215 for (int index = (mons->length()-1); index >= 0; index--) {
216 MonitorInfo* monitor = mons->at(index);
217 if (monitor->eliminated() && is_compiled_frame()) { // Eliminated in compiled code
218 if (monitor->owner_is_scalar_replaced()) {
219 Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
220 st->print("\t- eliminated <owner is scalar replaced> (a %s)", k->external_name());
221 } else {
222 Handle obj(THREAD, monitor->owner());
223 if (obj() != NULL) {
224 print_locked_object_class_name(st, obj, "eliminated");
225 }
226 }
227 continue;
228 }
229 if (monitor->owner() != NULL) {
230 // the monitor is associated with an object, i.e., it is locked
231
232 const char *lock_state = "locked"; // assume we have the monitor locked
233 if (!found_first_monitor && frame_count == 0) {
234 // If this is the first frame and we haven't found an owned
235 // monitor before, then we need to see if we have completed
236 // the lock or if we are blocked trying to acquire it. Only
237 // an inflated monitor that is first on the monitor list in
238 // the first frame can block us on a monitor enter.
239 markWord mark = monitor->owner()->mark();
240 // The first stage of async deflation does not affect any field
241 // used by this comparison so the ObjectMonitor* is usable here.
242 if (mark.has_monitor() &&
243 ( // we have marked ourself as pending on this monitor
244 mark.monitor() == thread()->current_pending_monitor() ||
245 // we are not the owner of this monitor
246 !mark.monitor()->is_entered(thread())
247 )) {
248 lock_state = "waiting to lock";
249 }
250 }
251 print_locked_object_class_name(st, Handle(THREAD, monitor->owner()), lock_state);
252
253 found_first_monitor = true;
254 }
255 }
256 }
257 }
258
259 // ------------- interpretedVFrame --------------
260
261 u_char* interpretedVFrame::bcp() const {
262 return fr().interpreter_frame_bcp();
263 }
264
265 void interpretedVFrame::set_bcp(u_char* bcp) {
266 fr().interpreter_frame_set_bcp(bcp);
267 }
268
269 intptr_t* interpretedVFrame::locals_addr_at(int offset) const {
270 assert(fr().is_interpreted_frame(), "frame should be an interpreted frame");
271 return fr().interpreter_frame_local_at(offset);
595 }
596
597 void entryVFrame::print() {
598 vframe::print();
599 tty->print_cr("C Chunk inbetween Java");
600 tty->print_cr("C link " INTPTR_FORMAT, p2i(_fr.link()));
601 }
602
603
604 // ------------- javaVFrame --------------
605
606 static void print_stack_values(const char* title, StackValueCollection* values) {
607 if (values->is_empty()) return;
608 tty->print_cr("\t%s:", title);
609 values->print();
610 }
611
612
613 void javaVFrame::print() {
614 ResourceMark rm;
615 vframe::print();
616 tty->print("\t");
617 method()->print_value();
618 tty->cr();
619 tty->print_cr("\tbci: %d", bci());
620
621 print_stack_values("locals", locals());
622 print_stack_values("expressions", expressions());
623
624 GrowableArray<MonitorInfo*>* list = monitors();
625 if (list->is_empty()) return;
626 tty->print_cr("\tmonitor list:");
627 for (int index = (list->length()-1); index >= 0; index--) {
628 MonitorInfo* monitor = list->at(index);
629 tty->print("\t obj\t");
630 if (monitor->owner_is_scalar_replaced()) {
631 Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
632 tty->print("( is scalar replaced %s)", k->external_name());
633 } else if (monitor->owner() == NULL) {
634 tty->print("( null )");
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/debugInfoRec.hpp"
31 #include "code/nmethod.hpp"
32 #include "code/pcDesc.hpp"
33 #include "code/scopeDesc.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/oopMapCache.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/frame.inline.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/monitorInfo.inline.hpp"
42 #include "runtime/objectMonitor.hpp"
43 #include "runtime/objectMonitor.inline.hpp"
44 #include "runtime/signature.hpp"
45 #include "runtime/stubRoutines.hpp"
46 #include "runtime/synchronizer.hpp"
47 #include "runtime/thread.inline.hpp"
48 #include "runtime/vframe.inline.hpp"
49 #include "runtime/vframeArray.hpp"
50 #include "runtime/vframe_hp.hpp"
51
52 vframe::vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread)
53 : _reg_map(reg_map), _thread(thread) {
54 assert(fr != NULL, "must have frame");
55 _fr = *fr;
56 }
57
58 vframe::vframe(const frame* fr, JavaThread* thread)
59 : _reg_map(thread), _thread(thread) {
60 assert(fr != NULL, "must have frame");
61 _fr = *fr;
120
121 GrowableArray<MonitorInfo*>* mons = monitors();
122 GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length());
123 if (mons->is_empty()) return result;
124
125 bool found_first_monitor = false;
126 // The ObjectMonitor* can't be async deflated since we are either
127 // at a safepoint or the calling thread is operating on itself so
128 // it cannot exit the ObjectMonitor so it remains busy.
129 ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor();
130 ObjectMonitor *pending_monitor = NULL;
131 if (waiting_monitor == NULL) {
132 pending_monitor = thread()->current_pending_monitor();
133 }
134 oop pending_obj = (pending_monitor != NULL ? (oop) pending_monitor->object() : (oop) NULL);
135 oop waiting_obj = (waiting_monitor != NULL ? (oop) waiting_monitor->object() : (oop) NULL);
136
137 for (int index = (mons->length()-1); index >= 0; index--) {
138 MonitorInfo* monitor = mons->at(index);
139 if (monitor->eliminated() && is_compiled_frame()) continue; // skip eliminated monitor
140 Handle obj_h = monitor->owner_h();
141 if (obj_h.is_null()) continue; // skip unowned monitor
142 //
143 // Skip the monitor that the thread is blocked to enter or waiting on
144 //
145 if (!found_first_monitor && (obj_h == pending_obj || obj_h == waiting_obj)) {
146 continue;
147 }
148 found_first_monitor = true;
149 result->append(monitor);
150 }
151 return result;
152 }
153
154 void javaVFrame::print_locked_object_class_name(outputStream* st, Handle obj, const char* lock_state) {
155 if (obj.not_null()) {
156 st->print("\t- %s <" INTPTR_FORMAT "> ", lock_state, p2i(obj()));
157 if (obj->klass() == SystemDictionary::Class_klass()) {
158 st->print_cr("(a java.lang.Class for %s)", java_lang_Class::as_external_name(obj()));
159 } else {
160 Klass* k = obj->klass();
161 st->print_cr("(a %s)", k->external_name());
162 }
163 }
164 }
165
166 void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
167 Thread* THREAD = Thread::current();
168 ResourceMark rm(THREAD);
169 HandleMark hm(THREAD);
170
171 // If this is the first frame and it is java.lang.Object.wait(...)
172 // then print out the receiver. Locals are not always available,
173 // e.g., compiled native frames have no scope so there are no locals.
174 if (frame_count == 0) {
175 if (method()->name() == vmSymbols::wait_name() &&
176 method()->method_holder()->name() == vmSymbols::java_lang_Object()) {
177 const char *wait_state = "waiting on"; // assume we are waiting
178 // If earlier in the output we reported java.lang.Thread.State ==
179 // "WAITING (on object monitor)" and now we report "waiting on", then
180 // we are still waiting for notification or timeout. Otherwise if
181 // we earlier reported java.lang.Thread.State == "BLOCKED (on object
182 // monitor)", then we are actually waiting to re-lock the monitor.
183 StackValueCollection* locs = locals();
184 if (!locs->is_empty()) {
185 StackValue* sv = locs->at(0);
186 if (sv->type() == T_OBJECT) {
187 Handle o = locs->at(0)->get_obj();
188 if (java_lang_Thread::get_thread_status(thread()->threadObj()) ==
189 java_lang_Thread::BLOCKED_ON_MONITOR_ENTER) {
204 // top-frame, so we should be waiting on a Class initialization monitor.
205 InstanceKlass* k = thread()->class_to_be_initialized();
206 if (k != NULL) {
207 st->print_cr("\t- waiting on the Class initialization monitor for %s", k->external_name());
208 }
209 }
210 }
211
212 // Print out all monitors that we have locked, or are trying to lock,
213 // including re-locking after being notified or timing out in a wait().
214 GrowableArray<MonitorInfo*>* mons = monitors();
215 if (!mons->is_empty()) {
216 bool found_first_monitor = false;
217 for (int index = (mons->length()-1); index >= 0; index--) {
218 MonitorInfo* monitor = mons->at(index);
219 if (monitor->eliminated() && is_compiled_frame()) { // Eliminated in compiled code
220 if (monitor->owner_is_scalar_replaced()) {
221 Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
222 st->print("\t- eliminated <owner is scalar replaced> (a %s)", k->external_name());
223 } else {
224 Handle obj_h = monitor->owner_h();
225 if (obj_h.not_null()) {
226 print_locked_object_class_name(st, obj_h, "eliminated");
227 }
228 }
229 continue;
230 }
231 if (monitor->owner_h().not_null()) {
232 // the monitor is associated with an object, i.e., it is locked
233
234 const char *lock_state = "locked"; // assume we have the monitor locked
235 if (!found_first_monitor && frame_count == 0) {
236 // If this is the first frame and we haven't found an owned
237 // monitor before, then we need to see if we have completed
238 // the lock or if we are blocked trying to acquire it. Only
239 // an inflated monitor that is first on the monitor list in
240 // the first frame can block us on a monitor enter.
241 markWord mark = monitor->owner()->mark();
242 // The first stage of async deflation does not affect any field
243 // used by this comparison so the ObjectMonitor* is usable here.
244 if (mark.has_monitor() &&
245 ( // we have marked ourself as pending on this monitor
246 mark.monitor() == thread()->current_pending_monitor() ||
247 // we are not the owner of this monitor
248 !mark.monitor()->is_entered(thread())
249 )) {
250 lock_state = "waiting to lock";
251 }
252 }
253 print_locked_object_class_name(st, monitor->owner_h(), lock_state);
254
255 found_first_monitor = true;
256 }
257 }
258 }
259 }
260
261 // ------------- interpretedVFrame --------------
262
263 u_char* interpretedVFrame::bcp() const {
264 return fr().interpreter_frame_bcp();
265 }
266
267 void interpretedVFrame::set_bcp(u_char* bcp) {
268 fr().interpreter_frame_set_bcp(bcp);
269 }
270
271 intptr_t* interpretedVFrame::locals_addr_at(int offset) const {
272 assert(fr().is_interpreted_frame(), "frame should be an interpreted frame");
273 return fr().interpreter_frame_local_at(offset);
597 }
598
599 void entryVFrame::print() {
600 vframe::print();
601 tty->print_cr("C Chunk inbetween Java");
602 tty->print_cr("C link " INTPTR_FORMAT, p2i(_fr.link()));
603 }
604
605
606 // ------------- javaVFrame --------------
607
608 static void print_stack_values(const char* title, StackValueCollection* values) {
609 if (values->is_empty()) return;
610 tty->print_cr("\t%s:", title);
611 values->print();
612 }
613
614
615 void javaVFrame::print() {
616 ResourceMark rm;
617 HandleMark hm;
618
619 vframe::print();
620 tty->print("\t");
621 method()->print_value();
622 tty->cr();
623 tty->print_cr("\tbci: %d", bci());
624
625 print_stack_values("locals", locals());
626 print_stack_values("expressions", expressions());
627
628 GrowableArray<MonitorInfo*>* list = monitors();
629 if (list->is_empty()) return;
630 tty->print_cr("\tmonitor list:");
631 for (int index = (list->length()-1); index >= 0; index--) {
632 MonitorInfo* monitor = list->at(index);
633 tty->print("\t obj\t");
634 if (monitor->owner_is_scalar_replaced()) {
635 Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
636 tty->print("( is scalar replaced %s)", k->external_name());
637 } else if (monitor->owner() == NULL) {
638 tty->print("( null )");
|