comparison src/share/vm/compiler/compileBroker.cpp @ 22714:9b3b66634d17

use timeout for JVMCI blocking compilation to avoid deadlock between compiler and app thread that submitted the blocking compilation
author Doug Simon <doug.simon@oracle.com>
date Sun, 01 Nov 2015 21:43:49 +0100
parents cfd7ebda543b
children 44bc739eae23
comparison
equal deleted inserted replaced
22713:088d24f0be35 22714:9b3b66634d17
252 if (task->is_blocking()) { 252 if (task->is_blocking()) {
253 MutexLocker notifier(task->lock(), thread); 253 MutexLocker notifier(task->lock(), thread);
254 task->mark_complete(); 254 task->mark_complete();
255 // Notify the waiting thread that the compilation has completed. 255 // Notify the waiting thread that the compilation has completed.
256 task->lock()->notify_all(); 256 task->lock()->notify_all();
257 #ifdef COMPILERJVMCI
258 if (CompileBroker::compiler(task->comp_level())->is_jvmci()) {
259 // Blocking JVMCI compilations are performed with a timeout so as
260 // to avoid deadlock between an application thread and a JVMCI
261 // compiler thread (both of which execute Java code). In this case,
262 // the compiling thread recycles the CompileTask.
263 CompileTask::free(task);
264 }
265 #endif
257 } else { 266 } else {
258 task->mark_complete(); 267 task->mark_complete();
259 268
260 // By convention, the compiling thread is responsible for 269 // By convention, the compiling thread is responsible for
261 // recycling a non-blocking CompileTask. 270 // recycling a non-blocking CompileTask.
1684 blocking); 1693 blocking);
1685 queue->add(new_task); 1694 queue->add(new_task);
1686 return new_task; 1695 return new_task;
1687 } 1696 }
1688 1697
1698 // 1 second should be long enough to complete most JVMCI compilations
1699 // and not too long to stall a blocking JVMCI compilation that
1700 // is trying to acquire a lock held by the app thread that submitted the
1701 // compilation.
1702 static const long BLOCKING_JVMCI_COMPILATION_TIMEOUT = 1000;
1689 1703
1690 /** 1704 /**
1691 * Wait for the compilation task to complete. 1705 * Wait for the compilation task to complete.
1692 */ 1706 */
1693 void CompileBroker::wait_for_completion(CompileTask* task) { 1707 void CompileBroker::wait_for_completion(CompileTask* task) {
1703 1717
1704 methodHandle method(thread, task->method()); 1718 methodHandle method(thread, task->method());
1705 { 1719 {
1706 MutexLocker waiter(task->lock(), thread); 1720 MutexLocker waiter(task->lock(), thread);
1707 1721
1722 #ifdef COMPILERJVMCI
1723 if (compiler(task->comp_level())->is_jvmci()) {
1724 // No need to check if compilation has completed - just
1725 // rely on the time out. The JVMCI compiler thread will
1726 // recycle the CompileTask.
1727 task->lock()->wait(!Mutex::_no_safepoint_check_flag, BLOCKING_JVMCI_COMPILATION_TIMEOUT);
1728 thread->set_blocked_on_compilation(false);
1729 return;
1730 }
1731 #endif
1708 while (!task->is_complete() && !is_compilation_disabled_forever()) { 1732 while (!task->is_complete() && !is_compilation_disabled_forever()) {
1709 task->lock()->wait(); 1733 task->lock()->wait();
1710 } 1734 }
1711 } 1735 }
1712 1736