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

src/hotspot/share/compiler/compileBroker.cpp

Print this page




1225   // some prerequisites that are compiler specific
1226   if (comp->is_c2()) {
1227     method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1228     // Resolve all classes seen in the signature of the method
1229     // we are compiling.
1230     Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1231   }
1232 
1233   // If the method is native, do the lookup in the thread requesting
1234   // the compilation. Native lookups can load code, which is not
1235   // permitted during compilation.
1236   //
1237   // Note: A native method implies non-osr compilation which is
1238   //       checked with an assertion at the entry of this method.
1239   if (method->is_native() && !method->is_method_handle_intrinsic()) {
1240     bool in_base_library;
1241     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1242     if (HAS_PENDING_EXCEPTION) {
1243       // In case of an exception looking up the method, we just forget
1244       // about it. The interpreter will kick-in and throw the exception.
1245       method->set_not_compilable(); // implies is_not_osr_compilable()
1246       CLEAR_PENDING_EXCEPTION;
1247       return NULL;
1248     }
1249     assert(method->has_native_function(), "must have native code by now");
1250   }
1251 
1252   // RedefineClasses() has replaced this method; just return
1253   if (method->is_old()) {
1254     return NULL;
1255   }
1256 
1257   // JVMTI -- post_compile_event requires jmethod_id() that may require
1258   // a lock the compiling thread can not acquire. Prefetch it here.
1259   if (JvmtiExport::should_post_compiled_method_load()) {
1260     method->jmethod_id();
1261   }
1262 
1263   // do the compilation
1264   if (method->is_native()) {
1265     if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {


1353  * for each method.  This means that the check below is overly
1354  * conservative in the sense that an osr compilation in the queue
1355  * will block a normal compilation from entering the queue (and vice
1356  * versa).  This can be remedied by a full queue search to disambiguate
1357  * cases.  If it is deemed profitable, this may be done.
1358  */
1359 bool CompileBroker::compilation_is_in_queue(const methodHandle& method) {
1360   return method->queued_for_compilation();
1361 }
1362 
1363 // ------------------------------------------------------------------
1364 // CompileBroker::compilation_is_prohibited
1365 //
1366 // See if this compilation is not allowed.
1367 bool CompileBroker::compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded) {
1368   bool is_native = method->is_native();
1369   // Some compilers may not support the compilation of natives.
1370   AbstractCompiler *comp = compiler(comp_level);
1371   if (is_native &&
1372       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
1373     method->set_not_compilable_quietly(comp_level);
1374     return true;
1375   }
1376 
1377   bool is_osr = (osr_bci != standard_entry_bci);
1378   // Some compilers may not support on stack replacement.
1379   if (is_osr &&
1380       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
1381     method->set_not_osr_compilable(comp_level);
1382     return true;
1383   }
1384 
1385   // The method may be explicitly excluded by the user.
1386   double scale;
1387   if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1388     bool quietly = CompilerOracle::should_exclude_quietly();
1389     if (PrintCompilation && !quietly) {
1390       // This does not happen quietly...
1391       ResourceMark rm;
1392       tty->print("### Excluding %s:%s",
1393                  method->is_native() ? "generation of native wrapper" : "compile",
1394                  (method->is_static() ? " static" : ""));
1395       method->print_short_name(tty);
1396       tty->cr();
1397     }
1398     method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand");
1399   }
1400 
1401   return false;
1402 }
1403 
1404 /**
1405  * Generate serialized IDs for compilation requests. If certain debugging flags are used
1406  * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1407  * The function also allows to generate separate compilation IDs for OSR compilations.
1408  */
1409 int CompileBroker::assign_compile_id(const methodHandle& method, int osr_bci) {
1410 #ifdef ASSERT
1411   bool is_osr = (osr_bci != standard_entry_bci);
1412   int id;
1413   if (method->is_native()) {
1414     assert(!is_osr, "can't be osr");
1415     // Adapters, native wrappers and method handle intrinsics
1416     // should be generated always.
1417     return Atomic::add(1, &_compilation_id);
1418   } else if (CICountOSR && is_osr) {
1419     id = Atomic::add(1, &_osr_compilation_id);
1420     if (CIStartOSR <= id && id < CIStopOSR) {
1421       return id;
1422     }
1423   } else {
1424     id = Atomic::add(1, &_compilation_id);
1425     if (CIStart <= id && id < CIStop) {
1426       return id;
1427     }
1428   }
1429 
1430   // Method was not in the appropriate compilation range.
1431   method->set_not_compilable_quietly();
1432   return 0;
1433 #else
1434   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1435   // only _compilation_id is incremented.
1436   return Atomic::add(1, &_compilation_id);
1437 #endif
1438 }
1439 
1440 // ------------------------------------------------------------------
1441 // CompileBroker::assign_compile_id_unlocked
1442 //
1443 // Public wrapper for assign_compile_id that acquires the needed locks
1444 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
1445   MutexLocker locker(MethodCompileQueue_lock, thread);
1446   return assign_compile_id(method, osr_bci);
1447 }
1448 
1449 // ------------------------------------------------------------------
1450 // CompileBroker::preload_classes
1451 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {


2178     tty->print("%4d ", compile_id);    // print compilation number
2179     tty->print("%s ", (is_osr ? "%" : " "));
2180     if (task->code() != NULL) {
2181       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2182     }
2183     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2184   }
2185 
2186   Log(compilation, codecache) log;
2187   if (log.is_debug()) {
2188     LogStream ls(log.debug());
2189     codecache_print(&ls, /* detailed= */ false);
2190   }
2191   if (PrintCodeCacheOnCompilation) {
2192     codecache_print(/* detailed= */ false);
2193   }
2194   // Disable compilation, if required.
2195   switch (compilable) {
2196   case ciEnv::MethodCompilable_never:
2197     if (is_osr)
2198       method->set_not_osr_compilable_quietly();
2199     else
2200       method->set_not_compilable_quietly();
2201     break;
2202   case ciEnv::MethodCompilable_not_at_tier:
2203     if (is_osr)
2204       method->set_not_osr_compilable_quietly(task_level);
2205     else
2206       method->set_not_compilable_quietly(task_level);
2207     break;
2208   }
2209 
2210   // Note that the queued_for_compilation bits are cleared without
2211   // protection of a mutex. [They were set by the requester thread,
2212   // when adding the task to the compile queue -- at which time the
2213   // compile queue lock was held. Subsequently, we acquired the compile
2214   // queue lock to get this task off the compile queue; thus (to belabour
2215   // the point somewhat) our clearing of the bits must be occurring
2216   // only after the setting of the bits. See also 14012000 above.
2217   method->clear_queued_for_compilation();
2218 }
2219 
2220 /**
2221  * The CodeCache is full. Print warning and disable compilation.
2222  * Schedule code cache cleaning so compilation can continue later.
2223  * This function needs to be called only from CodeCache::allocate(),
2224  * since we currently handle a full code cache uniformly.
2225  */
2226 void CompileBroker::handle_full_code_cache(int code_blob_type) {




1225   // some prerequisites that are compiler specific
1226   if (comp->is_c2()) {
1227     method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1228     // Resolve all classes seen in the signature of the method
1229     // we are compiling.
1230     Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1231   }
1232 
1233   // If the method is native, do the lookup in the thread requesting
1234   // the compilation. Native lookups can load code, which is not
1235   // permitted during compilation.
1236   //
1237   // Note: A native method implies non-osr compilation which is
1238   //       checked with an assertion at the entry of this method.
1239   if (method->is_native() && !method->is_method_handle_intrinsic()) {
1240     bool in_base_library;
1241     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1242     if (HAS_PENDING_EXCEPTION) {
1243       // In case of an exception looking up the method, we just forget
1244       // about it. The interpreter will kick-in and throw the exception.
1245       method->set_not_compilable("NativeLookup::lookup failed"); // implies is_not_osr_compilable()
1246       CLEAR_PENDING_EXCEPTION;
1247       return NULL;
1248     }
1249     assert(method->has_native_function(), "must have native code by now");
1250   }
1251 
1252   // RedefineClasses() has replaced this method; just return
1253   if (method->is_old()) {
1254     return NULL;
1255   }
1256 
1257   // JVMTI -- post_compile_event requires jmethod_id() that may require
1258   // a lock the compiling thread can not acquire. Prefetch it here.
1259   if (JvmtiExport::should_post_compiled_method_load()) {
1260     method->jmethod_id();
1261   }
1262 
1263   // do the compilation
1264   if (method->is_native()) {
1265     if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {


1353  * for each method.  This means that the check below is overly
1354  * conservative in the sense that an osr compilation in the queue
1355  * will block a normal compilation from entering the queue (and vice
1356  * versa).  This can be remedied by a full queue search to disambiguate
1357  * cases.  If it is deemed profitable, this may be done.
1358  */
1359 bool CompileBroker::compilation_is_in_queue(const methodHandle& method) {
1360   return method->queued_for_compilation();
1361 }
1362 
1363 // ------------------------------------------------------------------
1364 // CompileBroker::compilation_is_prohibited
1365 //
1366 // See if this compilation is not allowed.
1367 bool CompileBroker::compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded) {
1368   bool is_native = method->is_native();
1369   // Some compilers may not support the compilation of natives.
1370   AbstractCompiler *comp = compiler(comp_level);
1371   if (is_native &&
1372       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
1373     method->set_not_compilable_quietly("native methods not supported", comp_level);
1374     return true;
1375   }
1376 
1377   bool is_osr = (osr_bci != standard_entry_bci);
1378   // Some compilers may not support on stack replacement.
1379   if (is_osr &&
1380       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
1381     method->set_not_osr_compilable("OSR not supported", comp_level);
1382     return true;
1383   }
1384 
1385   // The method may be explicitly excluded by the user.
1386   double scale;
1387   if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1388     bool quietly = CompilerOracle::should_exclude_quietly();
1389     if (PrintCompilation && !quietly) {
1390       // This does not happen quietly...
1391       ResourceMark rm;
1392       tty->print("### Excluding %s:%s",
1393                  method->is_native() ? "generation of native wrapper" : "compile",
1394                  (method->is_static() ? " static" : ""));
1395       method->print_short_name(tty);
1396       tty->cr();
1397     }
1398     method->set_not_compilable("excluded by CompileCommand", comp_level, !quietly);
1399   }
1400 
1401   return false;
1402 }
1403 
1404 /**
1405  * Generate serialized IDs for compilation requests. If certain debugging flags are used
1406  * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1407  * The function also allows to generate separate compilation IDs for OSR compilations.
1408  */
1409 int CompileBroker::assign_compile_id(const methodHandle& method, int osr_bci) {
1410 #ifdef ASSERT
1411   bool is_osr = (osr_bci != standard_entry_bci);
1412   int id;
1413   if (method->is_native()) {
1414     assert(!is_osr, "can't be osr");
1415     // Adapters, native wrappers and method handle intrinsics
1416     // should be generated always.
1417     return Atomic::add(1, &_compilation_id);
1418   } else if (CICountOSR && is_osr) {
1419     id = Atomic::add(1, &_osr_compilation_id);
1420     if (CIStartOSR <= id && id < CIStopOSR) {
1421       return id;
1422     }
1423   } else {
1424     id = Atomic::add(1, &_compilation_id);
1425     if (CIStart <= id && id < CIStop) {
1426       return id;
1427     }
1428   }
1429 
1430   // Method was not in the appropriate compilation range.
1431   method->set_not_compilable_quietly("Not in requested compile id range");
1432   return 0;
1433 #else
1434   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1435   // only _compilation_id is incremented.
1436   return Atomic::add(1, &_compilation_id);
1437 #endif
1438 }
1439 
1440 // ------------------------------------------------------------------
1441 // CompileBroker::assign_compile_id_unlocked
1442 //
1443 // Public wrapper for assign_compile_id that acquires the needed locks
1444 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
1445   MutexLocker locker(MethodCompileQueue_lock, thread);
1446   return assign_compile_id(method, osr_bci);
1447 }
1448 
1449 // ------------------------------------------------------------------
1450 // CompileBroker::preload_classes
1451 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {


2178     tty->print("%4d ", compile_id);    // print compilation number
2179     tty->print("%s ", (is_osr ? "%" : " "));
2180     if (task->code() != NULL) {
2181       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2182     }
2183     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2184   }
2185 
2186   Log(compilation, codecache) log;
2187   if (log.is_debug()) {
2188     LogStream ls(log.debug());
2189     codecache_print(&ls, /* detailed= */ false);
2190   }
2191   if (PrintCodeCacheOnCompilation) {
2192     codecache_print(/* detailed= */ false);
2193   }
2194   // Disable compilation, if required.
2195   switch (compilable) {
2196   case ciEnv::MethodCompilable_never:
2197     if (is_osr)
2198       method->set_not_osr_compilable_quietly("MethodCompilable_never");
2199     else
2200       method->set_not_compilable_quietly("MethodCompilable_never");
2201     break;
2202   case ciEnv::MethodCompilable_not_at_tier:
2203     if (is_osr)
2204       method->set_not_osr_compilable_quietly("MethodCompilable_not_at_tier", task_level);
2205     else
2206       method->set_not_compilable_quietly("MethodCompilable_not_at_tier", task_level);
2207     break;
2208   }
2209 
2210   // Note that the queued_for_compilation bits are cleared without
2211   // protection of a mutex. [They were set by the requester thread,
2212   // when adding the task to the compile queue -- at which time the
2213   // compile queue lock was held. Subsequently, we acquired the compile
2214   // queue lock to get this task off the compile queue; thus (to belabour
2215   // the point somewhat) our clearing of the bits must be occurring
2216   // only after the setting of the bits. See also 14012000 above.
2217   method->clear_queued_for_compilation();
2218 }
2219 
2220 /**
2221  * The CodeCache is full. Print warning and disable compilation.
2222  * Schedule code cache cleaning so compilation can continue later.
2223  * This function needs to be called only from CodeCache::allocate(),
2224  * since we currently handle a full code cache uniformly.
2225  */
2226 void CompileBroker::handle_full_code_cache(int code_blob_type) {


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