< prev index next >

src/hotspot/share/prims/jvmtiExport.hpp

Print this page
rev 49244 : [mq]: event-only


 106   JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter)
 107   JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered)
 108   JVMTI_SUPPORT_FLAG(should_post_monitor_wait)
 109   JVMTI_SUPPORT_FLAG(should_post_monitor_waited)
 110   JVMTI_SUPPORT_FLAG(should_post_data_dump)
 111   JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start)
 112   JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish)
 113   JVMTI_SUPPORT_FLAG(should_post_on_exceptions)
 114 
 115   // ------ the below maybe don't have to be (but are for now)
 116   // fixed conditions here ------------
 117   // any events can be enabled
 118   JVMTI_SUPPORT_FLAG(should_post_thread_life)
 119   JVMTI_SUPPORT_FLAG(should_post_object_free)
 120   JVMTI_SUPPORT_FLAG(should_post_resource_exhausted)
 121 
 122   // we are holding objects on the heap - need to talk to GC - e.g.
 123   // breakpoint info
 124   JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects)
 125   JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)

 126 
 127   // If flag cannot be implemented, give an error if on=true
 128   static void report_unsupported(bool on);
 129 
 130   // these should only be called by the friend class
 131   friend class JvmtiManageCapabilities;
 132   inline static void set_can_modify_any_class(bool on) {
 133     JVMTI_ONLY(_can_modify_any_class = (on != 0);)
 134   }
 135   inline static void set_can_access_local_variables(bool on) {
 136     JVMTI_ONLY(_can_access_local_variables = (on != 0);)
 137   }
 138   inline static void set_can_hotswap_or_post_breakpoint(bool on) {
 139     JVMTI_ONLY(_can_hotswap_or_post_breakpoint = (on != 0);)
 140   }
 141   inline static void set_can_walk_any_space(bool on) {
 142     JVMTI_ONLY(_can_walk_any_space = (on != 0);)
 143   }
 144 
 145   enum {


 359   static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;
 360 
 361   static void post_garbage_collection_finish() NOT_JVMTI_RETURN;
 362   static void post_garbage_collection_start() NOT_JVMTI_RETURN;
 363   static void post_data_dump() NOT_JVMTI_RETURN;
 364   static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 365   static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 366   static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;
 367   static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;
 368   static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;
 369   static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;
 370   static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 371   // Post objects collected by vm_object_alloc_event_collector.
 372   static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 373   // Collects vm internal objects for later event posting.
 374   inline static void vm_object_alloc_event_collector(oop object) {
 375     if (should_post_vm_object_alloc()) {
 376       record_vm_internal_object_allocation(object);
 377     }
 378   }











 379   inline static void post_array_size_exhausted() {
 380     if (should_post_resource_exhausted()) {
 381       post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
 382                               "Requested array size exceeds VM limit");
 383     }
 384   }
 385 
 386   static void cleanup_thread             (JavaThread* thread) NOT_JVMTI_RETURN;
 387   static void clear_detected_exception   (JavaThread* thread) NOT_JVMTI_RETURN;
 388 
 389   static void oops_do(OopClosure* f) NOT_JVMTI_RETURN;
 390   static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN;
 391   static void gc_epilogue() NOT_JVMTI_RETURN;
 392 
 393   static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN;
 394 
 395 #if INCLUDE_SERVICES
 396   // attach support
 397   static jint load_agent_library(const char *agent, const char *absParam, const char *options, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
 398 #endif


 420  public:
 421   JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {
 422     assert(name != NULL, "all code blobs must be named");
 423     strncpy(_name, name, sizeof(_name));
 424     _name[sizeof(_name)-1] = '\0';
 425     _code_begin = code_begin;
 426     _code_end = code_end;
 427   }
 428   char* name()                  { return _name; }
 429   address code_begin()          { return _code_begin; }
 430   address code_end()            { return _code_end; }
 431 };
 432 
 433 // JvmtiEventCollector is a helper class to setup thread for
 434 // event collection.
 435 class JvmtiEventCollector : public StackObj {
 436  private:
 437   JvmtiEventCollector* _prev;  // Save previous one to support nested event collector.
 438 
 439  public:


 440   void setup_jvmti_thread_state(); // Set this collector in current thread.
 441   void unset_jvmti_thread_state(); // Reset previous collector in current thread.
 442   virtual bool is_dynamic_code_event()   { return false; }
 443   virtual bool is_vm_object_alloc_event(){ return false; }

 444   JvmtiEventCollector *get_prev()        { return _prev; }
 445 };
 446 
 447 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport
 448 // interface. It collects "dynamic code generated" events that are posted
 449 // while holding locks. When the event collector goes out of scope the
 450 // events will be posted.
 451 //
 452 // Usage :-
 453 //
 454 // {
 455 //   JvmtiDynamicCodeEventCollector event_collector;
 456 //   :
 457 //   { MutexLocker ml(...)
 458 //     :
 459 //     JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)
 460 //   }
 461 //   // event collector goes out of scope => post events to profiler.
 462 // }
 463 
 464 class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {
 465  private:
 466   GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;           // collected code blob events
 467 
 468   friend class JvmtiExport;
 469   void register_stub(const char* name, address start, address end);
 470 
 471  public:
 472   JvmtiDynamicCodeEventCollector()  NOT_JVMTI_RETURN;
 473   ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;
 474   bool is_dynamic_code_event()   { return true; }
 475 
 476 };
 477 
 478 // Used to record vm internally allocated object oops and post
 479 // vm object alloc event for objects visible to java world.
 480 // Constructor enables JvmtiThreadState flag and all vm allocated
 481 // objects are recorded in a growable array. When destructor is
 482 // called the vm object alloc event is posted for each objects
 483 // visible to java world.
 484 // See jvm.cpp file for its usage.
 485 //
 486 class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector {
 487  private:
 488   GrowableArray<oop>* _allocated; // field to record vm internally allocated object oop.
 489   bool _enable;                   // This flag is enabled in constructor and disabled
 490                                   // in destructor before posting event. To avoid
 491                                   // collection of objects allocated while running java code inside
 492                                   // agent post_vm_object_alloc() event handler.


 493 
 494   //GC support
 495   void oops_do(OopClosure* f);
 496 
 497   friend class JvmtiExport;
 498   // Record vm allocated object oop.
 499   inline void record_allocation(oop obj);
 500 
 501   //GC support
 502   static void oops_do_for_all_threads(OopClosure* f);
 503 
 504  public:
 505   JvmtiVMObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 506   ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;
 507   bool is_vm_object_alloc_event()   { return true; }
 508 
 509   bool is_enabled()                 { return _enable; }
 510   void set_enabled(bool on)         { _enable = on; }
 511 };
 512 














 513 













 514 
 515 // Marker class to disable the posting of VMObjectAlloc events
 516 // within its scope.
 517 //
 518 // Usage :-
 519 //
 520 // {
 521 //   NoJvmtiVMObjectAllocMark njm;
 522 //   :
 523 //   // VMObjAlloc event will not be posted
 524 //   JvmtiExport::vm_object_alloc_event_collector(obj);
 525 //   :
 526 // }
 527 
 528 class NoJvmtiVMObjectAllocMark : public StackObj {
 529  private:
 530   // enclosing collector if enabled, NULL otherwise
 531   JvmtiVMObjectAllocEventCollector *_collector;
 532 
 533   bool was_enabled()    { return _collector != NULL; }




 106   JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter)
 107   JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered)
 108   JVMTI_SUPPORT_FLAG(should_post_monitor_wait)
 109   JVMTI_SUPPORT_FLAG(should_post_monitor_waited)
 110   JVMTI_SUPPORT_FLAG(should_post_data_dump)
 111   JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start)
 112   JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish)
 113   JVMTI_SUPPORT_FLAG(should_post_on_exceptions)
 114 
 115   // ------ the below maybe don't have to be (but are for now)
 116   // fixed conditions here ------------
 117   // any events can be enabled
 118   JVMTI_SUPPORT_FLAG(should_post_thread_life)
 119   JVMTI_SUPPORT_FLAG(should_post_object_free)
 120   JVMTI_SUPPORT_FLAG(should_post_resource_exhausted)
 121 
 122   // we are holding objects on the heap - need to talk to GC - e.g.
 123   // breakpoint info
 124   JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects)
 125   JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)
 126   JVMTI_SUPPORT_FLAG(should_post_sampled_object_alloc)
 127 
 128   // If flag cannot be implemented, give an error if on=true
 129   static void report_unsupported(bool on);
 130 
 131   // these should only be called by the friend class
 132   friend class JvmtiManageCapabilities;
 133   inline static void set_can_modify_any_class(bool on) {
 134     JVMTI_ONLY(_can_modify_any_class = (on != 0);)
 135   }
 136   inline static void set_can_access_local_variables(bool on) {
 137     JVMTI_ONLY(_can_access_local_variables = (on != 0);)
 138   }
 139   inline static void set_can_hotswap_or_post_breakpoint(bool on) {
 140     JVMTI_ONLY(_can_hotswap_or_post_breakpoint = (on != 0);)
 141   }
 142   inline static void set_can_walk_any_space(bool on) {
 143     JVMTI_ONLY(_can_walk_any_space = (on != 0);)
 144   }
 145 
 146   enum {


 360   static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;
 361 
 362   static void post_garbage_collection_finish() NOT_JVMTI_RETURN;
 363   static void post_garbage_collection_start() NOT_JVMTI_RETURN;
 364   static void post_data_dump() NOT_JVMTI_RETURN;
 365   static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 366   static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 367   static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;
 368   static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;
 369   static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;
 370   static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;
 371   static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 372   // Post objects collected by vm_object_alloc_event_collector.
 373   static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 374   // Collects vm internal objects for later event posting.
 375   inline static void vm_object_alloc_event_collector(oop object) {
 376     if (should_post_vm_object_alloc()) {
 377       record_vm_internal_object_allocation(object);
 378     }
 379   }
 380 
 381   static void record_sampled_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 382   // Post objects collected by sampled_object_alloc_event_collector.
 383   static void post_sampled_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 384   // Collects vm internal objects for later event posting.
 385   inline static void sampled_object_alloc_event_collector(oop object) {
 386     if (should_post_sampled_object_alloc()) {
 387       record_sampled_internal_object_allocation(object);
 388     }
 389   }
 390 
 391   inline static void post_array_size_exhausted() {
 392     if (should_post_resource_exhausted()) {
 393       post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
 394                               "Requested array size exceeds VM limit");
 395     }
 396   }
 397 
 398   static void cleanup_thread             (JavaThread* thread) NOT_JVMTI_RETURN;
 399   static void clear_detected_exception   (JavaThread* thread) NOT_JVMTI_RETURN;
 400 
 401   static void oops_do(OopClosure* f) NOT_JVMTI_RETURN;
 402   static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN;
 403   static void gc_epilogue() NOT_JVMTI_RETURN;
 404 
 405   static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN;
 406 
 407 #if INCLUDE_SERVICES
 408   // attach support
 409   static jint load_agent_library(const char *agent, const char *absParam, const char *options, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
 410 #endif


 432  public:
 433   JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {
 434     assert(name != NULL, "all code blobs must be named");
 435     strncpy(_name, name, sizeof(_name));
 436     _name[sizeof(_name)-1] = '\0';
 437     _code_begin = code_begin;
 438     _code_end = code_end;
 439   }
 440   char* name()                  { return _name; }
 441   address code_begin()          { return _code_begin; }
 442   address code_end()            { return _code_end; }
 443 };
 444 
 445 // JvmtiEventCollector is a helper class to setup thread for
 446 // event collection.
 447 class JvmtiEventCollector : public StackObj {
 448  private:
 449   JvmtiEventCollector* _prev;  // Save previous one to support nested event collector.
 450 
 451  public:
 452   JvmtiEventCollector() : _prev(NULL) {}
 453 
 454   void setup_jvmti_thread_state(); // Set this collector in current thread.
 455   void unset_jvmti_thread_state(); // Reset previous collector in current thread.
 456   virtual bool is_dynamic_code_event()   { return false; }
 457   virtual bool is_vm_object_alloc_event(){ return false; }
 458   virtual bool is_sampled_object_alloc_event(){ return false; }
 459   JvmtiEventCollector *get_prev()        { return _prev; }
 460 };
 461 
 462 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport
 463 // interface. It collects "dynamic code generated" events that are posted
 464 // while holding locks. When the event collector goes out of scope the
 465 // events will be posted.
 466 //
 467 // Usage :-
 468 //
 469 // {
 470 //   JvmtiDynamicCodeEventCollector event_collector;
 471 //   :
 472 //   { MutexLocker ml(...)
 473 //     :
 474 //     JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)
 475 //   }
 476 //   // event collector goes out of scope => post events to profiler.
 477 // }
 478 
 479 class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {
 480  private:
 481   GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;           // collected code blob events
 482 
 483   friend class JvmtiExport;
 484   void register_stub(const char* name, address start, address end);
 485 
 486  public:
 487   JvmtiDynamicCodeEventCollector()  NOT_JVMTI_RETURN;
 488   ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;
 489   bool is_dynamic_code_event()   { return true; }
 490 
 491 };
 492 
 493 // Used as a base class for object allocation collection and then posting
 494 // the allocations to any event notification callbacks.





 495 //
 496 class JvmtiObjectAllocEventCollector : public JvmtiEventCollector {
 497  protected:
 498   GrowableArray<oop>* _allocated; // field to record vm internally allocated object oop.
 499   bool _enable;                   // This flag is enabled in constructor and disabled
 500                                   // in destructor before posting event. To avoid
 501                                   // collection of objects allocated while running java code inside
 502                                   // agent post_X_object_alloc() event handler.
 503   void (*_post_callback)(JavaThread*, oop); // what callback to use when destroying the collector.
 504   bool _callback_for_all_oops;
 505 
 506   //GC support
 507   void oops_do(OopClosure* f);
 508 
 509   friend class JvmtiExport;
 510   // Record vm allocated object oop.
 511   inline void record_allocation(oop obj);
 512 
 513   //GC support
 514   static void oops_do_for_all_threads(OopClosure* f);
 515 
 516  public:
 517   JvmtiObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 518 
 519   void generate_call_for_allocated();
 520 
 521   bool is_enabled()                 { return _enable; }
 522   void set_enabled(bool on)         { _enable = on; }
 523 };
 524 
 525 // Used to record vm internally allocated object oops and post
 526 // vm object alloc event for objects visible to java world.
 527 // Constructor enables JvmtiThreadState flag and all vm allocated
 528 // objects are recorded in a growable array. When destructor is
 529 // called the vm object alloc event is posted for each object
 530 // visible to java world.
 531 // See jvm.cpp file for its usage.
 532 //
 533 class JvmtiVMObjectAllocEventCollector : public JvmtiObjectAllocEventCollector {
 534  public:
 535   JvmtiVMObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 536   ~JvmtiVMObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 537   virtual bool is_vm_object_alloc_event()   { return true; }
 538 };
 539 
 540 // Used to record sampled allocated object oops and post
 541 // sampled object alloc event.
 542 // Constructor enables JvmtiThreadState flag and all sampled allocated
 543 // objects are recorded in a growable array. When destructor is
 544 // called the sampled object alloc event is posted for each sampled object.
 545 // See jvm.cpp file for its usage.
 546 //
 547 class JvmtiSampledObjectAllocEventCollector : public JvmtiObjectAllocEventCollector {
 548  public:
 549   JvmtiSampledObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 550   ~JvmtiSampledObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 551   bool is_sampled_object_alloc_event()   { return true; }
 552 };
 553 
 554 // Marker class to disable the posting of VMObjectAlloc events
 555 // within its scope.
 556 //
 557 // Usage :-
 558 //
 559 // {
 560 //   NoJvmtiVMObjectAllocMark njm;
 561 //   :
 562 //   // VMObjAlloc event will not be posted
 563 //   JvmtiExport::vm_object_alloc_event_collector(obj);
 564 //   :
 565 // }
 566 
 567 class NoJvmtiVMObjectAllocMark : public StackObj {
 568  private:
 569   // enclosing collector if enabled, NULL otherwise
 570   JvmtiVMObjectAllocEventCollector *_collector;
 571 
 572   bool was_enabled()    { return _collector != NULL; }


< prev index next >