src/hotspot/share/aot/aotLoader.cpp
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File open Sdiff src/hotspot/share/aot

src/hotspot/share/aot/aotLoader.cpp

Print this page




 166       }
 167     }
 168 
 169     // Load well-know AOT libraries from Java installation directory.
 170     const char* home = Arguments::get_java_home();
 171     const char* file_separator = os::file_separator();
 172 
 173     for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
 174       char library[JVM_MAXPATHLEN];
 175       jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s%s", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1", os::dll_file_extension());
 176       load_library(library, false);
 177     }
 178   }
 179 }
 180 
 181 void AOTLoader::universe_init() {
 182   if (UseAOT && libraries_count() > 0) {
 183     // Shifts are static values which initialized by 0 until java heap initialization.
 184     // AOT libs are loaded before heap initialized so shift values are not set.
 185     // It is okay since ObjectAlignmentInBytes flag which defines shifts value is set before AOT libs are loaded.
 186     // Set shifts value based on first AOT library config.

 187     if (UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
 188       int oop_shift = Universe::narrow_oop_shift();
 189       if (oop_shift == 0) {
 190         Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift());
 191       } else {
 192         FOR_ALL_AOT_LIBRARIES(lib) {
 193           (*lib)->verify_flag(AOTLib::narrow_oop_shift(), oop_shift, "Universe::narrow_oop_shift");
 194         }
 195       }
 196       if (UseCompressedClassPointers) { // It is set only if UseCompressedOops is set
 197         int klass_shift = Universe::narrow_klass_shift();
 198         if (klass_shift == 0) {
 199           Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
 200         } else {
 201           FOR_ALL_AOT_LIBRARIES(lib) {
 202             (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
 203           }
 204         }
 205       }
 206     }
 207     // Create heaps for all the libraries
 208     FOR_ALL_AOT_LIBRARIES(lib) {
 209       if ((*lib)->is_valid()) {
 210         AOTCodeHeap* heap = new AOTCodeHeap(*lib);
 211         {
 212           MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 213           add_heap(heap);
 214           CodeCache::add_heap(heap);
 215         }



 216       }
 217     }
 218   }
 219   if (heaps_count() == 0) {
 220     if (FLAG_IS_DEFAULT(UseAOT)) {
 221       FLAG_SET_DEFAULT(UseAOT, false);
 222     }
 223   }
 224 }
 225 






















 226 void AOTLoader::set_narrow_klass_shift() {
 227   // This method could be called from Metaspace::set_narrow_klass_base_and_shift().
 228   // In case it is not called (during dump CDS, for example) the corresponding code in
 229   // AOTLoader::universe_init(), which is called later, will set the shift value.
 230   if (UseAOT && libraries_count() > 0 &&
 231       UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
 232       UseCompressedClassPointers) {
 233     int klass_shift = Universe::narrow_klass_shift();
 234     if (klass_shift == 0) {
 235       Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
 236     } else {
 237       FOR_ALL_AOT_LIBRARIES(lib) {
 238         (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
 239       }
 240     }
 241   }
 242 }
 243 
 244 void AOTLoader::load_library(const char* name, bool exit_on_error) {
 245   // Skip library if a library with the same name is already loaded.
 246   const int file_separator = *os::file_separator();
 247   const char* start = strrchr(name, file_separator);
 248   const char* new_name = (start == NULL) ? name : (start + 1);
 249   FOR_ALL_AOT_LIBRARIES(lib) {




 166       }
 167     }
 168 
 169     // Load well-know AOT libraries from Java installation directory.
 170     const char* home = Arguments::get_java_home();
 171     const char* file_separator = os::file_separator();
 172 
 173     for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
 174       char library[JVM_MAXPATHLEN];
 175       jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s%s", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1", os::dll_file_extension());
 176       load_library(library, false);
 177     }
 178   }
 179 }
 180 
 181 void AOTLoader::universe_init() {
 182   if (UseAOT && libraries_count() > 0) {
 183     // Shifts are static values which initialized by 0 until java heap initialization.
 184     // AOT libs are loaded before heap initialized so shift values are not set.
 185     // It is okay since ObjectAlignmentInBytes flag which defines shifts value is set before AOT libs are loaded.
 186     // AOT sets shift values during heap and metaspace initialization.
 187     // Check shifts value to make sure thay did not change.
 188     if (UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
 189       int oop_shift = Universe::narrow_oop_shift();



 190       FOR_ALL_AOT_LIBRARIES(lib) {
 191         (*lib)->verify_flag(AOTLib::narrow_oop_shift(), oop_shift, "Universe::narrow_oop_shift");
 192       }

 193       if (UseCompressedClassPointers) { // It is set only if UseCompressedOops is set
 194         int klass_shift = Universe::narrow_klass_shift();



 195         FOR_ALL_AOT_LIBRARIES(lib) {
 196           (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
 197         }
 198       }
 199     }
 200     // Create heaps for all valid libraries

 201     FOR_ALL_AOT_LIBRARIES(lib) {
 202       if ((*lib)->is_valid()) {
 203         AOTCodeHeap* heap = new AOTCodeHeap(*lib);
 204         {
 205           MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 206           add_heap(heap);
 207           CodeCache::add_heap(heap);
 208         }
 209       } else {
 210         // Unload invalid libraries
 211         os::dll_unload((*lib)->dl_handle());
 212       }
 213     }
 214   }
 215   if (heaps_count() == 0) {
 216     if (FLAG_IS_DEFAULT(UseAOT)) {
 217       FLAG_SET_DEFAULT(UseAOT, false);
 218     }
 219   }
 220 }
 221 
 222 // Set shift value for compressed oops and classes based on first AOT library config.
 223 // AOTLoader::universe_init(), which is called later, will check the shift value again to make sure nobody change it.
 224 // This code is not executed during CDS dump because it runs in Interpreter mode and AOT is disabled in this mode.
 225 
 226 void AOTLoader::set_narrow_oop_shift() {
 227   // This method could be called from Universe::initialize_heap().
 228   if (UseAOT && libraries_count() > 0 &&
 229       UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
 230     int oop_shift = Universe::narrow_oop_shift();
 231     if (oop_shift == 0) {
 232       // 0 is valid shift value for small heap but we can safely increase it
 233       // at this point when nobody used it yet.
 234       Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift());
 235     } else {
 236       // Non 0 value can't be changed because we can't decrease it.
 237       FOR_ALL_AOT_LIBRARIES(lib) {
 238         (*lib)->verify_flag(AOTLib::narrow_oop_shift(), oop_shift, "Universe::narrow_oop_shift");
 239       }
 240     }
 241   }
 242 }
 243 
 244 void AOTLoader::set_narrow_klass_shift() {
 245   // This method is called from Metaspace::set_narrow_klass_base_and_shift().


 246   if (UseAOT && libraries_count() > 0 &&
 247       UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
 248       UseCompressedClassPointers) {
 249     int klass_shift = Universe::narrow_klass_shift();
 250     if (klass_shift == 0) {
 251       Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
 252     } else {
 253       FOR_ALL_AOT_LIBRARIES(lib) {
 254         (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
 255       }
 256     }
 257   }
 258 }
 259 
 260 void AOTLoader::load_library(const char* name, bool exit_on_error) {
 261   // Skip library if a library with the same name is already loaded.
 262   const int file_separator = *os::file_separator();
 263   const char* start = strrchr(name, file_separator);
 264   const char* new_name = (start == NULL) ? name : (start + 1);
 265   FOR_ALL_AOT_LIBRARIES(lib) {


src/hotspot/share/aot/aotLoader.cpp
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File