1388 while (e != NULL) {
1389 stream = e->open_stream(file_name, CHECK_NULL);
1390 // No context.check is required since CDS is not supported
1391 // for an exploded modules build or if --patch-module is specified.
1392 if (NULL != stream) {
1393 return stream;
1394 }
1395 e = e->next();
1396 }
1397 // If the module was located, break out even if the class was not
1398 // located successfully from that module's ClassPathEntry list.
1399 // There will not be another valid entry for that module.
1400 return NULL;
1401 }
1402 }
1403 }
1404
1405 return NULL;
1406 }
1407
1408 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
1409 assert(name != NULL, "invariant");
1410 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1411
1412 ResourceMark rm(THREAD);
1413 HandleMark hm(THREAD);
1414
1415 const char* const class_name = name->as_C_string();
1416
1417 EventMark m("loading class %s", class_name);
1418 ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion);
1419
1420 const char* const file_name = file_name_for_class_name(class_name,
1421 name->utf8_length());
1422 assert(file_name != NULL, "invariant");
1423
1424 ClassLoaderExt::Context context(class_name, file_name, THREAD);
1425
1426 // Lookup stream for parsing .class file
1427 ClassFileStream* stream = NULL;
1428 s2 classpath_index = 0;
1495 if (NULL != stream) {
1496 break;
1497 }
1498 e = e->next();
1499 ++classpath_index;
1500 }
1501 }
1502
1503 if (NULL == stream) {
1504 if (DumpSharedSpaces) {
1505 tty->print_cr("Preload Warning: Cannot find %s", class_name);
1506 }
1507 return NULL;
1508 }
1509
1510 stream->set_verify(context.should_verify(classpath_index));
1511
1512 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
1513 Handle protection_domain;
1514
1515 instanceKlassHandle result = KlassFactory::create_from_stream(stream,
1516 name,
1517 loader_data,
1518 protection_domain,
1519 NULL, // host_klass
1520 NULL, // cp_patches
1521 THREAD);
1522 if (HAS_PENDING_EXCEPTION) {
1523 if (DumpSharedSpaces) {
1524 tty->print_cr("Preload Error: Failed to load %s", class_name);
1525 }
1526 return NULL;
1527 }
1528
1529 return context.record_result(name, e, classpath_index, result, THREAD);
1530 }
1531
1532 // Initialize the class loader's access to methods in libzip. Parse and
1533 // process the boot classpath into a list ClassPathEntry objects. Once
1534 // this list has been created, it must not change order (see class PackageInfo)
1535 // it can be appended to and is by jvmti and the kernel vm.
1874
1875 return CompilationPolicy::can_be_compiled(m, comp_level);
1876 }
1877
1878 void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) {
1879 if (string_ends_with(name, ".class")) {
1880 // We have a .class file
1881 int len = (int)strlen(name);
1882 char buffer[2048];
1883 strncpy(buffer, name, len - 6);
1884 buffer[len-6] = 0;
1885 // If the file has a period after removing .class, it's not really a
1886 // valid class file. The class loader will check everything else.
1887 if (strchr(buffer, '.') == NULL) {
1888 _compile_the_world_class_counter++;
1889 if (_compile_the_world_class_counter > CompileTheWorldStopAt) return;
1890
1891 // Construct name without extension
1892 TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
1893 // Use loader to load and initialize class
1894 Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
1895 instanceKlassHandle k (THREAD, ik);
1896 if (k.not_null() && !HAS_PENDING_EXCEPTION) {
1897 k->initialize(THREAD);
1898 }
1899 bool exception_occurred = HAS_PENDING_EXCEPTION;
1900 clear_pending_exception_if_not_oom(CHECK);
1901 if (CompileTheWorldPreloadClasses && k.not_null()) {
1902 ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
1903 if (HAS_PENDING_EXCEPTION) {
1904 // If something went wrong in preloading we just ignore it
1905 clear_pending_exception_if_not_oom(CHECK);
1906 tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer);
1907 }
1908 }
1909
1910 if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
1911 if (k.is_null() || exception_occurred) {
1912 // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
1913 tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
1914 } else {
1915 tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer);
1916 // Preload all classes to get around uncommon traps
1917 // Iterate over all methods in class
1918 int comp_level = CompilationPolicy::policy()->initial_compile_level();
1919 for (int n = 0; n < k->methods()->length(); n++) {
1920 methodHandle m (THREAD, k->methods()->at(n));
1921 if (can_be_compiled(m, comp_level)) {
1922 if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
1923 // Give sweeper a chance to keep up with CTW
1924 VM_ForceSafepoint op;
1925 VMThread::execute(&op);
1926 _codecache_sweep_counter = 0;
1927 }
1928 // Force compilation
1929 CompileBroker::compile_method(m, InvocationEntryBci, comp_level,
1930 methodHandle(), 0, CompileTask::Reason_CTW, THREAD);
1931 if (HAS_PENDING_EXCEPTION) {
1932 clear_pending_exception_if_not_oom(CHECK);
1933 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string());
1934 } else {
1935 _compile_the_world_method_counter++;
1936 }
1937 if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
1938 // Clobber the first compile and force second tier compilation
1939 CompiledMethod* nm = m->code();
1940 if (nm != NULL && !m->is_method_handle_intrinsic()) {
|
1388 while (e != NULL) {
1389 stream = e->open_stream(file_name, CHECK_NULL);
1390 // No context.check is required since CDS is not supported
1391 // for an exploded modules build or if --patch-module is specified.
1392 if (NULL != stream) {
1393 return stream;
1394 }
1395 e = e->next();
1396 }
1397 // If the module was located, break out even if the class was not
1398 // located successfully from that module's ClassPathEntry list.
1399 // There will not be another valid entry for that module.
1400 return NULL;
1401 }
1402 }
1403 }
1404
1405 return NULL;
1406 }
1407
1408 InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
1409 assert(name != NULL, "invariant");
1410 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1411
1412 ResourceMark rm(THREAD);
1413 HandleMark hm(THREAD);
1414
1415 const char* const class_name = name->as_C_string();
1416
1417 EventMark m("loading class %s", class_name);
1418 ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion);
1419
1420 const char* const file_name = file_name_for_class_name(class_name,
1421 name->utf8_length());
1422 assert(file_name != NULL, "invariant");
1423
1424 ClassLoaderExt::Context context(class_name, file_name, THREAD);
1425
1426 // Lookup stream for parsing .class file
1427 ClassFileStream* stream = NULL;
1428 s2 classpath_index = 0;
1495 if (NULL != stream) {
1496 break;
1497 }
1498 e = e->next();
1499 ++classpath_index;
1500 }
1501 }
1502
1503 if (NULL == stream) {
1504 if (DumpSharedSpaces) {
1505 tty->print_cr("Preload Warning: Cannot find %s", class_name);
1506 }
1507 return NULL;
1508 }
1509
1510 stream->set_verify(context.should_verify(classpath_index));
1511
1512 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
1513 Handle protection_domain;
1514
1515 InstanceKlass* result = KlassFactory::create_from_stream(stream,
1516 name,
1517 loader_data,
1518 protection_domain,
1519 NULL, // host_klass
1520 NULL, // cp_patches
1521 THREAD);
1522 if (HAS_PENDING_EXCEPTION) {
1523 if (DumpSharedSpaces) {
1524 tty->print_cr("Preload Error: Failed to load %s", class_name);
1525 }
1526 return NULL;
1527 }
1528
1529 return context.record_result(name, e, classpath_index, result, THREAD);
1530 }
1531
1532 // Initialize the class loader's access to methods in libzip. Parse and
1533 // process the boot classpath into a list ClassPathEntry objects. Once
1534 // this list has been created, it must not change order (see class PackageInfo)
1535 // it can be appended to and is by jvmti and the kernel vm.
1874
1875 return CompilationPolicy::can_be_compiled(m, comp_level);
1876 }
1877
1878 void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) {
1879 if (string_ends_with(name, ".class")) {
1880 // We have a .class file
1881 int len = (int)strlen(name);
1882 char buffer[2048];
1883 strncpy(buffer, name, len - 6);
1884 buffer[len-6] = 0;
1885 // If the file has a period after removing .class, it's not really a
1886 // valid class file. The class loader will check everything else.
1887 if (strchr(buffer, '.') == NULL) {
1888 _compile_the_world_class_counter++;
1889 if (_compile_the_world_class_counter > CompileTheWorldStopAt) return;
1890
1891 // Construct name without extension
1892 TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
1893 // Use loader to load and initialize class
1894 Klass* k = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
1895 if (k != NULL && !HAS_PENDING_EXCEPTION) {
1896 k->initialize(THREAD);
1897 }
1898 bool exception_occurred = HAS_PENDING_EXCEPTION;
1899 clear_pending_exception_if_not_oom(CHECK);
1900 if (CompileTheWorldPreloadClasses && k != NULL) {
1901 InstanceKlass* ik = InstanceKlass::cast(k);
1902 ConstantPool::preload_and_initialize_all_classes(ik->constants(), THREAD);
1903 if (HAS_PENDING_EXCEPTION) {
1904 // If something went wrong in preloading we just ignore it
1905 clear_pending_exception_if_not_oom(CHECK);
1906 tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer);
1907 }
1908 }
1909
1910 if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
1911 if (k == NULL || exception_occurred) {
1912 // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
1913 tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
1914 } else {
1915 tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer);
1916 // Preload all classes to get around uncommon traps
1917 // Iterate over all methods in class
1918 int comp_level = CompilationPolicy::policy()->initial_compile_level();
1919 InstanceKlass* ik = InstanceKlass::cast(k);
1920 for (int n = 0; n < ik->methods()->length(); n++) {
1921 methodHandle m (THREAD, ik->methods()->at(n));
1922 if (can_be_compiled(m, comp_level)) {
1923 if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
1924 // Give sweeper a chance to keep up with CTW
1925 VM_ForceSafepoint op;
1926 VMThread::execute(&op);
1927 _codecache_sweep_counter = 0;
1928 }
1929 // Force compilation
1930 CompileBroker::compile_method(m, InvocationEntryBci, comp_level,
1931 methodHandle(), 0, CompileTask::Reason_CTW, THREAD);
1932 if (HAS_PENDING_EXCEPTION) {
1933 clear_pending_exception_if_not_oom(CHECK);
1934 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string());
1935 } else {
1936 _compile_the_world_method_counter++;
1937 }
1938 if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
1939 // Clobber the first compile and force second tier compilation
1940 CompiledMethod* nm = m->code();
1941 if (nm != NULL && !m->is_method_handle_intrinsic()) {
|