53 #include "runtime/sharedRuntime.hpp"
54 #include "runtime/sweeper.hpp"
55 #include "runtime/timerTrace.hpp"
56 #include "trace/tracing.hpp"
57 #include "utilities/debug.hpp"
58 #include "utilities/dtrace.hpp"
59 #include "utilities/events.hpp"
60 #include "utilities/formatBuffer.hpp"
61 #ifdef COMPILER1
62 #include "c1/c1_Compiler.hpp"
63 #endif
64 #if INCLUDE_JVMCI
65 #include "jvmci/jvmciCompiler.hpp"
66 #include "jvmci/jvmciRuntime.hpp"
67 #include "jvmci/jvmciJavaClasses.hpp"
68 #include "runtime/vframe.hpp"
69 #endif
70 #ifdef COMPILER2
71 #include "opto/c2compiler.hpp"
72 #endif
73 #ifdef SHARK
74 #include "shark/sharkCompiler.hpp"
75 #endif
76
77 #ifdef DTRACE_ENABLED
78
79 // Only bother with this argument setup if dtrace is available
80
81 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
82 { \
83 Symbol* klass_name = (method)->klass_name(); \
84 Symbol* name = (method)->name(); \
85 Symbol* signature = (method)->signature(); \
86 HOTSPOT_METHOD_COMPILE_BEGIN( \
87 (char *) comp_name, strlen(comp_name), \
88 (char *) klass_name->bytes(), klass_name->utf8_length(), \
89 (char *) name->bytes(), name->utf8_length(), \
90 (char *) signature->bytes(), signature->utf8_length()); \
91 }
92
93 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
94 { \
95 Symbol* klass_name = (method)->klass_name(); \
514 ttyLocker ttyl;
515 print(tty);
516 }
517
518 CompilerCounters::CompilerCounters() {
519 _current_method[0] = '\0';
520 _compile_type = CompileBroker::no_compile;
521 }
522
523 // ------------------------------------------------------------------
524 // CompileBroker::compilation_init
525 //
526 // Initialize the Compilation object
527 void CompileBroker::compilation_init(TRAPS) {
528 _last_method_compiled[0] = '\0';
529
530 // No need to initialize compilation system if we do not use it.
531 if (!UseCompiler) {
532 return;
533 }
534 #ifndef SHARK
535 // Set the interface to the current compiler(s).
536 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
537 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
538
539 #if INCLUDE_JVMCI
540 if (EnableJVMCI) {
541 // This is creating a JVMCICompiler singleton.
542 JVMCICompiler* jvmci = new JVMCICompiler();
543
544 if (UseJVMCICompiler) {
545 _compilers[1] = jvmci;
546 if (FLAG_IS_DEFAULT(JVMCIThreads)) {
547 if (BootstrapJVMCI) {
548 // JVMCI will bootstrap so give it more threads
549 c2_count = MIN2(32, os::active_processor_count());
550 }
551 } else {
552 c2_count = JVMCIThreads;
553 }
554 if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
556 c1_count = JVMCIHostThreads;
557 }
558 }
559 }
560 #endif // INCLUDE_JVMCI
561
562 #ifdef COMPILER1
563 if (c1_count > 0) {
564 _compilers[0] = new Compiler();
565 }
566 #endif // COMPILER1
567
568 #ifdef COMPILER2
569 if (true JVMCI_ONLY( && !UseJVMCICompiler)) {
570 if (c2_count > 0) {
571 _compilers[1] = new C2Compiler();
572 }
573 }
574 #endif // COMPILER2
575
576 #else // SHARK
577 int c1_count = 0;
578 int c2_count = 1;
579
580 _compilers[1] = new SharkCompiler();
581 #endif // SHARK
582
583 // Start the compiler thread(s) and the sweeper thread
584 init_compiler_sweeper_threads(c1_count, c2_count);
585 // totalTime performance counter is always created as it is required
586 // by the implementation of java.lang.management.CompilationMBean.
587 {
588 EXCEPTION_MARK;
589 _perf_total_compilation =
590 PerfDataManager::create_counter(JAVA_CI, "totalTime",
591 PerfData::U_Ticks, CHECK);
592 }
593
594 if (UsePerfData) {
595
596 EXCEPTION_MARK;
597
598 // create the jvmstat performance counters
599 _perf_osr_compilation =
600 PerfDataManager::create_counter(SUN_CI, "osrTime",
601 PerfData::U_Ticks, CHECK);
602
757 Threads::add(thread);
758 Thread::start(thread);
759 }
760 }
761
762 // First release lock before aborting VM.
763 if (thread == NULL || thread->osthread() == NULL) {
764 vm_exit_during_initialization("java.lang.OutOfMemoryError",
765 os::native_thread_creation_failed_msg());
766 }
767
768 // Let go of Threads_lock before yielding
769 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
770
771 return thread;
772 }
773
774
775 void CompileBroker::init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count) {
776 EXCEPTION_MARK;
777 #if !defined(ZERO) && !defined(SHARK)
778 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
779 #endif // !ZERO && !SHARK
780 // Initialize the compilation queue
781 if (c2_compiler_count > 0) {
782 const char* name = JVMCI_ONLY(UseJVMCICompiler ? "JVMCI compile queue" :) "C2 compile queue";
783 _c2_compile_queue = new CompileQueue(name);
784 _compilers[1]->set_num_compiler_threads(c2_compiler_count);
785 }
786 if (c1_compiler_count > 0) {
787 _c1_compile_queue = new CompileQueue("C1 compile queue");
788 _compilers[0]->set_num_compiler_threads(c1_compiler_count);
789 }
790
791 int compiler_count = c1_compiler_count + c2_compiler_count;
792
793 char name_buffer[256];
794 const bool compiler_thread = true;
795 for (int i = 0; i < c2_compiler_count; i++) {
796 // Create a name for our thread.
797 sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
798 CompilerCounters* counters = new CompilerCounters();
799 // Shark and C2
800 make_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], compiler_thread, CHECK);
801 }
802
803 for (int i = c2_compiler_count; i < compiler_count; i++) {
804 // Create a name for our thread.
805 sprintf(name_buffer, "C1 CompilerThread%d", i);
806 CompilerCounters* counters = new CompilerCounters();
807 // C1
808 make_thread(name_buffer, _c1_compile_queue, counters, _compilers[0], compiler_thread, CHECK);
809 }
810
811 if (UsePerfData) {
812 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK);
813 }
814
815 if (MethodFlushing) {
816 // Initialize the sweeper thread
817 make_thread("Sweeper thread", NULL, NULL, NULL, false, CHECK);
818 }
819 }
1083 }
1084 }
1085 if (method->is_not_compilable(comp_level)) {
1086 return NULL;
1087 }
1088 } else {
1089 // osr compilation
1090 #ifndef TIERED
1091 // seems like an assert of dubious value
1092 assert(comp_level == CompLevel_highest_tier,
1093 "all OSR compiles are assumed to be at a single compilation level");
1094 #endif // TIERED
1095 // We accept a higher level osr method
1096 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1097 if (nm != NULL) return nm;
1098 if (method->is_not_osr_compilable(comp_level)) return NULL;
1099 }
1100
1101 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1102 // some prerequisites that are compiler specific
1103 if (comp->is_c2() || comp->is_shark()) {
1104 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1105 // Resolve all classes seen in the signature of the method
1106 // we are compiling.
1107 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1108 }
1109
1110 // If the method is native, do the lookup in the thread requesting
1111 // the compilation. Native lookups can load code, which is not
1112 // permitted during compilation.
1113 //
1114 // Note: A native method implies non-osr compilation which is
1115 // checked with an assertion at the entry of this method.
1116 if (method->is_native() && !method->is_method_handle_intrinsic()) {
1117 bool in_base_library;
1118 address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1119 if (HAS_PENDING_EXCEPTION) {
1120 // In case of an exception looking up the method, we just forget
1121 // about it. The interpreter will kick-in and throw the exception.
1122 method->set_not_compilable(); // implies is_not_osr_compilable()
1123 CLEAR_PENDING_EXCEPTION;
1473
1474 int system_dictionary_modification_counter;
1475 {
1476 MutexLocker locker(Compile_lock, thread);
1477 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1478 }
1479
1480 {
1481 // Must switch to native to allocate ci_env
1482 ThreadToNativeFromVM ttn(thread);
1483 ciEnv ci_env(NULL, system_dictionary_modification_counter);
1484 // Cache Jvmti state
1485 ci_env.cache_jvmti_state();
1486 // Cache DTrace flags
1487 ci_env.cache_dtrace_flags();
1488
1489 // Switch back to VM state to do compiler initialization
1490 ThreadInVMfromNative tv(thread);
1491 ResetNoHandleMark rnhm;
1492
1493 if (!comp->is_shark()) {
1494 // Perform per-thread and global initializations
1495 comp->initialize();
1496 }
1497 }
1498
1499 if (comp->is_failed()) {
1500 disable_compilation_forever();
1501 // If compiler initialization failed, no compiler thread that is specific to a
1502 // particular compiler runtime will ever start to compile methods.
1503 shutdown_compiler_runtime(comp, thread);
1504 return false;
1505 }
1506
1507 // C1 specific check
1508 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1509 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1510 return false;
1511 }
1512
1513 return true;
1514 }
1515
1516 /**
|
53 #include "runtime/sharedRuntime.hpp"
54 #include "runtime/sweeper.hpp"
55 #include "runtime/timerTrace.hpp"
56 #include "trace/tracing.hpp"
57 #include "utilities/debug.hpp"
58 #include "utilities/dtrace.hpp"
59 #include "utilities/events.hpp"
60 #include "utilities/formatBuffer.hpp"
61 #ifdef COMPILER1
62 #include "c1/c1_Compiler.hpp"
63 #endif
64 #if INCLUDE_JVMCI
65 #include "jvmci/jvmciCompiler.hpp"
66 #include "jvmci/jvmciRuntime.hpp"
67 #include "jvmci/jvmciJavaClasses.hpp"
68 #include "runtime/vframe.hpp"
69 #endif
70 #ifdef COMPILER2
71 #include "opto/c2compiler.hpp"
72 #endif
73
74 #ifdef DTRACE_ENABLED
75
76 // Only bother with this argument setup if dtrace is available
77
78 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
79 { \
80 Symbol* klass_name = (method)->klass_name(); \
81 Symbol* name = (method)->name(); \
82 Symbol* signature = (method)->signature(); \
83 HOTSPOT_METHOD_COMPILE_BEGIN( \
84 (char *) comp_name, strlen(comp_name), \
85 (char *) klass_name->bytes(), klass_name->utf8_length(), \
86 (char *) name->bytes(), name->utf8_length(), \
87 (char *) signature->bytes(), signature->utf8_length()); \
88 }
89
90 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
91 { \
92 Symbol* klass_name = (method)->klass_name(); \
511 ttyLocker ttyl;
512 print(tty);
513 }
514
515 CompilerCounters::CompilerCounters() {
516 _current_method[0] = '\0';
517 _compile_type = CompileBroker::no_compile;
518 }
519
520 // ------------------------------------------------------------------
521 // CompileBroker::compilation_init
522 //
523 // Initialize the Compilation object
524 void CompileBroker::compilation_init(TRAPS) {
525 _last_method_compiled[0] = '\0';
526
527 // No need to initialize compilation system if we do not use it.
528 if (!UseCompiler) {
529 return;
530 }
531 // Set the interface to the current compiler(s).
532 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
533 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
534
535 #if INCLUDE_JVMCI
536 if (EnableJVMCI) {
537 // This is creating a JVMCICompiler singleton.
538 JVMCICompiler* jvmci = new JVMCICompiler();
539
540 if (UseJVMCICompiler) {
541 _compilers[1] = jvmci;
542 if (FLAG_IS_DEFAULT(JVMCIThreads)) {
543 if (BootstrapJVMCI) {
544 // JVMCI will bootstrap so give it more threads
545 c2_count = MIN2(32, os::active_processor_count());
546 }
547 } else {
548 c2_count = JVMCIThreads;
549 }
550 if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
552 c1_count = JVMCIHostThreads;
553 }
554 }
555 }
556 #endif // INCLUDE_JVMCI
557
558 #ifdef COMPILER1
559 if (c1_count > 0) {
560 _compilers[0] = new Compiler();
561 }
562 #endif // COMPILER1
563
564 #ifdef COMPILER2
565 if (true JVMCI_ONLY( && !UseJVMCICompiler)) {
566 if (c2_count > 0) {
567 _compilers[1] = new C2Compiler();
568 }
569 }
570 #endif // COMPILER2
571
572 // Start the compiler thread(s) and the sweeper thread
573 init_compiler_sweeper_threads(c1_count, c2_count);
574 // totalTime performance counter is always created as it is required
575 // by the implementation of java.lang.management.CompilationMBean.
576 {
577 EXCEPTION_MARK;
578 _perf_total_compilation =
579 PerfDataManager::create_counter(JAVA_CI, "totalTime",
580 PerfData::U_Ticks, CHECK);
581 }
582
583 if (UsePerfData) {
584
585 EXCEPTION_MARK;
586
587 // create the jvmstat performance counters
588 _perf_osr_compilation =
589 PerfDataManager::create_counter(SUN_CI, "osrTime",
590 PerfData::U_Ticks, CHECK);
591
746 Threads::add(thread);
747 Thread::start(thread);
748 }
749 }
750
751 // First release lock before aborting VM.
752 if (thread == NULL || thread->osthread() == NULL) {
753 vm_exit_during_initialization("java.lang.OutOfMemoryError",
754 os::native_thread_creation_failed_msg());
755 }
756
757 // Let go of Threads_lock before yielding
758 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
759
760 return thread;
761 }
762
763
764 void CompileBroker::init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count) {
765 EXCEPTION_MARK;
766 #if !defined(ZERO)
767 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
768 #endif // !ZERO
769 // Initialize the compilation queue
770 if (c2_compiler_count > 0) {
771 const char* name = JVMCI_ONLY(UseJVMCICompiler ? "JVMCI compile queue" :) "C2 compile queue";
772 _c2_compile_queue = new CompileQueue(name);
773 _compilers[1]->set_num_compiler_threads(c2_compiler_count);
774 }
775 if (c1_compiler_count > 0) {
776 _c1_compile_queue = new CompileQueue("C1 compile queue");
777 _compilers[0]->set_num_compiler_threads(c1_compiler_count);
778 }
779
780 int compiler_count = c1_compiler_count + c2_compiler_count;
781
782 char name_buffer[256];
783 const bool compiler_thread = true;
784 for (int i = 0; i < c2_compiler_count; i++) {
785 // Create a name for our thread.
786 sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
787 CompilerCounters* counters = new CompilerCounters();
788 make_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], compiler_thread, CHECK);
789 }
790
791 for (int i = c2_compiler_count; i < compiler_count; i++) {
792 // Create a name for our thread.
793 sprintf(name_buffer, "C1 CompilerThread%d", i);
794 CompilerCounters* counters = new CompilerCounters();
795 // C1
796 make_thread(name_buffer, _c1_compile_queue, counters, _compilers[0], compiler_thread, CHECK);
797 }
798
799 if (UsePerfData) {
800 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK);
801 }
802
803 if (MethodFlushing) {
804 // Initialize the sweeper thread
805 make_thread("Sweeper thread", NULL, NULL, NULL, false, CHECK);
806 }
807 }
1071 }
1072 }
1073 if (method->is_not_compilable(comp_level)) {
1074 return NULL;
1075 }
1076 } else {
1077 // osr compilation
1078 #ifndef TIERED
1079 // seems like an assert of dubious value
1080 assert(comp_level == CompLevel_highest_tier,
1081 "all OSR compiles are assumed to be at a single compilation level");
1082 #endif // TIERED
1083 // We accept a higher level osr method
1084 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1085 if (nm != NULL) return nm;
1086 if (method->is_not_osr_compilable(comp_level)) return NULL;
1087 }
1088
1089 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1090 // some prerequisites that are compiler specific
1091 if (comp->is_c2()) {
1092 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1093 // Resolve all classes seen in the signature of the method
1094 // we are compiling.
1095 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1096 }
1097
1098 // If the method is native, do the lookup in the thread requesting
1099 // the compilation. Native lookups can load code, which is not
1100 // permitted during compilation.
1101 //
1102 // Note: A native method implies non-osr compilation which is
1103 // checked with an assertion at the entry of this method.
1104 if (method->is_native() && !method->is_method_handle_intrinsic()) {
1105 bool in_base_library;
1106 address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1107 if (HAS_PENDING_EXCEPTION) {
1108 // In case of an exception looking up the method, we just forget
1109 // about it. The interpreter will kick-in and throw the exception.
1110 method->set_not_compilable(); // implies is_not_osr_compilable()
1111 CLEAR_PENDING_EXCEPTION;
1461
1462 int system_dictionary_modification_counter;
1463 {
1464 MutexLocker locker(Compile_lock, thread);
1465 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1466 }
1467
1468 {
1469 // Must switch to native to allocate ci_env
1470 ThreadToNativeFromVM ttn(thread);
1471 ciEnv ci_env(NULL, system_dictionary_modification_counter);
1472 // Cache Jvmti state
1473 ci_env.cache_jvmti_state();
1474 // Cache DTrace flags
1475 ci_env.cache_dtrace_flags();
1476
1477 // Switch back to VM state to do compiler initialization
1478 ThreadInVMfromNative tv(thread);
1479 ResetNoHandleMark rnhm;
1480
1481 // Perform per-thread and global initializations
1482 comp->initialize();
1483 }
1484
1485 if (comp->is_failed()) {
1486 disable_compilation_forever();
1487 // If compiler initialization failed, no compiler thread that is specific to a
1488 // particular compiler runtime will ever start to compile methods.
1489 shutdown_compiler_runtime(comp, thread);
1490 return false;
1491 }
1492
1493 // C1 specific check
1494 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1495 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1496 return false;
1497 }
1498
1499 return true;
1500 }
1501
1502 /**
|