src/share/vm/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8024275 Sdiff src/share/vm/classfile

src/share/vm/classfile/classLoader.cpp

Print this page




1302     // Print statistics as if before normal exit:
1303     extern void print_statistics();
1304     print_statistics();
1305   }
1306   vm_exit(0);
1307 }
1308 
1309 int ClassLoader::_compile_the_world_class_counter = 0;
1310 int ClassLoader::_compile_the_world_method_counter = 0;
1311 static int _codecache_sweep_counter = 0;
1312 
1313 // Filter out all exceptions except OOMs
1314 static void clear_pending_exception_if_not_oom(TRAPS) {
1315   if (HAS_PENDING_EXCEPTION &&
1316       !PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
1317     CLEAR_PENDING_EXCEPTION;
1318   }
1319   // The CHECK at the caller will propagate the exception out
1320 }
1321 



















1322 void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) {
1323   int len = (int)strlen(name);
1324   if (len > 6 && strcmp(".class", name + len - 6) == 0) {
1325     // We have a .class file
1326     char buffer[2048];
1327     strncpy(buffer, name, len - 6);
1328     buffer[len-6] = 0;
1329     // If the file has a period after removing .class, it's not really a
1330     // valid class file.  The class loader will check everything else.
1331     if (strchr(buffer, '.') == NULL) {
1332       _compile_the_world_class_counter++;
1333       if (_compile_the_world_class_counter > CompileTheWorldStopAt) return;
1334 
1335       // Construct name without extension
1336       TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
1337       // Use loader to load and initialize class
1338       Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
1339       instanceKlassHandle k (THREAD, ik);
1340       if (k.not_null() && !HAS_PENDING_EXCEPTION) {
1341         k->initialize(THREAD);


1345       if (CompileTheWorldPreloadClasses && k.not_null()) {
1346         ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
1347         if (HAS_PENDING_EXCEPTION) {
1348           // If something went wrong in preloading we just ignore it
1349           clear_pending_exception_if_not_oom(CHECK);
1350           tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer);
1351         }
1352       }
1353 
1354       if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
1355         if (k.is_null() || exception_occurred) {
1356           // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
1357           tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
1358         } else {
1359           tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer);
1360           // Preload all classes to get around uncommon traps
1361           // Iterate over all methods in class
1362           int comp_level = CompilationPolicy::policy()->initial_compile_level();
1363           for (int n = 0; n < k->methods()->length(); n++) {
1364             methodHandle m (THREAD, k->methods()->at(n));
1365             if (CompilationPolicy::can_be_compiled(m, comp_level)) {
1366 
1367               if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
1368                 // Give sweeper a chance to keep up with CTW
1369                 VM_ForceSafepoint op;
1370                 VMThread::execute(&op);
1371                 _codecache_sweep_counter = 0;
1372               }
1373               // Force compilation
1374               CompileBroker::compile_method(m, InvocationEntryBci, comp_level,
1375                                             methodHandle(), 0, "CTW", THREAD);
1376               if (HAS_PENDING_EXCEPTION) {
1377                 clear_pending_exception_if_not_oom(CHECK);
1378                 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string());
1379               } else {
1380                 _compile_the_world_method_counter++;
1381               }
1382               if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
1383                 // Clobber the first compile and force second tier compilation
1384                 nmethod* nm = m->code();
1385                 if (nm != NULL) {
1386                   // Throw out the code so that the code cache doesn't fill up
1387                   nm->make_not_entrant();
1388                   m->clear_code();
1389                 }
1390                 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization,
1391                                               methodHandle(), 0, "CTW", THREAD);
1392                 if (HAS_PENDING_EXCEPTION) {
1393                   clear_pending_exception_if_not_oom(CHECK);
1394                   tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string());
1395                 } else {
1396                   _compile_the_world_method_counter++;
1397                 }
1398               }




1399             }
1400 
1401             nmethod* nm = m->code();
1402             if (nm != NULL) {
1403               // Throw out the code so that the code cache doesn't fill up
1404               nm->make_not_entrant();
1405               m->clear_code();
1406             }
1407           }
1408         }
1409       }
1410     }
1411   }
1412 }
1413 
1414 #endif //PRODUCT
1415 
1416 // Please keep following two functions at end of this file. With them placed at top or in middle of the file,
1417 // they could get inlined by agressive compiler, an unknown trick, see bug 6966589.
1418 void PerfClassTraceTime::initialize() {




1302     // Print statistics as if before normal exit:
1303     extern void print_statistics();
1304     print_statistics();
1305   }
1306   vm_exit(0);
1307 }
1308 
1309 int ClassLoader::_compile_the_world_class_counter = 0;
1310 int ClassLoader::_compile_the_world_method_counter = 0;
1311 static int _codecache_sweep_counter = 0;
1312 
1313 // Filter out all exceptions except OOMs
1314 static void clear_pending_exception_if_not_oom(TRAPS) {
1315   if (HAS_PENDING_EXCEPTION &&
1316       !PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
1317     CLEAR_PENDING_EXCEPTION;
1318   }
1319   // The CHECK at the caller will propagate the exception out
1320 }
1321 
1322 /**
1323  * Returns if the given method should be compiled when doing compile-the-world.
1324  *
1325  * TODO:  This should be a private method in a CompileTheWorld class.
1326  */
1327 static bool can_be_compiled(methodHandle m, int comp_level) {
1328   assert(CompileTheWorld, "must be");
1329 
1330   // It's not valid to compile a native wrapper for MethodHandle methods
1331   // that take a MemberName appendix since the bytecode signature is not
1332   // correct.
1333   vmIntrinsics::ID iid = m->intrinsic_id();
1334   if (MethodHandles::is_signature_polymorphic(iid) && MethodHandles::has_member_arg(iid)) {
1335     return false;
1336   }
1337 
1338   return CompilationPolicy::can_be_compiled(m, comp_level);
1339 }
1340 
1341 void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) {
1342   int len = (int)strlen(name);
1343   if (len > 6 && strcmp(".class", name + len - 6) == 0) {
1344     // We have a .class file
1345     char buffer[2048];
1346     strncpy(buffer, name, len - 6);
1347     buffer[len-6] = 0;
1348     // If the file has a period after removing .class, it's not really a
1349     // valid class file.  The class loader will check everything else.
1350     if (strchr(buffer, '.') == NULL) {
1351       _compile_the_world_class_counter++;
1352       if (_compile_the_world_class_counter > CompileTheWorldStopAt) return;
1353 
1354       // Construct name without extension
1355       TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
1356       // Use loader to load and initialize class
1357       Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
1358       instanceKlassHandle k (THREAD, ik);
1359       if (k.not_null() && !HAS_PENDING_EXCEPTION) {
1360         k->initialize(THREAD);


1364       if (CompileTheWorldPreloadClasses && k.not_null()) {
1365         ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
1366         if (HAS_PENDING_EXCEPTION) {
1367           // If something went wrong in preloading we just ignore it
1368           clear_pending_exception_if_not_oom(CHECK);
1369           tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer);
1370         }
1371       }
1372 
1373       if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
1374         if (k.is_null() || exception_occurred) {
1375           // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
1376           tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
1377         } else {
1378           tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer);
1379           // Preload all classes to get around uncommon traps
1380           // Iterate over all methods in class
1381           int comp_level = CompilationPolicy::policy()->initial_compile_level();
1382           for (int n = 0; n < k->methods()->length(); n++) {
1383             methodHandle m (THREAD, k->methods()->at(n));
1384             if (can_be_compiled(m, comp_level)) {

1385               if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
1386                 // Give sweeper a chance to keep up with CTW
1387                 VM_ForceSafepoint op;
1388                 VMThread::execute(&op);
1389                 _codecache_sweep_counter = 0;
1390               }
1391               // Force compilation
1392               CompileBroker::compile_method(m, InvocationEntryBci, comp_level,
1393                                             methodHandle(), 0, "CTW", THREAD);
1394               if (HAS_PENDING_EXCEPTION) {
1395                 clear_pending_exception_if_not_oom(CHECK);
1396                 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string());
1397               } else {
1398                 _compile_the_world_method_counter++;
1399               }
1400               if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
1401                 // Clobber the first compile and force second tier compilation
1402                 nmethod* nm = m->code();
1403                 if (nm != NULL) {
1404                   // Throw out the code so that the code cache doesn't fill up
1405                   nm->make_not_entrant();
1406                   m->clear_code();
1407                 }
1408                 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization,
1409                                               methodHandle(), 0, "CTW", THREAD);
1410                 if (HAS_PENDING_EXCEPTION) {
1411                   clear_pending_exception_if_not_oom(CHECK);
1412                   tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string());
1413                 } else {
1414                   _compile_the_world_method_counter++;
1415                 }
1416               }
1417             } else {
1418               if (Verbose) {
1419                 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string());
1420               }
1421             }
1422 
1423             nmethod* nm = m->code();
1424             if (nm != NULL) {
1425               // Throw out the code so that the code cache doesn't fill up
1426               nm->make_not_entrant();
1427               m->clear_code();
1428             }
1429           }
1430         }
1431       }
1432     }
1433   }
1434 }
1435 
1436 #endif //PRODUCT
1437 
1438 // Please keep following two functions at end of this file. With them placed at top or in middle of the file,
1439 // they could get inlined by agressive compiler, an unknown trick, see bug 6966589.
1440 void PerfClassTraceTime::initialize() {


src/share/vm/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File