< prev index next >

src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp

Print this page

  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 

 25 #include "precompiled.hpp"
 26 #include "classfile/classLoaderDataGraph.hpp"
 27 #include "classfile/dictionary.hpp"
 28 #include "classfile/javaClasses.hpp"
 29 #include "gc/shared/collectedHeap.hpp"
 30 #include "memory/universe.hpp"
 31 #include "oops/klass.inline.hpp"
 32 #include "prims/jvmtiGetLoadedClasses.hpp"
 33 #include "runtime/handles.inline.hpp"
 34 #include "runtime/javaThread.hpp"
 35 #include "runtime/jniHandles.inline.hpp"
 36 #include "utilities/stack.inline.hpp"
 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   bool      _dictionary_walk;

 61   int get_count() {
 62     return (int)_classStack.size();
 63   }
 64 
 65 public:
 66   LoadedClassesClosure(JvmtiEnv* env, bool dictionary_walk) :
 67       _env(env),
 68       _cur_thread(Thread::current()),
 69       _dictionary_walk(dictionary_walk) {
 70   }
 71 
 72   void do_klass(Klass* k) {
 73     // Collect all jclasses
 74     _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
 75     if (_dictionary_walk) {
 76       // Collect array classes this way when walking the dictionary (because array classes are
 77       // not in the dictionary).
 78       for (Klass* l = k->array_klass_or_null(); l != nullptr; l = l->array_klass_or_null()) {
 79         _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, l->java_mirror())));
 80       }

 81     }
 82   }
 83 
 84   jvmtiError get_result(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
 85     // Return results by extracting the collected contents into a list
 86     // allocated via JvmtiEnv
 87     jclass* result_list;
 88     jvmtiError error = env->Allocate(get_count() * sizeof(jclass),
 89                                (unsigned char**)&result_list);
 90 
 91     if (error == JVMTI_ERROR_NONE) {
 92       int count = extract(result_list);
 93       *classCountPtr = count;
 94       *classesPtr = result_list;
 95     }
 96     return error;
 97   }
 98 };
 99 
100 jvmtiError

  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include <oops/inlineKlass.hpp>
 26 #include "precompiled.hpp"
 27 #include "classfile/classLoaderDataGraph.hpp"
 28 #include "classfile/dictionary.hpp"
 29 #include "classfile/javaClasses.hpp"
 30 #include "gc/shared/collectedHeap.hpp"
 31 #include "memory/universe.hpp"
 32 #include "oops/klass.inline.hpp"
 33 #include "prims/jvmtiGetLoadedClasses.hpp"
 34 #include "runtime/handles.inline.hpp"
 35 #include "runtime/javaThread.hpp"
 36 #include "runtime/jniHandles.inline.hpp"
 37 #include "utilities/stack.inline.hpp"
 38 
 39 // The closure for GetLoadedClasses
 40 class LoadedClassesClosure : public KlassClosure {
 41 private:
 42   Stack<jclass, mtInternal> _classStack;
 43   JvmtiEnv* _env;
 44   Thread*   _cur_thread;
 45   bool      _dictionary_walk;

 62   int get_count() {
 63     return (int)_classStack.size();
 64   }
 65 
 66 public:
 67   LoadedClassesClosure(JvmtiEnv* env, bool dictionary_walk) :
 68       _env(env),
 69       _cur_thread(Thread::current()),
 70       _dictionary_walk(dictionary_walk) {
 71   }
 72 
 73   void do_klass(Klass* k) {
 74     // Collect all jclasses
 75     _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
 76     if (_dictionary_walk) {
 77       // Collect array classes this way when walking the dictionary (because array classes are
 78       // not in the dictionary).
 79       for (Klass* l = k->array_klass_or_null(); l != nullptr; l = l->array_klass_or_null()) {
 80         _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, l->java_mirror())));
 81       }
 82       // CMH flat arrays (InlineKlass)
 83     }
 84   }
 85 
 86   jvmtiError get_result(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
 87     // Return results by extracting the collected contents into a list
 88     // allocated via JvmtiEnv
 89     jclass* result_list;
 90     jvmtiError error = env->Allocate(get_count() * sizeof(jclass),
 91                                (unsigned char**)&result_list);
 92 
 93     if (error == JVMTI_ERROR_NONE) {
 94       int count = extract(result_list);
 95       *classCountPtr = count;
 96       *classesPtr = result_list;
 97     }
 98     return error;
 99   }
100 };
101 
102 jvmtiError
< prev index next >