src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8015774 Sdiff src/share/vm/compiler

src/share/vm/compiler/compileBroker.cpp

Print this page




1726                     os::current_thread_id(),
1727                     os::current_process_id());
1728     log->stamp();
1729     log->end_elem();
1730   }
1731 
1732   // If compiler thread/runtime initialization fails, exit the compiler thread
1733   if (!init_compiler_runtime()) {
1734     return;
1735   }
1736 
1737   // Poll for new compilation tasks as long as the JVM runs. Compilation
1738   // should only be disabled if something went wrong while initializing the
1739   // compiler runtimes. This, in turn, should not happen. The only known case
1740   // when compiler runtime initialization fails is if there is not enough free
1741   // space in the code cache to generate the necessary stubs, etc.
1742   while (!is_compilation_disabled_forever()) {
1743     // We need this HandleMark to avoid leaking VM handles.
1744     HandleMark hm(thread);
1745 
1746     if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1747       // the code cache is really full
1748       handle_full_code_cache();


1749     }
1750 
1751     CompileTask* task = queue->get();
1752     if (task == NULL) {
1753       continue;
1754     }
1755 
1756     // Give compiler threads an extra quanta.  They tend to be bursty and
1757     // this helps the compiler to finish up the job.
1758     if( CompilerThreadHintNoPreempt )
1759       os::hint_no_preempt();
1760 
1761     // trace per thread time and compile statistics
1762     CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1763     PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1764 
1765     // Assign the task to the current thread.  Mark this compilation
1766     // thread as active for the profiler.
1767     CompileTaskWrapper ctw(task);
1768     nmethodLocker result_handle;  // (handle for the nmethod produced by this task)


2058   // compile queue lock was held. Subsequently, we acquired the compile
2059   // queue lock to get this task off the compile queue; thus (to belabour
2060   // the point somewhat) our clearing of the bits must be occurring
2061   // only after the setting of the bits. See also 14012000 above.
2062   method->clear_queued_for_compilation();
2063 
2064 #ifdef ASSERT
2065   if (CollectedHeap::fired_fake_oom()) {
2066     // The current compile received a fake OOM during compilation so
2067     // go ahead and exit the VM since the test apparently succeeded
2068     tty->print_cr("*** Shutting down VM after successful fake OOM");
2069     vm_exit(0);
2070   }
2071 #endif
2072 }
2073 
2074 /**
2075  * The CodeCache is full.  Print out warning and disable compilation
2076  * or try code cache cleaning so compilation can continue later.
2077  */
2078 void CompileBroker::handle_full_code_cache() {
2079   UseInterpreter = true;
2080   if (UseCompiler || AlwaysCompileLoopMethods ) {
2081     if (xtty != NULL) {
2082       ResourceMark rm;
2083       stringStream s;
2084       // Dump code cache state into a buffer before locking the tty,
2085       // because log_state() will use locks causing lock conflicts.
2086       CodeCache::log_state(&s);
2087       // Lock to prevent tearing
2088       ttyLocker ttyl;
2089       xtty->begin_elem("code_cache_full");
2090       xtty->print("%s", s.as_string());
2091       xtty->stamp();
2092       xtty->end_elem();
2093     }
2094 
2095     CodeCache::report_codemem_full();
2096 
2097 #ifndef PRODUCT
2098     if (CompileTheWorld || ExitOnFullCodeCache) {
2099       codecache_print(/* detailed= */ true);
2100       before_exit(JavaThread::current());
2101       exit_globals(); // will delete tty
2102       vm_direct_exit(CompileTheWorld ? 0 : 1);
2103     }
2104 #endif
2105     if (UseCodeCacheFlushing) {
2106       // Since code cache is full, immediately stop new compiles
2107       if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2108         NMethodSweeper::log_sweep("disable_compiler");
2109       }
2110       // Switch to 'vm_state'. This ensures that possibly_sweep() can be called
2111       // without having to consider the state in which the current thread is.
2112       ThreadInVMfromUnknown in_vm;
2113       NMethodSweeper::possibly_sweep();
2114     } else {
2115       disable_compilation_forever();
2116     }
2117 
2118     // Print warning only once
2119     if (should_print_compiler_warning()) {
2120       warning("CodeCache is full. Compiler has been disabled.");
2121       warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
2122       codecache_print(/* detailed= */ true);
2123     }
2124   }
2125 }
2126 
2127 // ------------------------------------------------------------------
2128 // CompileBroker::set_last_compile
2129 //
2130 // Record this compilation for debugging purposes.
2131 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
2132   ResourceMark rm;
2133   char* method_name = method->name()->as_C_string();
2134   strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
2135   _last_method_compiled[CompileBroker::name_buffer_length - 1] = '\0'; // ensure null terminated
2136   char current_method[CompilerCounters::cmname_buffer_length];
2137   size_t maxLen = CompilerCounters::cmname_buffer_length;
2138 
2139   if (UsePerfData) {
2140     const char* class_name = method->method_holder()->name()->as_C_string();
2141 
2142     size_t s1len = strlen(class_name);
2143     size_t s2len = strlen(method_name);




1726                     os::current_thread_id(),
1727                     os::current_process_id());
1728     log->stamp();
1729     log->end_elem();
1730   }
1731 
1732   // If compiler thread/runtime initialization fails, exit the compiler thread
1733   if (!init_compiler_runtime()) {
1734     return;
1735   }
1736 
1737   // Poll for new compilation tasks as long as the JVM runs. Compilation
1738   // should only be disabled if something went wrong while initializing the
1739   // compiler runtimes. This, in turn, should not happen. The only known case
1740   // when compiler runtime initialization fails is if there is not enough free
1741   // space in the code cache to generate the necessary stubs, etc.
1742   while (!is_compilation_disabled_forever()) {
1743     // We need this HandleMark to avoid leaking VM handles.
1744     HandleMark hm(thread);
1745 
1746     // Check if the CodeCache is full
1747     int code_blob_type = 0;
1748     if (CodeCache::is_full(&code_blob_type)) {
1749       // The CodeHeap for code_blob_type is really full
1750       handle_full_code_cache(code_blob_type);
1751     }
1752 
1753     CompileTask* task = queue->get();
1754     if (task == NULL) {
1755       continue;
1756     }
1757 
1758     // Give compiler threads an extra quanta.  They tend to be bursty and
1759     // this helps the compiler to finish up the job.
1760     if( CompilerThreadHintNoPreempt )
1761       os::hint_no_preempt();
1762 
1763     // trace per thread time and compile statistics
1764     CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1765     PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1766 
1767     // Assign the task to the current thread.  Mark this compilation
1768     // thread as active for the profiler.
1769     CompileTaskWrapper ctw(task);
1770     nmethodLocker result_handle;  // (handle for the nmethod produced by this task)


2060   // compile queue lock was held. Subsequently, we acquired the compile
2061   // queue lock to get this task off the compile queue; thus (to belabour
2062   // the point somewhat) our clearing of the bits must be occurring
2063   // only after the setting of the bits. See also 14012000 above.
2064   method->clear_queued_for_compilation();
2065 
2066 #ifdef ASSERT
2067   if (CollectedHeap::fired_fake_oom()) {
2068     // The current compile received a fake OOM during compilation so
2069     // go ahead and exit the VM since the test apparently succeeded
2070     tty->print_cr("*** Shutting down VM after successful fake OOM");
2071     vm_exit(0);
2072   }
2073 #endif
2074 }
2075 
2076 /**
2077  * The CodeCache is full.  Print out warning and disable compilation
2078  * or try code cache cleaning so compilation can continue later.
2079  */
2080 void CompileBroker::handle_full_code_cache(int code_blob_type) {
2081   UseInterpreter = true;
2082   if (UseCompiler || AlwaysCompileLoopMethods ) {
2083     if (xtty != NULL) {
2084       ResourceMark rm;
2085       stringStream s;
2086       // Dump code cache state into a buffer before locking the tty,
2087       // because log_state() will use locks causing lock conflicts.
2088       CodeCache::log_state(&s);
2089       // Lock to prevent tearing
2090       ttyLocker ttyl;
2091       xtty->begin_elem("code_cache_full");
2092       xtty->print("%s", s.as_string());
2093       xtty->stamp();
2094       xtty->end_elem();
2095     }
2096 


2097 #ifndef PRODUCT
2098     if (CompileTheWorld || ExitOnFullCodeCache) {
2099       codecache_print(/* detailed= */ true);
2100       before_exit(JavaThread::current());
2101       exit_globals(); // will delete tty
2102       vm_direct_exit(CompileTheWorld ? 0 : 1);
2103     }
2104 #endif
2105     if (UseCodeCacheFlushing) {
2106       // Since code cache is full, immediately stop new compiles
2107       if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2108         NMethodSweeper::log_sweep("disable_compiler");
2109       }
2110       // Switch to 'vm_state'. This ensures that possibly_sweep() can be called
2111       // without having to consider the state in which the current thread is.
2112       ThreadInVMfromUnknown in_vm;
2113       NMethodSweeper::possibly_sweep();
2114     } else {
2115       disable_compilation_forever();
2116     }
2117 
2118     CodeCache::report_codemem_full(code_blob_type, should_print_compiler_warning());





2119   }
2120 }
2121 
2122 // ------------------------------------------------------------------
2123 // CompileBroker::set_last_compile
2124 //
2125 // Record this compilation for debugging purposes.
2126 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
2127   ResourceMark rm;
2128   char* method_name = method->name()->as_C_string();
2129   strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
2130   _last_method_compiled[CompileBroker::name_buffer_length - 1] = '\0'; // ensure null terminated
2131   char current_method[CompilerCounters::cmname_buffer_length];
2132   size_t maxLen = CompilerCounters::cmname_buffer_length;
2133 
2134   if (UsePerfData) {
2135     const char* class_name = method->method_holder()->name()->as_C_string();
2136 
2137     size_t s1len = strlen(class_name);
2138     size_t s2len = strlen(method_name);


src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File