Mercurial > hg > graal-jvmci-8
comparison src/share/vm/compiler/compileBroker.cpp @ 22719:44bc739eae23
fixed logic deciding who frees the CompileTask for a JVMCI blocking compilation
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 02 Nov 2015 23:53:10 +0100 |
parents | 9b3b66634d17 |
children | 24fd08e99b35 |
comparison
equal
deleted
inserted
replaced
22718:f04d84a5f7c5 | 22719:44bc739eae23 |
---|---|
248 if (log != NULL) task->log_task_done(log); | 248 if (log != NULL) task->log_task_done(log); |
249 thread->set_task(NULL); | 249 thread->set_task(NULL); |
250 task->set_code_handle(NULL); | 250 task->set_code_handle(NULL); |
251 thread->set_env(NULL); | 251 thread->set_env(NULL); |
252 if (task->is_blocking()) { | 252 if (task->is_blocking()) { |
253 MutexLocker notifier(task->lock(), thread); | 253 bool free_task = false; |
254 task->mark_complete(); | 254 { |
255 // Notify the waiting thread that the compilation has completed. | 255 MutexLocker notifier(task->lock(), thread); |
256 task->lock()->notify_all(); | 256 task->mark_complete(); |
257 #ifdef COMPILERJVMCI | 257 #ifdef COMPILERJVMCI |
258 if (CompileBroker::compiler(task->comp_level())->is_jvmci()) { | 258 if (CompileBroker::compiler(task->comp_level())->is_jvmci()) { |
259 // Blocking JVMCI compilations are performed with a timeout so as | 259 // Blocking JVMCI compilations are performed with a timeout so as |
260 // to avoid deadlock between an application thread and a JVMCI | 260 // to avoid deadlock between an application thread and a JVMCI |
261 // compiler thread (both of which execute Java code). In this case, | 261 // compiler thread (both of which execute Java code). |
262 // the compiling thread recycles the CompileTask. | 262 if (task->has_waiter()) { |
263 // Notify the waiting thread that the compilation has completed | |
264 // and let it free the CompileTask. | |
265 task->lock()->notify_all(); | |
266 } else { | |
267 // The waiting thread timed out did not free the task. | |
268 free_task = true; | |
269 } | |
270 } else { | |
271 // Notify the waiting thread that the compilation has completed. | |
272 task->lock()->notify_all(); | |
273 } | |
274 #else | |
275 // Notify the waiting thread that the compilation has completed. | |
276 task->lock()->notify_all(); | |
277 #endif | |
278 } | |
279 if (free_task) { | |
280 // The task can only be freed once the task lock is released. | |
263 CompileTask::free(task); | 281 CompileTask::free(task); |
264 } | 282 } |
265 #endif | |
266 } else { | 283 } else { |
267 task->mark_complete(); | 284 task->mark_complete(); |
268 | 285 |
269 // By convention, the compiling thread is responsible for | 286 // By convention, the compiling thread is responsible for |
270 // recycling a non-blocking CompileTask. | 287 // recycling a non-blocking CompileTask. |
331 _compile_id = compile_id; | 348 _compile_id = compile_id; |
332 _method = method(); | 349 _method = method(); |
333 _method_holder = JNIHandles::make_global(method->method_holder()->klass_holder()); | 350 _method_holder = JNIHandles::make_global(method->method_holder()->klass_holder()); |
334 _osr_bci = osr_bci; | 351 _osr_bci = osr_bci; |
335 _is_blocking = is_blocking; | 352 _is_blocking = is_blocking; |
353 COMPILERJVMCI_PRESENT(_has_waiter = CompileBroker::compiler(comp_level)->is_jvmci();) | |
336 _comp_level = comp_level; | 354 _comp_level = comp_level; |
337 _num_inlined_bytecodes = 0; | 355 _num_inlined_bytecodes = 0; |
338 | 356 |
339 _is_complete = false; | 357 _is_complete = false; |
340 _is_success = false; | 358 _is_success = false; |
1714 | 1732 |
1715 JavaThread* thread = JavaThread::current(); | 1733 JavaThread* thread = JavaThread::current(); |
1716 thread->set_blocked_on_compilation(true); | 1734 thread->set_blocked_on_compilation(true); |
1717 | 1735 |
1718 methodHandle method(thread, task->method()); | 1736 methodHandle method(thread, task->method()); |
1719 { | 1737 bool free_task = true; |
1720 MutexLocker waiter(task->lock(), thread); | |
1721 | |
1722 #ifdef COMPILERJVMCI | 1738 #ifdef COMPILERJVMCI |
1723 if (compiler(task->comp_level())->is_jvmci()) { | 1739 if (compiler(task->comp_level())->is_jvmci()) { |
1740 { | |
1741 MutexLocker waiter(task->lock(), thread); | |
1724 // No need to check if compilation has completed - just | 1742 // No need to check if compilation has completed - just |
1725 // rely on the time out. The JVMCI compiler thread will | 1743 // rely on the time out. The JVMCI compiler thread will |
1726 // recycle the CompileTask. | 1744 // recycle the CompileTask. |
1727 task->lock()->wait(!Mutex::_no_safepoint_check_flag, BLOCKING_JVMCI_COMPILATION_TIMEOUT); | 1745 task->lock()->wait(!Mutex::_no_safepoint_check_flag, BLOCKING_JVMCI_COMPILATION_TIMEOUT); |
1728 thread->set_blocked_on_compilation(false); | 1746 // If the compilation completes while has_waiter is true then |
1729 return; | 1747 // this thread is responsible for freeing the task. Otherwise |
1730 } | 1748 // the compiler thread will free the task. |
1749 task->clear_waiter(); | |
1750 free_task = task->is_complete(); | |
1751 } | |
1752 } else | |
1731 #endif | 1753 #endif |
1754 { | |
1755 MutexLocker waiter(task->lock(), thread); | |
1732 while (!task->is_complete() && !is_compilation_disabled_forever()) { | 1756 while (!task->is_complete() && !is_compilation_disabled_forever()) { |
1733 task->lock()->wait(); | 1757 task->lock()->wait(); |
1734 } | 1758 } |
1735 } | 1759 } |
1736 | 1760 |
1737 thread->set_blocked_on_compilation(false); | 1761 thread->set_blocked_on_compilation(false); |
1738 if (is_compilation_disabled_forever()) { | 1762 if (free_task) { |
1763 if (is_compilation_disabled_forever()) { | |
1764 CompileTask::free(task); | |
1765 return; | |
1766 } | |
1767 | |
1768 // It is harmless to check this status without the lock, because | |
1769 // completion is a stable property (until the task object is recycled). | |
1770 assert(task->is_complete(), "Compilation should have completed"); | |
1771 assert(task->code_handle() == NULL, "must be reset"); | |
1772 | |
1773 // By convention, the waiter is responsible for recycling a | |
1774 // blocking CompileTask. Since there is only one waiter ever | |
1775 // waiting on a CompileTask, we know that no one else will | |
1776 // be using this CompileTask; we can free it. | |
1739 CompileTask::free(task); | 1777 CompileTask::free(task); |
1740 return; | 1778 } |
1741 } | |
1742 | |
1743 // It is harmless to check this status without the lock, because | |
1744 // completion is a stable property (until the task object is recycled). | |
1745 assert(task->is_complete(), "Compilation should have completed"); | |
1746 assert(task->code_handle() == NULL, "must be reset"); | |
1747 | |
1748 // By convention, the waiter is responsible for recycling a | |
1749 // blocking CompileTask. Since there is only one waiter ever | |
1750 // waiting on a CompileTask, we know that no one else will | |
1751 // be using this CompileTask; we can free it. | |
1752 CompileTask::free(task); | |
1753 } | 1779 } |
1754 | 1780 |
1755 /** | 1781 /** |
1756 * Initialize compiler thread(s) + compiler object(s). The postcondition | 1782 * Initialize compiler thread(s) + compiler object(s). The postcondition |
1757 * of this function is that the compiler runtimes are initialized and that | 1783 * of this function is that the compiler runtimes are initialized and that |