< prev index next >

src/hotspot/share/runtime/vframe.cpp

Print this page

  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 "classfile/javaClasses.inline.hpp"
 27 #include "classfile/javaThreadStatus.hpp"
 28 #include "classfile/vmClasses.hpp"
 29 #include "classfile/vmSymbols.hpp"
 30 #include "code/codeCache.hpp"
 31 #include "code/debugInfoRec.hpp"
 32 #include "code/nmethod.hpp"
 33 #include "code/pcDesc.hpp"
 34 #include "code/scopeDesc.hpp"
 35 #include "interpreter/interpreter.hpp"
 36 #include "interpreter/oopMapCache.hpp"
 37 #include "memory/resourceArea.hpp"
 38 #include "oops/instanceKlass.hpp"
 39 #include "oops/oop.inline.hpp"
 40 #include "prims/jvmtiExport.hpp"
 41 #include "runtime/frame.inline.hpp"

 42 #include "runtime/handles.inline.hpp"
 43 #include "runtime/objectMonitor.hpp"
 44 #include "runtime/objectMonitor.inline.hpp"
 45 #include "runtime/osThread.hpp"
 46 #include "runtime/signature.hpp"
 47 #include "runtime/stackFrameStream.inline.hpp"
 48 #include "runtime/stubRoutines.hpp"
 49 #include "runtime/synchronizer.hpp"
 50 #include "runtime/thread.inline.hpp"
 51 #include "runtime/vframe.inline.hpp"
 52 #include "runtime/vframeArray.hpp"
 53 #include "runtime/vframe_hp.hpp"
 54 
 55 vframe::vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread)
 56 : _reg_map(reg_map), _thread(thread) {

 57   assert(fr != NULL, "must have frame");
 58   _fr = *fr;
 59 }
 60 
 61 vframe::vframe(const frame* fr, JavaThread* thread)
 62 : _reg_map(thread), _thread(thread) {
 63   assert(fr != NULL, "must have frame");
 64   _fr = *fr;

 65 }
 66 
 67 vframe* vframe::new_vframe(StackFrameStream& fst, JavaThread* thread) {
 68   if (fst.current()->is_runtime_frame()) {
 69     fst.next();
 70   }
 71   guarantee(!fst.is_done(), "missing caller");
 72   return new_vframe(fst.current(), fst.register_map(), thread);
 73 }
 74 
 75 vframe* vframe::new_vframe(const frame* f, const RegisterMap* reg_map, JavaThread* thread) {
 76   // Interpreter frame
 77   if (f->is_interpreted_frame()) {
 78     return new interpretedVFrame(f, reg_map, thread);
 79   }
 80 
 81   // Compiled frame
 82   CodeBlob* cb = f->cb();
 83   if (cb != NULL) {
 84     if (cb->is_compiled()) {

 89     if (f->is_runtime_frame()) {
 90       // Skip this frame and try again.
 91       RegisterMap temp_map = *reg_map;
 92       frame s = f->sender(&temp_map);
 93       return new_vframe(&s, &temp_map, thread);
 94     }
 95   }
 96 
 97   // Entry frame
 98   if (f->is_entry_frame()) {
 99     return new entryVFrame(f, reg_map, thread);
100   }
101 
102   // External frame
103   return new externalVFrame(f, reg_map, thread);
104 }
105 
106 vframe* vframe::sender() const {
107   RegisterMap temp_map = *register_map();
108   assert(is_top(), "just checking");

109   if (_fr.is_entry_frame() && _fr.is_first_frame()) return NULL;
110   frame s = _fr.real_sender(&temp_map);
111   if (s.is_first_frame()) return NULL;




112   return vframe::new_vframe(&s, &temp_map, thread());
113 }
114 
115 vframe* vframe::top() const {
116   vframe* vf = (vframe*) this;
117   while (!vf->is_top()) vf = vf->sender();
118   return vf;
119 }
120 
121 
122 javaVFrame* vframe::java_sender() const {
123   vframe* f = sender();
124   while (f != NULL) {
125     if (f->is_java_frame()) return javaVFrame::cast(f);
126     f = f->sender();
127   }
128   return NULL;
129 }
130 













131 // ------------- javaVFrame --------------
132 
133 GrowableArray<MonitorInfo*>* javaVFrame::locked_monitors() {
134   assert(SafepointSynchronize::is_at_safepoint() || JavaThread::current() == thread(),
135          "must be at safepoint or it's a java frame of the current thread");
136 
137   GrowableArray<MonitorInfo*>* mons = monitors();
138   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length());
139   if (mons->is_empty()) return result;
140 
141   bool found_first_monitor = false;
142   // The ObjectMonitor* can't be async deflated since we are either
143   // at a safepoint or the calling thread is operating on itself so
144   // it cannot exit the ObjectMonitor so it remains busy.
145   ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor();
146   ObjectMonitor *pending_monitor = NULL;
147   if (waiting_monitor == NULL) {
148     pending_monitor = thread()->current_pending_monitor();
149   }
150   oop pending_obj = (pending_monitor != NULL ? pending_monitor->object() : (oop) NULL);

260           if (mark.has_monitor() &&
261               ( // we have marked ourself as pending on this monitor
262                 mark.monitor() == thread()->current_pending_monitor() ||
263                 // we are not the owner of this monitor
264                 !mark.monitor()->is_entered(thread())
265               )) {
266             lock_state = "waiting to lock";
267           }
268         }
269         print_locked_object_class_name(st, Handle(current, monitor->owner()), lock_state);
270 
271         found_first_monitor = true;
272       }
273     }
274   }
275 }
276 
277 // ------------- interpretedVFrame --------------
278 
279 u_char* interpretedVFrame::bcp() const {
280   return fr().interpreter_frame_bcp();
281 }
282 
283 void interpretedVFrame::set_bcp(u_char* bcp) {

284   fr().interpreter_frame_set_bcp(bcp);
285 }
286 
287 intptr_t* interpretedVFrame::locals_addr_at(int offset) const {

288   assert(fr().is_interpreted_frame(), "frame should be an interpreted frame");
289   return fr().interpreter_frame_local_at(offset);
290 }
291 
292 
293 GrowableArray<MonitorInfo*>* interpretedVFrame::monitors() const {
294   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(5);
295   for (BasicObjectLock* current = (fr().previous_monitor_in_interpreter_frame(fr().interpreter_frame_monitor_begin()));
296        current >= fr().interpreter_frame_monitor_end();
297        current = fr().previous_monitor_in_interpreter_frame(current)) {
298     result->push(new MonitorInfo(current->obj(), current->lock(), false, false));


299   }
300   return result;
301 }
302 
303 int interpretedVFrame::bci() const {
304   return method()->bci_from(bcp());
305 }
306 
307 Method* interpretedVFrame::method() const {
308   return fr().interpreter_frame_method();

309 }
310 
311 static StackValue* create_stack_value_from_oop_map(const InterpreterOopMap& oop_mask,
312                                                    int index,
313                                                    const intptr_t* const addr) {

314 
315   assert(index >= 0 &&
316          index < oop_mask.number_of_entries(), "invariant");
317 
318   // categorize using oop_mask
319   if (oop_mask.is_oop(index)) {








320     // reference (oop) "r"
321     Handle h(Thread::current(), addr != NULL ? (*(oop*)addr) : (oop)NULL);
322     return new StackValue(h);
323   }
324   // value (integer) "v"
325   return new StackValue(addr != NULL ? *addr : 0);
326 }
327 
328 static bool is_in_expression_stack(const frame& fr, const intptr_t* const addr) {
329   assert(addr != NULL, "invariant");
330 
331   // Ensure to be 'inside' the expresion stack (i.e., addr >= sp for Intel).
332   // In case of exceptions, the expression stack is invalid and the sp
333   // will be reset to express this condition.
334   if (frame::interpreter_frame_expression_stack_direction() > 0) {
335     return addr <= fr.interpreter_frame_tos_address();
336   }
337 
338   return addr >= fr.interpreter_frame_tos_address();
339 }
340 
341 static void stack_locals(StackValueCollection* result,
342                          int length,
343                          const InterpreterOopMap& oop_mask,
344                          const frame& fr) {

345 
346   assert(result != NULL, "invariant");
347 
348   for (int i = 0; i < length; ++i) {
349     const intptr_t* const addr = fr.interpreter_frame_local_at(i);






350     assert(addr != NULL, "invariant");
351     assert(addr >= fr.sp(), "must be inside the frame");
352 
353     StackValue* const sv = create_stack_value_from_oop_map(oop_mask, i, addr);
354     assert(sv != NULL, "sanity check");
355 
356     result->add(sv);
357   }
358 }
359 
360 static void stack_expressions(StackValueCollection* result,
361                               int length,
362                               int max_locals,
363                               const InterpreterOopMap& oop_mask,
364                               const frame& fr) {

365 
366   assert(result != NULL, "invariant");
367 
368   for (int i = 0; i < length; ++i) {
369     const intptr_t* addr = fr.interpreter_frame_expression_stack_at(i);
370     assert(addr != NULL, "invariant");
371     if (!is_in_expression_stack(fr, addr)) {
372       // Need to ensure no bogus escapes.
373       addr = NULL;





374     }
375 
376     StackValue* const sv = create_stack_value_from_oop_map(oop_mask,
377                                                            i + max_locals,
378                                                            addr);

379     assert(sv != NULL, "sanity check");
380 
381     result->add(sv);
382   }
383 }
384 
385 StackValueCollection* interpretedVFrame::locals() const {
386   return stack_data(false);
387 }
388 
389 StackValueCollection* interpretedVFrame::expressions() const {
390   return stack_data(true);
391 }
392 
393 /*
394  * Worker routine for fetching references and/or values
395  * for a particular bci in the interpretedVFrame.
396  *
397  * Returns data for either "locals" or "expressions",
398  * using bci relative oop_map (oop_mask) information.

407   method()->mask_for(bci(), &oop_mask);
408   const int mask_len = oop_mask.number_of_entries();
409 
410   // If the method is native, method()->max_locals() is not telling the truth.
411   // For our purposes, max locals instead equals the size of parameters.
412   const int max_locals = method()->is_native() ?
413     method()->size_of_parameters() : method()->max_locals();
414 
415   assert(mask_len >= max_locals, "invariant");
416 
417   const int length = expressions ? mask_len - max_locals : max_locals;
418   assert(length >= 0, "invariant");
419 
420   StackValueCollection* const result = new StackValueCollection(length);
421 
422   if (0 == length) {
423     return result;
424   }
425 
426   if (expressions) {
427     stack_expressions(result, length, max_locals, oop_mask, fr());
428   } else {
429     stack_locals(result, length, oop_mask, fr());
430   }
431 
432   assert(length == result->size(), "invariant");
433 
434   return result;
435 }
436 
437 void interpretedVFrame::set_locals(StackValueCollection* values) const {
438   if (values == NULL || values->size() == 0) return;
439 
440   // If the method is native, max_locals is not telling the truth.
441   // maxlocals then equals the size of parameters
442   const int max_locals = method()->is_native() ?
443     method()->size_of_parameters() : method()->max_locals();
444 
445   assert(max_locals == values->size(), "Mismatch between actual stack format and supplied data");
446 
447   // handle locals
448   for (int i = 0; i < max_locals; i++) {
449     // Find stack location

475     _owner = Handle();
476     _owner_klass = Handle(thread, owner);
477   }
478   _lock = lock;
479   _eliminated = eliminated;
480   _owner_is_scalar_replaced = owner_is_scalar_replaced;
481 }
482 
483 #ifdef ASSERT
484 void vframeStreamCommon::found_bad_method_frame() const {
485   // 6379830 Cut point for an assertion that occasionally fires when
486   // we are using the performance analyzer.
487   // Disable this assert when testing the analyzer with fastdebug.
488   // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number)
489   fatal("invalid bci or invalid scope desc");
490 }
491 #endif
492 
493 // top-frame will be skipped
494 vframeStream::vframeStream(JavaThread* thread, frame top_frame,
495                            bool stop_at_java_call_stub) :
496     vframeStreamCommon(thread, true /* process_frames */) {
497   _stop_at_java_call_stub = stop_at_java_call_stub;
498 
499   // skip top frame, as it may not be at safepoint
500   _prev_frame = top_frame;
501   _frame  = top_frame.sender(&_reg_map);
502   while (!fill_from_frame()) {
503     _prev_frame = _frame;







































504     _frame = _frame.sender(&_reg_map);
505   }
506 }
507 
508 
509 // Step back n frames, skip any pseudo frames in between.
510 // This function is used in Class.forName, Class.newInstance, Method.Invoke,
511 // AccessController.doPrivileged.
512 void vframeStreamCommon::security_get_caller_frame(int depth) {
513   assert(depth >= 0, "invalid depth: %d", depth);
514   for (int n = 0; !at_end(); security_next()) {
515     if (!method()->is_ignored_by_security_stack_walk()) {
516       if (n == depth) {
517         // We have reached the desired depth; return.
518         return;
519       }
520       n++;  // this is a non-skipped frame; count it against the depth
521     }
522   }
523   // NOTE: At this point there were not enough frames on the stack

556       break; // prefixed name isn't prefixed version of method name, can't be a wrapper
557     }
558     for (; prefix_index >= 0; --prefix_index) {
559       const char* possible_prefix = method_prefixes[prefix_index];
560       size_t possible_prefix_len = strlen(possible_prefix);
561       if (possible_prefix_len == prefix_len &&
562           strncmp(possible_prefix, prefixed_name, prefix_len) == 0) {
563         break; // matching prefix found
564       }
565     }
566     if (prefix_index < 0) {
567       break; // didn't find the prefix, can't be a wrapper
568     }
569     prefixed_name = name;
570     prefixed_name_len = name_len;
571   }
572 }
573 
574 javaVFrame* vframeStreamCommon::asJavaVFrame() {
575   javaVFrame* result = NULL;
576   if (_mode == compiled_mode) {
577     compiledVFrame* cvf;
578     if (_frame.is_native_frame()) {
579       cvf = compiledVFrame::cast(vframe::new_vframe(&_frame, &_reg_map, _thread));
580       assert(cvf->cb() == cb(), "wrong code blob");
581     } else {
582       assert(_frame.is_compiled_frame(), "expected compiled Java frame");
583 
584       // lazy update to register map
585       bool update_map = true;
586       RegisterMap map(_thread, update_map);
587       frame f = _prev_frame.sender(&map);
588 
589       assert(f.is_compiled_frame(), "expected compiled Java frame");
590 
591       cvf = compiledVFrame::cast(vframe::new_vframe(&f, &map, _thread));
592 
593       assert(cvf->cb() == cb(), "wrong code blob");
594 
595       // get the same scope as this stream
596       cvf = cvf->at_scope(_decode_offset, _vframe_id);
597 
598       assert(cvf->scope()->decode_offset() == _decode_offset, "wrong scope");
599       assert(cvf->scope()->sender_decode_offset() == _sender_decode_offset, "wrong scope");
600     }
601     assert(cvf->vframe_id() == _vframe_id, "wrong vframe");
602 
603     result = cvf;
604   } else {
605     result = javaVFrame::cast(vframe::new_vframe(&_frame, &_reg_map, _thread));
606   }
607   assert(result->method() == method(), "wrong method");
608   return result;
609 }
610 
611 
612 #ifndef PRODUCT
613 void vframe::print() {
614   if (WizardMode) _fr.print_value_on(tty,NULL);
615 }
616 
617 
618 void vframe::print_value() const {
619   ((vframe*)this)->print();
620 }
621 

686 
687 void javaVFrame::print_value() const {
688   Method*    m = method();
689   InstanceKlass*     k = m->method_holder();
690   tty->print_cr("frame( sp=" INTPTR_FORMAT ", unextended_sp=" INTPTR_FORMAT ", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT ")",
691                 p2i(_fr.sp()),  p2i(_fr.unextended_sp()), p2i(_fr.fp()), p2i(_fr.pc()));
692   tty->print("%s.%s", k->internal_name(), m->name()->as_C_string());
693 
694   if (!m->is_native()) {
695     Symbol*  source_name = k->source_file_name();
696     int        line_number = m->line_number_from_bci(bci());
697     if (source_name != NULL && (line_number != -1)) {
698       tty->print("(%s:%d)", source_name->as_C_string(), line_number);
699     }
700   } else {
701     tty->print("(Native Method)");
702   }
703   // Check frame size and print warning if it looks suspiciously large
704   if (fr().sp() != NULL) {
705     RegisterMap map = *register_map();
706     uint size = fr().frame_size(&map);
707 #ifdef _LP64
708     if (size > 8*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size);
709 #else
710     if (size > 4*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size);
711 #endif
712   }
713 }
714 
715 
716 bool javaVFrame::structural_compare(javaVFrame* other) {
717   // Check static part
718   if (method() != other->method()) return false;
719   if (bci()    != other->bci())    return false;
720 
721   // Check locals
722   StackValueCollection *locs = locals();
723   StackValueCollection *other_locs = other->locals();
724   assert(locs->size() == other_locs->size(), "sanity check");
725   int i;
726   for(i = 0; i < locs->size(); i++) {

  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 "oops/stackChunkOop.hpp"
 26 #include "precompiled.hpp"
 27 #include "classfile/javaClasses.inline.hpp"
 28 #include "classfile/javaThreadStatus.hpp"
 29 #include "classfile/vmClasses.hpp"
 30 #include "classfile/vmSymbols.hpp"
 31 #include "code/codeCache.hpp"
 32 #include "code/debugInfoRec.hpp"
 33 #include "code/nmethod.hpp"
 34 #include "code/pcDesc.hpp"
 35 #include "code/scopeDesc.hpp"
 36 #include "interpreter/interpreter.hpp"
 37 #include "interpreter/oopMapCache.hpp"
 38 #include "memory/resourceArea.hpp"
 39 #include "oops/instanceKlass.hpp"
 40 #include "oops/oop.inline.hpp"
 41 #include "prims/jvmtiExport.hpp"
 42 #include "runtime/frame.inline.hpp"
 43 #include "runtime/globals.hpp"
 44 #include "runtime/handles.inline.hpp"
 45 #include "runtime/objectMonitor.hpp"
 46 #include "runtime/objectMonitor.inline.hpp"
 47 #include "runtime/osThread.hpp"
 48 #include "runtime/signature.hpp"
 49 #include "runtime/stackFrameStream.inline.hpp"
 50 #include "runtime/stubRoutines.hpp"
 51 #include "runtime/synchronizer.hpp"
 52 #include "runtime/thread.inline.hpp"
 53 #include "runtime/vframe.inline.hpp"
 54 #include "runtime/vframeArray.hpp"
 55 #include "runtime/vframe_hp.hpp"
 56 
 57 vframe::vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread)
 58 : _reg_map(reg_map), _thread(thread), 
 59   _chunk(Thread::current(), reg_map->stack_chunk()(), reg_map->stack_chunk().not_null()) {
 60   assert(fr != NULL, "must have frame");
 61   _fr = *fr;
 62 }
 63 
 64 vframe::vframe(const frame* fr, JavaThread* thread)
 65 : _reg_map(thread), _thread(thread), _chunk() {
 66   assert(fr != NULL, "must have frame");
 67   _fr = *fr;
 68   assert (!_reg_map.in_cont(), "");
 69 }
 70 
 71 vframe* vframe::new_vframe(StackFrameStream& fst, JavaThread* thread) {
 72   if (fst.current()->is_runtime_frame()) {
 73     fst.next();
 74   }
 75   guarantee(!fst.is_done(), "missing caller");
 76   return new_vframe(fst.current(), fst.register_map(), thread);
 77 }
 78 
 79 vframe* vframe::new_vframe(const frame* f, const RegisterMap* reg_map, JavaThread* thread) {
 80   // Interpreter frame
 81   if (f->is_interpreted_frame()) {
 82     return new interpretedVFrame(f, reg_map, thread);
 83   }
 84 
 85   // Compiled frame
 86   CodeBlob* cb = f->cb();
 87   if (cb != NULL) {
 88     if (cb->is_compiled()) {

 93     if (f->is_runtime_frame()) {
 94       // Skip this frame and try again.
 95       RegisterMap temp_map = *reg_map;
 96       frame s = f->sender(&temp_map);
 97       return new_vframe(&s, &temp_map, thread);
 98     }
 99   }
100 
101   // Entry frame
102   if (f->is_entry_frame()) {
103     return new entryVFrame(f, reg_map, thread);
104   }
105 
106   // External frame
107   return new externalVFrame(f, reg_map, thread);
108 }
109 
110 vframe* vframe::sender() const {
111   RegisterMap temp_map = *register_map();
112   assert(is_top(), "just checking");
113   if (_fr.is_empty()) return NULL;
114   if (_fr.is_entry_frame() && _fr.is_first_frame()) return NULL;
115   frame s = _fr.real_sender(&temp_map);
116   if (s.is_first_frame()) return NULL;
117   if (Continuation::is_continuation_enterSpecial(s)) {
118     if (Continuation::continuation_scope(Continuation::get_continuation_for_frame(temp_map.thread(), _fr)) == java_lang_VirtualThread::vthread_scope())
119       return NULL;
120   }
121   return vframe::new_vframe(&s, &temp_map, thread());
122 }
123 
124 vframe* vframe::top() const {
125   vframe* vf = (vframe*) this;
126   while (!vf->is_top()) vf = vf->sender();
127   return vf;
128 }
129 
130 
131 javaVFrame* vframe::java_sender() const {
132   vframe* f = sender();
133   while (f != NULL) {
134     if (f->is_java_frame() && !javaVFrame::cast(f)->method()->is_continuation_enter_intrinsic()) return javaVFrame::cast(f);
135     f = f->sender();
136   }
137   return NULL;
138 }
139 
140 extern "C" bool dbg_is_safe(const void* p, intptr_t errvalue);
141 
142 void vframe::restore_register_map() const {
143   assert (this != NULL, "");
144   assert (dbg_is_safe(this, -1), "");
145   assert (register_map() != NULL, "");
146   assert (dbg_is_safe(register_map(), -1), "");
147 
148   if (_reg_map.stack_chunk()() != stack_chunk()) {
149     const_cast<vframe*>(this)->_reg_map.set_stack_chunk(stack_chunk());
150   }
151 }
152 
153 // ------------- javaVFrame --------------
154 
155 GrowableArray<MonitorInfo*>* javaVFrame::locked_monitors() {
156   assert(SafepointSynchronize::is_at_safepoint() || JavaThread::current() == thread(),
157          "must be at safepoint or it's a java frame of the current thread");
158 
159   GrowableArray<MonitorInfo*>* mons = monitors();
160   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length());
161   if (mons->is_empty()) return result;
162 
163   bool found_first_monitor = false;
164   // The ObjectMonitor* can't be async deflated since we are either
165   // at a safepoint or the calling thread is operating on itself so
166   // it cannot exit the ObjectMonitor so it remains busy.
167   ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor();
168   ObjectMonitor *pending_monitor = NULL;
169   if (waiting_monitor == NULL) {
170     pending_monitor = thread()->current_pending_monitor();
171   }
172   oop pending_obj = (pending_monitor != NULL ? pending_monitor->object() : (oop) NULL);

282           if (mark.has_monitor() &&
283               ( // we have marked ourself as pending on this monitor
284                 mark.monitor() == thread()->current_pending_monitor() ||
285                 // we are not the owner of this monitor
286                 !mark.monitor()->is_entered(thread())
287               )) {
288             lock_state = "waiting to lock";
289           }
290         }
291         print_locked_object_class_name(st, Handle(current, monitor->owner()), lock_state);
292 
293         found_first_monitor = true;
294       }
295     }
296   }
297 }
298 
299 // ------------- interpretedVFrame --------------
300 
301 u_char* interpretedVFrame::bcp() const {
302   return stack_chunk() == NULL ? fr().interpreter_frame_bcp() : stack_chunk()->interpreter_frame_bcp(fr());
303 }
304 
305 void interpretedVFrame::set_bcp(u_char* bcp) {
306   assert (stack_chunk() == NULL, ""); // unsupported for now because seems to be unused
307   fr().interpreter_frame_set_bcp(bcp);
308 }
309 
310 intptr_t* interpretedVFrame::locals_addr_at(int offset) const {
311   assert (stack_chunk() == NULL, ""); // unsupported for now because seems to be unused
312   assert(fr().is_interpreted_frame(), "frame should be an interpreted frame");
313   return fr().interpreter_frame_local_at(offset);
314 }
315 
316 
317 GrowableArray<MonitorInfo*>* interpretedVFrame::monitors() const {
318   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(5);
319   if (stack_chunk() == NULL) { // no monitors in continuations
320     for (BasicObjectLock* current = (fr().previous_monitor_in_interpreter_frame(fr().interpreter_frame_monitor_begin()));
321         current >= fr().interpreter_frame_monitor_end();
322         current = fr().previous_monitor_in_interpreter_frame(current)) {
323       result->push(new MonitorInfo(current->obj(), current->lock(), false, false));
324     }
325   }
326   return result;
327 }
328 
329 int interpretedVFrame::bci() const {
330   return method()->bci_from(bcp());
331 }
332 
333 Method* interpretedVFrame::method() const {
334   // assert ((stack_chunk() != NULL) == register_map()->in_cont(), "_in_cont: %d register_map()->in_cont(): %d", stack_chunk() != NULL, register_map()->in_cont());
335   return stack_chunk() == NULL ? fr().interpreter_frame_method() : stack_chunk()->interpreter_frame_method(fr());
336 }
337 
338 static StackValue* create_stack_value_from_oop_map(const InterpreterOopMap& oop_mask,
339                                                    int index,
340                                                    const intptr_t* const addr,
341                                                    stackChunkOop chunk) {
342 
343   assert(index >= 0 &&
344          index < oop_mask.number_of_entries(), "invariant");
345 
346   // categorize using oop_mask
347   if (oop_mask.is_oop(index)) {
348     oop obj = NULL;
349     if (addr != NULL) {
350       if (chunk != NULL) {
351         obj = (chunk->has_bitmap() && UseCompressedOops) ? (oop)HeapAccess<>::oop_load((narrowOop*)addr) : HeapAccess<>::oop_load((oop*)addr);
352       } else {
353         obj = *(oop*)addr;
354       }
355     }
356     // reference (oop) "r"
357     Handle h(Thread::current(), obj);
358     return new StackValue(h);
359   }
360   // value (integer) "v"
361   return new StackValue(addr != NULL ? *addr : 0);
362 }
363 
364 static bool is_in_expression_stack(const frame& fr, const intptr_t* const addr) {
365   assert(addr != NULL, "invariant");
366 
367   // Ensure to be 'inside' the expresion stack (i.e., addr >= sp for Intel).
368   // In case of exceptions, the expression stack is invalid and the sp
369   // will be reset to express this condition.
370   if (frame::interpreter_frame_expression_stack_direction() > 0) {
371     return addr <= fr.interpreter_frame_tos_address();
372   }
373 
374   return addr >= fr.interpreter_frame_tos_address();
375 }
376 
377 static void stack_locals(StackValueCollection* result,
378                          int length,
379                          const InterpreterOopMap& oop_mask,
380                          const frame& fr,
381                          const stackChunkOop chunk) {
382 
383   assert(result != NULL, "invariant");
384 
385   for (int i = 0; i < length; ++i) {
386     const intptr_t* addr;
387     if (chunk == NULL) {
388       addr = fr.interpreter_frame_local_at(i);
389       assert(addr >= fr.sp(), "must be inside the frame");
390     } else {
391       addr = chunk->interpreter_frame_local_at(fr, i);
392     }
393     assert(addr != NULL, "invariant");

394 
395     StackValue* const sv = create_stack_value_from_oop_map(oop_mask, i, addr, chunk);
396     assert(sv != NULL, "sanity check");
397 
398     result->add(sv);
399   }
400 }
401 
402 static void stack_expressions(StackValueCollection* result,
403                               int length,
404                               int max_locals,
405                               const InterpreterOopMap& oop_mask,
406                               const frame& fr,
407                               const stackChunkOop chunk) {
408 
409   assert(result != NULL, "invariant");
410 
411   for (int i = 0; i < length; ++i) {
412     const intptr_t* addr;
413     if (chunk == NULL) {
414       addr = fr.interpreter_frame_expression_stack_at(i);
415       assert(addr != NULL, "invariant");
416       if (!is_in_expression_stack(fr, addr)) {
417         // Need to ensure no bogus escapes.
418         addr = NULL;
419       }
420     } else {
421       addr = chunk->interpreter_frame_expression_stack_at(fr, i);
422     }
423 
424     StackValue* const sv = create_stack_value_from_oop_map(oop_mask,
425                                                            i + max_locals,
426                                                            addr,
427                                                            chunk);
428     assert(sv != NULL, "sanity check");
429 
430     result->add(sv);
431   }
432 }
433 
434 StackValueCollection* interpretedVFrame::locals() const {
435   return stack_data(false);
436 }
437 
438 StackValueCollection* interpretedVFrame::expressions() const {
439   return stack_data(true);
440 }
441 
442 /*
443  * Worker routine for fetching references and/or values
444  * for a particular bci in the interpretedVFrame.
445  *
446  * Returns data for either "locals" or "expressions",
447  * using bci relative oop_map (oop_mask) information.

456   method()->mask_for(bci(), &oop_mask);
457   const int mask_len = oop_mask.number_of_entries();
458 
459   // If the method is native, method()->max_locals() is not telling the truth.
460   // For our purposes, max locals instead equals the size of parameters.
461   const int max_locals = method()->is_native() ?
462     method()->size_of_parameters() : method()->max_locals();
463 
464   assert(mask_len >= max_locals, "invariant");
465 
466   const int length = expressions ? mask_len - max_locals : max_locals;
467   assert(length >= 0, "invariant");
468 
469   StackValueCollection* const result = new StackValueCollection(length);
470 
471   if (0 == length) {
472     return result;
473   }
474 
475   if (expressions) {
476     stack_expressions(result, length, max_locals, oop_mask, fr(), stack_chunk());
477   } else {
478     stack_locals(result, length, oop_mask, fr(), stack_chunk());
479   }
480 
481   assert(length == result->size(), "invariant");
482 
483   return result;
484 }
485 
486 void interpretedVFrame::set_locals(StackValueCollection* values) const {
487   if (values == NULL || values->size() == 0) return;
488 
489   // If the method is native, max_locals is not telling the truth.
490   // maxlocals then equals the size of parameters
491   const int max_locals = method()->is_native() ?
492     method()->size_of_parameters() : method()->max_locals();
493 
494   assert(max_locals == values->size(), "Mismatch between actual stack format and supplied data");
495 
496   // handle locals
497   for (int i = 0; i < max_locals; i++) {
498     // Find stack location

524     _owner = Handle();
525     _owner_klass = Handle(thread, owner);
526   }
527   _lock = lock;
528   _eliminated = eliminated;
529   _owner_is_scalar_replaced = owner_is_scalar_replaced;
530 }
531 
532 #ifdef ASSERT
533 void vframeStreamCommon::found_bad_method_frame() const {
534   // 6379830 Cut point for an assertion that occasionally fires when
535   // we are using the performance analyzer.
536   // Disable this assert when testing the analyzer with fastdebug.
537   // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number)
538   fatal("invalid bci or invalid scope desc");
539 }
540 #endif
541 
542 // top-frame will be skipped
543 vframeStream::vframeStream(JavaThread* thread, frame top_frame,
544                           bool stop_at_java_call_stub) : 
545     vframeStreamCommon(RegisterMap(thread, true, true, true)) {
546   _stop_at_java_call_stub = stop_at_java_call_stub;
547 
548   // skip top frame, as it may not be at safepoint

549   _frame  = top_frame.sender(&_reg_map);
550   while (!fill_from_frame()) {
551     _frame = _frame.sender(&_reg_map);
552   }
553 }
554 
555 vframeStream::vframeStream(JavaThread* thread, Handle continuation_scope, bool stop_at_java_call_stub) 
556  : vframeStreamCommon(RegisterMap(thread, true, true, true)) {
557 
558   _stop_at_java_call_stub = stop_at_java_call_stub;
559   _continuation_scope = continuation_scope;
560   
561   if (!thread->has_last_Java_frame()) {
562     _mode = at_end_mode;
563     return;
564   }
565 
566   _frame = _thread->last_frame();
567   _cont = _thread->last_continuation();
568   while (!fill_from_frame()) {
569     if (Continuation::is_continuation_enterSpecial(_frame)) {
570       assert (_cont != NULL, "");
571       _cont = _cont->parent();
572     }
573     _frame = _frame.sender(&_reg_map);
574   }
575 }
576 
577 vframeStream::vframeStream(oop continuation, Handle continuation_scope) 
578  : vframeStreamCommon(RegisterMap(continuation, true)) {
579 
580   _stop_at_java_call_stub = false;
581   _continuation_scope = continuation_scope;
582   
583   if (!Continuation::has_last_Java_frame(continuation)) {
584     _mode = at_end_mode;
585     return;
586   }
587 
588   _frame = Continuation::last_frame(continuation, &_reg_map);
589   // _chunk = _reg_map.stack_chunk();
590   while (!fill_from_frame()) {
591     _frame = _frame.sender(&_reg_map);
592   }
593 }
594 
595 
596 // Step back n frames, skip any pseudo frames in between.
597 // This function is used in Class.forName, Class.newInstance, Method.Invoke,
598 // AccessController.doPrivileged.
599 void vframeStreamCommon::security_get_caller_frame(int depth) {
600   assert(depth >= 0, "invalid depth: %d", depth);
601   for (int n = 0; !at_end(); security_next()) {
602     if (!method()->is_ignored_by_security_stack_walk()) {
603       if (n == depth) {
604         // We have reached the desired depth; return.
605         return;
606       }
607       n++;  // this is a non-skipped frame; count it against the depth
608     }
609   }
610   // NOTE: At this point there were not enough frames on the stack

643       break; // prefixed name isn't prefixed version of method name, can't be a wrapper
644     }
645     for (; prefix_index >= 0; --prefix_index) {
646       const char* possible_prefix = method_prefixes[prefix_index];
647       size_t possible_prefix_len = strlen(possible_prefix);
648       if (possible_prefix_len == prefix_len &&
649           strncmp(possible_prefix, prefixed_name, prefix_len) == 0) {
650         break; // matching prefix found
651       }
652     }
653     if (prefix_index < 0) {
654       break; // didn't find the prefix, can't be a wrapper
655     }
656     prefixed_name = name;
657     prefixed_name_len = name_len;
658   }
659 }
660 
661 javaVFrame* vframeStreamCommon::asJavaVFrame() {
662   javaVFrame* result = NULL;
663   // FIXME, need to re-do JDK-8271140 and check is_native_frame?
664   if (_mode == compiled_mode && _frame.is_compiled_frame()) {
665     assert(_frame.is_compiled_frame() || _frame.is_native_frame(), "expected compiled Java frame");
666     guarantee(_reg_map.update_map(), "");








667 
668     compiledVFrame* cvf = compiledVFrame::cast(vframe::new_vframe(&_frame, &_reg_map, _thread));
669 
670     guarantee(cvf->cb() == cb(), "wrong code blob");
671 
672     cvf = cvf->at_scope(_decode_offset, _vframe_id); // get the same scope as this stream
673 
674     guarantee(cvf->scope()->decode_offset() == _decode_offset, "wrong scope");
675     guarantee(cvf->scope()->sender_decode_offset() == _sender_decode_offset, "wrong scope");
676     guarantee(cvf->vframe_id() == _vframe_id, "wrong vframe");




677 
678     result = cvf;
679   } else {
680     result = javaVFrame::cast(vframe::new_vframe(&_frame, &_reg_map, _thread));
681   }
682   assert(result->method() == method(), "wrong method");
683   return result;
684 }
685 
686 
687 #ifndef PRODUCT
688 void vframe::print() {
689   if (WizardMode) _fr.print_value_on(tty,NULL);
690 }
691 
692 
693 void vframe::print_value() const {
694   ((vframe*)this)->print();
695 }
696 

761 
762 void javaVFrame::print_value() const {
763   Method*    m = method();
764   InstanceKlass*     k = m->method_holder();
765   tty->print_cr("frame( sp=" INTPTR_FORMAT ", unextended_sp=" INTPTR_FORMAT ", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT ")",
766                 p2i(_fr.sp()),  p2i(_fr.unextended_sp()), p2i(_fr.fp()), p2i(_fr.pc()));
767   tty->print("%s.%s", k->internal_name(), m->name()->as_C_string());
768 
769   if (!m->is_native()) {
770     Symbol*  source_name = k->source_file_name();
771     int        line_number = m->line_number_from_bci(bci());
772     if (source_name != NULL && (line_number != -1)) {
773       tty->print("(%s:%d)", source_name->as_C_string(), line_number);
774     }
775   } else {
776     tty->print("(Native Method)");
777   }
778   // Check frame size and print warning if it looks suspiciously large
779   if (fr().sp() != NULL) {
780     RegisterMap map = *register_map();
781     uint size = fr().frame_size();
782 #ifdef _LP64
783     if (size > 8*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size);
784 #else
785     if (size > 4*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size);
786 #endif
787   }
788 }
789 
790 
791 bool javaVFrame::structural_compare(javaVFrame* other) {
792   // Check static part
793   if (method() != other->method()) return false;
794   if (bci()    != other->bci())    return false;
795 
796   // Check locals
797   StackValueCollection *locs = locals();
798   StackValueCollection *other_locs = other->locals();
799   assert(locs->size() == other_locs->size(), "sanity check");
800   int i;
801   for(i = 0; i < locs->size(); i++) {
< prev index next >