hotspot/src/share/vm/classfile/classLoader.cpp
changeset 18060 7cfaa4558c12
parent 17004 4d2371d76a19
child 17126 42a942feeea2
equal deleted inserted replaced
18059:bbc8eb959138 18060:7cfaa4558c12
  1272   BackgroundCompilation = false;
  1272   BackgroundCompilation = false;
  1273   // Find bootstrap loader
  1273   // Find bootstrap loader
  1274   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
  1274   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
  1275   // Iterate over all bootstrap class path entries
  1275   // Iterate over all bootstrap class path entries
  1276   ClassPathEntry* e = _first_entry;
  1276   ClassPathEntry* e = _first_entry;
       
  1277   jlong start = os::javaTimeMillis();
  1277   while (e != NULL) {
  1278   while (e != NULL) {
  1278     // We stop at rt.jar, unless it is the first bootstrap path entry
  1279     // We stop at rt.jar, unless it is the first bootstrap path entry
  1279     if (e->is_rt_jar() && e != _first_entry) break;
  1280     if (e->is_rt_jar() && e != _first_entry) break;
  1280     e->compile_the_world(system_class_loader, CATCH);
  1281     e->compile_the_world(system_class_loader, CATCH);
  1281     e = e->next();
  1282     e = e->next();
  1282   }
  1283   }
  1283   tty->print_cr("CompileTheWorld : Done");
  1284   jlong end = os::javaTimeMillis();
       
  1285   tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, %d ms)",
       
  1286                 _compile_the_world_class_counter, _compile_the_world_method_counter, (end - start));
  1284   {
  1287   {
  1285     // Print statistics as if before normal exit:
  1288     // Print statistics as if before normal exit:
  1286     extern void print_statistics();
  1289     extern void print_statistics();
  1287     print_statistics();
  1290     print_statistics();
  1288   }
  1291   }
  1289   vm_exit(0);
  1292   vm_exit(0);
  1290 }
  1293 }
  1291 
  1294 
  1292 int ClassLoader::_compile_the_world_counter = 0;
  1295 int ClassLoader::_compile_the_world_class_counter = 0;
       
  1296 int ClassLoader::_compile_the_world_method_counter = 0;
  1293 static int _codecache_sweep_counter = 0;
  1297 static int _codecache_sweep_counter = 0;
  1294 
  1298 
  1295 // Filter out all exceptions except OOMs
  1299 // Filter out all exceptions except OOMs
  1296 static void clear_pending_exception_if_not_oom(TRAPS) {
  1300 static void clear_pending_exception_if_not_oom(TRAPS) {
  1297   if (HAS_PENDING_EXCEPTION &&
  1301   if (HAS_PENDING_EXCEPTION &&
  1309     strncpy(buffer, name, len - 6);
  1313     strncpy(buffer, name, len - 6);
  1310     buffer[len-6] = 0;
  1314     buffer[len-6] = 0;
  1311     // If the file has a period after removing .class, it's not really a
  1315     // If the file has a period after removing .class, it's not really a
  1312     // valid class file.  The class loader will check everything else.
  1316     // valid class file.  The class loader will check everything else.
  1313     if (strchr(buffer, '.') == NULL) {
  1317     if (strchr(buffer, '.') == NULL) {
  1314       _compile_the_world_counter++;
  1318       _compile_the_world_class_counter++;
  1315       if (_compile_the_world_counter > CompileTheWorldStopAt) return;
  1319       if (_compile_the_world_class_counter > CompileTheWorldStopAt) return;
  1316 
  1320 
  1317       // Construct name without extension
  1321       // Construct name without extension
  1318       TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
  1322       TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
  1319       // Use loader to load and initialize class
  1323       // Use loader to load and initialize class
  1320       Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
  1324       Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
  1327       if (CompileTheWorldPreloadClasses && k.not_null()) {
  1331       if (CompileTheWorldPreloadClasses && k.not_null()) {
  1328         ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
  1332         ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
  1329         if (HAS_PENDING_EXCEPTION) {
  1333         if (HAS_PENDING_EXCEPTION) {
  1330           // If something went wrong in preloading we just ignore it
  1334           // If something went wrong in preloading we just ignore it
  1331           clear_pending_exception_if_not_oom(CHECK);
  1335           clear_pending_exception_if_not_oom(CHECK);
  1332           tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_counter, buffer);
  1336           tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer);
  1333         }
  1337         }
  1334       }
  1338       }
  1335 
  1339 
  1336       if (_compile_the_world_counter >= CompileTheWorldStartAt) {
  1340       if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
  1337         if (k.is_null() || exception_occurred) {
  1341         if (k.is_null() || exception_occurred) {
  1338           // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
  1342           // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
  1339           tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_counter, buffer);
  1343           tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
  1340         } else {
  1344         } else {
  1341           tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_counter, buffer);
  1345           tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer);
  1342           // Preload all classes to get around uncommon traps
  1346           // Preload all classes to get around uncommon traps
  1343           // Iterate over all methods in class
  1347           // Iterate over all methods in class
  1344           for (int n = 0; n < k->methods()->length(); n++) {
  1348           for (int n = 0; n < k->methods()->length(); n++) {
  1345             methodHandle m (THREAD, k->methods()->at(n));
  1349             methodHandle m (THREAD, k->methods()->at(n));
  1346             if (CompilationPolicy::can_be_compiled(m)) {
  1350             if (CompilationPolicy::can_be_compiled(m)) {
  1354               // Force compilation
  1358               // Force compilation
  1355               CompileBroker::compile_method(m, InvocationEntryBci, CompilationPolicy::policy()->initial_compile_level(),
  1359               CompileBroker::compile_method(m, InvocationEntryBci, CompilationPolicy::policy()->initial_compile_level(),
  1356                                             methodHandle(), 0, "CTW", THREAD);
  1360                                             methodHandle(), 0, "CTW", THREAD);
  1357               if (HAS_PENDING_EXCEPTION) {
  1361               if (HAS_PENDING_EXCEPTION) {
  1358                 clear_pending_exception_if_not_oom(CHECK);
  1362                 clear_pending_exception_if_not_oom(CHECK);
  1359                 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string());
  1363                 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string());
       
  1364               } else {
       
  1365                 _compile_the_world_method_counter++;
  1360               }
  1366               }
  1361               if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
  1367               if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
  1362                 // Clobber the first compile and force second tier compilation
  1368                 // Clobber the first compile and force second tier compilation
  1363                 nmethod* nm = m->code();
  1369                 nmethod* nm = m->code();
  1364                 if (nm != NULL) {
  1370                 if (nm != NULL) {
  1368                 }
  1374                 }
  1369                 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization,
  1375                 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization,
  1370                                               methodHandle(), 0, "CTW", THREAD);
  1376                                               methodHandle(), 0, "CTW", THREAD);
  1371                 if (HAS_PENDING_EXCEPTION) {
  1377                 if (HAS_PENDING_EXCEPTION) {
  1372                   clear_pending_exception_if_not_oom(CHECK);
  1378                   clear_pending_exception_if_not_oom(CHECK);
  1373                   tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string());
  1379                   tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string());
       
  1380                 } else {
       
  1381                   _compile_the_world_method_counter++;
  1374                 }
  1382                 }
  1375               }
  1383               }
  1376             }
  1384             }
  1377 
  1385 
  1378             nmethod* nm = m->code();
  1386             nmethod* nm = m->code();