< prev index next >

src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp

Print this page




  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "gc/shared/collectedHeap.hpp"
  28 #include "memory/universe.hpp"
  29 #include "prims/jvmtiGetLoadedClasses.hpp"
  30 #include "runtime/jniHandles.inline.hpp"
  31 #include "runtime/thread.hpp"
  32 #include "utilities/stack.inline.hpp"
  33 #if INCLUDE_ALL_GCS
  34 #include "gc/g1/g1BarrierSet.hpp"
  35 #endif
  36 
  37 
  38 // The closure for GetLoadedClasses
  39 class LoadedClassesClosure : public KlassClosure {
  40 private:
  41   Stack<jclass, mtInternal> _classStack;
  42   JvmtiEnv* _env;
  43   Thread*   _cur_thread;
  44 
  45 // Tell the GC to keep this klass alive
  46 static void ensure_klass_alive(oop o) {
  47   // A klass that was previously considered dead can be looked up in the
  48   // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
  49   // or a reachable object making it alive again. The SATB part of G1 needs
  50   // to get notified about this potential resurrection, otherwise the marking
  51   // might not find the object.
  52 #if INCLUDE_ALL_GCS
  53   if (UseG1GC && o != NULL) {
  54     G1BarrierSet::enqueue(o);
  55   }
  56 #endif
  57 }
  58 
  59 public:
  60   LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
  61     assert(_cur_thread == Thread::current(), "must be current thread");
  62   }
  63 
  64   void do_klass(Klass* k) {
  65     // Collect all jclasses
  66     _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
  67     ensure_klass_alive(k->java_mirror());
  68   }
  69 
  70   int extract(jclass* result_list) {
  71     // The size of the Stack will be 0 after extract, so get it here
  72     int count = (int)_classStack.size();
  73     int i = count;
  74 
  75     // Pop all jclasses, fill backwards
  76     while (!_classStack.is_empty()) {
  77       result_list[--i] = _classStack.pop();
  78     }
  79 
  80     // Return the number of elements written
  81     return count;
  82   }
  83 
  84   // Return current size of the Stack
  85   int get_count() {
  86     return (int)_classStack.size();
  87   }




  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "gc/shared/collectedHeap.hpp"
  28 #include "memory/universe.hpp"
  29 #include "prims/jvmtiGetLoadedClasses.hpp"
  30 #include "runtime/jniHandles.inline.hpp"
  31 #include "runtime/thread.hpp"
  32 #include "utilities/stack.inline.hpp"
  33 #if INCLUDE_ALL_GCS
  34 #include "gc/g1/g1BarrierSet.hpp"
  35 #endif
  36 
  37 
  38 // The closure for GetLoadedClasses
  39 class LoadedClassesClosure : public KlassClosure {
  40 private:
  41   Stack<jclass, mtInternal> _classStack;
  42   JvmtiEnv* _env;
  43   Thread*   _cur_thread;
  44 














  45 public:
  46   LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
  47     assert(_cur_thread == Thread::current(), "must be current thread");
  48   }
  49 
  50   void do_klass(Klass* k) {
  51     // Collect all jclasses
  52     _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));

  53   }
  54 
  55   int extract(jclass* result_list) {
  56     // The size of the Stack will be 0 after extract, so get it here
  57     int count = (int)_classStack.size();
  58     int i = count;
  59 
  60     // Pop all jclasses, fill backwards
  61     while (!_classStack.is_empty()) {
  62       result_list[--i] = _classStack.pop();
  63     }
  64 
  65     // Return the number of elements written
  66     return count;
  67   }
  68 
  69   // Return current size of the Stack
  70   int get_count() {
  71     return (int)_classStack.size();
  72   }


< prev index next >