1 /* |
1 /* |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" |
26 #include "classfile/systemDictionary.hpp" |
27 #include "memory/universe.inline.hpp" |
27 #include "memory/universe.inline.hpp" |
28 #include "prims/jvmtiGetLoadedClasses.hpp" |
28 #include "prims/jvmtiGetLoadedClasses.hpp" |
29 #include "runtime/thread.hpp" |
29 #include "runtime/thread.hpp" |
|
30 #if INCLUDE_ALL_GCS |
|
31 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
|
32 #endif |
30 |
33 |
31 |
34 |
32 // The closure for GetLoadedClasses |
35 // The closure for GetLoadedClasses |
33 class LoadedClassesClosure : public KlassClosure { |
36 class LoadedClassesClosure : public KlassClosure { |
34 private: |
37 private: |
35 Stack<jclass, mtInternal> _classStack; |
38 Stack<jclass, mtInternal> _classStack; |
36 JvmtiEnv* _env; |
39 JvmtiEnv* _env; |
37 |
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 |
38 public: |
55 public: |
39 LoadedClassesClosure(JvmtiEnv* env) { |
56 LoadedClassesClosure(JvmtiEnv* env) { |
40 _env = env; |
57 _env = env; |
41 } |
58 } |
42 |
59 |
43 void do_klass(Klass* k) { |
60 void do_klass(Klass* k) { |
44 // Collect all jclasses |
61 // Collect all jclasses |
45 _classStack.push((jclass) _env->jni_reference(k->java_mirror())); |
62 _classStack.push((jclass) _env->jni_reference(k->java_mirror())); |
|
63 ensure_klass_alive(k->java_mirror()); |
46 } |
64 } |
47 |
65 |
48 int extract(jclass* result_list) { |
66 int extract(jclass* result_list) { |
49 // The size of the Stack will be 0 after extract, so get it here |
67 // The size of the Stack will be 0 after extract, so get it here |
50 int count = (int)_classStack.size(); |
68 int count = (int)_classStack.size(); |