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;
|
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/g1BarrierSet.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 G1BarrierSet::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;
|