hotspot/src/share/vm/compiler/compileBroker.cpp
changeset 35845 30025047885d
parent 35825 7c7652ee137b
child 36078 954c49c0ba57
equal deleted inserted replaced
35844:8a1952516600 35845:30025047885d
   543       if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
   543       if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
   544       } else {
   544       } else {
   545         c1_count = JVMCIHostThreads;
   545         c1_count = JVMCIHostThreads;
   546       }
   546       }
   547 
   547 
   548       if (!UseInterpreter) {
   548       if (!UseInterpreter || !BackgroundCompilation) {
   549         // Force initialization of JVMCI compiler otherwise JVMCI
   549         // Force initialization of JVMCI compiler otherwise JVMCI
   550         // compilations will not block until JVMCI is initialized
   550         // compilations will not block until JVMCI is initialized
   551         ResourceMark rm;
   551         ResourceMark rm;
   552         TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK);
   552         TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK);
   553         TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK);
   553         TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK);
  1344   queue->add(new_task);
  1344   queue->add(new_task);
  1345   return new_task;
  1345   return new_task;
  1346 }
  1346 }
  1347 
  1347 
  1348 #if INCLUDE_JVMCI
  1348 #if INCLUDE_JVMCI
  1349 // The number of milliseconds to wait before checking if the
  1349 // The number of milliseconds to wait before checking if
  1350 // JVMCI compiler thread is blocked.
  1350 // JVMCI compilation has made progress.
  1351 static const long BLOCKING_JVMCI_COMPILATION_WAIT_TIMESLICE = 500;
  1351 static const long JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE = 500;
  1352 
  1352 
  1353 // The number of successive times the above check is allowed to
  1353 // The number of JVMCI compilation progress checks that must fail
  1354 // see a blocked JVMCI compiler thread before unblocking the
  1354 // before unblocking a thread waiting for a blocking compilation.
  1355 // thread waiting for the compilation to finish.
  1355 static const int JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS = 5;
  1356 static const int BLOCKING_JVMCI_COMPILATION_WAIT_TO_UNBLOCK_ATTEMPTS = 5;
       
  1357 
  1356 
  1358 /**
  1357 /**
  1359  * Waits for a JVMCI compiler to complete a given task. This thread
  1358  * Waits for a JVMCI compiler to complete a given task. This thread
  1360  * waits until either the task completes or it sees the JVMCI compiler
  1359  * waits until either the task completes or it sees no JVMCI compilation
  1361  * thread is blocked for N consecutive milliseconds where N is
  1360  * progress for N consecutive milliseconds where N is
  1362  * BLOCKING_JVMCI_COMPILATION_WAIT_TIMESLICE *
  1361  * JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE *
  1363  * BLOCKING_JVMCI_COMPILATION_WAIT_TO_UNBLOCK_ATTEMPTS.
  1362  * JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS.
  1364  *
  1363  *
  1365  * @return true if this thread needs to free/recycle the task
  1364  * @return true if this thread needs to free/recycle the task
  1366  */
  1365  */
  1367 bool CompileBroker::wait_for_jvmci_completion(CompileTask* task, JavaThread* thread) {
  1366 bool CompileBroker::wait_for_jvmci_completion(JVMCICompiler* jvmci, CompileTask* task, JavaThread* thread) {
  1368   MutexLocker waiter(task->lock(), thread);
  1367   MutexLocker waiter(task->lock(), thread);
  1369   int consecutively_blocked = 0;
  1368   int progress_wait_attempts = 0;
  1370   while (task->lock()->wait(!Mutex::_no_safepoint_check_flag, BLOCKING_JVMCI_COMPILATION_WAIT_TIMESLICE)) {
  1369   int methods_compiled = jvmci->methods_compiled();
       
  1370   while (!task->is_complete() && !is_compilation_disabled_forever() &&
       
  1371          task->lock()->wait(!Mutex::_no_safepoint_check_flag, JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE)) {
  1371     CompilerThread* jvmci_compiler_thread = task->jvmci_compiler_thread();
  1372     CompilerThread* jvmci_compiler_thread = task->jvmci_compiler_thread();
       
  1373 
       
  1374     bool progress;
  1372     if (jvmci_compiler_thread != NULL) {
  1375     if (jvmci_compiler_thread != NULL) {
  1373       JavaThreadState state;
  1376       // If the JVMCI compiler thread is not blocked, we deem it to be making progress.
  1374       {
  1377       progress = jvmci_compiler_thread->thread_state() != _thread_blocked;
  1375         // A JVMCI compiler thread should not disappear at this point
  1378     } else {
  1376         // but let's be extra safe.
  1379       // Still waiting on JVMCI compiler queue. This thread may be holding a lock
  1377         MutexLocker mu(Threads_lock, thread);
  1380       // that all JVMCI compiler threads are blocked on. We use the counter for
  1378         state = jvmci_compiler_thread->thread_state();
  1381       // successful JVMCI compilations to determine whether JVMCI compilation
  1379       }
  1382       // is still making progress through the JVMCI compiler queue.
  1380       if (state == _thread_blocked) {
  1383       progress = jvmci->methods_compiled() != methods_compiled;
  1381         if (++consecutively_blocked == BLOCKING_JVMCI_COMPILATION_WAIT_TO_UNBLOCK_ATTEMPTS) {
  1384     }
  1382           if (PrintCompilation) {
  1385 
  1383             task->print(tty, "wait for blocking compilation timed out");
  1386     if (!progress) {
  1384           }
  1387       if (++progress_wait_attempts == JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS) {
  1385           break;
  1388         if (PrintCompilation) {
       
  1389           task->print(tty, "wait for blocking compilation timed out");
  1386         }
  1390         }
  1387       } else {
  1391         break;
  1388         consecutively_blocked = 0;
       
  1389       }
  1392       }
  1390     } else {
  1393     } else {
  1391       // Still waiting on JVMCI compiler queue
  1394       progress_wait_attempts = 0;
       
  1395       if (jvmci_compiler_thread == NULL) {
       
  1396         methods_compiled = jvmci->methods_compiled();
       
  1397       }
  1392     }
  1398     }
  1393   }
  1399   }
  1394   task->clear_waiter();
  1400   task->clear_waiter();
  1395   return task->is_complete();
  1401   return task->is_complete();
  1396 }
  1402 }
  1411   thread->set_blocked_on_compilation(true);
  1417   thread->set_blocked_on_compilation(true);
  1412 
  1418 
  1413   methodHandle method(thread, task->method());
  1419   methodHandle method(thread, task->method());
  1414   bool free_task;
  1420   bool free_task;
  1415 #if INCLUDE_JVMCI
  1421 #if INCLUDE_JVMCI
  1416   if (compiler(task->comp_level())->is_jvmci()) {
  1422   AbstractCompiler* comp = compiler(task->comp_level());
  1417     free_task = wait_for_jvmci_completion(task, thread);
  1423   if (comp->is_jvmci()) {
       
  1424     free_task = wait_for_jvmci_completion((JVMCICompiler*) comp, task, thread);
  1418   } else
  1425   } else
  1419 #endif
  1426 #endif
  1420   {
  1427   {
  1421     MutexLocker waiter(task->lock(), thread);
  1428     MutexLocker waiter(task->lock(), thread);
  1422     free_task = true;
  1429     free_task = true;