comparison src/share/vm/compiler/compileBroker.cpp @ 8771:75a28f465a12

8008663: [parfait] Null pointer deference in hotspot/src/share/vm/compiler/compileBroker.cpp Summary: add NULL checks for compiler name Reviewed-by: twisti, kvn
author morris
date Tue, 19 Mar 2013 07:23:29 -0700
parents b7c2c5b2572c
children 46f6f063b272
comparison
equal deleted inserted replaced
8770:f15df3af32c5 8771:75a28f465a12
63 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin, 63 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin,
64 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t); 64 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t);
65 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end, 65 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end,
66 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool); 66 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool);
67 67
68 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) \ 68 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name) \
69 { \ 69 { \
70 char* comp_name = (char*)(compiler)->name(); \
71 Symbol* klass_name = (method)->klass_name(); \ 70 Symbol* klass_name = (method)->klass_name(); \
72 Symbol* name = (method)->name(); \ 71 Symbol* name = (method)->name(); \
73 Symbol* signature = (method)->signature(); \ 72 Symbol* signature = (method)->signature(); \
74 HS_DTRACE_PROBE8(hotspot, method__compile__begin, \ 73 HS_DTRACE_PROBE8(hotspot, method__compile__begin, \
75 comp_name, strlen(comp_name), \ 74 comp_name, strlen(comp_name), \
76 klass_name->bytes(), klass_name->utf8_length(), \ 75 klass_name->bytes(), klass_name->utf8_length(), \
77 name->bytes(), name->utf8_length(), \ 76 name->bytes(), name->utf8_length(), \
78 signature->bytes(), signature->utf8_length()); \ 77 signature->bytes(), signature->utf8_length()); \
79 } 78 }
80 79
81 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) \ 80 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, \
81 comp_name, success) \
82 { \ 82 { \
83 char* comp_name = (char*)(compiler)->name(); \
84 Symbol* klass_name = (method)->klass_name(); \ 83 Symbol* klass_name = (method)->klass_name(); \
85 Symbol* name = (method)->name(); \ 84 Symbol* name = (method)->name(); \
86 Symbol* signature = (method)->signature(); \ 85 Symbol* signature = (method)->signature(); \
87 HS_DTRACE_PROBE9(hotspot, method__compile__end, \ 86 HS_DTRACE_PROBE9(hotspot, method__compile__end, \
88 comp_name, strlen(comp_name), \ 87 comp_name, strlen(comp_name), \
91 signature->bytes(), signature->utf8_length(), (success)); \ 90 signature->bytes(), signature->utf8_length(), (success)); \
92 } 91 }
93 92
94 #else /* USDT2 */ 93 #else /* USDT2 */
95 94
96 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) \ 95 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name) \
97 { \ 96 { \
98 char* comp_name = (char*)(compiler)->name(); \
99 Symbol* klass_name = (method)->klass_name(); \ 97 Symbol* klass_name = (method)->klass_name(); \
100 Symbol* name = (method)->name(); \ 98 Symbol* name = (method)->name(); \
101 Symbol* signature = (method)->signature(); \ 99 Symbol* signature = (method)->signature(); \
102 HOTSPOT_METHOD_COMPILE_BEGIN( \ 100 HOTSPOT_METHOD_COMPILE_BEGIN( \
103 comp_name, strlen(comp_name), \ 101 comp_name, strlen(comp_name), \
104 (char *) klass_name->bytes(), klass_name->utf8_length(), \ 102 (char *) klass_name->bytes(), klass_name->utf8_length(), \
105 (char *) name->bytes(), name->utf8_length(), \ 103 (char *) name->bytes(), name->utf8_length(), \
106 (char *) signature->bytes(), signature->utf8_length()); \ 104 (char *) signature->bytes(), signature->utf8_length()); \
107 } 105 }
108 106
109 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) \ 107 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, \
108 comp_name, success) \
110 { \ 109 { \
111 char* comp_name = (char*)(compiler)->name(); \
112 Symbol* klass_name = (method)->klass_name(); \ 110 Symbol* klass_name = (method)->klass_name(); \
113 Symbol* name = (method)->name(); \ 111 Symbol* name = (method)->name(); \
114 Symbol* signature = (method)->signature(); \ 112 Symbol* signature = (method)->signature(); \
115 HOTSPOT_METHOD_COMPILE_END( \ 113 HOTSPOT_METHOD_COMPILE_END( \
116 comp_name, strlen(comp_name), \ 114 comp_name, strlen(comp_name), \
120 } 118 }
121 #endif /* USDT2 */ 119 #endif /* USDT2 */
122 120
123 #else // ndef DTRACE_ENABLED 121 #else // ndef DTRACE_ENABLED
124 122
125 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) 123 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name)
126 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) 124 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, comp_name, success)
127 125
128 #endif // ndef DTRACE_ENABLED 126 #endif // ndef DTRACE_ENABLED
129 127
130 bool CompileBroker::_initialized = false; 128 bool CompileBroker::_initialized = false;
131 volatile bool CompileBroker::_should_block = false; 129 volatile bool CompileBroker::_should_block = false;
357 // 355 //
358 // Otherwise it's the same as CompileTask::print_line() 356 // Otherwise it's the same as CompileTask::print_line()
359 // 357 //
360 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { 358 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) {
361 // print compiler name 359 // print compiler name
362 st->print("%s:", CompileBroker::compiler(comp_level())->name()); 360 st->print("%s:", CompileBroker::compiler_name(comp_level()));
363 print_compilation(st); 361 print_compilation(st);
364 } 362 }
365 363
366 // ------------------------------------------------------------------ 364 // ------------------------------------------------------------------
367 // CompileTask::print_line 365 // CompileTask::print_line
368 void CompileTask::print_line() { 366 void CompileTask::print_line() {
369 ttyLocker ttyl; // keep the following output all in one block 367 ttyLocker ttyl; // keep the following output all in one block
370 // print compiler name if requested 368 // print compiler name if requested
371 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); 369 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler_name(comp_level()));
372 print_compilation(); 370 print_compilation();
373 } 371 }
374 372
375 373
376 // ------------------------------------------------------------------ 374 // ------------------------------------------------------------------
1215 1213
1216 // return quickly if possible 1214 // return quickly if possible
1217 1215
1218 // lock, make sure that the compilation 1216 // lock, make sure that the compilation
1219 // isn't prohibited in a straightforward way. 1217 // isn't prohibited in a straightforward way.
1220 1218 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1221 if (compiler(comp_level) == NULL || !compiler(comp_level)->can_compile_method(method) || compilation_is_prohibited(method, osr_bci, comp_level)) { 1219 if (comp == NULL || !comp->can_compile_method(method) ||
1220 compilation_is_prohibited(method, osr_bci, comp_level)) {
1222 return NULL; 1221 return NULL;
1223 } 1222 }
1224 1223
1225 if (osr_bci == InvocationEntryBci) { 1224 if (osr_bci == InvocationEntryBci) {
1226 // standard compilation 1225 // standard compilation
1253 if (method->is_not_osr_compilable(comp_level)) return NULL; 1252 if (method->is_not_osr_compilable(comp_level)) return NULL;
1254 } 1253 }
1255 1254
1256 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); 1255 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1257 // some prerequisites that are compiler specific 1256 // some prerequisites that are compiler specific
1258 if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { 1257 if (comp->is_c2() || comp->is_shark()) {
1259 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL); 1258 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL);
1260 // Resolve all classes seen in the signature of the method 1259 // Resolve all classes seen in the signature of the method
1261 // we are compiling. 1260 // we are compiling.
1262 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL); 1261 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL);
1263 } 1262 }
1370 // 1369 //
1371 // See if this compilation is not allowed. 1370 // See if this compilation is not allowed.
1372 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { 1371 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) {
1373 bool is_native = method->is_native(); 1372 bool is_native = method->is_native();
1374 // Some compilers may not support the compilation of natives. 1373 // Some compilers may not support the compilation of natives.
1374 AbstractCompiler *comp = compiler(comp_level);
1375 if (is_native && 1375 if (is_native &&
1376 (!CICompileNatives || !compiler(comp_level)->supports_native())) { 1376 (!CICompileNatives || comp == NULL || !comp->supports_native())) {
1377 method->set_not_compilable_quietly(comp_level); 1377 method->set_not_compilable_quietly(comp_level);
1378 return true; 1378 return true;
1379 } 1379 }
1380 1380
1381 bool is_osr = (osr_bci != standard_entry_bci); 1381 bool is_osr = (osr_bci != standard_entry_bci);
1382 // Some compilers may not support on stack replacement. 1382 // Some compilers may not support on stack replacement.
1383 if (is_osr && 1383 if (is_osr &&
1384 (!CICompileOSR || !compiler(comp_level)->supports_osr())) { 1384 (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
1385 method->set_not_osr_compilable(comp_level); 1385 method->set_not_osr_compilable(comp_level);
1386 return true; 1386 return true;
1387 } 1387 }
1388 1388
1389 // The method may be explicitly excluded by the user. 1389 // The method may be explicitly excluded by the user.
1751 uint compile_id = task->compile_id(); 1751 uint compile_id = task->compile_id();
1752 int osr_bci = task->osr_bci(); 1752 int osr_bci = task->osr_bci();
1753 bool is_osr = (osr_bci != standard_entry_bci); 1753 bool is_osr = (osr_bci != standard_entry_bci);
1754 bool should_log = (thread->log() != NULL); 1754 bool should_log = (thread->log() != NULL);
1755 bool should_break = false; 1755 bool should_break = false;
1756 int task_level = task->comp_level();
1756 { 1757 {
1757 // create the handle inside it's own block so it can't 1758 // create the handle inside it's own block so it can't
1758 // accidentally be referenced once the thread transitions to 1759 // accidentally be referenced once the thread transitions to
1759 // native. The NoHandleMark before the transition should catch 1760 // native. The NoHandleMark before the transition should catch
1760 // any cases where this occurs in the future. 1761 // any cases where this occurs in the future.
1764 should_log = false; 1765 should_log = false;
1765 } 1766 }
1766 assert(!method->is_native(), "no longer compile natives"); 1767 assert(!method->is_native(), "no longer compile natives");
1767 1768
1768 // Save information about this method in case of failure. 1769 // Save information about this method in case of failure.
1769 set_last_compile(thread, method, is_osr, task->comp_level()); 1770 set_last_compile(thread, method, is_osr, task_level);
1770 1771
1771 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task->comp_level()), method); 1772 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task_level), method,
1773 compiler_name(task_level));
1772 } 1774 }
1773 1775
1774 // Allocate a new set of JNI handles. 1776 // Allocate a new set of JNI handles.
1775 push_jni_handle_block(); 1777 push_jni_handle_block();
1776 Method* target_handle = task->method(); 1778 Method* target_handle = task->method();
1803 1805
1804 ciMethod* target = ci_env.get_method_from_handle(target_handle); 1806 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1805 1807
1806 TraceTime t1("compilation", &time); 1808 TraceTime t1("compilation", &time);
1807 1809
1808 compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci); 1810 AbstractCompiler *comp = compiler(task_level);
1811 if (comp == NULL) {
1812 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1813 } else {
1814 comp->compile_method(&ci_env, target, osr_bci);
1815 }
1809 1816
1810 if (!ci_env.failing() && task->code() == NULL) { 1817 if (!ci_env.failing() && task->code() == NULL) {
1811 //assert(false, "compiler should always document failure"); 1818 //assert(false, "compiler should always document failure");
1812 // The compiler elected, without comment, not to register a result. 1819 // The compiler elected, without comment, not to register a result.
1813 // Do not attempt further compilations of this method. 1820 // Do not attempt further compilations of this method.
1841 } 1848 }
1842 pop_jni_handle_block(); 1849 pop_jni_handle_block();
1843 1850
1844 methodHandle method(thread, task->method()); 1851 methodHandle method(thread, task->method());
1845 1852
1846 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task->comp_level()), method, task->is_success()); 1853 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task_level), method,
1854 compiler_name(task_level), task->is_success());
1847 1855
1848 collect_statistics(thread, time, task); 1856 collect_statistics(thread, time, task);
1849 1857
1850 if (PrintCompilation && PrintCompilation2) { 1858 if (PrintCompilation && PrintCompilation2) {
1851 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp 1859 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
1866 else 1874 else
1867 method->set_not_compilable_quietly(); 1875 method->set_not_compilable_quietly();
1868 break; 1876 break;
1869 case ciEnv::MethodCompilable_not_at_tier: 1877 case ciEnv::MethodCompilable_not_at_tier:
1870 if (is_osr) 1878 if (is_osr)
1871 method->set_not_osr_compilable_quietly(task->comp_level()); 1879 method->set_not_osr_compilable_quietly(task_level);
1872 else 1880 else
1873 method->set_not_compilable_quietly(task->comp_level()); 1881 method->set_not_compilable_quietly(task_level);
1874 break; 1882 break;
1875 } 1883 }
1876 1884
1877 // Note that the queued_for_compilation bits are cleared without 1885 // Note that the queued_for_compilation bits are cleared without
1878 // protection of a mutex. [They were set by the requester thread, 1886 // protection of a mutex. [They were set by the requester thread,
2126 } 2134 }
2127 // set the current method for the thread to null 2135 // set the current method for the thread to null
2128 if (UsePerfData) counters->set_current_method(""); 2136 if (UsePerfData) counters->set_current_method("");
2129 } 2137 }
2130 2138
2131 2139 const char* CompileBroker::compiler_name(int comp_level) {
2140 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
2141 if (comp == NULL) {
2142 return "no compiler";
2143 } else {
2144 return (comp->name());
2145 }
2146 }
2132 2147
2133 void CompileBroker::print_times() { 2148 void CompileBroker::print_times() {
2134 tty->cr(); 2149 tty->cr();
2135 tty->print_cr("Accumulated compiler times (for compiled methods only)"); 2150 tty->print_cr("Accumulated compiler times (for compiled methods only)");
2136 tty->print_cr("------------------------------------------------"); 2151 tty->print_cr("------------------------------------------------");
2140 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", 2155 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f",
2141 CompileBroker::_t_standard_compilation.seconds(), 2156 CompileBroker::_t_standard_compilation.seconds(),
2142 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); 2157 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count);
2143 tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count); 2158 tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count);
2144 2159
2145 if (compiler(CompLevel_simple) != NULL) { 2160 AbstractCompiler *comp = compiler(CompLevel_simple);
2146 compiler(CompLevel_simple)->print_timers(); 2161 if (comp != NULL) {
2147 } 2162 comp->print_timers();
2148 if (compiler(CompLevel_full_optimization) != NULL) { 2163 }
2149 compiler(CompLevel_full_optimization)->print_timers(); 2164 comp = compiler(CompLevel_full_optimization);
2165 if (comp != NULL) {
2166 comp->print_timers();
2150 } 2167 }
2151 tty->cr(); 2168 tty->cr();
2152 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; 2169 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled;
2153 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); 2170 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb);
2154 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); 2171 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled);