< prev index next >

src/hotspot/share/prims/stackwalk.hpp

Print this page

 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 
 26 #ifndef SHARE_PRIMS_STACKWALK_HPP
 27 #define SHARE_PRIMS_STACKWALK_HPP
 28 
 29 #include "jvm.h"
 30 #include "oops/oop.hpp"

 31 #include "runtime/vframe.hpp"
 32 
 33 // BaseFrameStream is an abstract base class for encapsulating the VM-side
 34 // implementation of the StackWalker API.  There are two concrete subclasses:
 35 // - JavaFrameStream:
 36 //     -based on vframeStream; used in most instances
 37 // - LiveFrameStream:
 38 //     -based on javaVFrame; used for retrieving locals/monitors/operands for
 39 //      LiveStackFrame
 40 class BaseFrameStream : public StackObj {
 41 private:
 42   enum {
 43     magic_pos = 0
 44   };
 45 
 46   JavaThread*           _thread;

 47   jlong                 _anchor;

 48 protected:
 49   void fill_stackframe(Handle stackFrame, const methodHandle& method, TRAPS);
 50 public:
 51   BaseFrameStream(JavaThread* thread) : _thread(thread), _anchor(0L) {}
 52 
 53   virtual void    next()=0;
 54   virtual bool    at_end()=0;
 55 
 56   virtual Method* method()=0;
 57   virtual int     bci()=0;



 58 
 59   virtual void    fill_frame(int index, objArrayHandle  frames_array,
 60                              const methodHandle& method, TRAPS)=0;



 61 
 62   void setup_magic_on_entry(objArrayHandle frames_array);
 63   bool check_magic(objArrayHandle frames_array);
 64   bool cleanup_magic_on_exit(objArrayHandle frames_array);
 65 
 66   bool is_valid_in(Thread* thread, objArrayHandle frames_array) {
 67     return (_thread == thread && check_magic(frames_array));
 68   }
 69 
 70   jlong address_value() {
 71     return (jlong) castable_address(this);
 72   }
 73 
 74   static BaseFrameStream* from_current(JavaThread* thread, jlong magic, objArrayHandle frames_array);
 75 };
 76 
 77 class JavaFrameStream : public BaseFrameStream {
 78 private:
 79   vframeStream          _vfst;
 80   bool                  _need_method_info;

 81 public:
 82   JavaFrameStream(JavaThread* thread, int mode);


 83 
 84   void next();
 85   bool at_end()    { return _vfst.at_end(); }
 86 
 87   Method* method() { return _vfst.method(); }
 88   int bci()        { return _vfst.bci(); }

 89 
 90   void fill_frame(int index, objArrayHandle  frames_array,
 91                   const methodHandle& method, TRAPS);
 92 };
 93 
 94 class LiveFrameStream : public BaseFrameStream {
 95 private:
 96   enum {
 97     MODE_INTERPRETED = 0x01,
 98     MODE_COMPILED    = 0x02
 99   };
100 
101   javaVFrame*           _jvf;




102 
103   void fill_live_stackframe(Handle stackFrame, const methodHandle& method, TRAPS);
104   static oop create_primitive_slot_instance(StackValueCollection* values,
105                                             int i, BasicType type, TRAPS);
106   static objArrayHandle monitors_to_object_array(GrowableArray<MonitorInfo*>* monitors,
107                                                  TRAPS);
108   static objArrayHandle values_to_object_array(StackValueCollection* values, TRAPS);
109 public:
110   LiveFrameStream(JavaThread* thread, RegisterMap* rm) : BaseFrameStream(thread) {
111     _jvf = thread->last_java_vframe(rm);
112   }
113 
114   void next()      { _jvf = _jvf->java_sender(); }
115   bool at_end()    { return _jvf == NULL; }
116 
117   Method* method() { return _jvf->method(); }
118   int bci()        { return _jvf->bci(); }




119 
120   void fill_frame(int index, objArrayHandle  frames_array,
121                   const methodHandle& method, TRAPS);
122 };
123 
124 class StackWalk : public AllStatic {
125 private:
126   static int fill_in_frames(jlong mode, BaseFrameStream& stream,
127                             int max_nframes, int start_index,
128                             objArrayHandle frames_array,
129                             int& end_index, TRAPS);
130 
131   static inline bool get_caller_class(int mode) {
132     return (mode & JVM_STACKWALK_GET_CALLER_CLASS) != 0;
133   }
134   static inline bool skip_hidden_frames(int mode) {
135     return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0;
136   }
137   static inline bool live_frame_info(int mode) {
138     return (mode & JVM_STACKWALK_FILL_LIVE_STACK_FRAMES) != 0;
139   }
140 
141 public:
142   static inline bool need_method_info(int mode) {
143     return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
144   }
145   static inline bool use_frames_array(int mode) {
146     return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
147   }
148   static oop walk(Handle stackStream, jlong mode,
149                   int skip_frames, int frame_count, int start_index,
150                   objArrayHandle frames_array,
151                   TRAPS);
152 
153   static oop fetchFirstBatch(BaseFrameStream& stream, Handle stackStream,
154                              jlong mode, int skip_frames, int frame_count,
155                              int start_index, objArrayHandle frames_array, TRAPS);
156 
157   static jint fetchNextBatch(Handle stackStream, jlong mode, jlong magic,
158                              int frame_count, int start_index,
159                              objArrayHandle frames_array, TRAPS);



160 };
161 #endif // SHARE_PRIMS_STACKWALK_HPP

 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 
 26 #ifndef SHARE_PRIMS_STACKWALK_HPP
 27 #define SHARE_PRIMS_STACKWALK_HPP
 28 
 29 #include "jvm.h"
 30 #include "oops/oop.hpp"
 31 #include "runtime/continuation.hpp"
 32 #include "runtime/vframe.hpp"
 33 
 34 // BaseFrameStream is an abstract base class for encapsulating the VM-side
 35 // implementation of the StackWalker API.  There are two concrete subclasses:
 36 // - JavaFrameStream:
 37 //     -based on vframeStream; used in most instances
 38 // - LiveFrameStream:
 39 //     -based on javaVFrame; used for retrieving locals/monitors/operands for
 40 //      LiveStackFrame
 41 class BaseFrameStream : public StackObj {
 42 private:
 43   enum {
 44     magic_pos = 0
 45   };
 46 
 47   JavaThread*           _thread;
 48   Handle                _continuation;
 49   jlong                 _anchor;
 50 
 51 protected:
 52   void fill_stackframe(Handle stackFrame, const methodHandle& method, TRAPS);
 53 public:
 54   BaseFrameStream(JavaThread* thread, Handle continuation);
 55 
 56   virtual void    next()=0;
 57   virtual bool    at_end()=0;
 58 
 59   virtual Method* method()=0;
 60   virtual int     bci()=0;
 61   virtual oop     cont()=0; // returns the current continuation (even when walking a thread)
 62 
 63   virtual const RegisterMap* reg_map()=0;
 64 
 65   virtual void    fill_frame(int index, objArrayHandle  frames_array,
 66                              const methodHandle& method, TRAPS)=0;
 67   
 68   oop continuation() { return _continuation(); }
 69   void set_continuation(Handle cont);
 70 
 71   void setup_magic_on_entry(objArrayHandle frames_array);
 72   bool check_magic(objArrayHandle frames_array);
 73   bool cleanup_magic_on_exit(objArrayHandle frames_array);
 74 
 75   bool is_valid_in(Thread* thread, objArrayHandle frames_array) {
 76     return (_thread == thread && check_magic(frames_array));
 77   }
 78 
 79   jlong address_value() {
 80     return (jlong) castable_address(this);
 81   }
 82 
 83   static BaseFrameStream* from_current(JavaThread* thread, jlong magic, objArrayHandle frames_array);
 84 };
 85 
 86 class JavaFrameStream : public BaseFrameStream {
 87 private:
 88   vframeStream          _vfst;
 89   bool                  _need_method_info;
 90 
 91 public:
 92   JavaFrameStream(JavaThread* thread, int mode, Handle cont_scope, Handle cont);
 93 
 94   const RegisterMap* reg_map() override { return _vfst.reg_map(); };
 95 
 96   void next()   override;
 97   bool at_end() override { return _vfst.at_end(); }
 98 
 99   Method* method() override { return _vfst.method(); }
100   int bci()        override { return _vfst.bci(); }
101   oop cont()       override { return _vfst.continuation(); }
102 
103   void fill_frame(int index, objArrayHandle  frames_array,
104                   const methodHandle& method, TRAPS) override;
105 };
106 
107 class LiveFrameStream : public BaseFrameStream {
108 private:
109   enum {
110     MODE_INTERPRETED = 0x01,
111     MODE_COMPILED    = 0x02
112   };
113 
114   Handle              _cont_scope;  // the delimitation of this walk
115 
116   RegisterMap*        _map;
117   javaVFrame*         _jvf;
118   ContinuationEntry* _cont;
119 
120   void fill_live_stackframe(Handle stackFrame, const methodHandle& method, TRAPS);
121   static oop create_primitive_slot_instance(StackValueCollection* values,
122                                             int i, BasicType type, TRAPS);
123   static objArrayHandle monitors_to_object_array(GrowableArray<MonitorInfo*>* monitors,
124                                                  TRAPS);
125   static objArrayHandle values_to_object_array(StackValueCollection* values, TRAPS);
126 public:
127   LiveFrameStream(JavaThread* thread, RegisterMap* rm, Handle cont_scope, Handle cont);


128 
129   const RegisterMap* reg_map() override { return _map; };

130 
131   void next()   override;
132   bool at_end() override { return _jvf == NULL; }
133 
134   Method* method() override { return _jvf->method(); }
135   int bci()        override { return _jvf->bci(); }
136   oop cont() override { return continuation() != NULL ? continuation(): _cont->cont_oop(); }
137 
138   void fill_frame(int index, objArrayHandle  frames_array,
139                   const methodHandle& method, TRAPS) override;
140 };
141 
142 class StackWalk : public AllStatic {
143 private:
144   static int fill_in_frames(jlong mode, BaseFrameStream& stream,
145                             int max_nframes, int start_index,
146                             objArrayHandle frames_array,
147                             int& end_index, TRAPS);
148 
149   static inline bool get_caller_class(int mode) {
150     return (mode & JVM_STACKWALK_GET_CALLER_CLASS) != 0;
151   }
152   static inline bool skip_hidden_frames(int mode) {
153     return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0;
154   }
155   static inline bool live_frame_info(int mode) {
156     return (mode & JVM_STACKWALK_FILL_LIVE_STACK_FRAMES) != 0;
157   }
158 
159 public:
160   static inline bool need_method_info(int mode) {
161     return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
162   }
163   static inline bool use_frames_array(int mode) {
164     return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
165   }
166   static oop walk(Handle stackStream, jlong mode, int skip_frames, Handle cont_scope, Handle cont,
167                   int frame_count, int start_index, objArrayHandle frames_array,

168                   TRAPS);
169 
170   static oop fetchFirstBatch(BaseFrameStream& stream, Handle stackStream,
171                              jlong mode, int skip_frames, int frame_count,
172                              int start_index, objArrayHandle frames_array, TRAPS);
173 
174   static jint fetchNextBatch(Handle stackStream, jlong mode, jlong magic,
175                              int frame_count, int start_index,
176                              objArrayHandle frames_array, TRAPS);
177 
178   static void setContinuation(Handle stackStream, jlong magic, objArrayHandle frames_array, 
179                               Handle cont, TRAPS);
180 };
181 #endif // SHARE_PRIMS_STACKWALK_HPP
< prev index next >