src/share/vm/prims/jvmtiImpl.hpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 187   Method* method() { return _method; }
 188 
 189   // GrowableElement implementation
 190   address getCacheValue()         { return getBcp(); }
 191   bool lessThan(GrowableElement* e) { Unimplemented(); return false; }
 192   bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); }
 193   void oops_do(OopClosure* f)     {
 194     // Mark the method loader as live
 195     f->do_oop(&_class_loader);
 196   }
 197   GrowableElement *clone()        {
 198     JvmtiBreakpoint *bp = new JvmtiBreakpoint();
 199     bp->copy(*this);
 200     return bp;
 201   }
 202 };
 203 
 204 
 205 ///////////////////////////////////////////////////////////////
 206 //
 207 // class VM_ChangeBreakpoints
 208 // Used by              : JvmtiBreakpoints
 209 // Used by JVMTI methods: none directly.
 210 // Note: A Helper class.
 211 //
 212 // VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class.
 213 //
 214 
 215 class VM_ChangeBreakpoints : public VM_Operation {
 216 private:
 217   JvmtiBreakpoints* _breakpoints;
 218   int               _operation;
 219   JvmtiBreakpoint*  _bp;
 220 
 221 public:
 222   enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1, CLEAR_ALL_BREAKPOINT=2 };
 223 
 224   VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation) {
 225     _breakpoints = breakpoints;
 226     _bp = NULL;
 227     _operation = operation;
 228     assert(breakpoints != NULL, "breakpoints != NULL");
 229     assert(operation == CLEAR_ALL_BREAKPOINT, "unknown breakpoint operation");
 230   }
 231   VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation, JvmtiBreakpoint *bp) {
 232     _breakpoints = breakpoints;
 233     _bp = bp;
 234     _operation = operation;
 235     assert(breakpoints != NULL, "breakpoints != NULL");
 236     assert(bp != NULL, "bp != NULL");
 237     assert(operation == SET_BREAKPOINT || operation == CLEAR_BREAKPOINT , "unknown breakpoint operation");
 238   }
 239 
 240   VMOp_Type type() const { return VMOp_ChangeBreakpoints; }
 241   void doit();
 242   void oops_do(OopClosure* f);
 243 };
 244 
 245 
 246 ///////////////////////////////////////////////////////////////
 247 //
 248 // class JvmtiBreakpoints
 249 // Used by              : JvmtiCurrentBreakpoints
 250 // Used by JVMTI methods: none directly
 251 // Note: A Helper class
 252 //
 253 // JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint.
 254 // All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints.
 255 //
 256 // Because _bps is only modified at safepoints, its possible to always use the
 257 // cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints).
 258 //
 259 // It would be possible to make JvmtiBreakpoints a static class, but I've made it
 260 // CHeap allocated to emphasize its similarity to JvmtiFramePops.
 261 //
 262 
 263 class JvmtiBreakpoints : public CHeapObj<mtInternal> {
 264 private:
 265 
 266   JvmtiBreakpointCache _bps;
 267 
 268   // These should only be used by VM_ChangeBreakpoints
 269   // to insure they only occur at safepoints.
 270   // Todo: add checks for safepoint
 271   friend class VM_ChangeBreakpoints;
 272   void set_at_safepoint(JvmtiBreakpoint& bp);
 273   void clear_at_safepoint(JvmtiBreakpoint& bp);
 274   void clearall_at_safepoint();
 275 
 276   static void do_element(GrowableElement *e);
 277 
 278 public:
 279   JvmtiBreakpoints(void listener_fun(void *, address *));
 280   ~JvmtiBreakpoints();
 281 
 282   int length();
 283   void oops_do(OopClosure* f);
 284   void print();
 285 
 286   int  set(JvmtiBreakpoint& bp);
 287   int  clear(JvmtiBreakpoint& bp);
 288   void clearall_in_class_at_safepoint(Klass* klass);
 289   void clearall();
 290   void gc_epilogue();
 291 };
 292 
 293 
 294 ///////////////////////////////////////////////////////////////
 295 //
 296 // class JvmtiCurrentBreakpoints
 297 //
 298 // A static wrapper class for the JvmtiBreakpoints that provides:
 299 // 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint).
 300 // 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary,
 301 //    but I'm copying the code from JvmtiThreadState which needs to lazily initialize
 302 //    JvmtiFramePops).
 303 // 3. An oops_do entry point for GC'ing the breakpoint array.
 304 //
 305 
 306 class JvmtiCurrentBreakpoints : public AllStatic {
 307 
 308 private:
 309 


 327   // lazily create _jvmti_breakpoints and _breakpoint_list
 328   static JvmtiBreakpoints& get_jvmti_breakpoints();
 329 
 330   // quickly test whether the bcp matches a cached breakpoint in the list
 331   static inline bool is_breakpoint(address bcp);
 332 
 333   static void oops_do(OopClosure* f);
 334   static void gc_epilogue();
 335 };
 336 
 337 // quickly test whether the bcp matches a cached breakpoint in the list
 338 bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) {
 339     address *bps = get_breakpoint_list();
 340     if (bps == NULL) return false;
 341     for ( ; (*bps) != NULL; bps++) {
 342       if ((*bps) == bcp) return true;
 343     }
 344     return false;
 345 }
 346 


































 347 ///////////////////////////////////////////////////////////////
 348 // The get/set local operations must only be done by the VM thread
 349 // because the interpreter version needs to access oop maps, which can
 350 // only safely be done by the VM thread
 351 //
 352 // I'm told that in 1.5 oop maps are now protected by a lock and
 353 // we could get rid of the VM op
 354 // However if the VM op is removed then the target thread must
 355 // be suspended AND a lock will be needed to prevent concurrent
 356 // setting of locals to the same java thread. This lock is needed
 357 // to prevent compiledVFrames from trying to add deferred updates
 358 // to the thread simultaneously.
 359 //
 360 class VM_GetOrSetLocal : public VM_Operation {
 361  protected:
 362   JavaThread* _thread;
 363   JavaThread* _calling_thread;
 364   jint        _depth;
 365   jint        _index;
 366   BasicType   _type;




 187   Method* method() { return _method; }
 188 
 189   // GrowableElement implementation
 190   address getCacheValue()         { return getBcp(); }
 191   bool lessThan(GrowableElement* e) { Unimplemented(); return false; }
 192   bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); }
 193   void oops_do(OopClosure* f)     {
 194     // Mark the method loader as live
 195     f->do_oop(&_class_loader);
 196   }
 197   GrowableElement *clone()        {
 198     JvmtiBreakpoint *bp = new JvmtiBreakpoint();
 199     bp->copy(*this);
 200     return bp;
 201   }
 202 };
 203 
 204 
 205 ///////////////////////////////////////////////////////////////
 206 //









































 207 // class JvmtiBreakpoints
 208 // Used by              : JvmtiCurrentBreakpoints
 209 // Used by JVMTI methods: none directly
 210 // Note: A Helper class
 211 //
 212 // JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint.
 213 // All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints.
 214 //
 215 // Because _bps is only modified at safepoints, its possible to always use the
 216 // cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints).
 217 //
 218 // It would be possible to make JvmtiBreakpoints a static class, but I've made it
 219 // CHeap allocated to emphasize its similarity to JvmtiFramePops.
 220 //
 221 
 222 class JvmtiBreakpoints : public CHeapObj<mtInternal> {
 223 private:
 224 
 225   JvmtiBreakpointCache _bps;
 226 
 227   // These should only be used by VM_ChangeBreakpoints
 228   // to insure they only occur at safepoints.
 229   // Todo: add checks for safepoint
 230   friend class VM_ChangeBreakpoints;
 231   void set_at_safepoint(JvmtiBreakpoint& bp);
 232   void clear_at_safepoint(JvmtiBreakpoint& bp);

 233 
 234   static void do_element(GrowableElement *e);
 235 
 236 public:
 237   JvmtiBreakpoints(void listener_fun(void *, address *));
 238   ~JvmtiBreakpoints();
 239 
 240   int length();
 241   void oops_do(OopClosure* f);
 242   void print();
 243 
 244   int  set(JvmtiBreakpoint& bp);
 245   int  clear(JvmtiBreakpoint& bp);
 246   void clearall_in_class_at_safepoint(Klass* klass);

 247   void gc_epilogue();
 248 };
 249 
 250 
 251 ///////////////////////////////////////////////////////////////
 252 //
 253 // class JvmtiCurrentBreakpoints
 254 //
 255 // A static wrapper class for the JvmtiBreakpoints that provides:
 256 // 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint).
 257 // 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary,
 258 //    but I'm copying the code from JvmtiThreadState which needs to lazily initialize
 259 //    JvmtiFramePops).
 260 // 3. An oops_do entry point for GC'ing the breakpoint array.
 261 //
 262 
 263 class JvmtiCurrentBreakpoints : public AllStatic {
 264 
 265 private:
 266 


 284   // lazily create _jvmti_breakpoints and _breakpoint_list
 285   static JvmtiBreakpoints& get_jvmti_breakpoints();
 286 
 287   // quickly test whether the bcp matches a cached breakpoint in the list
 288   static inline bool is_breakpoint(address bcp);
 289 
 290   static void oops_do(OopClosure* f);
 291   static void gc_epilogue();
 292 };
 293 
 294 // quickly test whether the bcp matches a cached breakpoint in the list
 295 bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) {
 296     address *bps = get_breakpoint_list();
 297     if (bps == NULL) return false;
 298     for ( ; (*bps) != NULL; bps++) {
 299       if ((*bps) == bcp) return true;
 300     }
 301     return false;
 302 }
 303 
 304 
 305 ///////////////////////////////////////////////////////////////
 306 //
 307 // class VM_ChangeBreakpoints
 308 // Used by              : JvmtiBreakpoints
 309 // Used by JVMTI methods: none directly.
 310 // Note: A Helper class.
 311 //
 312 // VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class.
 313 //
 314 
 315 class VM_ChangeBreakpoints : public VM_Operation {
 316 private:
 317   JvmtiBreakpoints* _breakpoints;
 318   int               _operation;
 319   JvmtiBreakpoint*  _bp;
 320 
 321 public:
 322   enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1 };
 323 
 324   VM_ChangeBreakpoints(int operation, JvmtiBreakpoint *bp) {
 325     JvmtiBreakpoints& current_bps = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
 326     _breakpoints = &current_bps;
 327     _bp = bp;
 328     _operation = operation;
 329     assert(bp != NULL, "bp != NULL");
 330   }
 331 
 332   VMOp_Type type() const { return VMOp_ChangeBreakpoints; }
 333   void doit();
 334   void oops_do(OopClosure* f);
 335 };
 336 
 337 
 338 ///////////////////////////////////////////////////////////////
 339 // The get/set local operations must only be done by the VM thread
 340 // because the interpreter version needs to access oop maps, which can
 341 // only safely be done by the VM thread
 342 //
 343 // I'm told that in 1.5 oop maps are now protected by a lock and
 344 // we could get rid of the VM op
 345 // However if the VM op is removed then the target thread must
 346 // be suspended AND a lock will be needed to prevent concurrent
 347 // setting of locals to the same java thread. This lock is needed
 348 // to prevent compiledVFrames from trying to add deferred updates
 349 // to the thread simultaneously.
 350 //
 351 class VM_GetOrSetLocal : public VM_Operation {
 352  protected:
 353   JavaThread* _thread;
 354   JavaThread* _calling_thread;
 355   jint        _depth;
 356   jint        _index;
 357   BasicType   _type;