617 if (CIPrintCompileQueue) {
618 print();
619 }
620
621 if (LogCompilation && xtty != NULL) {
622 task->log_task_queued();
623 }
624
625 // Notify CompilerThreads that a task is available.
626 lock()->notify_all();
627 }
628
629 // ------------------------------------------------------------------
630 // CompileQueue::get
631 //
632 // Get the next CompileTask from a CompileQueue
633 CompileTask* CompileQueue::get() {
634 NMethodSweeper::possibly_sweep();
635
636 MutexLocker locker(lock());
637 // Wait for an available CompileTask.
638 while (_first == NULL) {
639 // There is no work to be done right now. Wait.
640 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) {
641 // During the emergency sweeping periods, wake up and sweep occasionally
642 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000);
643 if (timedout) {
644 MutexUnlocker ul(lock());
645 // When otherwise not busy, run nmethod sweeping
646 NMethodSweeper::possibly_sweep();
647 }
648 } else {
649 // During normal operation no need to wake up on timer
650 lock()->wait();
651 }
652 }
653 CompileTask* task = CompilationPolicy::policy()->select_task(this);
654 remove(task);
655 return task;
656 }
657
658 void CompileQueue::remove(CompileTask* task)
659 {
660 assert(lock()->owned_by_self(), "must own lock");
661 if (task->prev() != NULL) {
662 task->prev()->set_next(task->next());
663 } else {
664 // max is the first element
665 assert(task == _first, "Sanity");
666 _first = task->next();
667 }
668
669 if (task->next() != NULL) {
1210 // allow any levels for WhiteBox
1211 assert(WhiteBoxAPI || TieredCompilation || comp_level == CompLevel_highest_tier, "only CompLevel_highest_tier must be used in non-tiered");
1212 // return quickly if possible
1213
1214 // lock, make sure that the compilation
1215 // isn't prohibited in a straightforward way.
1216 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1217 if (comp == NULL || !comp->can_compile_method(method) ||
1218 compilation_is_prohibited(method, osr_bci, comp_level)) {
1219 return NULL;
1220 }
1221
1222 if (osr_bci == InvocationEntryBci) {
1223 // standard compilation
1224 nmethod* method_code = method->code();
1225 if (method_code != NULL) {
1226 if (compilation_is_complete(method, osr_bci, comp_level)) {
1227 return method_code;
1228 }
1229 }
1230 if (method->is_not_compilable(comp_level)) return NULL;
1231
1232 if (UseCodeCacheFlushing) {
1233 nmethod* saved = CodeCache::reanimate_saved_code(method());
1234 if (saved != NULL) {
1235 method->set_code(method, saved);
1236 return saved;
1237 }
1238 }
1239
1240 } else {
1241 // osr compilation
1242 #ifndef TIERED
1243 // seems like an assert of dubious value
1244 assert(comp_level == CompLevel_highest_tier,
1245 "all OSR compiles are assumed to be at a single compilation lavel");
1246 #endif // TIERED
1247 // We accept a higher level osr method
1248 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1249 if (nm != NULL) return nm;
1250 if (method->is_not_osr_compilable(comp_level)) return NULL;
1251 }
1252
1253 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1254 // some prerequisites that are compiler specific
1255 if (comp->is_c2() || comp->is_shark()) {
1256 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1257 // Resolve all classes seen in the signature of the method
1258 // we are compiling.
1259 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1568 init_compiler_thread_log();
1569 }
1570 CompileLog* log = thread->log();
1571 if (log != NULL) {
1572 log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'",
1573 thread->name(),
1574 os::current_thread_id(),
1575 os::current_process_id());
1576 log->stamp();
1577 log->end_elem();
1578 }
1579
1580 while (true) {
1581 {
1582 // We need this HandleMark to avoid leaking VM handles.
1583 HandleMark hm(thread);
1584
1585 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1586 // the code cache is really full
1587 handle_full_code_cache();
1588 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) {
1589 // Attempt to start cleaning the code cache while there is still a little headroom
1590 NMethodSweeper::handle_full_code_cache(false);
1591 }
1592
1593 CompileTask* task = queue->get();
1594
1595 // Give compiler threads an extra quanta. They tend to be bursty and
1596 // this helps the compiler to finish up the job.
1597 if( CompilerThreadHintNoPreempt )
1598 os::hint_no_preempt();
1599
1600 // trace per thread time and compile statistics
1601 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1602 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1603
1604 // Assign the task to the current thread. Mark this compilation
1605 // thread as active for the profiler.
1606 CompileTaskWrapper ctw(task);
1607 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1608 task->set_code_handle(&result_handle);
1609 methodHandle method(thread, task->method());
1610
1926 xtty->begin_elem("code_cache_full");
1927 xtty->print(s.as_string());
1928 xtty->stamp();
1929 xtty->end_elem();
1930 }
1931 warning("CodeCache is full. Compiler has been disabled.");
1932 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1933
1934 CodeCache::report_codemem_full();
1935
1936
1937 #ifndef PRODUCT
1938 if (CompileTheWorld || ExitOnFullCodeCache) {
1939 codecache_print(/* detailed= */ true);
1940 before_exit(JavaThread::current());
1941 exit_globals(); // will delete tty
1942 vm_direct_exit(CompileTheWorld ? 0 : 1);
1943 }
1944 #endif
1945 if (UseCodeCacheFlushing) {
1946 NMethodSweeper::handle_full_code_cache(true);
1947 } else {
1948 UseCompiler = false;
1949 AlwaysCompileLoopMethods = false;
1950 }
1951 }
1952 codecache_print(/* detailed= */ true);
1953 }
1954
1955 // ------------------------------------------------------------------
1956 // CompileBroker::set_last_compile
1957 //
1958 // Record this compilation for debugging purposes.
1959 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
1960 ResourceMark rm;
1961 char* method_name = method->name()->as_C_string();
1962 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
1963 char current_method[CompilerCounters::cmname_buffer_length];
1964 size_t maxLen = CompilerCounters::cmname_buffer_length;
1965
1966 if (UsePerfData) {
|
617 if (CIPrintCompileQueue) {
618 print();
619 }
620
621 if (LogCompilation && xtty != NULL) {
622 task->log_task_queued();
623 }
624
625 // Notify CompilerThreads that a task is available.
626 lock()->notify_all();
627 }
628
629 // ------------------------------------------------------------------
630 // CompileQueue::get
631 //
632 // Get the next CompileTask from a CompileQueue
633 CompileTask* CompileQueue::get() {
634 NMethodSweeper::possibly_sweep();
635
636 MutexLocker locker(lock());
637 // If _first is NULL we have no more compile jobs. There are two reasons for
638 // having no compile jobs: First, we compiled everything we wanted. Second,
639 // we ran out of code cache so compilation has been disabled. In the latter
640 // case we perform code cache sweeps to free memory such that we can re-enable
641 // compilation.
642 while (_first == NULL) {
643 if (UseCodeCacheFlushing && !CompileBroker::should_compile_new_jobs()) {
644 // Wait a certain amount of time to possibly do another sweep.
645 // We must wait until stack scanning has happened so that we can
646 // transition a method's state from 'not_entrant' to 'zombie'.
647 long wait_time = NmethodSweepCheckInterval * 1000;
648 if (FLAG_IS_DEFAULT(NmethodSweepCheckInterval)) {
649 // Only one thread at a time can do sweeping. Scale the
650 // wait time according to the number of compiler threads.
651 // As a result, the next sweep is likely to happen every 100ms
652 // with an arbitrary number of threads that do sweeping.
653 wait_time = 100 * CICompilerCount;
654 }
655 bool timeout = lock()->wait(!Mutex::_no_safepoint_check_flag, wait_time);
656 if (timeout) {
657 MutexUnlocker ul(lock());
658 NMethodSweeper::possibly_sweep();
659 }
660 } else {
661 // If there are no compilation tasks and we can compile new jobs
662 // (i.e., there is enough free space in the code cache) there is
663 // no need to invoke the sweeper. As a result, the hotness of methods
664 // remains unchanged. This behavior is desired, since we want to keep
665 // the stable state, i.e., we do not want to evict methods from the
666 // code cache if it is unnecessary.
667 lock()->wait();
668 }
669 }
670 CompileTask* task = CompilationPolicy::policy()->select_task(this);
671 remove(task);
672 return task;
673 }
674
675 void CompileQueue::remove(CompileTask* task)
676 {
677 assert(lock()->owned_by_self(), "must own lock");
678 if (task->prev() != NULL) {
679 task->prev()->set_next(task->next());
680 } else {
681 // max is the first element
682 assert(task == _first, "Sanity");
683 _first = task->next();
684 }
685
686 if (task->next() != NULL) {
1227 // allow any levels for WhiteBox
1228 assert(WhiteBoxAPI || TieredCompilation || comp_level == CompLevel_highest_tier, "only CompLevel_highest_tier must be used in non-tiered");
1229 // return quickly if possible
1230
1231 // lock, make sure that the compilation
1232 // isn't prohibited in a straightforward way.
1233 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1234 if (comp == NULL || !comp->can_compile_method(method) ||
1235 compilation_is_prohibited(method, osr_bci, comp_level)) {
1236 return NULL;
1237 }
1238
1239 if (osr_bci == InvocationEntryBci) {
1240 // standard compilation
1241 nmethod* method_code = method->code();
1242 if (method_code != NULL) {
1243 if (compilation_is_complete(method, osr_bci, comp_level)) {
1244 return method_code;
1245 }
1246 }
1247 if (method->is_not_compilable(comp_level)) {
1248 return NULL;
1249 }
1250 } else {
1251 // osr compilation
1252 #ifndef TIERED
1253 // seems like an assert of dubious value
1254 assert(comp_level == CompLevel_highest_tier,
1255 "all OSR compiles are assumed to be at a single compilation lavel");
1256 #endif // TIERED
1257 // We accept a higher level osr method
1258 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1259 if (nm != NULL) return nm;
1260 if (method->is_not_osr_compilable(comp_level)) return NULL;
1261 }
1262
1263 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1264 // some prerequisites that are compiler specific
1265 if (comp->is_c2() || comp->is_shark()) {
1266 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1267 // Resolve all classes seen in the signature of the method
1268 // we are compiling.
1269 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
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
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) {
|