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 "cds/aotClassLinker.hpp"
26 #include "cds/aotArtifactFinder.hpp"
27 #include "cds/aotClassInitializer.hpp"
28 #include "cds/dumpTimeClassInfo.inline.hpp"
29 #include "cds/heapShared.hpp"
30 #include "cds/lambdaProxyClassDictionary.hpp"
31 #include "classfile/systemDictionaryShared.hpp"
32 #include "logging/log.hpp"
33 #include "memory/metaspaceClosure.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/objArrayKlass.hpp"
36 #include "utilities/resourceHash.hpp"
37
38 // All the classes that should be included in the AOT cache (in at least the "allocated" state)
39 static GrowableArrayCHeap<Klass*, mtClassShared>* _all_cached_classes = nullptr;
40
41 // This is a stack that tracks all the AOT-inited classes that are waiting to be passed
42 // to HeapShared::copy_and_rescan_aot_inited_mirror().
43 static GrowableArrayCHeap<InstanceKlass*, mtClassShared>* _pending_aot_inited_classes = nullptr;
44
45 static const int TABLE_SIZE = 15889; // prime number
46 using ClassesTable = ResourceHashtable<Klass*, bool, TABLE_SIZE, AnyObj::C_HEAP, mtClassShared>;
47 static ClassesTable* _seen_classes; // all classes that have been seen by AOTArtifactFinder
48 static ClassesTable* _aot_inited_classes; // all classes that need to be AOT-initialized.
49
50 void AOTArtifactFinder::initialize() {
51 _all_cached_classes = new GrowableArrayCHeap<Klass*, mtClassShared>();
52 _pending_aot_inited_classes = new GrowableArrayCHeap<InstanceKlass*, mtClassShared>();
53 _seen_classes = new (mtClass)ClassesTable();
54 _aot_inited_classes = new (mtClass)ClassesTable();
55 }
145 InstanceKlass* ik = _pending_aot_inited_classes->pop();
146 HeapShared::copy_and_rescan_aot_inited_mirror(ik);
147 }
148 }
149 #endif
150
151 // Exclude all the (hidden) classes that have not been discovered by the code above.
152 SystemDictionaryShared::dumptime_table()->iterate_all_live_classes([&] (InstanceKlass* k, DumpTimeClassInfo& info) {
153 if (!info.is_excluded() && _seen_classes->get(k) == nullptr) {
154 info.set_excluded();
155 info.set_has_checked_exclusion();
156 if (log_is_enabled(Debug, cds)) {
157 ResourceMark rm;
158 log_debug(cds)("Skipping %s: %s class", k->name()->as_C_string(),
159 k->is_hidden() ? "Unreferenced hidden" : "AOT tooling");
160 }
161 }
162 });
163
164 end_scanning_for_oops();
165 }
166
167 void AOTArtifactFinder::start_scanning_for_oops() {
168 #if INCLUDE_CDS_JAVA_HEAP
169 if (CDSConfig::is_dumping_heap()) {
170 HeapShared::start_scanning_for_oops();
171 }
172 #endif
173 }
174
175 void AOTArtifactFinder::end_scanning_for_oops() {
176 #if INCLUDE_CDS_JAVA_HEAP
177 if (CDSConfig::is_dumping_heap()) {
178 HeapShared::end_scanning_for_oops();
179 }
180 #endif
181 }
182
183 void AOTArtifactFinder::add_aot_inited_class(InstanceKlass* ik) {
184 if (CDSConfig::is_initing_classes_at_dump_time()) {
|
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 "cds/aotClassLinker.hpp"
26 #include "cds/aotArtifactFinder.hpp"
27 #include "cds/aotClassInitializer.hpp"
28 #include "cds/dumpTimeClassInfo.inline.hpp"
29 #include "cds/heapShared.hpp"
30 #include "cds/lambdaProxyClassDictionary.hpp"
31 #include "classfile/systemDictionaryShared.hpp"
32 #include "logging/log.hpp"
33 #include "memory/metaspaceClosure.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/objArrayKlass.hpp"
36 #include "oops/trainingData.hpp"
37 #include "utilities/resourceHash.hpp"
38
39 // All the classes that should be included in the AOT cache (in at least the "allocated" state)
40 static GrowableArrayCHeap<Klass*, mtClassShared>* _all_cached_classes = nullptr;
41
42 // This is a stack that tracks all the AOT-inited classes that are waiting to be passed
43 // to HeapShared::copy_and_rescan_aot_inited_mirror().
44 static GrowableArrayCHeap<InstanceKlass*, mtClassShared>* _pending_aot_inited_classes = nullptr;
45
46 static const int TABLE_SIZE = 15889; // prime number
47 using ClassesTable = ResourceHashtable<Klass*, bool, TABLE_SIZE, AnyObj::C_HEAP, mtClassShared>;
48 static ClassesTable* _seen_classes; // all classes that have been seen by AOTArtifactFinder
49 static ClassesTable* _aot_inited_classes; // all classes that need to be AOT-initialized.
50
51 void AOTArtifactFinder::initialize() {
52 _all_cached_classes = new GrowableArrayCHeap<Klass*, mtClassShared>();
53 _pending_aot_inited_classes = new GrowableArrayCHeap<InstanceKlass*, mtClassShared>();
54 _seen_classes = new (mtClass)ClassesTable();
55 _aot_inited_classes = new (mtClass)ClassesTable();
56 }
146 InstanceKlass* ik = _pending_aot_inited_classes->pop();
147 HeapShared::copy_and_rescan_aot_inited_mirror(ik);
148 }
149 }
150 #endif
151
152 // Exclude all the (hidden) classes that have not been discovered by the code above.
153 SystemDictionaryShared::dumptime_table()->iterate_all_live_classes([&] (InstanceKlass* k, DumpTimeClassInfo& info) {
154 if (!info.is_excluded() && _seen_classes->get(k) == nullptr) {
155 info.set_excluded();
156 info.set_has_checked_exclusion();
157 if (log_is_enabled(Debug, cds)) {
158 ResourceMark rm;
159 log_debug(cds)("Skipping %s: %s class", k->name()->as_C_string(),
160 k->is_hidden() ? "Unreferenced hidden" : "AOT tooling");
161 }
162 }
163 });
164
165 end_scanning_for_oops();
166
167 TrainingData::cleanup_training_data();
168 }
169
170 void AOTArtifactFinder::start_scanning_for_oops() {
171 #if INCLUDE_CDS_JAVA_HEAP
172 if (CDSConfig::is_dumping_heap()) {
173 HeapShared::start_scanning_for_oops();
174 }
175 #endif
176 }
177
178 void AOTArtifactFinder::end_scanning_for_oops() {
179 #if INCLUDE_CDS_JAVA_HEAP
180 if (CDSConfig::is_dumping_heap()) {
181 HeapShared::end_scanning_for_oops();
182 }
183 #endif
184 }
185
186 void AOTArtifactFinder::add_aot_inited_class(InstanceKlass* ik) {
187 if (CDSConfig::is_initing_classes_at_dump_time()) {
|