< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47289 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp
rev 47292 : stefank, coleenp CR - refactor most JavaThreadIterator usage to use JavaThreadIteratorWithHandle.


  36 #include "oops/objArrayOop.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "prims/jvmtiCodeBlobEvents.hpp"
  39 #include "prims/jvmtiEventController.hpp"
  40 #include "prims/jvmtiEventController.inline.hpp"
  41 #include "prims/jvmtiExport.hpp"
  42 #include "prims/jvmtiImpl.hpp"
  43 #include "prims/jvmtiManageCapabilities.hpp"
  44 #include "prims/jvmtiRawMonitor.hpp"
  45 #include "prims/jvmtiRedefineClasses.hpp"
  46 #include "prims/jvmtiTagMap.hpp"
  47 #include "prims/jvmtiThreadState.inline.hpp"
  48 #include "runtime/arguments.hpp"
  49 #include "runtime/handles.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/objectMonitor.hpp"
  53 #include "runtime/objectMonitor.inline.hpp"
  54 #include "runtime/os.inline.hpp"
  55 #include "runtime/thread.inline.hpp"

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


 704       }
 705     }
 706   }
 707 
 708   JvmtiEnvBase::set_phase(JVMTI_PHASE_DEAD);
 709   JvmtiEventController::vm_death();
 710 }
 711 
 712 char**
 713 JvmtiExport::get_all_native_method_prefixes(int* count_ptr) {
 714   // Have to grab JVMTI thread state lock to be sure environment doesn't
 715   // go away while we iterate them.  No locks during VM bring-up.
 716   if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) {
 717     return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
 718   } else {
 719     MutexLocker mu(JvmtiThreadState_lock);
 720     return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
 721   }
 722 }
 723 






































































































 724 class JvmtiClassFileLoadHookPoster : public StackObj {
 725  private:
 726   Symbol*            _h_name;
 727   Handle               _class_loader;
 728   Handle               _h_protection_domain;
 729   unsigned char **     _data_ptr;
 730   unsigned char **     _end_ptr;
 731   JavaThread *         _thread;
 732   jint                 _curr_len;
 733   unsigned char *      _curr_data;
 734   JvmtiEnv *           _curr_env;
 735   JvmtiCachedClassFileData ** _cached_class_file_ptr;
 736   JvmtiThreadState *   _state;
 737   Klass*               _class_being_redefined;
 738   JvmtiClassLoadKind   _load_kind;
 739   bool                 _has_been_modified;
 740 
 741  public:
 742   inline JvmtiClassFileLoadHookPoster(Symbol* h_name, Handle class_loader,
 743                                       Handle h_protection_domain,


2668   _allocated->push(obj);
2669 }
2670 
2671 // GC support.
2672 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
2673   if (_allocated != NULL) {
2674     for(int i=_allocated->length() - 1; i >= 0; i--) {
2675       if (_allocated->at(i) != NULL) {
2676         f->do_oop(_allocated->adr_at(i));
2677       }
2678     }
2679   }
2680 }
2681 
2682 void JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(OopClosure* f) {
2683   // no-op if jvmti not enabled
2684   if (!JvmtiEnv::environments_might_exist()) {
2685     return;
2686   }
2687 
2688   // Runs at safepoint. So no need to acquire Threads_lock.
2689   for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) {
2690     JvmtiThreadState *state = jthr->jvmti_thread_state();
2691     if (state != NULL) {
2692       JvmtiVMObjectAllocEventCollector *collector;
2693       collector = state->get_vm_object_alloc_event_collector();
2694       while (collector != NULL) {
2695         collector->oops_do(f);
2696         collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
2697       }
2698     }
2699   }
2700 }
2701 
2702 
2703 // Disable collection of VMObjectAlloc events
2704 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
2705   // a no-op if VMObjectAlloc event is not enabled
2706   if (!JvmtiExport::should_post_vm_object_alloc()) {
2707     return;
2708   }
2709   Thread* thread = Thread::current_or_null();




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


 705       }
 706     }
 707   }
 708 
 709   JvmtiEnvBase::set_phase(JVMTI_PHASE_DEAD);
 710   JvmtiEventController::vm_death();
 711 }
 712 
 713 char**
 714 JvmtiExport::get_all_native_method_prefixes(int* count_ptr) {
 715   // Have to grab JVMTI thread state lock to be sure environment doesn't
 716   // go away while we iterate them.  No locks during VM bring-up.
 717   if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) {
 718     return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
 719   } else {
 720     MutexLocker mu(JvmtiThreadState_lock);
 721     return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
 722   }
 723 }
 724 
 725 // Convert an external thread reference to a JavaThread found on the
 726 // specified ThreadsList. The ThreadsListHandle in the caller "protects"
 727 // the returned JavaThread *.
 728 //
 729 // If thread_oop_p is not NULL, then the caller wants to use the oop
 730 // after this call so the oop is returned. On success, *jt_pp is set
 731 // to the converted JavaThread * and JVMTI_ERROR_NONE is returned.
 732 // On error, returns various JVMTI_ERROR_* values.
 733 //
 734 jvmtiError
 735 JvmtiExport::cv_external_thread_to_JavaThread(ThreadsList * t_list,
 736                                               jthread thread,
 737                                               JavaThread ** jt_pp,
 738                                               oop * thread_oop_p) {
 739   assert(t_list != NULL, "must have a ThreadsList");
 740   assert(jt_pp != NULL, "must have a return JavaThread pointer");
 741   // thread_oop_p is optional so no assert()
 742 
 743   oop thread_oop = JNIHandles::resolve_external_guard(thread);
 744   if (thread_oop == NULL) {
 745     // NULL jthread, GC'ed jthread or a bad JNI handle.
 746     return JVMTI_ERROR_INVALID_THREAD;
 747   }
 748   // Looks like an oop at this point.
 749 
 750   if (!thread_oop->is_a(SystemDictionary::Thread_klass())) {
 751     // The oop is not a java.lang.Thread.
 752     return JVMTI_ERROR_INVALID_THREAD;
 753   }
 754   // Looks like a java.lang.Thread oop at this point.
 755 
 756   if (thread_oop_p != NULL) {
 757     // Return the oop to the caller; the caller may still want
 758     // the oop even if this function returns an error.
 759     *thread_oop_p = thread_oop;
 760   }
 761 
 762   JavaThread * java_thread = java_lang_Thread::thread(thread_oop);
 763   if (java_thread == NULL) {
 764     // The java.lang.Thread does not contain a JavaThread * so it has
 765     // not yet run or it has died.
 766     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 767   }
 768   // Looks like a live JavaThread at this point.
 769 
 770   // We do not check the EnableThreadSMRExtraValidityChecks option
 771   // for this includes() call because JVM/TI's spec is tighter.
 772   if (!t_list->includes(java_thread)) {
 773     // Not on the JavaThreads list so it is not alive.
 774     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 775   }
 776 
 777   // Return a live JavaThread that is "protected" by the
 778   // ThreadsListHandle in the caller.
 779   *jt_pp = java_thread;
 780 
 781   return JVMTI_ERROR_NONE;
 782 }
 783 
 784 // Convert an oop to a JavaThread found on the specified ThreadsList.
 785 // The ThreadsListHandle in the caller "protects" the returned
 786 // JavaThread *.
 787 //
 788 // On success, *jt_pp is set to the converted JavaThread * and
 789 // JVMTI_ERROR_NONE is returned. On error, returns various
 790 // JVMTI_ERROR_* values.
 791 //
 792 jvmtiError
 793 JvmtiExport::cv_oop_to_JavaThread(ThreadsList * t_list, oop thread_oop,
 794                                   JavaThread ** jt_pp) {
 795   assert(t_list != NULL, "must have a ThreadsList");
 796   assert(thread_oop != NULL, "must have an oop");
 797   assert(jt_pp != NULL, "must have a return JavaThread pointer");
 798 
 799   if (!thread_oop->is_a(SystemDictionary::Thread_klass())) {
 800     // The oop is not a java.lang.Thread.
 801     return JVMTI_ERROR_INVALID_THREAD;
 802   }
 803   // Looks like a java.lang.Thread oop at this point.
 804 
 805   JavaThread * java_thread = java_lang_Thread::thread(thread_oop);
 806   if (java_thread == NULL) {
 807     // The java.lang.Thread does not contain a JavaThread * so it has
 808     // not yet run or it has died.
 809     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 810   }
 811   // Looks like a live JavaThread at this point.
 812 
 813   // We do not check the EnableThreadSMRExtraValidityChecks option
 814   // for this includes() call because JVM/TI's spec is tighter.
 815   if (!t_list->includes(java_thread)) {
 816     // Not on the JavaThreads list so it is not alive.
 817     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 818   }
 819 
 820   // Return a live JavaThread that is "protected" by the
 821   // ThreadsListHandle in the caller.
 822   *jt_pp = java_thread;
 823 
 824   return JVMTI_ERROR_NONE;
 825 }
 826 
 827 class JvmtiClassFileLoadHookPoster : public StackObj {
 828  private:
 829   Symbol*            _h_name;
 830   Handle               _class_loader;
 831   Handle               _h_protection_domain;
 832   unsigned char **     _data_ptr;
 833   unsigned char **     _end_ptr;
 834   JavaThread *         _thread;
 835   jint                 _curr_len;
 836   unsigned char *      _curr_data;
 837   JvmtiEnv *           _curr_env;
 838   JvmtiCachedClassFileData ** _cached_class_file_ptr;
 839   JvmtiThreadState *   _state;
 840   Klass*               _class_being_redefined;
 841   JvmtiClassLoadKind   _load_kind;
 842   bool                 _has_been_modified;
 843 
 844  public:
 845   inline JvmtiClassFileLoadHookPoster(Symbol* h_name, Handle class_loader,
 846                                       Handle h_protection_domain,


2771   _allocated->push(obj);
2772 }
2773 
2774 // GC support.
2775 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
2776   if (_allocated != NULL) {
2777     for(int i=_allocated->length() - 1; i >= 0; i--) {
2778       if (_allocated->at(i) != NULL) {
2779         f->do_oop(_allocated->adr_at(i));
2780       }
2781     }
2782   }
2783 }
2784 
2785 void JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(OopClosure* f) {
2786   // no-op if jvmti not enabled
2787   if (!JvmtiEnv::environments_might_exist()) {
2788     return;
2789   }
2790 
2791   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jthr = jtiwh.next(); ) {

2792     JvmtiThreadState *state = jthr->jvmti_thread_state();
2793     if (state != NULL) {
2794       JvmtiVMObjectAllocEventCollector *collector;
2795       collector = state->get_vm_object_alloc_event_collector();
2796       while (collector != NULL) {
2797         collector->oops_do(f);
2798         collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
2799       }
2800     }
2801   }
2802 }
2803 
2804 
2805 // Disable collection of VMObjectAlloc events
2806 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
2807   // a no-op if VMObjectAlloc event is not enabled
2808   if (!JvmtiExport::should_post_vm_object_alloc()) {
2809     return;
2810   }
2811   Thread* thread = Thread::current_or_null();


< prev index next >