< prev index next >

src/hotspot/share/prims/jvmtiExport.hpp

Print this page
rev 50392 : JEP 331


 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 {


 346   static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;
 347 
 348   static void post_garbage_collection_finish() NOT_JVMTI_RETURN;
 349   static void post_garbage_collection_start() NOT_JVMTI_RETURN;
 350   static void post_data_dump() NOT_JVMTI_RETURN;
 351   static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 352   static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 353   static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;
 354   static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;
 355   static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;
 356   static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;
 357   static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 358   // Post objects collected by vm_object_alloc_event_collector.
 359   static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 360   // Collects vm internal objects for later event posting.
 361   inline static void vm_object_alloc_event_collector(oop object) {
 362     if (should_post_vm_object_alloc()) {
 363       record_vm_internal_object_allocation(object);
 364     }
 365   }












 366   inline static void post_array_size_exhausted() {
 367     if (should_post_resource_exhausted()) {
 368       post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
 369                               "Requested array size exceeds VM limit");
 370     }
 371   }
 372 
 373   static void cleanup_thread             (JavaThread* thread) NOT_JVMTI_RETURN;
 374   static void clear_detected_exception   (JavaThread* thread) NOT_JVMTI_RETURN;
 375 
 376   static void oops_do(OopClosure* f) NOT_JVMTI_RETURN;
 377   static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN;
 378   static void gc_epilogue() NOT_JVMTI_RETURN;
 379 
 380   static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN;
 381 
 382 #if INCLUDE_SERVICES
 383   // attach support
 384   static jint load_agent_library(const char *agent, const char *absParam, const char *options, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
 385 #endif


 405   address _code_end;
 406 
 407  public:
 408   JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {
 409     assert(name != NULL, "all code blobs must be named");
 410     strncpy(_name, name, sizeof(_name));
 411     _name[sizeof(_name)-1] = '\0';
 412     _code_begin = code_begin;
 413     _code_end = code_end;
 414   }
 415   char* name()                  { return _name; }
 416   address code_begin()          { return _code_begin; }
 417   address code_end()            { return _code_end; }
 418 };
 419 
 420 // JvmtiEventCollector is a helper class to setup thread for
 421 // event collection.
 422 class JvmtiEventCollector : public StackObj {
 423  private:
 424   JvmtiEventCollector* _prev;  // Save previous one to support nested event collector.

 425 
 426  public:
 427   void setup_jvmti_thread_state(); // Set this collector in current thread.


 428   void unset_jvmti_thread_state(); // Reset previous collector in current thread.
 429   virtual bool is_dynamic_code_event()   { return false; }
 430   virtual bool is_vm_object_alloc_event(){ return false; }

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

 480 
 481   //GC support
 482   void oops_do(OopClosure* f);
 483 
 484   friend class JvmtiExport;
 485   // Record vm allocated object oop.

 486   inline void record_allocation(oop obj);
 487 
 488   //GC support
 489   static void oops_do_for_all_threads(OopClosure* f);
 490 
 491  public:
 492   JvmtiVMObjectAllocEventCollector()  NOT_JVMTI_RETURN;
 493   ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;
 494   bool is_vm_object_alloc_event()   { return true; }
 495 
 496   bool is_enabled()                 { return _enable; }
 497   void set_enabled(bool on)         { _enable = on; }
 498 };
 499 














 500 














 501 
 502 // Marker class to disable the posting of VMObjectAlloc events
 503 // within its scope.
 504 //
 505 // Usage :-
 506 //
 507 // {
 508 //   NoJvmtiVMObjectAllocMark njm;
 509 //   :
 510 //   // VMObjAlloc event will not be posted
 511 //   JvmtiExport::vm_object_alloc_event_collector(obj);
 512 //   :
 513 // }
 514 
 515 class NoJvmtiVMObjectAllocMark : public StackObj {
 516  private:
 517   // enclosing collector if enabled, NULL otherwise
 518   JvmtiVMObjectAllocEventCollector *_collector;
 519 
 520   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 {


 347   static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;
 348 
 349   static void post_garbage_collection_finish() NOT_JVMTI_RETURN;
 350   static void post_garbage_collection_start() NOT_JVMTI_RETURN;
 351   static void post_data_dump() NOT_JVMTI_RETURN;
 352   static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 353   static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
 354   static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;
 355   static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;
 356   static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;
 357   static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;
 358   static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 359   // Post objects collected by vm_object_alloc_event_collector.
 360   static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 361   // Collects vm internal objects for later event posting.
 362   inline static void vm_object_alloc_event_collector(oop object) {
 363     if (should_post_vm_object_alloc()) {
 364       record_vm_internal_object_allocation(object);
 365     }
 366   }
 367 
 368   static void record_sampled_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
 369   // Post objects collected by sampled_object_alloc_event_collector.
 370   static void post_sampled_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
 371 
 372   // Collects vm internal objects for later event posting.
 373   inline static void sampled_object_alloc_event_collector(oop object) {
 374     if (should_post_sampled_object_alloc()) {
 375       record_sampled_internal_object_allocation(object);
 376     }
 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


 418   address _code_end;
 419 
 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   bool _unset_jvmti_thread_state;
 439 
 440  public:
 441   JvmtiEventCollector() : _prev(NULL), _unset_jvmti_thread_state(false) {}
 442 
 443   void setup_jvmti_thread_state(); // Set this collector in current thread, returns if success.
 444   void unset_jvmti_thread_state(); // Reset previous collector in current thread.
 445   virtual bool is_dynamic_code_event()   { return false; }
 446   virtual bool is_vm_object_alloc_event(){ return false; }
 447   virtual bool is_sampled_object_alloc_event(){ return false; }
 448   JvmtiEventCollector *get_prev()        { return _prev; }
 449 };
 450 
 451 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport
 452 // interface. It collects "dynamic code generated" events that are posted
 453 // while holding locks. When the event collector goes out of scope the
 454 // events will be posted.
 455 //
 456 // Usage :-
 457 //
 458 // {
 459 //   JvmtiDynamicCodeEventCollector event_collector;
 460 //   :
 461 //   { MutexLocker ml(...)
 462 //     :
 463 //     JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)
 464 //   }
 465 //   // event collector goes out of scope => post events to profiler.
 466 // }
 467 
 468 class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {
 469  private:
 470   GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;           // collected code blob events
 471 
 472   friend class JvmtiExport;
 473   void register_stub(const char* name, address start, address end);
 474 
 475  public:
 476   JvmtiDynamicCodeEventCollector()  NOT_JVMTI_RETURN;
 477   ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;
 478   bool is_dynamic_code_event()   { return true; }
 479 
 480 };
 481 
 482 // Used as a base class for object allocation collection and then posting
 483 // the allocations to any event notification callbacks.





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


< prev index next >