< prev index next >

src/hotspot/share/cds/aotLinkedClassBulkLoader.cpp

Print this page

  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 #include "cds/aotClassInitializer.hpp"
 26 #include "cds/aotClassLinker.hpp"
 27 #include "cds/aotLinkedClassBulkLoader.hpp"
 28 #include "cds/aotLinkedClassTable.hpp"
 29 #include "cds/cdsConfig.hpp"
 30 #include "cds/heapShared.hpp"
 31 #include "classfile/classLoaderData.hpp"
 32 #include "classfile/classLoaderDataShared.hpp"
 33 #include "classfile/javaClasses.hpp"
 34 #include "classfile/systemDictionary.hpp"
 35 #include "classfile/systemDictionaryShared.hpp"
 36 #include "classfile/vmClasses.hpp"
 37 #include "compiler/compilationPolicy.hpp"
 38 #include "gc/shared/gcVMOperations.hpp"
 39 #include "memory/resourceArea.hpp"
 40 #include "oops/instanceKlass.hpp"
 41 #include "oops/klass.inline.hpp"
 42 #include "oops/trainingData.hpp"
 43 #include "runtime/handles.inline.hpp"
 44 #include "runtime/java.hpp"

 45 #include "runtime/serviceThread.hpp"
 46 #include "utilities/growableArray.hpp"
 47 



 48 void AOTLinkedClassBulkLoader::serialize(SerializeClosure* soc) {
 49   AOTLinkedClassTable::get()->serialize(soc);






 50 }
 51 
 52 // This function is called before the VM executes any Java code (include AOT-compiled Java methods).
 53 //
 54 // We populate the boot/platform/app class loaders with classes from the AOT cache. This is a fundamental
 55 // step in restoring the JVM's state from the snapshot recorded in the AOT cache: other AOT optimizations
 56 // such as AOT compiled methods can make direct references to the preloaded classes, knowing that
 57 // these classes are guaranteed to be in at least the "loaded" state.
 58 //
 59 // Note: we can't link the classes yet because SharedRuntime is not yet ready to generate adapters.
 60 void AOTLinkedClassBulkLoader::preload_classes(JavaThread* current) {
 61   preload_classes_impl(current);
 62   if (current->has_pending_exception()) {
 63     exit_on_exception(current);
 64   }
 65 }
 66 
 67 void AOTLinkedClassBulkLoader::preload_classes_impl(TRAPS) {
 68   precond(CDSConfig::is_using_aot_linked_classes());
 69 

 76   preload_classes_in_table(table->boot1(), "boot1", Handle(), CHECK);
 77   preload_classes_in_table(table->boot2(), "boot2", Handle(), CHECK);
 78 
 79   initiate_loading(THREAD, "plat", h_platform_loader, table->boot1());
 80   initiate_loading(THREAD, "plat", h_platform_loader, table->boot2());
 81   preload_classes_in_table(table->platform(), "plat", h_platform_loader, CHECK);
 82 
 83   initiate_loading(THREAD, "app", h_system_loader, table->boot1());
 84   initiate_loading(THREAD, "app", h_system_loader, table->boot2());
 85   initiate_loading(THREAD, "app", h_system_loader, table->platform());
 86   preload_classes_in_table(table->app(), "app", h_system_loader, CHECK);
 87 }
 88 
 89 void AOTLinkedClassBulkLoader::preload_classes_in_table(Array<InstanceKlass*>* classes,
 90                                                         const char* category_name, Handle loader, TRAPS) {
 91   if (classes == nullptr) {
 92     return;
 93   }
 94 
 95   for (int i = 0; i < classes->length(); i++) {




 96     InstanceKlass* ik = classes->at(i);
 97     if (log_is_enabled(Info, aot, load)) {
 98       ResourceMark rm(THREAD);
 99       log_info(aot, load)("%-5s %s%s", category_name, ik->external_name(),
100                           ik->is_hidden() ? " (hidden)" : "");
101     }
102 
103     SystemDictionary::preload_class(loader, ik, CHECK);
104 
105     if (ik->is_hidden()) {
106       DEBUG_ONLY({
107         // Make sure we don't make this hidden class available by name, even if we don't
108         // use any special ClassLoaderData.
109         ResourceMark rm(THREAD);
110         assert(SystemDictionary::find_instance_klass(THREAD, ik->name(), loader) == nullptr,
111                "hidden classes cannot be accessible by name: %s", ik->external_name());
112       });
113     } else {
114       precond(SystemDictionary::find_instance_klass(THREAD, ik->name(), loader) == ik);
115     }

345 void AOTLinkedClassBulkLoader::replay_training_at_init(Array<InstanceKlass*>* classes, TRAPS) {
346   if (classes != nullptr) {
347     for (int i = 0; i < classes->length(); i++) {
348       InstanceKlass* ik = classes->at(i);
349       if (ik->has_aot_initialized_mirror() && ik->is_initialized() && !ik->has_init_deps_processed()) {
350         CompilationPolicy::replay_training_at_init(ik, CHECK);
351       }
352     }
353   }
354 }
355 
356 void AOTLinkedClassBulkLoader::replay_training_at_init_for_preloaded_classes(TRAPS) {
357   if (CDSConfig::is_using_aot_linked_classes() && TrainingData::have_data()) {
358     AOTLinkedClassTable* table = AOTLinkedClassTable::get();
359     replay_training_at_init(table->boot1(),    CHECK);
360     replay_training_at_init(table->boot2(),    CHECK);
361     replay_training_at_init(table->platform(), CHECK);
362     replay_training_at_init(table->app(),      CHECK);
363   }
364 }











  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 #include "cds/aotCacheAccess.hpp"
 26 #include "cds/aotClassInitializer.hpp"
 27 #include "cds/aotClassLinker.hpp"
 28 #include "cds/aotLinkedClassBulkLoader.hpp"
 29 #include "cds/aotLinkedClassTable.hpp"
 30 #include "cds/cdsConfig.hpp"
 31 #include "cds/heapShared.hpp"
 32 #include "classfile/classLoaderData.hpp"
 33 #include "classfile/classLoaderDataShared.hpp"
 34 #include "classfile/javaClasses.hpp"
 35 #include "classfile/systemDictionary.hpp"
 36 #include "classfile/systemDictionaryShared.hpp"
 37 #include "classfile/vmClasses.hpp"
 38 #include "compiler/compilationPolicy.hpp"
 39 #include "gc/shared/gcVMOperations.hpp"
 40 #include "memory/resourceArea.hpp"
 41 #include "oops/instanceKlass.hpp"
 42 #include "oops/klass.inline.hpp"
 43 #include "oops/trainingData.hpp"
 44 #include "runtime/handles.inline.hpp"
 45 #include "runtime/java.hpp"
 46 #include "runtime/perfData.inline.hpp"
 47 #include "runtime/serviceThread.hpp"
 48 #include "utilities/growableArray.hpp"
 49 
 50 static PerfCounter* _perf_classes_preloaded = nullptr;
 51 static PerfTickCounters* _perf_class_preload_counters = nullptr;
 52 
 53 void AOTLinkedClassBulkLoader::serialize(SerializeClosure* soc) {
 54   AOTLinkedClassTable::get()->serialize(soc);
 55 
 56   if (soc->reading() && UsePerfData) {
 57     JavaThread* THREAD = JavaThread::current();
 58     NEWPERFEVENTCOUNTER(_perf_classes_preloaded, SUN_CLS, "preloadedClasses");
 59     NEWPERFTICKCOUNTERS(_perf_class_preload_counters, SUN_CLS, "classPreload");
 60   }
 61 }
 62 
 63 // This function is called before the VM executes any Java code (include AOT-compiled Java methods).
 64 //
 65 // We populate the boot/platform/app class loaders with classes from the AOT cache. This is a fundamental
 66 // step in restoring the JVM's state from the snapshot recorded in the AOT cache: other AOT optimizations
 67 // such as AOT compiled methods can make direct references to the preloaded classes, knowing that
 68 // these classes are guaranteed to be in at least the "loaded" state.
 69 //
 70 // Note: we can't link the classes yet because SharedRuntime is not yet ready to generate adapters.
 71 void AOTLinkedClassBulkLoader::preload_classes(JavaThread* current) {
 72   preload_classes_impl(current);
 73   if (current->has_pending_exception()) {
 74     exit_on_exception(current);
 75   }
 76 }
 77 
 78 void AOTLinkedClassBulkLoader::preload_classes_impl(TRAPS) {
 79   precond(CDSConfig::is_using_aot_linked_classes());
 80 

 87   preload_classes_in_table(table->boot1(), "boot1", Handle(), CHECK);
 88   preload_classes_in_table(table->boot2(), "boot2", Handle(), CHECK);
 89 
 90   initiate_loading(THREAD, "plat", h_platform_loader, table->boot1());
 91   initiate_loading(THREAD, "plat", h_platform_loader, table->boot2());
 92   preload_classes_in_table(table->platform(), "plat", h_platform_loader, CHECK);
 93 
 94   initiate_loading(THREAD, "app", h_system_loader, table->boot1());
 95   initiate_loading(THREAD, "app", h_system_loader, table->boot2());
 96   initiate_loading(THREAD, "app", h_system_loader, table->platform());
 97   preload_classes_in_table(table->app(), "app", h_system_loader, CHECK);
 98 }
 99 
100 void AOTLinkedClassBulkLoader::preload_classes_in_table(Array<InstanceKlass*>* classes,
101                                                         const char* category_name, Handle loader, TRAPS) {
102   if (classes == nullptr) {
103     return;
104   }
105 
106   for (int i = 0; i < classes->length(); i++) {
107     if (UsePerfData) {
108       _perf_classes_preloaded->inc();
109     }
110 
111     InstanceKlass* ik = classes->at(i);
112     if (log_is_enabled(Info, aot, load)) {
113       ResourceMark rm(THREAD);
114       log_info(aot, load)("%-5s %s%s", category_name, ik->external_name(),
115                           ik->is_hidden() ? " (hidden)" : "");
116     }
117 
118     SystemDictionary::preload_class(loader, ik, CHECK);
119 
120     if (ik->is_hidden()) {
121       DEBUG_ONLY({
122         // Make sure we don't make this hidden class available by name, even if we don't
123         // use any special ClassLoaderData.
124         ResourceMark rm(THREAD);
125         assert(SystemDictionary::find_instance_klass(THREAD, ik->name(), loader) == nullptr,
126                "hidden classes cannot be accessible by name: %s", ik->external_name());
127       });
128     } else {
129       precond(SystemDictionary::find_instance_klass(THREAD, ik->name(), loader) == ik);
130     }

360 void AOTLinkedClassBulkLoader::replay_training_at_init(Array<InstanceKlass*>* classes, TRAPS) {
361   if (classes != nullptr) {
362     for (int i = 0; i < classes->length(); i++) {
363       InstanceKlass* ik = classes->at(i);
364       if (ik->has_aot_initialized_mirror() && ik->is_initialized() && !ik->has_init_deps_processed()) {
365         CompilationPolicy::replay_training_at_init(ik, CHECK);
366       }
367     }
368   }
369 }
370 
371 void AOTLinkedClassBulkLoader::replay_training_at_init_for_preloaded_classes(TRAPS) {
372   if (CDSConfig::is_using_aot_linked_classes() && TrainingData::have_data()) {
373     AOTLinkedClassTable* table = AOTLinkedClassTable::get();
374     replay_training_at_init(table->boot1(),    CHECK);
375     replay_training_at_init(table->boot2(),    CHECK);
376     replay_training_at_init(table->platform(), CHECK);
377     replay_training_at_init(table->app(),      CHECK);
378   }
379 }
380 
381 void AOTLinkedClassBulkLoader::print_counters_on(outputStream* st) {
382   if (UsePerfData && _perf_class_preload_counters != nullptr) {
383     st->print_cr("AOTLinkedClassBulkLoader:");
384     st->print_cr("  preload:           " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) " (thread) / " JLONG_FORMAT_W(5) " events",
385                  _perf_class_preload_counters->elapsed_counter_value_us(),
386                  _perf_class_preload_counters->thread_counter_value_us(),
387                  _perf_classes_preloaded->get_value());
388   }
389 }
< prev index next >