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 wait_time = 100 * CICompilerCount;
652 }
653 bool timeout = lock()->wait(!Mutex::_no_safepoint_check_flag, wait_time);
654 if (timeout) {
655 MutexUnlocker ul(lock());
656 NMethodSweeper::possibly_sweep();
657 }
658 } else {
659 // If there are no compilation tasks and we can compile new jobs
660 // (i.e., there is enough free space in the code cache) there is
661 // no need to invoke the sweeper. As a result, the hotness of methods
662 // remains unchanged. This behavior is desired, since we want to keep
663 // the stable state, i.e., we do not want to evict methods from the
664 // code cache if it is unnecessary.
665 lock()->wait();
666 }
667 }
668 CompileTask* task = CompilationPolicy::policy()->select_task(this);
669 remove(task);
670 return task;
671 }
672
673 void CompileQueue::remove(CompileTask* task)
674 {
675 assert(lock()->owned_by_self(), "must own lock");
676 if (task->prev() != NULL) {
677 task->prev()->set_next(task->next());
678 } else {
679 // max is the first element
680 assert(task == _first, "Sanity");
681 _first = task->next();
682 }
683
684 if (task->next() != NULL) {
1225 // allow any levels for WhiteBox
1226 assert(WhiteBoxAPI || TieredCompilation || comp_level == CompLevel_highest_tier, "only CompLevel_highest_tier must be used in non-tiered");
1227 // return quickly if possible
1228
1229 // lock, make sure that the compilation
1230 // isn't prohibited in a straightforward way.
1231 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1232 if (comp == NULL || !comp->can_compile_method(method) ||
1233 compilation_is_prohibited(method, osr_bci, comp_level)) {
1234 return NULL;
1235 }
1236
1237 if (osr_bci == InvocationEntryBci) {
1238 // standard compilation
1239 nmethod* method_code = method->code();
1240 if (method_code != NULL) {
1241 if (compilation_is_complete(method, osr_bci, comp_level)) {
1242 return method_code;
1243 }
1244 }
1245 if (method->is_not_compilable(comp_level)) {
1246 return NULL;
1247 }
1248 } else {
1249 // osr compilation
1250 #ifndef TIERED
1251 // seems like an assert of dubious value
1252 assert(comp_level == CompLevel_highest_tier,
1253 "all OSR compiles are assumed to be at a single compilation lavel");
1254 #endif // TIERED
1255 // We accept a higher level osr method
1256 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1257 if (nm != NULL) return nm;
1258 if (method->is_not_osr_compilable(comp_level)) return NULL;
1259 }
1260
1261 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1262 // some prerequisites that are compiler specific
1263 if (comp->is_c2() || comp->is_shark()) {
1264 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1265 // Resolve all classes seen in the signature of the method
1266 // we are compiling.
1267 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1576 init_compiler_thread_log();
1577 }
1578 CompileLog* log = thread->log();
1579 if (log != NULL) {
1580 log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'",
1581 thread->name(),
1582 os::current_thread_id(),
1583 os::current_process_id());
1584 log->stamp();
1585 log->end_elem();
1586 }
1587
1588 while (true) {
1589 {
1590 // We need this HandleMark to avoid leaking VM handles.
1591 HandleMark hm(thread);
1592
1593 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1594 // the code cache is really full
1595 handle_full_code_cache();
1596 }
1597
1598 CompileTask* task = queue->get();
1599
1600 // Give compiler threads an extra quanta. They tend to be bursty and
1601 // this helps the compiler to finish up the job.
1602 if( CompilerThreadHintNoPreempt )
1603 os::hint_no_preempt();
1604
1605 // trace per thread time and compile statistics
1606 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1607 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1608
1609 // Assign the task to the current thread. Mark this compilation
1610 // thread as active for the profiler.
1611 CompileTaskWrapper ctw(task);
1612 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1613 task->set_code_handle(&result_handle);
1614 methodHandle method(thread, task->method());
1615
1931 xtty->begin_elem("code_cache_full");
1932 xtty->print(s.as_string());
1933 xtty->stamp();
1934 xtty->end_elem();
1935 }
1936 warning("CodeCache is full. Compiler has been disabled.");
1937 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1938
1939 CodeCache::report_codemem_full();
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::possibly_sweep();
1954 NMethodSweeper::log_sweep("disable_compiler");
1955 }
1956 } else {
1957 UseCompiler = false;
1958 AlwaysCompileLoopMethods = false;
1959 }
1960 }
1961 codecache_print(/* detailed= */ true);
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) {
|