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) { 250 const char* lib_name = (*lib)->name(); 251 start = strrchr(lib_name, file_separator); 252 const char* old_name = (start == NULL) ? lib_name : (start + 1); 253 if (strcmp(old_name, new_name) == 0) { 254 if (PrintAOT) { 255 warning("AOT library %s is already loaded as %s.", name, lib_name); 256 } 257 return; 258 } 259 } | 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((*lib)->config()->_narrowOopShift, 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((*lib)->config()->_narrowKlassShift, 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 is called from Universe::initialize_heap(). 228 if (UseAOT && libraries_count() > 0 && 229 UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) { 230 if (Universe::narrow_oop_shift() == 0) { 231 // 0 is valid shift value for small heap but we can safely increase it 232 // at this point when nobody used it yet. 233 Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift()); 234 } 235 } 236 } 237 238 void AOTLoader::set_narrow_klass_shift() { 239 // This method is called from Metaspace::set_narrow_klass_base_and_shift(). 240 if (UseAOT && libraries_count() > 0 && 241 UseCompressedOops && AOTLib::narrow_oop_shift_initialized() && 242 UseCompressedClassPointers) { 243 if (Universe::narrow_klass_shift() == 0) { 244 Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift()); 245 } 246 } 247 } 248 249 void AOTLoader::load_library(const char* name, bool exit_on_error) { 250 // Skip library if a library with the same name is already loaded. 251 const int file_separator = *os::file_separator(); 252 const char* start = strrchr(name, file_separator); 253 const char* new_name = (start == NULL) ? name : (start + 1); 254 FOR_ALL_AOT_LIBRARIES(lib) { 255 const char* lib_name = (*lib)->name(); 256 start = strrchr(lib_name, file_separator); 257 const char* old_name = (start == NULL) ? lib_name : (start + 1); 258 if (strcmp(old_name, new_name) == 0) { 259 if (PrintAOT) { 260 warning("AOT library %s is already loaded as %s.", name, lib_name); 261 } 262 return; 263 } 264 } |