< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page




  40 #include "prims/jvmtiEventController.hpp"
  41 #include "prims/jvmtiEventController.inline.hpp"
  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/jvmtiImpl.hpp"
  44 #include "prims/jvmtiManageCapabilities.hpp"
  45 #include "prims/jvmtiRawMonitor.hpp"
  46 #include "prims/jvmtiRedefineClasses.hpp"
  47 #include "prims/jvmtiTagMap.hpp"
  48 #include "prims/jvmtiThreadState.inline.hpp"
  49 #include "runtime/arguments.hpp"
  50 #include "runtime/handles.hpp"
  51 #include "runtime/interfaceSupport.inline.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/jniHandles.inline.hpp"
  54 #include "runtime/objectMonitor.hpp"
  55 #include "runtime/objectMonitor.inline.hpp"
  56 #include "runtime/os.inline.hpp"
  57 #include "runtime/thread.inline.hpp"
  58 #include "runtime/threadSMR.hpp"
  59 #include "runtime/vframe.hpp"
  60 #include "services/serviceUtil.hpp"
  61 #include "utilities/macros.hpp"
  62 #if INCLUDE_ALL_GCS
  63 #include "gc/parallel/psMarkSweep.hpp"
  64 #endif // INCLUDE_ALL_GCS
  65 
  66 #ifdef JVMTI_TRACE
  67 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; log_trace(jvmti) out; }
  68 #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; log_trace(jvmti) out; }
  69 #else
  70 #define EVT_TRIG_TRACE(evt,out)
  71 #define EVT_TRACE(evt,out)
  72 #endif
  73 
  74 ///////////////////////////////////////////////////////////////
  75 //
  76 // JvmtiEventTransition
  77 //
  78 // TO DO --
  79 //  more handle purging
  80 


2346                  ("[%s] data dump request event triggered",
2347                   JvmtiTrace::safe_get_thread_name(thread)));
2348   JvmtiEnvIterator it;
2349   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2350     if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
2351       EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
2352                 ("[%s] data dump request event sent",
2353                  JvmtiTrace::safe_get_thread_name(thread)));
2354      JvmtiThreadEventTransition jet(thread);
2355      // JNIEnv is NULL here because this event is posted from VM Thread
2356      jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
2357      if (callback != NULL) {
2358        (*callback)(env->jvmti_external());
2359      }
2360     }
2361   }
2362 }
2363 
2364 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
2365   oop object = (oop)obj_mntr->object();
2366   if (!ServiceUtil::visible_oop(object)) {
2367     // Ignore monitor contended enter for vm internal object.
2368     return;
2369   }
2370   JvmtiThreadState *state = thread->jvmti_thread_state();
2371   if (state == NULL) {
2372     return;
2373   }
2374 
2375   HandleMark hm(thread);
2376   Handle h(thread, object);
2377 
2378   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2379                      ("[%s] montior contended enter event triggered",
2380                       JvmtiTrace::safe_get_thread_name(thread)));
2381 
2382   JvmtiEnvThreadStateIterator it(state);
2383   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2384     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
2385       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2386                    ("[%s] monitor contended enter event sent",
2387                     JvmtiTrace::safe_get_thread_name(thread)));
2388       JvmtiMonitorEventMark  jem(thread, h());
2389       JvmtiEnv *env = ets->get_env();
2390       JvmtiThreadEventTransition jet(thread);
2391       jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
2392       if (callback != NULL) {
2393         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2394       }
2395     }
2396   }
2397 }
2398 
2399 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
2400   oop object = (oop)obj_mntr->object();
2401   if (!ServiceUtil::visible_oop(object)) {
2402     // Ignore monitor contended entered for vm internal object.
2403     return;
2404   }
2405   JvmtiThreadState *state = thread->jvmti_thread_state();
2406   if (state == NULL) {
2407     return;
2408   }
2409 
2410   HandleMark hm(thread);
2411   Handle h(thread, object);
2412 
2413   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2414                      ("[%s] montior contended entered event triggered",
2415                       JvmtiTrace::safe_get_thread_name(thread)));
2416 
2417   JvmtiEnvThreadStateIterator it(state);
2418   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2419     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
2420       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2421                    ("[%s] monitor contended enter event sent",
2422                     JvmtiTrace::safe_get_thread_name(thread)));
2423       JvmtiMonitorEventMark  jem(thread, h());
2424       JvmtiEnv *env = ets->get_env();


2448   JvmtiEnvThreadStateIterator it(state);
2449   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2450     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
2451       EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2452                    ("[%s] monitor wait event sent",
2453                     JvmtiTrace::safe_get_thread_name(thread)));
2454       JvmtiMonitorEventMark  jem(thread, h());
2455       JvmtiEnv *env = ets->get_env();
2456       JvmtiThreadEventTransition jet(thread);
2457       jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
2458       if (callback != NULL) {
2459         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2460                     jem.jni_object(), timeout);
2461       }
2462     }
2463   }
2464 }
2465 
2466 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2467   oop object = (oop)obj_mntr->object();
2468   if (!ServiceUtil::visible_oop(object)) {
2469     // Ignore monitor waited for vm internal object.
2470     return;
2471   }
2472   JvmtiThreadState *state = thread->jvmti_thread_state();
2473   if (state == NULL) {
2474     return;
2475   }
2476 
2477   HandleMark hm(thread);
2478   Handle h(thread, object);
2479 
2480   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2481                      ("[%s] montior waited event triggered",
2482                       JvmtiTrace::safe_get_thread_name(thread)));
2483 
2484   JvmtiEnvThreadStateIterator it(state);
2485   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2486     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2487       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2488                    ("[%s] monitor waited event sent",
2489                     JvmtiTrace::safe_get_thread_name(thread)));
2490       JvmtiMonitorEventMark  jem(thread, h());
2491       JvmtiEnv *env = ets->get_env();


2744  _code_blobs->append(new JvmtiCodeBlobDesc(name, start, end));
2745 }
2746 
2747 // Setup current thread to record vm allocated objects.
2748 JvmtiVMObjectAllocEventCollector::JvmtiVMObjectAllocEventCollector() : _allocated(NULL) {
2749   if (JvmtiExport::should_post_vm_object_alloc()) {
2750     _enable = true;
2751     setup_jvmti_thread_state();
2752   } else {
2753     _enable = false;
2754   }
2755 }
2756 
2757 // Post vm_object_alloc event for vm allocated objects visible to java
2758 // world.
2759 JvmtiVMObjectAllocEventCollector::~JvmtiVMObjectAllocEventCollector() {
2760   if (_allocated != NULL) {
2761     set_enabled(false);
2762     for (int i = 0; i < _allocated->length(); i++) {
2763       oop obj = _allocated->at(i);
2764       if (ServiceUtil::visible_oop(obj)) {
2765         JvmtiExport::post_vm_object_alloc(JavaThread::current(), obj);
2766       }
2767     }
2768     delete _allocated;
2769   }
2770   unset_jvmti_thread_state();
2771 }
2772 
2773 void JvmtiVMObjectAllocEventCollector::record_allocation(oop obj) {
2774   assert(is_enabled(), "VM object alloc event collector is not enabled");
2775   if (_allocated == NULL) {
2776     _allocated = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(1, true);
2777   }
2778   _allocated->push(obj);
2779 }
2780 
2781 // GC support.
2782 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
2783   if (_allocated != NULL) {
2784     for(int i=_allocated->length() - 1; i >= 0; i--) {
2785       if (_allocated->at(i) != NULL) {
2786         f->do_oop(_allocated->adr_at(i));
2787       }




  40 #include "prims/jvmtiEventController.hpp"
  41 #include "prims/jvmtiEventController.inline.hpp"
  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/jvmtiImpl.hpp"
  44 #include "prims/jvmtiManageCapabilities.hpp"
  45 #include "prims/jvmtiRawMonitor.hpp"
  46 #include "prims/jvmtiRedefineClasses.hpp"
  47 #include "prims/jvmtiTagMap.hpp"
  48 #include "prims/jvmtiThreadState.inline.hpp"
  49 #include "runtime/arguments.hpp"
  50 #include "runtime/handles.hpp"
  51 #include "runtime/interfaceSupport.inline.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/jniHandles.inline.hpp"
  54 #include "runtime/objectMonitor.hpp"
  55 #include "runtime/objectMonitor.inline.hpp"
  56 #include "runtime/os.inline.hpp"
  57 #include "runtime/thread.inline.hpp"
  58 #include "runtime/threadSMR.hpp"
  59 #include "runtime/vframe.hpp"

  60 #include "utilities/macros.hpp"
  61 #if INCLUDE_ALL_GCS
  62 #include "gc/parallel/psMarkSweep.hpp"
  63 #endif // INCLUDE_ALL_GCS
  64 
  65 #ifdef JVMTI_TRACE
  66 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; log_trace(jvmti) out; }
  67 #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; log_trace(jvmti) out; }
  68 #else
  69 #define EVT_TRIG_TRACE(evt,out)
  70 #define EVT_TRACE(evt,out)
  71 #endif
  72 
  73 ///////////////////////////////////////////////////////////////
  74 //
  75 // JvmtiEventTransition
  76 //
  77 // TO DO --
  78 //  more handle purging
  79 


2345                  ("[%s] data dump request event triggered",
2346                   JvmtiTrace::safe_get_thread_name(thread)));
2347   JvmtiEnvIterator it;
2348   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2349     if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
2350       EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
2351                 ("[%s] data dump request event sent",
2352                  JvmtiTrace::safe_get_thread_name(thread)));
2353      JvmtiThreadEventTransition jet(thread);
2354      // JNIEnv is NULL here because this event is posted from VM Thread
2355      jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
2356      if (callback != NULL) {
2357        (*callback)(env->jvmti_external());
2358      }
2359     }
2360   }
2361 }
2362 
2363 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
2364   oop object = (oop)obj_mntr->object();




2365   JvmtiThreadState *state = thread->jvmti_thread_state();
2366   if (state == NULL) {
2367     return;
2368   }
2369 
2370   HandleMark hm(thread);
2371   Handle h(thread, object);
2372 
2373   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2374                      ("[%s] montior contended enter event triggered",
2375                       JvmtiTrace::safe_get_thread_name(thread)));
2376 
2377   JvmtiEnvThreadStateIterator it(state);
2378   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2379     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
2380       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2381                    ("[%s] monitor contended enter event sent",
2382                     JvmtiTrace::safe_get_thread_name(thread)));
2383       JvmtiMonitorEventMark  jem(thread, h());
2384       JvmtiEnv *env = ets->get_env();
2385       JvmtiThreadEventTransition jet(thread);
2386       jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
2387       if (callback != NULL) {
2388         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2389       }
2390     }
2391   }
2392 }
2393 
2394 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
2395   oop object = (oop)obj_mntr->object();




2396   JvmtiThreadState *state = thread->jvmti_thread_state();
2397   if (state == NULL) {
2398     return;
2399   }
2400 
2401   HandleMark hm(thread);
2402   Handle h(thread, object);
2403 
2404   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2405                      ("[%s] montior contended entered event triggered",
2406                       JvmtiTrace::safe_get_thread_name(thread)));
2407 
2408   JvmtiEnvThreadStateIterator it(state);
2409   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2410     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
2411       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2412                    ("[%s] monitor contended enter event sent",
2413                     JvmtiTrace::safe_get_thread_name(thread)));
2414       JvmtiMonitorEventMark  jem(thread, h());
2415       JvmtiEnv *env = ets->get_env();


2439   JvmtiEnvThreadStateIterator it(state);
2440   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2441     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
2442       EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2443                    ("[%s] monitor wait event sent",
2444                     JvmtiTrace::safe_get_thread_name(thread)));
2445       JvmtiMonitorEventMark  jem(thread, h());
2446       JvmtiEnv *env = ets->get_env();
2447       JvmtiThreadEventTransition jet(thread);
2448       jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
2449       if (callback != NULL) {
2450         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2451                     jem.jni_object(), timeout);
2452       }
2453     }
2454   }
2455 }
2456 
2457 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2458   oop object = (oop)obj_mntr->object();




2459   JvmtiThreadState *state = thread->jvmti_thread_state();
2460   if (state == NULL) {
2461     return;
2462   }
2463 
2464   HandleMark hm(thread);
2465   Handle h(thread, object);
2466 
2467   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2468                      ("[%s] montior waited event triggered",
2469                       JvmtiTrace::safe_get_thread_name(thread)));
2470 
2471   JvmtiEnvThreadStateIterator it(state);
2472   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2473     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2474       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2475                    ("[%s] monitor waited event sent",
2476                     JvmtiTrace::safe_get_thread_name(thread)));
2477       JvmtiMonitorEventMark  jem(thread, h());
2478       JvmtiEnv *env = ets->get_env();


2731  _code_blobs->append(new JvmtiCodeBlobDesc(name, start, end));
2732 }
2733 
2734 // Setup current thread to record vm allocated objects.
2735 JvmtiVMObjectAllocEventCollector::JvmtiVMObjectAllocEventCollector() : _allocated(NULL) {
2736   if (JvmtiExport::should_post_vm_object_alloc()) {
2737     _enable = true;
2738     setup_jvmti_thread_state();
2739   } else {
2740     _enable = false;
2741   }
2742 }
2743 
2744 // Post vm_object_alloc event for vm allocated objects visible to java
2745 // world.
2746 JvmtiVMObjectAllocEventCollector::~JvmtiVMObjectAllocEventCollector() {
2747   if (_allocated != NULL) {
2748     set_enabled(false);
2749     for (int i = 0; i < _allocated->length(); i++) {
2750       oop obj = _allocated->at(i);

2751       JvmtiExport::post_vm_object_alloc(JavaThread::current(), obj);
2752     }

2753     delete _allocated;
2754   }
2755   unset_jvmti_thread_state();
2756 }
2757 
2758 void JvmtiVMObjectAllocEventCollector::record_allocation(oop obj) {
2759   assert(is_enabled(), "VM object alloc event collector is not enabled");
2760   if (_allocated == NULL) {
2761     _allocated = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(1, true);
2762   }
2763   _allocated->push(obj);
2764 }
2765 
2766 // GC support.
2767 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
2768   if (_allocated != NULL) {
2769     for(int i=_allocated->length() - 1; i >= 0; i--) {
2770       if (_allocated->at(i) != NULL) {
2771         f->do_oop(_allocated->adr_at(i));
2772       }


< prev index next >