11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "classfile/systemDictionary.hpp"
26 #include "gc/shared/collectedHeap.hpp"
27 #include "memory/universe.inline.hpp"
28 #include "prims/jvmtiGetLoadedClasses.hpp"
29 #include "runtime/thread.hpp"
30 #include "utilities/stack.inline.hpp"
31 #if INCLUDE_ALL_GCS
32 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
33 #endif
34
35
36 // The closure for GetLoadedClasses
37 class LoadedClassesClosure : public KlassClosure {
38 private:
39 Stack<jclass, mtInternal> _classStack;
40 JvmtiEnv* _env;
41 Thread* _cur_thread;
42
43 // Tell the GC to keep this klass alive
44 static void ensure_klass_alive(oop o) {
45 // A klass that was previously considered dead can be looked up in the
46 // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
47 // or a reachable object making it alive again. The SATB part of G1 needs
48 // to get notified about this potential resurrection, otherwise the marking
49 // might not find the object.
50 #if INCLUDE_ALL_GCS
51 if (UseG1GC && o != NULL) {
52 G1SATBCardTableModRefBS::enqueue(o);
53 }
54 #endif
55 }
56
57 public:
58 LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
59 assert(_cur_thread == Thread::current(), "must be current thread");
60 }
61
62 void do_klass(Klass* k) {
63 // Collect all jclasses
64 _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
65 ensure_klass_alive(k->java_mirror());
66 }
67
68 int extract(jclass* result_list) {
69 // The size of the Stack will be 0 after extract, so get it here
70 int count = (int)_classStack.size();
71 int i = count;
72
73 // Pop all jclasses, fill backwards
74 while (!_classStack.is_empty()) {
75 result_list[--i] = _classStack.pop();
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();
|
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "classfile/systemDictionary.hpp"
26 #include "gc/shared/collectedHeap.hpp"
27 #include "memory/universe.inline.hpp"
28 #include "prims/jvmtiGetLoadedClasses.hpp"
29 #include "runtime/thread.hpp"
30 #include "utilities/stack.inline.hpp"
31
32
33 // The closure for GetLoadedClasses
34 class LoadedClassesClosure : public KlassClosure {
35 private:
36 Stack<jclass, mtInternal> _classStack;
37 JvmtiEnv* _env;
38 Thread* _cur_thread;
39
40 public:
41 LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
42 assert(_cur_thread == Thread::current(), "must be current thread");
43 }
44
45 void do_klass(Klass* k) {
46 // Collect all jclasses
47 oop mirror = k->java_mirror_phantom(); // make sure the class is not unloaded during
48 // concurrent marking by using the phantom getter.
49 _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, mirror)));
50 }
51
52 int extract(jclass* result_list) {
53 // The size of the Stack will be 0 after extract, so get it here
54 int count = (int)_classStack.size();
55 int i = count;
56
57 // Pop all jclasses, fill backwards
58 while (!_classStack.is_empty()) {
59 result_list[--i] = _classStack.pop();
60 }
61
62 // Return the number of elements written
63 return count;
64 }
65
66 // Return current size of the Stack
67 int get_count() {
68 return (int)_classStack.size();
|