1568 shutdown_compiler_runtime(comp, thread);
1569 return false;
1570 }
1571
1572 // C1 specific check
1573 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1574 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1575 return false;
1576 }
1577
1578 return true;
1579 }
1580
1581 // If C1 and/or C2 initialization failed, we shut down all compilation.
1582 // We do this to keep things simple. This can be changed if it ever turns out to be
1583 // a problem.
1584 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) {
1585 // Free buffer blob, if allocated
1586 if (thread->get_buffer_blob() != NULL) {
1587 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1588 CodeCache::free(thread->get_buffer_blob());
1589 }
1590
1591 if (comp->should_perform_shutdown()) {
1592 // There are two reasons for shutting down the compiler
1593 // 1) compiler runtime initialization failed
1594 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing
1595 warning("Shutting down compiler %s (no space to run compilers)", comp->name());
1596
1597 // Only one thread per compiler runtime object enters here
1598 // Set state to shut down
1599 comp->set_shut_down();
1600
1601 MutexLocker mu(MethodCompileQueue_lock, thread);
1602 CompileQueue* queue;
1603 if (_c1_method_queue != NULL) {
1604 _c1_method_queue->delete_all();
1605 queue = _c1_method_queue;
1606 _c1_method_queue = NULL;
1607 delete _c1_method_queue;
1608 }
1652 os::current_thread_id(),
1653 os::current_process_id());
1654 log->stamp();
1655 log->end_elem();
1656 }
1657
1658 // If compiler thread/runtime initialization fails, exit the compiler thread
1659 if (!init_compiler_runtime()) {
1660 return;
1661 }
1662
1663 // Poll for new compilation tasks as long as the JVM runs. Compilation
1664 // should only be disabled if something went wrong while initializing the
1665 // compiler runtimes. This, in turn, should not happen. The only known case
1666 // when compiler runtime initialization fails is if there is not enough free
1667 // space in the code cache to generate the necessary stubs, etc.
1668 while (!is_compilation_disabled_forever()) {
1669 // We need this HandleMark to avoid leaking VM handles.
1670 HandleMark hm(thread);
1671
1672 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1673 // the code cache is really full
1674 handle_full_code_cache();
1675 }
1676
1677 CompileTask* task = queue->get();
1678 if (task == NULL) {
1679 continue;
1680 }
1681
1682 // Give compiler threads an extra quanta. They tend to be bursty and
1683 // this helps the compiler to finish up the job.
1684 if( CompilerThreadHintNoPreempt )
1685 os::hint_no_preempt();
1686
1687 // trace per thread time and compile statistics
1688 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1689 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1690
1691 // Assign the task to the current thread. Mark this compilation
1692 // thread as active for the profiler.
1693 CompileTaskWrapper ctw(task);
1694 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1982 // compile queue lock was held. Subsequently, we acquired the compile
1983 // queue lock to get this task off the compile queue; thus (to belabour
1984 // the point somewhat) our clearing of the bits must be occurring
1985 // only after the setting of the bits. See also 14012000 above.
1986 method->clear_queued_for_compilation();
1987
1988 #ifdef ASSERT
1989 if (CollectedHeap::fired_fake_oom()) {
1990 // The current compile received a fake OOM during compilation so
1991 // go ahead and exit the VM since the test apparently succeeded
1992 tty->print_cr("*** Shutting down VM after successful fake OOM");
1993 vm_exit(0);
1994 }
1995 #endif
1996 }
1997
1998 /**
1999 * The CodeCache is full. Print out warning and disable compilation
2000 * or try code cache cleaning so compilation can continue later.
2001 */
2002 void CompileBroker::handle_full_code_cache() {
2003 UseInterpreter = true;
2004 if (UseCompiler || AlwaysCompileLoopMethods ) {
2005 if (xtty != NULL) {
2006 ResourceMark rm;
2007 stringStream s;
2008 // Dump code cache state into a buffer before locking the tty,
2009 // because log_state() will use locks causing lock conflicts.
2010 CodeCache::log_state(&s);
2011 // Lock to prevent tearing
2012 ttyLocker ttyl;
2013 xtty->begin_elem("code_cache_full");
2014 xtty->print(s.as_string());
2015 xtty->stamp();
2016 xtty->end_elem();
2017 }
2018
2019 CodeCache::report_codemem_full();
2020
2021 #ifndef PRODUCT
2022 if (CompileTheWorld || ExitOnFullCodeCache) {
2023 codecache_print(/* detailed= */ true);
2024 before_exit(JavaThread::current());
2025 exit_globals(); // will delete tty
2026 vm_direct_exit(CompileTheWorld ? 0 : 1);
2027 }
2028 #endif
2029 if (UseCodeCacheFlushing) {
2030 // Since code cache is full, immediately stop new compiles
2031 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2032 NMethodSweeper::log_sweep("disable_compiler");
2033 }
2034 // Switch to 'vm_state'. This ensures that possibly_sweep() can be called
2035 // without having to consider the state in which the current thread is.
2036 ThreadInVMfromUnknown in_vm;
2037 NMethodSweeper::possibly_sweep();
2038 } else {
2039 disable_compilation_forever();
2040 }
2041
2042 // Print warning only once
2043 if (should_print_compiler_warning()) {
2044 warning("CodeCache is full. Compiler has been disabled.");
2045 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
2046 codecache_print(/* detailed= */ true);
2047 }
2048 }
2049 }
2050
2051 // ------------------------------------------------------------------
2052 // CompileBroker::set_last_compile
2053 //
2054 // Record this compilation for debugging purposes.
2055 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
2056 ResourceMark rm;
2057 char* method_name = method->name()->as_C_string();
2058 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
2059 char current_method[CompilerCounters::cmname_buffer_length];
2060 size_t maxLen = CompilerCounters::cmname_buffer_length;
2061
2062 if (UsePerfData) {
2063 const char* class_name = method->method_holder()->name()->as_C_string();
2064
2065 size_t s1len = strlen(class_name);
2066 size_t s2len = strlen(method_name);
2067
|
1568 shutdown_compiler_runtime(comp, thread);
1569 return false;
1570 }
1571
1572 // C1 specific check
1573 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1574 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1575 return false;
1576 }
1577
1578 return true;
1579 }
1580
1581 // If C1 and/or C2 initialization failed, we shut down all compilation.
1582 // We do this to keep things simple. This can be changed if it ever turns out to be
1583 // a problem.
1584 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) {
1585 // Free buffer blob, if allocated
1586 if (thread->get_buffer_blob() != NULL) {
1587 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1588 CodeCache::free(thread->get_buffer_blob(), CodeBlobType::NonMethod);
1589 }
1590
1591 if (comp->should_perform_shutdown()) {
1592 // There are two reasons for shutting down the compiler
1593 // 1) compiler runtime initialization failed
1594 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing
1595 warning("Shutting down compiler %s (no space to run compilers)", comp->name());
1596
1597 // Only one thread per compiler runtime object enters here
1598 // Set state to shut down
1599 comp->set_shut_down();
1600
1601 MutexLocker mu(MethodCompileQueue_lock, thread);
1602 CompileQueue* queue;
1603 if (_c1_method_queue != NULL) {
1604 _c1_method_queue->delete_all();
1605 queue = _c1_method_queue;
1606 _c1_method_queue = NULL;
1607 delete _c1_method_queue;
1608 }
1652 os::current_thread_id(),
1653 os::current_process_id());
1654 log->stamp();
1655 log->end_elem();
1656 }
1657
1658 // If compiler thread/runtime initialization fails, exit the compiler thread
1659 if (!init_compiler_runtime()) {
1660 return;
1661 }
1662
1663 // Poll for new compilation tasks as long as the JVM runs. Compilation
1664 // should only be disabled if something went wrong while initializing the
1665 // compiler runtimes. This, in turn, should not happen. The only known case
1666 // when compiler runtime initialization fails is if there is not enough free
1667 // space in the code cache to generate the necessary stubs, etc.
1668 while (!is_compilation_disabled_forever()) {
1669 // We need this HandleMark to avoid leaking VM handles.
1670 HandleMark hm(thread);
1671
1672 // Iterate over non-profiled and profiled nmethods
1673 for (int code_blob_type = CodeBlobType::MethodNonProfiled; code_blob_type <= CodeBlobType::MethodProfiled; ++code_blob_type) {
1674 if (CodeCache::is_full(code_blob_type)) {
1675 // The CodeHeap for CodeBlobType is really full
1676 handle_full_code_cache(code_blob_type);
1677 }
1678 }
1679
1680 CompileTask* task = queue->get();
1681 if (task == NULL) {
1682 continue;
1683 }
1684
1685 // Give compiler threads an extra quanta. They tend to be bursty and
1686 // this helps the compiler to finish up the job.
1687 if( CompilerThreadHintNoPreempt )
1688 os::hint_no_preempt();
1689
1690 // trace per thread time and compile statistics
1691 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1692 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1693
1694 // Assign the task to the current thread. Mark this compilation
1695 // thread as active for the profiler.
1696 CompileTaskWrapper ctw(task);
1697 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1985 // compile queue lock was held. Subsequently, we acquired the compile
1986 // queue lock to get this task off the compile queue; thus (to belabour
1987 // the point somewhat) our clearing of the bits must be occurring
1988 // only after the setting of the bits. See also 14012000 above.
1989 method->clear_queued_for_compilation();
1990
1991 #ifdef ASSERT
1992 if (CollectedHeap::fired_fake_oom()) {
1993 // The current compile received a fake OOM during compilation so
1994 // go ahead and exit the VM since the test apparently succeeded
1995 tty->print_cr("*** Shutting down VM after successful fake OOM");
1996 vm_exit(0);
1997 }
1998 #endif
1999 }
2000
2001 /**
2002 * The CodeCache is full. Print out warning and disable compilation
2003 * or try code cache cleaning so compilation can continue later.
2004 */
2005 void CompileBroker::handle_full_code_cache(int code_blob_type) {
2006 UseInterpreter = true;
2007 if (UseCompiler || AlwaysCompileLoopMethods ) {
2008 if (xtty != NULL) {
2009 ResourceMark rm;
2010 stringStream s;
2011 // Dump code cache state into a buffer before locking the tty,
2012 // because log_state() will use locks causing lock conflicts.
2013 CodeCache::log_state(&s);
2014 // Lock to prevent tearing
2015 ttyLocker ttyl;
2016 xtty->begin_elem("code_cache_full");
2017 xtty->print(s.as_string());
2018 xtty->stamp();
2019 xtty->end_elem();
2020 }
2021
2022 #ifndef PRODUCT
2023 if (CompileTheWorld || ExitOnFullCodeCache) {
2024 codecache_print(/* detailed= */ true);
2025 before_exit(JavaThread::current());
2026 exit_globals(); // will delete tty
2027 vm_direct_exit(CompileTheWorld ? 0 : 1);
2028 }
2029 #endif
2030 if (UseCodeCacheFlushing) {
2031 // Since code cache is full, immediately stop new compiles
2032 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2033 NMethodSweeper::log_sweep("disable_compiler");
2034 }
2035 // Switch to 'vm_state'. This ensures that possibly_sweep() can be called
2036 // without having to consider the state in which the current thread is.
2037 ThreadInVMfromUnknown in_vm;
2038 NMethodSweeper::possibly_sweep();
2039 } else {
2040 disable_compilation_forever();
2041 }
2042
2043 CodeCache::report_codemem_full(code_blob_type, should_print_compiler_warning());
2044 }
2045 }
2046
2047 // ------------------------------------------------------------------
2048 // CompileBroker::set_last_compile
2049 //
2050 // Record this compilation for debugging purposes.
2051 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
2052 ResourceMark rm;
2053 char* method_name = method->name()->as_C_string();
2054 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
2055 char current_method[CompilerCounters::cmname_buffer_length];
2056 size_t maxLen = CompilerCounters::cmname_buffer_length;
2057
2058 if (UsePerfData) {
2059 const char* class_name = method->method_holder()->name()->as_C_string();
2060
2061 size_t s1len = strlen(class_name);
2062 size_t s2len = strlen(method_name);
2063
|