< prev index next >

src/share/vm/prims/jvmtiGetLoadedClasses.cpp

Print this page




  29 #include "runtime/thread.hpp"
  30 #if INCLUDE_ALL_GCS
  31 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  32 #endif
  33 
  34 
  35 // The closure for GetLoadedClasses
  36 class LoadedClassesClosure : public KlassClosure {
  37 private:
  38   Stack<jclass, mtInternal> _classStack;
  39   JvmtiEnv* _env;
  40 
  41 // Tell the GC to keep this klass alive
  42 static void ensure_klass_alive(oop o) {
  43   // A klass that was previously considered dead can be looked up in the
  44   // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
  45   // or a reachable object making it alive again. The SATB part of G1 needs
  46   // to get notified about this potential resurrection, otherwise the marking
  47   // might not find the object.
  48 #if INCLUDE_ALL_GCS
  49   if (UseG1GC && o != NULL) {
  50     G1SATBCardTableModRefBS::enqueue(o);
  51   }
  52 #endif
  53 }
  54 
  55 public:
  56   LoadedClassesClosure(JvmtiEnv* env) {
  57     _env = env;
  58   }
  59 
  60   void do_klass(Klass* k) {
  61     // Collect all jclasses
  62     _classStack.push((jclass) _env->jni_reference(k->java_mirror()));
  63     ensure_klass_alive(k->java_mirror());
  64   }
  65 
  66   int extract(jclass* result_list) {
  67     // The size of the Stack will be 0 after extract, so get it here
  68     int count = (int)_classStack.size();
  69     int i = count;
  70 
  71     // Pop all jclasses, fill backwards
  72     while (!_classStack.is_empty()) {
  73       result_list[--i] = _classStack.pop();



  74     }
  75 
  76     // Return the number of elements written
  77     return count;
  78   }
  79 
  80   // Return current size of the Stack
  81   int get_count() {
  82     return (int)_classStack.size();
  83   }
  84 };
  85 
  86 // The closure for GetClassLoaderClasses
  87 class JvmtiGetLoadedClassesClosure : public StackObj {
  88   // Since the SystemDictionary::classes_do callback
  89   // doesn't pass a closureData pointer,
  90   // we use a thread-local slot to hold a pointer to
  91   // a stack allocated instance of this structure.
  92  private:
  93   jobject _initiatingLoader;




  29 #include "runtime/thread.hpp"
  30 #if INCLUDE_ALL_GCS
  31 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  32 #endif
  33 
  34 
  35 // The closure for GetLoadedClasses
  36 class LoadedClassesClosure : public KlassClosure {
  37 private:
  38   Stack<jclass, mtInternal> _classStack;
  39   JvmtiEnv* _env;
  40 
  41 // Tell the GC to keep this klass alive
  42 static void ensure_klass_alive(oop o) {
  43   // A klass that was previously considered dead can be looked up in the
  44   // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
  45   // or a reachable object making it alive again. The SATB part of G1 needs
  46   // to get notified about this potential resurrection, otherwise the marking
  47   // might not find the object.
  48 #if INCLUDE_ALL_GCS
  49   if ((o != NULL) && (UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier))) {
  50     G1SATBCardTableModRefBS::enqueue(o);
  51   }
  52 #endif
  53 }
  54 
  55 public:
  56   LoadedClassesClosure(JvmtiEnv* env) {
  57     _env = env;
  58   }
  59 
  60   void do_klass(Klass* k) {
  61     // Collect all jclasses
  62     _classStack.push((jclass) _env->jni_reference(k->java_mirror()));

  63   }
  64 
  65   int extract(jclass* result_list) {
  66     // The size of the Stack will be 0 after extract, so get it here
  67     int count = (int)_classStack.size();
  68     int i = count;
  69 
  70     // Pop all jclasses, fill backwards
  71     while (!_classStack.is_empty()) {
  72       jclass klass_handle = _classStack.pop();
  73       oop klass_mirror = JNIHandles::resolve(klass_handle);
  74       ensure_klass_alive(klass_mirror);
  75       result_list[--i] = klass_handle;
  76     }
  77 
  78     // Return the number of elements written
  79     return count;
  80   }
  81 
  82   // Return current size of the Stack
  83   int get_count() {
  84     return (int)_classStack.size();
  85   }
  86 };
  87 
  88 // The closure for GetClassLoaderClasses
  89 class JvmtiGetLoadedClassesClosure : public StackObj {
  90   // Since the SystemDictionary::classes_do callback
  91   // doesn't pass a closureData pointer,
  92   // we use a thread-local slot to hold a pointer to
  93   // a stack allocated instance of this structure.
  94  private:
  95   jobject _initiatingLoader;


< prev index next >