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 "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 "classfile/systemDictionaryShared.hpp"
31 #include "logging/log.hpp"
32 #include "memory/metaspaceClosure.hpp"
33 #include "oops/instanceKlass.hpp"
34 #include "oops/objArrayKlass.hpp"
35 #include "utilities/resourceHash.hpp"
36
37 // All the classes that should be included in the AOT cache (in at least the "allocated" state)
38 static GrowableArrayCHeap<Klass*, mtClassShared>* _all_cached_classes = nullptr;
39
40 // This is a stack that tracks all the AOT-inited classes that are waiting to be passed
41 // to HeapShared::copy_and_rescan_aot_inited_mirror().
42 static GrowableArrayCHeap<InstanceKlass*, mtClassShared>* _pending_aot_inited_classes = nullptr;
43
44 static const int TABLE_SIZE = 15889; // prime number
45 using ClassesTable = ResourceHashtable<Klass*, bool, TABLE_SIZE, AnyObj::C_HEAP, mtClassShared>;
46 static ClassesTable* _seen_classes; // all classes that have been seen by AOTArtifactFinder
47 static ClassesTable* _aot_inited_classes; // all classes that need to be AOT-initialized.
48
49 void AOTArtifactFinder::initialize() {
50 _all_cached_classes = new GrowableArrayCHeap<Klass*, mtClassShared>();
51 _pending_aot_inited_classes = new GrowableArrayCHeap<InstanceKlass*, mtClassShared>();
52 _seen_classes = new (mtClass)ClassesTable();
53 _aot_inited_classes = new (mtClass)ClassesTable();
54 }
131 add_aot_inited_class(ik);
132 }
133 }
134 }
135 });
136
137 #if INCLUDE_CDS_JAVA_HEAP
138 // Keep scanning until we discover no more class that need to be AOT-initialized.
139 if (CDSConfig::is_initing_classes_at_dump_time()) {
140 while (_pending_aot_inited_classes->length() > 0) {
141 InstanceKlass* ik = _pending_aot_inited_classes->pop();
142 HeapShared::copy_and_rescan_aot_inited_mirror(ik);
143 }
144 }
145 #endif
146
147 // Exclude all the (hidden) classes that have not been discovered by the code above.
148 SystemDictionaryShared::dumptime_table()->iterate_all_live_classes([&] (InstanceKlass* k, DumpTimeClassInfo& info) {
149 if (!info.is_excluded() && _seen_classes->get(k) == nullptr) {
150 info.set_excluded();
151 assert(k->is_hidden(), "must be");
152 if (log_is_enabled(Info, cds)) {
153 ResourceMark rm;
154 log_info(cds)("Skipping %s: Hidden class", k->name()->as_C_string());
155 }
156 }
157 });
158
159 end_scanning_for_oops();
160 }
161
162 void AOTArtifactFinder::start_scanning_for_oops() {
163 #if INCLUDE_CDS_JAVA_HEAP
164 if (CDSConfig::is_dumping_heap()) {
165 HeapShared::start_scanning_for_oops();
166 }
167 #endif
168 }
169
170 void AOTArtifactFinder::end_scanning_for_oops() {
171 #if INCLUDE_CDS_JAVA_HEAP
172 if (CDSConfig::is_dumping_heap()) {
173 HeapShared::end_scanning_for_oops();
174 }
175 #endif
176 }
177
178 void AOTArtifactFinder::add_aot_inited_class(InstanceKlass* ik) {
179 if (CDSConfig::is_initing_classes_at_dump_time()) {
190 add_aot_inited_class(s);
191 }
192
193 Array<InstanceKlass*>* interfaces = ik->local_interfaces();
194 int len = interfaces->length();
195 for (int i = 0; i < len; i++) {
196 InstanceKlass* intf = interfaces->at(i);
197 if (intf->is_initialized()) {
198 add_aot_inited_class(intf);
199 }
200 }
201 }
202 }
203 }
204
205 void AOTArtifactFinder::add_cached_instance_class(InstanceKlass* ik) {
206 bool created;
207 _seen_classes->put_if_absent(ik, &created);
208 if (created) {
209 _all_cached_classes->append(ik);
210 scan_oops_in_instance_class(ik);
211 if (ik->is_hidden() && CDSConfig::is_initing_classes_at_dump_time()) {
212 bool succeed = AOTClassLinker::try_add_candidate(ik);
213 guarantee(succeed, "All cached hidden classes must be aot-linkable");
214 add_aot_inited_class(ik);
215 }
216 }
217 }
218
219 void AOTArtifactFinder::add_cached_type_array_class(TypeArrayKlass* tak) {
220 bool created;
221 _seen_classes->put_if_absent(tak, &created);
222 if (created) {
223 _all_cached_classes->append(tak);
224 scan_oops_in_array_class(tak);
225 }
226 }
227
228 void AOTArtifactFinder::add_cached_class(Klass* k) {
229 if (k->is_typeArray_klass()) {
|
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 "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 "classfile/systemDictionaryShared.hpp"
31 #include "logging/log.hpp"
32 #include "memory/metaspaceClosure.hpp"
33 #include "oops/instanceKlass.hpp"
34 #include "oops/objArrayKlass.hpp"
35 #include "oops/trainingData.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 }
132 add_aot_inited_class(ik);
133 }
134 }
135 }
136 });
137
138 #if INCLUDE_CDS_JAVA_HEAP
139 // Keep scanning until we discover no more class that need to be AOT-initialized.
140 if (CDSConfig::is_initing_classes_at_dump_time()) {
141 while (_pending_aot_inited_classes->length() > 0) {
142 InstanceKlass* ik = _pending_aot_inited_classes->pop();
143 HeapShared::copy_and_rescan_aot_inited_mirror(ik);
144 }
145 }
146 #endif
147
148 // Exclude all the (hidden) classes that have not been discovered by the code above.
149 SystemDictionaryShared::dumptime_table()->iterate_all_live_classes([&] (InstanceKlass* k, DumpTimeClassInfo& info) {
150 if (!info.is_excluded() && _seen_classes->get(k) == nullptr) {
151 info.set_excluded();
152 info.set_has_checked_exclusion();
153 assert(k->is_hidden(), "must be");
154 if (log_is_enabled(Info, cds)) {
155 ResourceMark rm;
156 log_debug(cds)("Skipping %s: Unreferenced hidden class", k->name()->as_C_string());
157 }
158 }
159 });
160
161 end_scanning_for_oops();
162
163 TrainingData::cleanup_training_data();
164 }
165
166 void AOTArtifactFinder::start_scanning_for_oops() {
167 #if INCLUDE_CDS_JAVA_HEAP
168 if (CDSConfig::is_dumping_heap()) {
169 HeapShared::start_scanning_for_oops();
170 }
171 #endif
172 }
173
174 void AOTArtifactFinder::end_scanning_for_oops() {
175 #if INCLUDE_CDS_JAVA_HEAP
176 if (CDSConfig::is_dumping_heap()) {
177 HeapShared::end_scanning_for_oops();
178 }
179 #endif
180 }
181
182 void AOTArtifactFinder::add_aot_inited_class(InstanceKlass* ik) {
183 if (CDSConfig::is_initing_classes_at_dump_time()) {
194 add_aot_inited_class(s);
195 }
196
197 Array<InstanceKlass*>* interfaces = ik->local_interfaces();
198 int len = interfaces->length();
199 for (int i = 0; i < len; i++) {
200 InstanceKlass* intf = interfaces->at(i);
201 if (intf->is_initialized()) {
202 add_aot_inited_class(intf);
203 }
204 }
205 }
206 }
207 }
208
209 void AOTArtifactFinder::add_cached_instance_class(InstanceKlass* ik) {
210 bool created;
211 _seen_classes->put_if_absent(ik, &created);
212 if (created) {
213 _all_cached_classes->append(ik);
214 if (CDSConfig::is_dumping_final_static_archive() && ik->is_shared_unregistered_class()) {
215 // The following are not appliable to unregistered classes
216 return;
217 }
218 scan_oops_in_instance_class(ik);
219 if (ik->is_hidden() && CDSConfig::is_initing_classes_at_dump_time()) {
220 bool succeed = AOTClassLinker::try_add_candidate(ik);
221 guarantee(succeed, "All cached hidden classes must be aot-linkable");
222 add_aot_inited_class(ik);
223 }
224 }
225 }
226
227 void AOTArtifactFinder::add_cached_type_array_class(TypeArrayKlass* tak) {
228 bool created;
229 _seen_classes->put_if_absent(tak, &created);
230 if (created) {
231 _all_cached_classes->append(tak);
232 scan_oops_in_array_class(tak);
233 }
234 }
235
236 void AOTArtifactFinder::add_cached_class(Klass* k) {
237 if (k->is_typeArray_klass()) {
|