1 /*
 2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 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
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
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 #ifndef SHARE_CDS_AOTLINKEDCLASSBULKLOADER_HPP
26 #define SHARE_CDS_AOTLINKEDCLASSBULKLOADER_HPP
27 
28 #include "memory/allStatic.hpp"
29 #include "memory/allocation.hpp"
30 #include "runtime/handles.hpp"
31 #include "utilities/exceptions.hpp"
32 #include "utilities/macros.hpp"
33 
34 class AOTLinkedClassTable;
35 class ClassLoaderData;
36 class InstanceKlass;
37 class SerializeClosure;
38 template <typename T> class Array;
39 enum class AOTLinkedClassCategory : int;
40 
41 // During a Production Run, the AOTLinkedClassBulkLoader loads all classes from
42 // a AOTLinkedClassTable into their respective ClassLoaders. This happens very early
43 // in the JVM bootstrap stage, before any application code is executed.
44 //
45 class AOTLinkedClassBulkLoader :  AllStatic {
46   static bool _boot2_completed;
47   static bool _platform_completed;
48   static bool _app_completed;
49   static bool _all_completed;
50   static bool _preloading_non_javavase_classes;
51   static Array<InstanceKlass*>* _unregistered_classes_from_preimage;
52 
53   static void load_classes_in_loader(JavaThread* current, AOTLinkedClassCategory class_category, oop class_loader_oop);
54   static void load_classes_in_loader_impl(AOTLinkedClassCategory class_category, oop class_loader_oop, TRAPS);
55   static void load_table(AOTLinkedClassTable* table, AOTLinkedClassCategory class_category, Handle loader, TRAPS);
56   static void initiate_loading(JavaThread* current, const char* category, Handle initiating_loader, Array<InstanceKlass*>* classes);
57   static void load_classes_impl(AOTLinkedClassCategory class_category, Array<InstanceKlass*>* classes,
58                                 const char* category_name, Handle loader, TRAPS);
59   static void load_hidden_class(ClassLoaderData* loader_data, InstanceKlass* ik, TRAPS);
60   static void init_required_classes_for_loader(Handle class_loader, Array<InstanceKlass*>* classes, TRAPS);
61   static void replay_training_at_init(Array<InstanceKlass*>* classes, TRAPS) NOT_CDS_RETURN;
62 public:
63   static void serialize(SerializeClosure* soc, bool is_static_archive) NOT_CDS_RETURN;
64   static void record_unregistered_classes() NOT_CDS_RETURN;
65   static void load_javabase_classes(JavaThread* current) NOT_CDS_RETURN;
66   static void load_non_javabase_classes(JavaThread* current) NOT_CDS_RETURN;
67   static void finish_loading_javabase_classes(TRAPS) NOT_CDS_RETURN;
68   static void exit_on_exception(JavaThread* current);
69   static void replay_training_at_init_for_preloaded_classes(TRAPS) NOT_CDS_RETURN;
70   static bool class_preloading_finished();
71   static void print_counters_on(outputStream* st) NOT_CDS_RETURN;
72   static bool is_pending_aot_linked_class(Klass* k) NOT_CDS_RETURN_(false);
73 };
74 
75 #endif // SHARE_CDS_AOTLINKEDCLASSBULKLOADER_HPP