< prev index next >

src/share/vm/compiler/compileBroker.cpp

Print this page




  34 #include "oops/methodData.hpp"
  35 #include "oops/method.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "prims/nativeLookup.hpp"
  38 #include "prims/whitebox.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/atomic.inline.hpp"
  41 #include "runtime/compilationPolicy.hpp"
  42 #include "runtime/init.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/os.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/sweeper.hpp"
  48 #include "trace/tracing.hpp"
  49 #include "utilities/dtrace.hpp"
  50 #include "utilities/events.hpp"
  51 #ifdef COMPILER1
  52 #include "c1/c1_Compiler.hpp"
  53 #endif





  54 #ifdef COMPILER2
  55 #include "opto/c2compiler.hpp"
  56 #endif
  57 #ifdef SHARK
  58 #include "shark/sharkCompiler.hpp"
  59 #endif
  60 
  61 #ifdef DTRACE_ENABLED
  62 
  63 // Only bother with this argument setup if dtrace is available
  64 
  65 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)             \
  66   {                                                                      \
  67     Symbol* klass_name = (method)->klass_name();                         \
  68     Symbol* name = (method)->name();                                     \
  69     Symbol* signature = (method)->signature();                           \
  70     HOTSPOT_METHOD_COMPILE_BEGIN(                                        \
  71       (char *) comp_name, strlen(comp_name),                             \
  72       (char *) klass_name->bytes(), klass_name->utf8_length(),           \
  73       (char *) name->bytes(), name->utf8_length(),                       \


 488     _perf_compiles = PerfDataManager::create_counter(SUN_CI, name,
 489                                                      PerfData::U_Events, CHECK);
 490   }
 491 }
 492 
 493 // ------------------------------------------------------------------
 494 // CompileBroker::compilation_init
 495 //
 496 // Initialize the Compilation object
 497 void CompileBroker::compilation_init() {
 498   _last_method_compiled[0] = '\0';
 499 
 500   // No need to initialize compilation system if we do not use it.
 501   if (!UseCompiler) {
 502     return;
 503   }
 504 #ifndef SHARK
 505   // Set the interface to the current compiler(s).
 506   int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
 507   int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
























 508 #ifdef COMPILER1
 509   if (c1_count > 0) {
 510     _compilers[0] = new Compiler();
 511   }
 512 #endif // COMPILER1
 513 
 514 #ifdef COMPILER2

 515   if (c2_count > 0) {
 516     _compilers[1] = new C2Compiler();
 517   }

 518 #endif // COMPILER2
 519 
 520 #else // SHARK
 521   int c1_count = 0;
 522   int c2_count = 1;
 523 
 524   _compilers[1] = new SharkCompiler();
 525 #endif // SHARK
 526 
 527   // Start the compiler thread(s) and the sweeper thread
 528   init_compiler_sweeper_threads(c1_count, c2_count);
 529   // totalTime performance counter is always created as it is required
 530   // by the implementation of java.lang.management.CompilationMBean.
 531   {
 532     EXCEPTION_MARK;
 533     _perf_total_compilation =
 534                  PerfDataManager::create_counter(JAVA_CI, "totalTime",
 535                                                  PerfData::U_Ticks, CHECK);
 536   }
 537 


 716   EXCEPTION_MARK;
 717 #if !defined(ZERO) && !defined(SHARK)
 718   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 719 #endif // !ZERO && !SHARK
 720   // Initialize the compilation queue
 721   if (c2_compiler_count > 0) {
 722     _c2_compile_queue  = new CompileQueue("C2 compile queue");
 723     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
 724   }
 725   if (c1_compiler_count > 0) {
 726     _c1_compile_queue  = new CompileQueue("C1 compile queue");
 727     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
 728   }
 729 
 730   int compiler_count = c1_compiler_count + c2_compiler_count;
 731 
 732   char name_buffer[256];
 733   const bool compiler_thread = true;
 734   for (int i = 0; i < c2_compiler_count; i++) {
 735     // Create a name for our thread.
 736     sprintf(name_buffer, "C2 CompilerThread%d", i);
 737     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 738     // Shark and C2
 739     make_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], compiler_thread, CHECK);
 740   }
 741 
 742   for (int i = c2_compiler_count; i < compiler_count; i++) {
 743     // Create a name for our thread.
 744     sprintf(name_buffer, "C1 CompilerThread%d", i);
 745     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 746     // C1
 747     make_thread(name_buffer, _c1_compile_queue, counters, _compilers[0], compiler_thread, CHECK);
 748   }
 749 
 750   if (UsePerfData) {
 751     PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK);
 752   }
 753 
 754   if (MethodFlushing) {
 755     // Initialize the sweeper thread
 756     make_thread("Sweeper thread", NULL, NULL, NULL, false, CHECK);


 786                                         const char* comment,
 787                                         Thread* thread) {
 788   // do nothing if compiler thread(s) is not available
 789   if (!_initialized) {
 790     return;
 791   }
 792 
 793   guarantee(!method->is_abstract(), "cannot compile abstract methods");
 794   assert(method->method_holder()->oop_is_instance(),
 795          "sanity check");
 796   assert(!method->method_holder()->is_not_initialized(),
 797          "method holder must be initialized");
 798   assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
 799 
 800   if (CIPrintRequests) {
 801     tty->print("request: ");
 802     method->print_short_name(tty);
 803     if (osr_bci != InvocationEntryBci) {
 804       tty->print(" osr_bci: %d", osr_bci);
 805     }
 806     tty->print(" comment: %s count: %d", comment, hot_count);
 807     if (!hot_method.is_null()) {
 808       tty->print(" hot: ");
 809       if (hot_method() != method()) {
 810           hot_method->print_short_name(tty);
 811       } else {
 812         tty->print("yes");
 813       }
 814     }
 815     tty->cr();
 816   }
 817 
 818   // A request has been made for compilation.  Before we do any
 819   // real work, check to see if the method has been compiled
 820   // in the meantime with a definitive result.
 821   if (compilation_is_complete(method, osr_bci, comp_level)) {
 822     return;
 823   }
 824 
 825 #ifndef PRODUCT
 826   if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) {


 878 
 879     // We need to check again to see if the compilation has
 880     // completed.  A previous compilation may have registered
 881     // some result.
 882     if (compilation_is_complete(method, osr_bci, comp_level)) {
 883       return;
 884     }
 885 
 886     // We now know that this compilation is not pending, complete,
 887     // or prohibited.  Assign a compile_id to this compilation
 888     // and check to see if it is in our [Start..Stop) range.
 889     int compile_id = assign_compile_id(method, osr_bci);
 890     if (compile_id == 0) {
 891       // The compilation falls outside the allowed range.
 892       return;
 893     }
 894 
 895     // Should this thread wait for completion of the compile?
 896     blocking = is_compile_blocking();
 897 



































 898     // We will enter the compilation in the queue.
 899     // 14012000: Note that this sets the queued_for_compile bits in
 900     // the target method. We can now reason that a method cannot be
 901     // queued for compilation more than once, as follows:
 902     // Before a thread queues a task for compilation, it first acquires
 903     // the compile queue lock, then checks if the method's queued bits
 904     // are set or it has already been compiled. Thus there can not be two
 905     // instances of a compilation task for the same method on the
 906     // compilation queue. Consider now the case where the compilation
 907     // thread has already removed a task for that method from the queue
 908     // and is in the midst of compiling it. In this case, the
 909     // queued_for_compile bits must be set in the method (and these
 910     // will be visible to the current thread, since the bits were set
 911     // under protection of the compile queue lock, which we hold now.
 912     // When the compilation completes, the compiler thread first sets
 913     // the compilation result and then clears the queued_for_compile
 914     // bits. Neither of these actions are protected by a barrier (or done
 915     // under the protection of a lock), so the only guarantee we have
 916     // (on machines with TSO (Total Store Order)) is that these values
 917     // will update in that order. As a result, the only combinations of


1059       // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1060       //
1061       // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1062       // in this case.  If we can't generate one and use it we can not execute the out-of-line method handle calls.
1063       AdapterHandlerLibrary::create_native_wrapper(method);
1064     } else {
1065       return NULL;
1066     }
1067   } else {
1068     // If the compiler is shut off due to code cache getting full
1069     // fail out now so blocking compiles dont hang the java thread
1070     if (!should_compile_new_jobs()) {
1071       CompilationPolicy::policy()->delay_compilation(method());
1072       return NULL;
1073     }
1074     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1075   }
1076 
1077   // return requested nmethod
1078   // We accept a higher level osr method
1079   return osr_bci  == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);



1080 }
1081 
1082 
1083 // ------------------------------------------------------------------
1084 // CompileBroker::compilation_is_complete
1085 //
1086 // See if compilation of this method is already complete.
1087 bool CompileBroker::compilation_is_complete(methodHandle method,
1088                                             int          osr_bci,
1089                                             int          comp_level) {
1090   bool is_osr = (osr_bci != standard_entry_bci);
1091   if (is_osr) {
1092     if (method->is_not_osr_compilable(comp_level)) {
1093       return true;
1094     } else {
1095       nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true);
1096       return (result != NULL);
1097     }
1098   } else {
1099     if (method->is_not_compilable(comp_level)) {


1182     if (CIStartOSR <= id && id < CIStopOSR) {
1183       return id;
1184     }
1185   } else {
1186     id = Atomic::add(1, &_compilation_id);
1187     if (CIStart <= id && id < CIStop) {
1188       return id;
1189     }
1190   }
1191 
1192   // Method was not in the appropriate compilation range.
1193   method->set_not_compilable_quietly();
1194   return 0;
1195 #else
1196   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1197   // only _compilation_id is incremented.
1198   return Atomic::add(1, &_compilation_id);
1199 #endif
1200 }
1201 









1202 /**
1203  * Should the current thread block until this compilation request
1204  * has been fulfilled?
1205  */
1206 bool CompileBroker::is_compile_blocking() {
1207   assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1208   return !BackgroundCompilation;
1209 }
1210 
1211 
1212 // ------------------------------------------------------------------
1213 // CompileBroker::preload_classes
1214 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1215   // Move this code over from c1_Compiler.cpp
1216   ShouldNotReachHere();
1217 }
1218 
1219 
1220 // ------------------------------------------------------------------
1221 // CompileBroker::create_compile_task


1541       tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1542 #endif
1543     ThreadInVMfromNative tivfn(JavaThread::current());
1544   }
1545 }
1546 
1547 // wrapper for CodeCache::print_summary()
1548 static void codecache_print(bool detailed)
1549 {
1550   ResourceMark rm;
1551   stringStream s;
1552   // Dump code cache  into a buffer before locking the tty,
1553   {
1554     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1555     CodeCache::print_summary(&s, detailed);
1556   }
1557   ttyLocker ttyl;
1558   tty->print("%s", s.as_string());
1559 }
1560 





























1561 // ------------------------------------------------------------------
1562 // CompileBroker::invoke_compiler_on_method
1563 //
1564 // Compile a method.
1565 //
1566 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1567   if (PrintCompilation) {
1568     ResourceMark rm;
1569     task->print_tty();
1570   }
1571   elapsedTimer time;
1572 
1573   CompilerThread* thread = CompilerThread::current();
1574   ResourceMark rm(thread);
1575 
1576   if (LogEvents) {
1577     _compilation_log->log_compile(thread, task);
1578   }
1579 
1580   // Common flags.


1589     // accidentally be referenced once the thread transitions to
1590     // native.  The NoHandleMark before the transition should catch
1591     // any cases where this occurs in the future.
1592     methodHandle method(thread, task->method());
1593     should_break = check_break_at(method, compile_id, is_osr);
1594     if (should_log && !CompilerOracle::should_log(method)) {
1595       should_log = false;
1596     }
1597     assert(!method->is_native(), "no longer compile natives");
1598 
1599     // Save information about this method in case of failure.
1600     set_last_compile(thread, method, is_osr, task_level);
1601 
1602     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
1603   }
1604 
1605   // Allocate a new set of JNI handles.
1606   push_jni_handle_block();
1607   Method* target_handle = task->method();
1608   int compilable = ciEnv::MethodCompilable;
1609   {

1610     int system_dictionary_modification_counter;
1611     {
1612       MutexLocker locker(Compile_lock, thread);
1613       system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1614     }














1615 
1616     NoHandleMark  nhm;
1617     ThreadToNativeFromVM ttn(thread);
1618 
1619     ciEnv ci_env(task, system_dictionary_modification_counter);
1620     if (should_break) {
1621       ci_env.set_break_at_compile(true);
1622     }
1623     if (should_log) {
1624       ci_env.set_log(thread->log());
1625     }
1626     assert(thread->env() == &ci_env, "set by ci_env");
1627     // The thread-env() field is cleared in ~CompileTaskWrapper.
1628 
1629     // Cache Jvmti state
1630     ci_env.cache_jvmti_state();
1631 
1632     // Cache DTrace flags
1633     ci_env.cache_dtrace_flags();
1634 
1635     ciMethod* target = ci_env.get_method_from_handle(target_handle);
1636 
1637     TraceTime t1("compilation", &time);
1638     EventCompilation event;
1639 
1640     AbstractCompiler *comp = compiler(task_level);
1641     if (comp == NULL) {
1642       ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1643     } else {
1644       if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1645         MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1646         while (WhiteBox::compilation_locked) {
1647           locker.wait(Mutex::_no_safepoint_check_flag);
1648         }
1649       }
1650       comp->compile_method(&ci_env, target, osr_bci);
1651     }
1652 
1653     if (!ci_env.failing() && task->code() == NULL) {
1654       //assert(false, "compiler should always document failure");
1655       // The compiler elected, without comment, not to register a result.
1656       // Do not attempt further compilations of this method.
1657       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1658     }
1659 
1660     // Copy this bit to the enclosing block:
1661     compilable = ci_env.compilable();
1662 
1663     if (ci_env.failing()) {
1664       task->set_failure_reason(ci_env.failure_reason());
1665       ci_env.report_failure(ci_env.failure_reason());
1666       const char* retry_message = ci_env.retry_message();
1667       if (_compilation_log != NULL) {
1668         _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
1669       }
1670       if (PrintCompilation) {
1671         FormatBufferResource msg = retry_message != NULL ?
1672             err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) :
1673             err_msg_res("COMPILE SKIPPED: %s",      ci_env.failure_reason());
1674         task->print(tty, msg);
1675       }
1676     } else {
1677       task->mark_success();
1678       task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes());
1679       if (_compilation_log != NULL) {
1680         nmethod* code = task->code();
1681         if (code != NULL) {
1682           _compilation_log->log_nmethod(thread, code);
1683         }
1684       }
1685     }
1686     // simulate crash during compilation
1687     assert(task->compile_id() != CICrashAt, "just as planned");
1688     if (event.should_commit()) {
1689       event.set_method(target->get_Method());
1690       event.set_compileID(compile_id);
1691       event.set_compileLevel(task->comp_level());
1692       event.set_succeded(task->is_success());
1693       event.set_isOsr(is_osr);
1694       event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1695       event.set_inlinedBytes(task->num_inlined_bytecodes());
1696       event.commit();
1697     }


1698   }
1699   pop_jni_handle_block();
1700 
1701   methodHandle method(thread, task->method());
1702 
1703   DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
1704 
1705   collect_statistics(thread, time, task);
1706 
1707   if (PrintCompilation && PrintCompilation2) {
1708     tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
1709     tty->print("%4d ", compile_id);    // print compilation number
1710     tty->print("%s ", (is_osr ? "%" : " "));
1711     if (task->code() != NULL) {
1712       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
1713     }
1714     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
1715   }
1716 
1717   if (PrintCodeCacheOnCompilation)


1928       _perf_total_bailout_count->inc();
1929     }
1930     _t_bailedout_compilation.add(time);
1931   } else if (code == NULL) {
1932     if (UsePerfData) {
1933       _perf_last_invalidated_method->set_value(counters->current_method());
1934       _perf_last_invalidated_type->set_value(counters->compile_type());
1935       _perf_total_invalidated_count->inc();
1936     }
1937     _total_invalidated_count++;
1938     _t_invalidated_compilation.add(time);
1939   } else {
1940     // Compilation succeeded
1941 
1942     // update compilation ticks - used by the implementation of
1943     // java.lang.management.CompilationMBean
1944     _perf_total_compilation->inc(time.ticks());
1945     _peak_compilation_time = time.milliseconds() > _peak_compilation_time ? time.milliseconds() : _peak_compilation_time;
1946 
1947     if (CITime) {


1948       if (is_osr) {
1949         _t_osr_compilation.add(time);
1950         _sum_osr_bytes_compiled += method->code_size() + task->num_inlined_bytecodes();

1951       } else {
1952         _t_standard_compilation.add(time);
1953         _sum_standard_bytes_compiled += method->code_size() + task->num_inlined_bytecodes();

1954       }


1955     }
1956 
1957     if (UsePerfData) {
1958       // save the name of the last method compiled
1959       _perf_last_method->set_value(counters->current_method());
1960       _perf_last_compile_type->set_value(counters->compile_type());
1961       _perf_last_compile_size->set_value(method->code_size() +
1962                                          task->num_inlined_bytecodes());
1963       if (is_osr) {
1964         _perf_osr_compilation->inc(time.ticks());
1965         _perf_sum_osr_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
1966       } else {
1967         _perf_standard_compilation->inc(time.ticks());
1968         _perf_sum_standard_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
1969       }
1970     }
1971 
1972     if (CITimeEach) {
1973       float bytes_per_sec = 1.0 * (method->code_size() + task->num_inlined_bytecodes()) / time.seconds();
1974       tty->print_cr("%3d   seconds: %f bytes/sec : %f (bytes %d + %d inlined)",


1990       if (UsePerfData) _perf_total_osr_compile_count->inc();
1991       _total_osr_compile_count++;
1992     } else {
1993       if (UsePerfData) _perf_total_standard_compile_count->inc();
1994       _total_standard_compile_count++;
1995     }
1996   }
1997   // set the current method for the thread to null
1998   if (UsePerfData) counters->set_current_method("");
1999 }
2000 
2001 const char* CompileBroker::compiler_name(int comp_level) {
2002   AbstractCompiler *comp = CompileBroker::compiler(comp_level);
2003   if (comp == NULL) {
2004     return "no compiler";
2005   } else {
2006     return (comp->name());
2007   }
2008 }
2009 
2010 void CompileBroker::print_times() {




















































































2011   tty->cr();
2012   tty->print_cr("Accumulated compiler times");
2013   tty->print_cr("----------------------------------------------------------");
2014                //0000000000111111111122222222223333333333444444444455555555556666666666
2015                //0123456789012345678901234567890123456789012345678901234567890123456789
2016   tty->print_cr("  Total compilation time   : %7.3f s", CompileBroker::_t_total_compilation.seconds());
2017   tty->print_cr("    Standard compilation   : %7.3f s, Average : %2.3f s",
2018                 CompileBroker::_t_standard_compilation.seconds(),
2019                 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count);
2020   tty->print_cr("    Bailed out compilation : %7.3f s, Average : %2.3f s",
2021                 CompileBroker::_t_bailedout_compilation.seconds(),
2022                 CompileBroker::_t_bailedout_compilation.seconds() / CompileBroker::_total_bailout_count);
2023   tty->print_cr("    On stack replacement   : %7.3f s, Average : %2.3f s",
2024                 CompileBroker::_t_osr_compilation.seconds(),
2025                 CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count);
2026   tty->print_cr("    Invalidated            : %7.3f s, Average : %2.3f s",
2027                 CompileBroker::_t_invalidated_compilation.seconds(),
2028                 CompileBroker::_t_invalidated_compilation.seconds() / CompileBroker::_total_invalidated_count);
2029 
2030   AbstractCompiler *comp = compiler(CompLevel_simple);
2031   if (comp != NULL) {
2032     tty->cr();
2033     comp->print_timers();
2034   }
2035   comp = compiler(CompLevel_full_optimization);
2036   if (comp != NULL) {
2037     tty->cr();
2038     comp->print_timers();
2039   }
2040   tty->cr();
2041   tty->print_cr("  Total compiled methods    : %8d methods", CompileBroker::_total_compile_count);
2042   tty->print_cr("    Standard compilation    : %8d methods", CompileBroker::_total_standard_compile_count);
2043   tty->print_cr("    On stack replacement    : %8d methods", CompileBroker::_total_osr_compile_count);
2044   int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled;
2045   tty->print_cr("  Total compiled bytecodes  : %8d bytes", tcb);
2046   tty->print_cr("    Standard compilation    : %8d bytes", CompileBroker::_sum_standard_bytes_compiled);
2047   tty->print_cr("    On stack replacement    : %8d bytes", CompileBroker::_sum_osr_bytes_compiled);
2048   int bps = (int)(tcb / CompileBroker::_t_total_compilation.seconds());

2049   tty->print_cr("  Average compilation speed : %8d bytes/s", bps);
2050   tty->cr();
2051   tty->print_cr("  nmethod code size         : %8d bytes", CompileBroker::_sum_nmethod_code_size);
2052   tty->print_cr("  nmethod total size        : %8d bytes", CompileBroker::_sum_nmethod_size);
2053 }
2054 
2055 // Debugging output for failure
2056 void CompileBroker::print_last_compile() {
2057   if ( _last_compile_level != CompLevel_none &&
2058        compiler(_last_compile_level) != NULL &&
2059        _last_method_compiled != NULL &&
2060        _last_compile_type != no_compile) {
2061     if (_last_compile_type == osr_compile) {
2062       tty->print_cr("Last parse:  [osr]%d+++(%d) %s",
2063                     _osr_compilation_id, _last_compile_level, _last_method_compiled);
2064     } else {
2065       tty->print_cr("Last parse:  %d+++(%d) %s",
2066                     _compilation_id, _last_compile_level, _last_method_compiled);
2067     }
2068   }
2069 }
2070 
2071 
2072 void CompileBroker::print_compiler_threads_on(outputStream* st) {


  34 #include "oops/methodData.hpp"
  35 #include "oops/method.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "prims/nativeLookup.hpp"
  38 #include "prims/whitebox.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/atomic.inline.hpp"
  41 #include "runtime/compilationPolicy.hpp"
  42 #include "runtime/init.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/os.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/sweeper.hpp"
  48 #include "trace/tracing.hpp"
  49 #include "utilities/dtrace.hpp"
  50 #include "utilities/events.hpp"
  51 #ifdef COMPILER1
  52 #include "c1/c1_Compiler.hpp"
  53 #endif
  54 #if INCLUDE_JVMCI
  55 #include "jvmci/jvmciCompiler.hpp"
  56 #include "jvmci/jvmciRuntime.hpp"
  57 #include "runtime/vframe.hpp"
  58 #endif
  59 #ifdef COMPILER2
  60 #include "opto/c2compiler.hpp"
  61 #endif
  62 #ifdef SHARK
  63 #include "shark/sharkCompiler.hpp"
  64 #endif
  65 
  66 #ifdef DTRACE_ENABLED
  67 
  68 // Only bother with this argument setup if dtrace is available
  69 
  70 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)             \
  71   {                                                                      \
  72     Symbol* klass_name = (method)->klass_name();                         \
  73     Symbol* name = (method)->name();                                     \
  74     Symbol* signature = (method)->signature();                           \
  75     HOTSPOT_METHOD_COMPILE_BEGIN(                                        \
  76       (char *) comp_name, strlen(comp_name),                             \
  77       (char *) klass_name->bytes(), klass_name->utf8_length(),           \
  78       (char *) name->bytes(), name->utf8_length(),                       \


 493     _perf_compiles = PerfDataManager::create_counter(SUN_CI, name,
 494                                                      PerfData::U_Events, CHECK);
 495   }
 496 }
 497 
 498 // ------------------------------------------------------------------
 499 // CompileBroker::compilation_init
 500 //
 501 // Initialize the Compilation object
 502 void CompileBroker::compilation_init() {
 503   _last_method_compiled[0] = '\0';
 504 
 505   // No need to initialize compilation system if we do not use it.
 506   if (!UseCompiler) {
 507     return;
 508   }
 509 #ifndef SHARK
 510   // Set the interface to the current compiler(s).
 511   int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
 512   int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
 513 
 514 #if INCLUDE_JVMCI
 515   if (EnableJVMCI) {
 516     // This is creating a JVMCICompiler singleton.
 517     JVMCICompiler* jvmci = new JVMCICompiler();
 518 
 519     if (UseJVMCICompiler) {
 520       _compilers[1] = jvmci;
 521       if (FLAG_IS_DEFAULT(JVMCIThreads)) {
 522         if (BootstrapJVMCI) {
 523           // JVMCI will bootstrap so give it more threads
 524           c2_count = MIN2(32, os::active_processor_count());
 525         }
 526       } else {
 527         c2_count = JVMCIThreads;
 528       }
 529       if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
 530       } else {
 531         c1_count = JVMCIHostThreads;
 532       }
 533     }
 534   }
 535 #endif // INCLUDE_JVMCI
 536 
 537 #ifdef COMPILER1
 538   if (c1_count > 0) {
 539     _compilers[0] = new Compiler();
 540   }
 541 #endif // COMPILER1
 542 
 543 #ifdef COMPILER2
 544   if (true JVMCI_ONLY( && !UseJVMCICompiler)) {
 545     if (c2_count > 0) {
 546       _compilers[1] = new C2Compiler();
 547     }
 548   }
 549 #endif // COMPILER2
 550 
 551 #else // SHARK
 552   int c1_count = 0;
 553   int c2_count = 1;
 554 
 555   _compilers[1] = new SharkCompiler();
 556 #endif // SHARK
 557 
 558   // Start the compiler thread(s) and the sweeper thread
 559   init_compiler_sweeper_threads(c1_count, c2_count);
 560   // totalTime performance counter is always created as it is required
 561   // by the implementation of java.lang.management.CompilationMBean.
 562   {
 563     EXCEPTION_MARK;
 564     _perf_total_compilation =
 565                  PerfDataManager::create_counter(JAVA_CI, "totalTime",
 566                                                  PerfData::U_Ticks, CHECK);
 567   }
 568 


 747   EXCEPTION_MARK;
 748 #if !defined(ZERO) && !defined(SHARK)
 749   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 750 #endif // !ZERO && !SHARK
 751   // Initialize the compilation queue
 752   if (c2_compiler_count > 0) {
 753     _c2_compile_queue  = new CompileQueue("C2 compile queue");
 754     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
 755   }
 756   if (c1_compiler_count > 0) {
 757     _c1_compile_queue  = new CompileQueue("C1 compile queue");
 758     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
 759   }
 760 
 761   int compiler_count = c1_compiler_count + c2_compiler_count;
 762 
 763   char name_buffer[256];
 764   const bool compiler_thread = true;
 765   for (int i = 0; i < c2_compiler_count; i++) {
 766     // Create a name for our thread.
 767     sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
 768     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 769     // Shark and C2
 770     make_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], compiler_thread, CHECK);
 771   }
 772 
 773   for (int i = c2_compiler_count; i < compiler_count; i++) {
 774     // Create a name for our thread.
 775     sprintf(name_buffer, "C1 CompilerThread%d", i);
 776     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 777     // C1
 778     make_thread(name_buffer, _c1_compile_queue, counters, _compilers[0], compiler_thread, CHECK);
 779   }
 780 
 781   if (UsePerfData) {
 782     PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK);
 783   }
 784 
 785   if (MethodFlushing) {
 786     // Initialize the sweeper thread
 787     make_thread("Sweeper thread", NULL, NULL, NULL, false, CHECK);


 817                                         const char* comment,
 818                                         Thread* thread) {
 819   // do nothing if compiler thread(s) is not available
 820   if (!_initialized) {
 821     return;
 822   }
 823 
 824   guarantee(!method->is_abstract(), "cannot compile abstract methods");
 825   assert(method->method_holder()->oop_is_instance(),
 826          "sanity check");
 827   assert(!method->method_holder()->is_not_initialized(),
 828          "method holder must be initialized");
 829   assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
 830 
 831   if (CIPrintRequests) {
 832     tty->print("request: ");
 833     method->print_short_name(tty);
 834     if (osr_bci != InvocationEntryBci) {
 835       tty->print(" osr_bci: %d", osr_bci);
 836     }
 837     tty->print(" level: %d comment: %s count: %d", comp_level, comment, hot_count);
 838     if (!hot_method.is_null()) {
 839       tty->print(" hot: ");
 840       if (hot_method() != method()) {
 841           hot_method->print_short_name(tty);
 842       } else {
 843         tty->print("yes");
 844       }
 845     }
 846     tty->cr();
 847   }
 848 
 849   // A request has been made for compilation.  Before we do any
 850   // real work, check to see if the method has been compiled
 851   // in the meantime with a definitive result.
 852   if (compilation_is_complete(method, osr_bci, comp_level)) {
 853     return;
 854   }
 855 
 856 #ifndef PRODUCT
 857   if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) {


 909 
 910     // We need to check again to see if the compilation has
 911     // completed.  A previous compilation may have registered
 912     // some result.
 913     if (compilation_is_complete(method, osr_bci, comp_level)) {
 914       return;
 915     }
 916 
 917     // We now know that this compilation is not pending, complete,
 918     // or prohibited.  Assign a compile_id to this compilation
 919     // and check to see if it is in our [Start..Stop) range.
 920     int compile_id = assign_compile_id(method, osr_bci);
 921     if (compile_id == 0) {
 922       // The compilation falls outside the allowed range.
 923       return;
 924     }
 925 
 926     // Should this thread wait for completion of the compile?
 927     blocking = is_compile_blocking();
 928 
 929 #if INCLUDE_JVMCI
 930     if (UseJVMCICompiler) {
 931       if (blocking) {
 932         // Don't allow blocking compiles for requests triggered by JVMCI.
 933         if (thread->is_Compiler_thread()) {
 934           blocking = false;
 935         }
 936 
 937         // Don't allow blocking compiles if inside a class initializer or while performing class loading
 938         vframeStream vfst((JavaThread*) thread);
 939         for (; !vfst.at_end(); vfst.next()) {
 940           if (vfst.method()->is_static_initializer() ||
 941               (vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass()) &&
 942                   vfst.method()->name() == vmSymbols::loadClass_name())) {
 943             blocking = false;
 944             break;
 945           }
 946         }
 947 
 948         // Don't allow blocking compilation requests to JVMCI
 949         // if JVMCI itself is not yet initialized
 950         if (!JVMCIRuntime::is_HotSpotJVMCIRuntime_initialized() && compiler(comp_level)->is_jvmci()) {
 951           blocking = false;
 952         }
 953 
 954         // Don't allow blocking compilation requests if we are in JVMCIRuntime::shutdown
 955         // to avoid deadlock between compiler thread(s) and threads run at shutdown
 956         // such as the DestroyJavaVM thread.
 957         if (JVMCIRuntime::shutdown_called()) {
 958           blocking = false;
 959         }
 960       }
 961     }
 962 #endif // INCLUDE_JVMCI
 963 
 964     // We will enter the compilation in the queue.
 965     // 14012000: Note that this sets the queued_for_compile bits in
 966     // the target method. We can now reason that a method cannot be
 967     // queued for compilation more than once, as follows:
 968     // Before a thread queues a task for compilation, it first acquires
 969     // the compile queue lock, then checks if the method's queued bits
 970     // are set or it has already been compiled. Thus there can not be two
 971     // instances of a compilation task for the same method on the
 972     // compilation queue. Consider now the case where the compilation
 973     // thread has already removed a task for that method from the queue
 974     // and is in the midst of compiling it. In this case, the
 975     // queued_for_compile bits must be set in the method (and these
 976     // will be visible to the current thread, since the bits were set
 977     // under protection of the compile queue lock, which we hold now.
 978     // When the compilation completes, the compiler thread first sets
 979     // the compilation result and then clears the queued_for_compile
 980     // bits. Neither of these actions are protected by a barrier (or done
 981     // under the protection of a lock), so the only guarantee we have
 982     // (on machines with TSO (Total Store Order)) is that these values
 983     // will update in that order. As a result, the only combinations of


1125       // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1126       //
1127       // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1128       // in this case.  If we can't generate one and use it we can not execute the out-of-line method handle calls.
1129       AdapterHandlerLibrary::create_native_wrapper(method);
1130     } else {
1131       return NULL;
1132     }
1133   } else {
1134     // If the compiler is shut off due to code cache getting full
1135     // fail out now so blocking compiles dont hang the java thread
1136     if (!should_compile_new_jobs()) {
1137       CompilationPolicy::policy()->delay_compilation(method());
1138       return NULL;
1139     }
1140     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1141   }
1142 
1143   // return requested nmethod
1144   // We accept a higher level osr method
1145   if (osr_bci == InvocationEntryBci) {
1146     return method->code();
1147   }
1148   return method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1149 }
1150 
1151 
1152 // ------------------------------------------------------------------
1153 // CompileBroker::compilation_is_complete
1154 //
1155 // See if compilation of this method is already complete.
1156 bool CompileBroker::compilation_is_complete(methodHandle method,
1157                                             int          osr_bci,
1158                                             int          comp_level) {
1159   bool is_osr = (osr_bci != standard_entry_bci);
1160   if (is_osr) {
1161     if (method->is_not_osr_compilable(comp_level)) {
1162       return true;
1163     } else {
1164       nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true);
1165       return (result != NULL);
1166     }
1167   } else {
1168     if (method->is_not_compilable(comp_level)) {


1251     if (CIStartOSR <= id && id < CIStopOSR) {
1252       return id;
1253     }
1254   } else {
1255     id = Atomic::add(1, &_compilation_id);
1256     if (CIStart <= id && id < CIStop) {
1257       return id;
1258     }
1259   }
1260 
1261   // Method was not in the appropriate compilation range.
1262   method->set_not_compilable_quietly();
1263   return 0;
1264 #else
1265   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1266   // only _compilation_id is incremented.
1267   return Atomic::add(1, &_compilation_id);
1268 #endif
1269 }
1270 
1271 // ------------------------------------------------------------------
1272 // CompileBroker::assign_compile_id_unlocked
1273 //
1274 // Public wrapper for assign_compile_id that acquires the needed locks
1275 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, methodHandle method, int osr_bci) {
1276   MutexLocker locker(MethodCompileQueue_lock, thread);
1277   return assign_compile_id(method, osr_bci);
1278 }
1279 
1280 /**
1281  * Should the current thread block until this compilation request
1282  * has been fulfilled?
1283  */
1284 bool CompileBroker::is_compile_blocking() {
1285   assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1286   return !BackgroundCompilation;
1287 }
1288 
1289 
1290 // ------------------------------------------------------------------
1291 // CompileBroker::preload_classes
1292 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1293   // Move this code over from c1_Compiler.cpp
1294   ShouldNotReachHere();
1295 }
1296 
1297 
1298 // ------------------------------------------------------------------
1299 // CompileBroker::create_compile_task


1619       tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1620 #endif
1621     ThreadInVMfromNative tivfn(JavaThread::current());
1622   }
1623 }
1624 
1625 // wrapper for CodeCache::print_summary()
1626 static void codecache_print(bool detailed)
1627 {
1628   ResourceMark rm;
1629   stringStream s;
1630   // Dump code cache  into a buffer before locking the tty,
1631   {
1632     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1633     CodeCache::print_summary(&s, detailed);
1634   }
1635   ttyLocker ttyl;
1636   tty->print("%s", s.as_string());
1637 }
1638 
1639 void CompileBroker::post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env) {
1640 
1641   if (success) {
1642     task->mark_success();
1643     if (ci_env != NULL) {
1644       task->set_num_inlined_bytecodes(ci_env->num_inlined_bytecodes());
1645     }
1646     if (_compilation_log != NULL) {
1647       nmethod* code = task->code();
1648       if (code != NULL) {
1649         _compilation_log->log_nmethod(thread, code);
1650       }
1651     }
1652   }
1653 
1654   // simulate crash during compilation
1655   assert(task->compile_id() != CICrashAt, "just as planned");
1656   if (event.should_commit()) {
1657     event.set_method(task->method());
1658     event.set_compileID(task->compile_id());
1659     event.set_compileLevel(task->comp_level());
1660     event.set_succeded(task->is_success());
1661     event.set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci);
1662     event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1663     event.set_inlinedBytes(task->num_inlined_bytecodes());
1664     event.commit();
1665   }
1666 }
1667 
1668 // ------------------------------------------------------------------
1669 // CompileBroker::invoke_compiler_on_method
1670 //
1671 // Compile a method.
1672 //
1673 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1674   if (PrintCompilation) {
1675     ResourceMark rm;
1676     task->print_tty();
1677   }
1678   elapsedTimer time;
1679 
1680   CompilerThread* thread = CompilerThread::current();
1681   ResourceMark rm(thread);
1682 
1683   if (LogEvents) {
1684     _compilation_log->log_compile(thread, task);
1685   }
1686 
1687   // Common flags.


1696     // accidentally be referenced once the thread transitions to
1697     // native.  The NoHandleMark before the transition should catch
1698     // any cases where this occurs in the future.
1699     methodHandle method(thread, task->method());
1700     should_break = check_break_at(method, compile_id, is_osr);
1701     if (should_log && !CompilerOracle::should_log(method)) {
1702       should_log = false;
1703     }
1704     assert(!method->is_native(), "no longer compile natives");
1705 
1706     // Save information about this method in case of failure.
1707     set_last_compile(thread, method, is_osr, task_level);
1708 
1709     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
1710   }
1711 
1712   // Allocate a new set of JNI handles.
1713   push_jni_handle_block();
1714   Method* target_handle = task->method();
1715   int compilable = ciEnv::MethodCompilable;
1716   AbstractCompiler *comp = compiler(task_level);
1717 
1718   int system_dictionary_modification_counter;
1719   {
1720     MutexLocker locker(Compile_lock, thread);
1721     system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1722   }
1723 #if INCLUDE_JVMCI
1724   if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
1725     JVMCICompiler* jvmci = (JVMCICompiler*) comp;
1726 
1727     TraceTime t1("compilation", &time);
1728     EventCompilation event;
1729 
1730     JVMCIEnv env(task, system_dictionary_modification_counter);
1731     jvmci->compile_method(target_handle, osr_bci, &env);
1732 
1733     post_compile(thread, task, event, task->code() != NULL, NULL);
1734   } else
1735 #endif // INCLUDE_JVMCI
1736   {
1737 
1738     NoHandleMark  nhm;
1739     ThreadToNativeFromVM ttn(thread);
1740 
1741     ciEnv ci_env(task, system_dictionary_modification_counter);
1742     if (should_break) {
1743       ci_env.set_break_at_compile(true);
1744     }
1745     if (should_log) {
1746       ci_env.set_log(thread->log());
1747     }
1748     assert(thread->env() == &ci_env, "set by ci_env");
1749     // The thread-env() field is cleared in ~CompileTaskWrapper.
1750 
1751     // Cache Jvmti state
1752     ci_env.cache_jvmti_state();
1753 
1754     // Cache DTrace flags
1755     ci_env.cache_dtrace_flags();
1756 
1757     ciMethod* target = ci_env.get_method_from_handle(target_handle);
1758 
1759     TraceTime t1("compilation", &time);
1760     EventCompilation event;
1761 

1762     if (comp == NULL) {
1763       ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1764     } else {
1765       if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1766         MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1767         while (WhiteBox::compilation_locked) {
1768           locker.wait(Mutex::_no_safepoint_check_flag);
1769         }
1770       }
1771       comp->compile_method(&ci_env, target, osr_bci);
1772     }
1773 
1774     if (!ci_env.failing() && task->code() == NULL) {
1775       //assert(false, "compiler should always document failure");
1776       // The compiler elected, without comment, not to register a result.
1777       // Do not attempt further compilations of this method.
1778       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1779     }
1780 
1781     // Copy this bit to the enclosing block:
1782     compilable = ci_env.compilable();
1783 
1784     if (ci_env.failing()) {
1785       task->set_failure_reason(ci_env.failure_reason());
1786       ci_env.report_failure(ci_env.failure_reason());
1787       const char* retry_message = ci_env.retry_message();
1788       if (_compilation_log != NULL) {
1789         _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
1790       }
1791       if (PrintCompilation) {
1792         FormatBufferResource msg = retry_message != NULL ?
1793             err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) :
1794             err_msg_res("COMPILE SKIPPED: %s",      ci_env.failure_reason());
1795         task->print(tty, msg);
1796       }





















1797     }
1798 
1799     post_compile(thread, task, event, !ci_env.failing(), &ci_env);
1800   }
1801   pop_jni_handle_block();
1802 
1803   methodHandle method(thread, task->method());
1804 
1805   DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
1806 
1807   collect_statistics(thread, time, task);
1808 
1809   if (PrintCompilation && PrintCompilation2) {
1810     tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
1811     tty->print("%4d ", compile_id);    // print compilation number
1812     tty->print("%s ", (is_osr ? "%" : " "));
1813     if (task->code() != NULL) {
1814       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
1815     }
1816     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
1817   }
1818 
1819   if (PrintCodeCacheOnCompilation)


2030       _perf_total_bailout_count->inc();
2031     }
2032     _t_bailedout_compilation.add(time);
2033   } else if (code == NULL) {
2034     if (UsePerfData) {
2035       _perf_last_invalidated_method->set_value(counters->current_method());
2036       _perf_last_invalidated_type->set_value(counters->compile_type());
2037       _perf_total_invalidated_count->inc();
2038     }
2039     _total_invalidated_count++;
2040     _t_invalidated_compilation.add(time);
2041   } else {
2042     // Compilation succeeded
2043 
2044     // update compilation ticks - used by the implementation of
2045     // java.lang.management.CompilationMBean
2046     _perf_total_compilation->inc(time.ticks());
2047     _peak_compilation_time = time.milliseconds() > _peak_compilation_time ? time.milliseconds() : _peak_compilation_time;
2048 
2049     if (CITime) {
2050       int bytes_compiled = method->code_size() + task->num_inlined_bytecodes();
2051       JVMCI_ONLY(CompilerStatistics* stats = compiler(task->comp_level())->stats();)
2052       if (is_osr) {
2053         _t_osr_compilation.add(time);
2054         _sum_osr_bytes_compiled += bytes_compiled;
2055         JVMCI_ONLY(stats->_osr.update(time, bytes_compiled);)
2056       } else {
2057         _t_standard_compilation.add(time);
2058         _sum_standard_bytes_compiled += method->code_size() + task->num_inlined_bytecodes();
2059         JVMCI_ONLY(stats->_standard.update(time, bytes_compiled);)
2060       }
2061       JVMCI_ONLY(stats->_nmethods_size += code->total_size();)
2062       JVMCI_ONLY(stats->_nmethods_code_size += code->insts_size();)
2063     }
2064 
2065     if (UsePerfData) {
2066       // save the name of the last method compiled
2067       _perf_last_method->set_value(counters->current_method());
2068       _perf_last_compile_type->set_value(counters->compile_type());
2069       _perf_last_compile_size->set_value(method->code_size() +
2070                                          task->num_inlined_bytecodes());
2071       if (is_osr) {
2072         _perf_osr_compilation->inc(time.ticks());
2073         _perf_sum_osr_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
2074       } else {
2075         _perf_standard_compilation->inc(time.ticks());
2076         _perf_sum_standard_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
2077       }
2078     }
2079 
2080     if (CITimeEach) {
2081       float bytes_per_sec = 1.0 * (method->code_size() + task->num_inlined_bytecodes()) / time.seconds();
2082       tty->print_cr("%3d   seconds: %f bytes/sec : %f (bytes %d + %d inlined)",


2098       if (UsePerfData) _perf_total_osr_compile_count->inc();
2099       _total_osr_compile_count++;
2100     } else {
2101       if (UsePerfData) _perf_total_standard_compile_count->inc();
2102       _total_standard_compile_count++;
2103     }
2104   }
2105   // set the current method for the thread to null
2106   if (UsePerfData) counters->set_current_method("");
2107 }
2108 
2109 const char* CompileBroker::compiler_name(int comp_level) {
2110   AbstractCompiler *comp = CompileBroker::compiler(comp_level);
2111   if (comp == NULL) {
2112     return "no compiler";
2113   } else {
2114     return (comp->name());
2115   }
2116 }
2117 
2118 #if INCLUDE_JVMCI
2119 void CompileBroker::print_times(AbstractCompiler* comp) {
2120   CompilerStatistics* stats = comp->stats();
2121   tty->print_cr("  %s {speed: %d bytes/s; standard: %6.3f s, %d bytes, %d methods; osr: %6.3f s, %d bytes, %d methods; nmethods_size: %d bytes; nmethods_code_size: %d bytes}",
2122                 comp->name(), stats->bytes_per_second(),
2123                 stats->_standard._time.seconds(), stats->_standard._bytes, stats->_standard._count,
2124                 stats->_osr._time.seconds(), stats->_osr._bytes, stats->_osr._count,
2125                 stats->_nmethods_size, stats->_nmethods_code_size);
2126   comp->print_timers();
2127 }
2128 #endif // INCLUDE_JVMCI
2129 
2130 void CompileBroker::print_times(bool per_compiler, bool aggregate) {
2131 #if INCLUDE_JVMCI
2132   elapsedTimer standard_compilation;
2133   elapsedTimer total_compilation;
2134   elapsedTimer osr_compilation;
2135 
2136   int standard_bytes_compiled = 0;
2137   int osr_bytes_compiled = 0;
2138 
2139   int standard_compile_count = 0;
2140   int osr_compile_count = 0;
2141   int total_compile_count = 0;
2142 
2143   int nmethods_size = 0;
2144   int nmethods_code_size = 0;
2145   bool printedHeader = false;
2146 
2147   for (unsigned int i = 0; i < sizeof(_compilers) / sizeof(AbstractCompiler*); i++) {
2148     AbstractCompiler* comp = _compilers[i];
2149     if (comp != NULL) {
2150       if (per_compiler && aggregate && !printedHeader) {
2151         printedHeader = true;
2152         tty->cr();
2153         tty->print_cr("Individual compiler times (for compiled methods only)");
2154         tty->print_cr("------------------------------------------------");
2155         tty->cr();
2156       }
2157       CompilerStatistics* stats = comp->stats();
2158 
2159       standard_compilation.add(stats->_standard._time);
2160       osr_compilation.add(stats->_osr._time);
2161 
2162       standard_bytes_compiled += stats->_standard._bytes;
2163       osr_bytes_compiled += stats->_osr._bytes;
2164 
2165       standard_compile_count += stats->_standard._count;
2166       osr_compile_count += stats->_osr._count;
2167 
2168       nmethods_size += stats->_nmethods_size;
2169       nmethods_code_size += stats->_nmethods_code_size;
2170 
2171       if (per_compiler) {
2172         print_times(comp);
2173       }
2174     }
2175   }
2176   total_compile_count = osr_compile_count + standard_compile_count;
2177   total_compilation.add(osr_compilation);
2178   total_compilation.add(standard_compilation);
2179 
2180   // In hosted mode, print the JVMCI compiler specific counters manually.
2181   if (!UseJVMCICompiler) {
2182     JVMCICompiler::print_compilation_timers();
2183   }
2184 #else // INCLUDE_JVMCI
2185   elapsedTimer standard_compilation = CompileBroker::_t_standard_compilation;
2186   elapsedTimer osr_compilation = CompileBroker::_t_osr_compilation;
2187   elapsedTimer total_compilation = CompileBroker::_t_total_compilation;
2188 
2189   int standard_bytes_compiled = CompileBroker::_sum_standard_bytes_compiled;
2190   int osr_bytes_compiled = CompileBroker::_sum_osr_bytes_compiled;
2191 
2192   int standard_compile_count = CompileBroker::_total_standard_compile_count;
2193   int osr_compile_count = CompileBroker::_total_osr_compile_count;
2194   int total_compile_count = CompileBroker::_total_compile_count;
2195 
2196   int nmethods_size = CompileBroker::_sum_nmethod_code_size;
2197   int nmethods_code_size = CompileBroker::_sum_nmethod_size;
2198 #endif // INCLUDE_JVMCI
2199 
2200   if (!aggregate) {
2201     return;
2202   }
2203   tty->cr();
2204   tty->print_cr("Accumulated compiler times");
2205   tty->print_cr("----------------------------------------------------------");
2206                //0000000000111111111122222222223333333333444444444455555555556666666666
2207                //0123456789012345678901234567890123456789012345678901234567890123456789
2208   tty->print_cr("  Total compilation time   : %7.3f s", total_compilation.seconds());
2209   tty->print_cr("    Standard compilation   : %7.3f s, Average : %2.3f s",
2210                 standard_compilation.seconds(),
2211                 standard_compilation.seconds() / standard_compile_count);
2212   tty->print_cr("    Bailed out compilation : %7.3f s, Average : %2.3f s",
2213                 CompileBroker::_t_bailedout_compilation.seconds(),
2214                 CompileBroker::_t_bailedout_compilation.seconds() / CompileBroker::_total_bailout_count);
2215   tty->print_cr("    On stack replacement   : %7.3f s, Average : %2.3f s",
2216                 osr_compilation.seconds(),
2217                 osr_compilation.seconds() / osr_compile_count);
2218   tty->print_cr("    Invalidated            : %7.3f s, Average : %2.3f s",
2219                 CompileBroker::_t_invalidated_compilation.seconds(),
2220                 CompileBroker::_t_invalidated_compilation.seconds() / CompileBroker::_total_invalidated_count);
2221 
2222   AbstractCompiler *comp = compiler(CompLevel_simple);
2223   if (comp != NULL) {
2224     tty->cr();
2225     comp->print_timers();
2226   }
2227   comp = compiler(CompLevel_full_optimization);
2228   if (comp != NULL) {
2229     tty->cr();
2230     comp->print_timers();
2231   }
2232   tty->cr();
2233   tty->print_cr("  Total compiled methods    : %8d methods", total_compile_count);
2234   tty->print_cr("    Standard compilation    : %8d methods", standard_compile_count);
2235   tty->print_cr("    On stack replacement    : %8d methods", osr_compile_count);
2236   int tcb = osr_bytes_compiled + standard_bytes_compiled;
2237   tty->print_cr("  Total compiled bytecodes  : %8d bytes", tcb);
2238   tty->print_cr("    Standard compilation    : %8d bytes", standard_bytes_compiled);
2239   tty->print_cr("    On stack replacement    : %8d bytes", osr_bytes_compiled);
2240   double tcs = total_compilation.seconds();
2241   int bps = tcs == 0.0 ? 0 : (int)(tcb / tcs);
2242   tty->print_cr("  Average compilation speed : %8d bytes/s", bps);
2243   tty->cr();
2244   tty->print_cr("  nmethod code size         : %8d bytes", nmethods_code_size);
2245   tty->print_cr("  nmethod total size        : %8d bytes", nmethods_size);
2246 }
2247 
2248 // Debugging output for failure
2249 void CompileBroker::print_last_compile() {
2250   if ( _last_compile_level != CompLevel_none &&
2251        compiler(_last_compile_level) != NULL &&
2252        _last_method_compiled != NULL &&
2253        _last_compile_type != no_compile) {
2254     if (_last_compile_type == osr_compile) {
2255       tty->print_cr("Last parse:  [osr]%d+++(%d) %s",
2256                     _osr_compilation_id, _last_compile_level, _last_method_compiled);
2257     } else {
2258       tty->print_cr("Last parse:  %d+++(%d) %s",
2259                     _compilation_id, _last_compile_level, _last_method_compiled);
2260     }
2261   }
2262 }
2263 
2264 
2265 void CompileBroker::print_compiler_threads_on(outputStream* st) {
< prev index next >