< prev index next >

src/hotspot/share/prims/stackwalk.cpp

roman_version

30 #include "memory/oopFactory.hpp"                                                                                                     
31 #include "oops/oop.inline.hpp"                                                                                                       
32 #include "oops/objArrayOop.inline.hpp"                                                                                               
33 #include "prims/stackwalk.hpp"                                                                                                       
34 #include "runtime/globals.hpp"                                                                                                       
35 #include "runtime/handles.inline.hpp"                                                                                                
36 #include "runtime/javaCalls.hpp"                                                                                                     
37 #include "runtime/vframe.inline.hpp"                                                                                                 
38 #include "utilities/globalDefinitions.hpp"                                                                                           
39 
40 // setup and cleanup actions                                                                                                         
41 void BaseFrameStream::setup_magic_on_entry(objArrayHandle frames_array) {                                                            
42   frames_array->obj_at_put(magic_pos, _thread->threadObj());                                                                         
43   _anchor = address_value();                                                                                                         
44   assert(check_magic(frames_array), "invalid magic");                                                                                
45 }                                                                                                                                    
46 
47 bool BaseFrameStream::check_magic(objArrayHandle frames_array) {                                                                     
48   oop   m1 = frames_array->obj_at(magic_pos);                                                                                        
49   jlong m2 = _anchor;                                                                                                                
50   if (m1 == _thread->threadObj() && m2 == address_value())  return true;                                                             
51   return false;                                                                                                                      
52 }                                                                                                                                    
53 
54 bool BaseFrameStream::cleanup_magic_on_exit(objArrayHandle frames_array) {                                                           
55   bool ok = check_magic(frames_array);                                                                                               
56   frames_array->obj_at_put(magic_pos, NULL);                                                                                         
57   _anchor = 0L;                                                                                                                      
58   return ok;                                                                                                                         
59 }                                                                                                                                    
60 
61 JavaFrameStream::JavaFrameStream(JavaThread* thread, int mode)                                                                       
62   : BaseFrameStream(thread), _vfst(thread) {                                                                                         
63   _need_method_info = StackWalk::need_method_info(mode);                                                                             
64 }                                                                                                                                    
65 
66 void JavaFrameStream::next() { _vfst.next();}                                                                                        
67 
68 // Returns the BaseFrameStream for the current stack being traversed.                                                                
69 //                                                                                                                                   
70 // Parameters:                                                                                                                       
71 //  thread         Current Java thread.                                                                                              
72 //  magic          Magic value used for each stack walking                                                                           
73 //  frames_array   User-supplied buffers.  The 0th element is reserved                                                               
74 //                 for this BaseFrameStream to use                                                                                   
75 //                                                                                                                                   
76 BaseFrameStream* BaseFrameStream::from_current(JavaThread* thread, jlong magic,                                                      
77                                                objArrayHandle frames_array)                                                          
78 {                                                                                                                                    
79   assert(thread != NULL && thread->is_Java_thread(), "");                                                                            
80   oop m1 = frames_array->obj_at(magic_pos);                                                                                          
81   if (m1 != thread->threadObj())      return NULL;                                                                                   
82   if (magic == 0L)                    return NULL;                                                                                   
83   BaseFrameStream* stream = (BaseFrameStream*) (intptr_t) magic;                                                                     
84   if (!stream->is_valid_in(thread, frames_array))   return NULL;                                                                     
85   return stream;                                                                                                                     
86 }                                                                                                                                    
87 
88 // Unpacks one or more frames into user-supplied buffers.                                                                            
89 // Updates the end index, and returns the number of unpacked frames.                                                                 
90 // Always start with the existing vfst.method and bci.                                                                               
91 // Do not call vfst.next to advance over the last returned value.                                                                    
92 // In other words, do not leave any stale data in the vfst.                                                                          
93 //                                                                                                                                   
94 // Parameters:                                                                                                                       
95 //   mode             Restrict which frames to be decoded.                                                                           
96 //   BaseFrameStream  stream of frames                                                                                               
97 //   max_nframes      Maximum number of frames to be filled.                                                                         
98 //   start_index      Start index to the user-supplied buffers.                                                                      
99 //   frames_array     Buffer to store Class or StackFrame in, starting at start_index.                                               
100 //                    frames array is a Class<?>[] array when only getting caller                                                    

30 #include "memory/oopFactory.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "oops/objArrayOop.inline.hpp"
33 #include "prims/stackwalk.hpp"
34 #include "runtime/globals.hpp"
35 #include "runtime/handles.inline.hpp"
36 #include "runtime/javaCalls.hpp"
37 #include "runtime/vframe.inline.hpp"
38 #include "utilities/globalDefinitions.hpp"
39 
40 // setup and cleanup actions
41 void BaseFrameStream::setup_magic_on_entry(objArrayHandle frames_array) {
42   frames_array->obj_at_put(magic_pos, _thread->threadObj());
43   _anchor = address_value();
44   assert(check_magic(frames_array), "invalid magic");
45 }
46 
47 bool BaseFrameStream::check_magic(objArrayHandle frames_array) {
48   oop   m1 = frames_array->obj_at(magic_pos);
49   jlong m2 = _anchor;
50   if (oopDesc::equals(m1, _thread->threadObj()) && m2 == address_value())  return true;
51   return false;
52 }
53 
54 bool BaseFrameStream::cleanup_magic_on_exit(objArrayHandle frames_array) {
55   bool ok = check_magic(frames_array);
56   frames_array->obj_at_put(magic_pos, NULL);
57   _anchor = 0L;
58   return ok;
59 }
60 
61 JavaFrameStream::JavaFrameStream(JavaThread* thread, int mode)
62   : BaseFrameStream(thread), _vfst(thread) {
63   _need_method_info = StackWalk::need_method_info(mode);
64 }
65 
66 void JavaFrameStream::next() { _vfst.next();}
67 
68 // Returns the BaseFrameStream for the current stack being traversed.
69 //
70 // Parameters:
71 //  thread         Current Java thread.
72 //  magic          Magic value used for each stack walking
73 //  frames_array   User-supplied buffers.  The 0th element is reserved
74 //                 for this BaseFrameStream to use
75 //
76 BaseFrameStream* BaseFrameStream::from_current(JavaThread* thread, jlong magic,
77                                                objArrayHandle frames_array)
78 {
79   assert(thread != NULL && thread->is_Java_thread(), "");
80   oop m1 = frames_array->obj_at(magic_pos);
81   if (!oopDesc::equals(m1, thread->threadObj())) return NULL;
82   if (magic == 0L)                    return NULL;
83   BaseFrameStream* stream = (BaseFrameStream*) (intptr_t) magic;
84   if (!stream->is_valid_in(thread, frames_array))   return NULL;
85   return stream;
86 }
87 
88 // Unpacks one or more frames into user-supplied buffers.
89 // Updates the end index, and returns the number of unpacked frames.
90 // Always start with the existing vfst.method and bci.
91 // Do not call vfst.next to advance over the last returned value.
92 // In other words, do not leave any stale data in the vfst.
93 //
94 // Parameters:
95 //   mode             Restrict which frames to be decoded.
96 //   BaseFrameStream  stream of frames
97 //   max_nframes      Maximum number of frames to be filled.
98 //   start_index      Start index to the user-supplied buffers.
99 //   frames_array     Buffer to store Class or StackFrame in, starting at start_index.
100 //                    frames array is a Class<?>[] array when only getting caller
< prev index next >