1575 1576 // Open a log. 1577 if (LogCompilation) { 1578 init_compiler_thread_log(); 1579 } 1580 CompileLog* log = thread->log(); 1581 if (log != NULL) { 1582 log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'", 1583 thread->name(), 1584 os::current_thread_id(), 1585 os::current_process_id()); 1586 log->stamp(); 1587 log->end_elem(); 1588 } 1589 1590 while (true) { 1591 { 1592 // We need this HandleMark to avoid leaking VM handles. 1593 HandleMark hm(thread); 1594 1595 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { 1596 // the code cache is really full 1597 handle_full_code_cache(); 1598 } 1599 1600 CompileTask* task = queue->get(); 1601 1602 // Give compiler threads an extra quanta. They tend to be bursty and 1603 // this helps the compiler to finish up the job. 1604 if( CompilerThreadHintNoPreempt ) 1605 os::hint_no_preempt(); 1606 1607 // trace per thread time and compile statistics 1608 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); 1609 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); 1610 1611 // Assign the task to the current thread. Mark this compilation 1612 // thread as active for the profiler. 1613 CompileTaskWrapper ctw(task); 1614 nmethodLocker result_handle; // (handle for the nmethod produced by this task) 1615 task->set_code_handle(&result_handle); 1616 methodHandle method(thread, task->method()); 1617 1900 // when adding the task to the complie queue -- at which time the 1901 // compile queue lock was held. Subsequently, we acquired the compile 1902 // queue lock to get this task off the compile queue; thus (to belabour 1903 // the point somewhat) our clearing of the bits must be occurring 1904 // only after the setting of the bits. See also 14012000 above. 1905 method->clear_queued_for_compilation(); 1906 1907 #ifdef ASSERT 1908 if (CollectedHeap::fired_fake_oom()) { 1909 // The current compile received a fake OOM during compilation so 1910 // go ahead and exit the VM since the test apparently succeeded 1911 tty->print_cr("*** Shutting down VM after successful fake OOM"); 1912 vm_exit(0); 1913 } 1914 #endif 1915 } 1916 1917 // ------------------------------------------------------------------ 1918 // CompileBroker::handle_full_code_cache 1919 // 1920 // The CodeCache is full. Print out warning and disable compilation or 1921 // try code cache cleaning so compilation can continue later. 1922 void CompileBroker::handle_full_code_cache() { 1923 UseInterpreter = true; 1924 if (UseCompiler || AlwaysCompileLoopMethods ) { 1925 if (xtty != NULL) { 1926 ResourceMark rm; 1927 stringStream s; 1928 // Dump code cache state into a buffer before locking the tty, 1929 // because log_state() will use locks causing lock conflicts. 1930 CodeCache::log_state(&s); 1931 // Lock to prevent tearing 1932 ttyLocker ttyl; 1933 xtty->begin_elem("code_cache_full"); 1934 xtty->print(s.as_string()); 1935 xtty->stamp(); 1936 xtty->end_elem(); 1937 } 1938 warning("CodeCache is full. Compiler has been disabled."); 1939 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize="); 1940 1941 CodeCache::report_codemem_full(); 1942 1943 1944 #ifndef PRODUCT 1945 if (CompileTheWorld || ExitOnFullCodeCache) { 1946 codecache_print(/* detailed= */ true); 1947 before_exit(JavaThread::current()); 1948 exit_globals(); // will delete tty 1949 vm_direct_exit(CompileTheWorld ? 0 : 1); 1950 } 1951 #endif 1952 if (UseCodeCacheFlushing) { 1953 // Since code cache is full, immediately stop new compiles 1954 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) { 1955 NMethodSweeper::log_sweep("disable_compiler"); 1956 NMethodSweeper::possibly_sweep(); 1957 } 1958 } else { 1959 UseCompiler = false; 1960 AlwaysCompileLoopMethods = false; 1961 } 1962 } 1963 codecache_print(/* detailed= */ true); 1964 } 1965 1966 // ------------------------------------------------------------------ 1967 // CompileBroker::set_last_compile 1968 // 1969 // Record this compilation for debugging purposes. 1970 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { 1971 ResourceMark rm; 1972 char* method_name = method->name()->as_C_string(); 1973 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); 1974 char current_method[CompilerCounters::cmname_buffer_length]; 1975 size_t maxLen = CompilerCounters::cmname_buffer_length; 1976 1977 if (UsePerfData) { 1978 const char* class_name = method->method_holder()->name()->as_C_string(); 1979 1980 size_t s1len = strlen(class_name); 1981 size_t s2len = strlen(method_name); 1982 1983 // check if we need to truncate the string | 1575 1576 // Open a log. 1577 if (LogCompilation) { 1578 init_compiler_thread_log(); 1579 } 1580 CompileLog* log = thread->log(); 1581 if (log != NULL) { 1582 log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'", 1583 thread->name(), 1584 os::current_thread_id(), 1585 os::current_process_id()); 1586 log->stamp(); 1587 log->end_elem(); 1588 } 1589 1590 while (true) { 1591 { 1592 // We need this HandleMark to avoid leaking VM handles. 1593 HandleMark hm(thread); 1594 1595 // Iterate over non-profiled and profiled nmethods 1596 for (int code_blob_type = CodeBlobType::MethodNonProfiled; code_blob_type <= CodeBlobType::MethodProfiled; ++code_blob_type) { 1597 if (CodeCache::is_full(code_blob_type)) { 1598 // The CodeHeap for this compilation level is really full 1599 handle_full_code_cache(code_blob_type); 1600 } 1601 } 1602 1603 CompileTask* task = queue->get(); 1604 1605 // Give compiler threads an extra quanta. They tend to be bursty and 1606 // this helps the compiler to finish up the job. 1607 if( CompilerThreadHintNoPreempt ) 1608 os::hint_no_preempt(); 1609 1610 // trace per thread time and compile statistics 1611 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); 1612 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); 1613 1614 // Assign the task to the current thread. Mark this compilation 1615 // thread as active for the profiler. 1616 CompileTaskWrapper ctw(task); 1617 nmethodLocker result_handle; // (handle for the nmethod produced by this task) 1618 task->set_code_handle(&result_handle); 1619 methodHandle method(thread, task->method()); 1620 1903 // when adding the task to the complie queue -- at which time the 1904 // compile queue lock was held. Subsequently, we acquired the compile 1905 // queue lock to get this task off the compile queue; thus (to belabour 1906 // the point somewhat) our clearing of the bits must be occurring 1907 // only after the setting of the bits. See also 14012000 above. 1908 method->clear_queued_for_compilation(); 1909 1910 #ifdef ASSERT 1911 if (CollectedHeap::fired_fake_oom()) { 1912 // The current compile received a fake OOM during compilation so 1913 // go ahead and exit the VM since the test apparently succeeded 1914 tty->print_cr("*** Shutting down VM after successful fake OOM"); 1915 vm_exit(0); 1916 } 1917 #endif 1918 } 1919 1920 // ------------------------------------------------------------------ 1921 // CompileBroker::handle_full_code_cache 1922 // 1923 // The CodeCache is full. Disable compilation or try code cache 1924 // cleaning so compilation can continue later. 1925 void CompileBroker::handle_full_code_cache(int code_blob_type) { 1926 UseInterpreter = true; 1927 if (UseCompiler || AlwaysCompileLoopMethods ) { 1928 if (xtty != NULL) { 1929 ResourceMark rm; 1930 stringStream s; 1931 // Dump code cache state into a buffer before locking the tty, 1932 // because log_state() will use locks causing lock conflicts. 1933 CodeCache::log_state(&s); 1934 // Lock to prevent tearing 1935 ttyLocker ttyl; 1936 xtty->begin_elem("code_cache_full"); 1937 xtty->print(s.as_string()); 1938 xtty->stamp(); 1939 xtty->end_elem(); 1940 } 1941 1942 #ifndef PRODUCT 1943 if (CompileTheWorld || ExitOnFullCodeCache) { 1944 codecache_print(/* detailed= */ true); 1945 before_exit(JavaThread::current()); 1946 exit_globals(); // will delete tty 1947 vm_direct_exit(CompileTheWorld ? 0 : 1); 1948 } 1949 #endif 1950 if (UseCodeCacheFlushing) { 1951 // Since code cache is full, immediately stop new compiles 1952 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) { 1953 NMethodSweeper::log_sweep("disable_compiler"); 1954 NMethodSweeper::possibly_sweep(); 1955 } 1956 } else { 1957 UseCompiler = false; 1958 AlwaysCompileLoopMethods = false; 1959 } 1960 } 1961 CodeCache::report_codemem_full(code_blob_type); 1962 } 1963 1964 // ------------------------------------------------------------------ 1965 // CompileBroker::set_last_compile 1966 // 1967 // Record this compilation for debugging purposes. 1968 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { 1969 ResourceMark rm; 1970 char* method_name = method->name()->as_C_string(); 1971 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); 1972 char current_method[CompilerCounters::cmname_buffer_length]; 1973 size_t maxLen = CompilerCounters::cmname_buffer_length; 1974 1975 if (UsePerfData) { 1976 const char* class_name = method->method_holder()->name()->as_C_string(); 1977 1978 size_t s1len = strlen(class_name); 1979 size_t s2len = strlen(method_name); 1980 1981 // check if we need to truncate the string |