361 inline static void vm_object_alloc_event_collector(oop object) { |
362 inline static void vm_object_alloc_event_collector(oop object) { |
362 if (should_post_vm_object_alloc()) { |
363 if (should_post_vm_object_alloc()) { |
363 record_vm_internal_object_allocation(object); |
364 record_vm_internal_object_allocation(object); |
364 } |
365 } |
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 |
366 inline static void post_array_size_exhausted() { |
379 inline static void post_array_size_exhausted() { |
367 if (should_post_resource_exhausted()) { |
380 if (should_post_resource_exhausted()) { |
368 post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, |
381 post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, |
369 "Requested array size exceeds VM limit"); |
382 "Requested array size exceeds VM limit"); |
370 } |
383 } |
420 // JvmtiEventCollector is a helper class to setup thread for |
433 // JvmtiEventCollector is a helper class to setup thread for |
421 // event collection. |
434 // event collection. |
422 class JvmtiEventCollector : public StackObj { |
435 class JvmtiEventCollector : public StackObj { |
423 private: |
436 private: |
424 JvmtiEventCollector* _prev; // Save previous one to support nested event collector. |
437 JvmtiEventCollector* _prev; // Save previous one to support nested event collector. |
425 |
438 bool _unset_jvmti_thread_state; |
426 public: |
439 |
427 void setup_jvmti_thread_state(); // Set this collector in current thread. |
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. |
428 void unset_jvmti_thread_state(); // Reset previous collector in current thread. |
444 void unset_jvmti_thread_state(); // Reset previous collector in current thread. |
429 virtual bool is_dynamic_code_event() { return false; } |
445 virtual bool is_dynamic_code_event() { return false; } |
430 virtual bool is_vm_object_alloc_event(){ return false; } |
446 virtual bool is_vm_object_alloc_event(){ return false; } |
|
447 virtual bool is_sampled_object_alloc_event(){ return false; } |
431 JvmtiEventCollector *get_prev() { return _prev; } |
448 JvmtiEventCollector *get_prev() { return _prev; } |
432 }; |
449 }; |
433 |
450 |
434 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport |
451 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport |
435 // interface. It collects "dynamic code generated" events that are posted |
452 // interface. It collects "dynamic code generated" events that are posted |
460 ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN; |
477 ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN; |
461 bool is_dynamic_code_event() { return true; } |
478 bool is_dynamic_code_event() { return true; } |
462 |
479 |
463 }; |
480 }; |
464 |
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 |
465 // Used to record vm internally allocated object oops and post |
514 // Used to record vm internally allocated object oops and post |
466 // vm object alloc event for objects visible to java world. |
515 // vm object alloc event for objects visible to java world. |
467 // Constructor enables JvmtiThreadState flag and all vm allocated |
516 // Constructor enables JvmtiThreadState flag and all vm allocated |
468 // objects are recorded in a growable array. When destructor is |
517 // objects are recorded in a growable array. When destructor is |
469 // called the vm object alloc event is posted for each objects |
518 // called the vm object alloc event is posted for each object |
470 // visible to java world. |
519 // visible to java world. |
471 // See jvm.cpp file for its usage. |
520 // See jvm.cpp file for its usage. |
472 // |
521 // |
473 class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector { |
522 class JvmtiVMObjectAllocEventCollector : public JvmtiObjectAllocEventCollector { |
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: |
523 public: |
492 JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; |
524 JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; |
493 ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; |
525 ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; |
494 bool is_vm_object_alloc_event() { return true; } |
526 virtual bool is_vm_object_alloc_event() { return true; } |
495 |
527 }; |
496 bool is_enabled() { return _enable; } |
528 |
497 void set_enabled(bool on) { _enable = on; } |
529 // Used to record sampled allocated object oops and post |
498 }; |
530 // sampled object alloc event. |
499 |
531 // Constructor enables JvmtiThreadState flag and all sampled allocated |
500 |
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 }; |
501 |
543 |
502 // Marker class to disable the posting of VMObjectAlloc events |
544 // Marker class to disable the posting of VMObjectAlloc events |
503 // within its scope. |
545 // within its scope. |
504 // |
546 // |
505 // Usage :- |
547 // Usage :- |