75 #include "utilities/macros.hpp" 76 #include "utilities/vmError.hpp" 77 #ifdef COMPILER1 78 #include "c1/c1_Compiler.hpp" 79 #include "c1/c1_Runtime1.hpp" 80 #endif 81 #ifdef COMPILER2 82 #include "code/compiledIC.hpp" 83 #include "compiler/methodLiveness.hpp" 84 #include "opto/compile.hpp" 85 #include "opto/indexSet.hpp" 86 #include "opto/runtime.hpp" 87 #endif 88 #if INCLUDE_JFR 89 #include "jfr/jfr.hpp" 90 #endif 91 92 GrowableArray<Method*>* collected_profiled_methods; 93 94 int compare_methods(Method** a, Method** b) { 95 // %%% there can be 32-bit overflow here 96 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) 97 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); 98 } 99 100 void collect_profiled_methods(Method* m) { 101 Thread* thread = Thread::current(); 102 methodHandle mh(thread, m); 103 if ((m->method_data() != NULL) && 104 (PrintMethodData || CompilerOracle::should_print(mh))) { 105 collected_profiled_methods->push(m); 106 } 107 } 108 109 void print_method_profiling_data() { 110 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) && 111 (PrintMethodData || CompilerOracle::should_print_methods())) { 112 ResourceMark rm; 113 HandleMark hm; 114 collected_profiled_methods = new GrowableArray<Method*>(1024); 115 SystemDictionary::methods_do(collect_profiled_methods); 116 collected_profiled_methods->sort(&compare_methods); 117 130 tty->fill_to(2); 131 m->method_data()->parameters_type_data()->print_data_on(tty); 132 } 133 m->print_codes(); 134 total_size += m->method_data()->size_in_bytes(); 135 } 136 tty->print_cr("------------------------------------------------------------------------"); 137 tty->print_cr("Total MDO size: %d bytes", total_size); 138 } 139 } 140 } 141 142 143 #ifndef PRODUCT 144 145 // Statistics printing (method invocation histogram) 146 147 GrowableArray<Method*>* collected_invoked_methods; 148 149 void collect_invoked_methods(Method* m) { 150 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) { 151 collected_invoked_methods->push(m); 152 } 153 } 154 155 156 157 158 void print_method_invocation_histogram() { 159 ResourceMark rm; 160 HandleMark hm; 161 collected_invoked_methods = new GrowableArray<Method*>(1024); 162 SystemDictionary::methods_do(collect_invoked_methods); 163 collected_invoked_methods->sort(&compare_methods); 164 // 165 tty->cr(); 166 tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff); 167 tty->cr(); 168 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); 169 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0, 170 synch_total = 0, nativ_total = 0, acces_total = 0; 171 for (int index = 0; index < collected_invoked_methods->length(); index++) { 172 Method* m = collected_invoked_methods->at(index); 173 int c = m->invocation_count() + m->compiled_invocation_count(); 174 if (c >= MethodHistogramCutoff) m->print_invocation_count(); 175 int_total += m->invocation_count(); 176 comp_total += m->compiled_invocation_count(); 177 if (m->is_final()) final_total += c; 178 if (m->is_static()) static_total += c; 179 if (m->is_synchronized()) synch_total += c; 180 if (m->is_native()) nativ_total += c; 181 if (m->is_accessor()) acces_total += c; 182 } 183 tty->cr(); 184 total = int_total + comp_total; 185 tty->print_cr("Invocations summary:"); 186 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total); 187 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total); 188 tty->print_cr("\t%9d (100%%) total", total); 189 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total); 190 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total); 191 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total); 192 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total); 193 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total); 194 tty->cr(); 195 SharedRuntime::print_call_statistics(comp_total); 196 } 197 198 void print_bytecode_count() { 199 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 200 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); 201 } 202 } 203 204 AllocStats alloc_stats; 205 206 207 208 // General statistics printing (profiling ...) 209 void print_statistics() { 210 #ifdef ASSERT 211 212 if (CountRuntimeCalls) { 213 extern Histogram *RuntimeHistogram; | 75 #include "utilities/macros.hpp" 76 #include "utilities/vmError.hpp" 77 #ifdef COMPILER1 78 #include "c1/c1_Compiler.hpp" 79 #include "c1/c1_Runtime1.hpp" 80 #endif 81 #ifdef COMPILER2 82 #include "code/compiledIC.hpp" 83 #include "compiler/methodLiveness.hpp" 84 #include "opto/compile.hpp" 85 #include "opto/indexSet.hpp" 86 #include "opto/runtime.hpp" 87 #endif 88 #if INCLUDE_JFR 89 #include "jfr/jfr.hpp" 90 #endif 91 92 GrowableArray<Method*>* collected_profiled_methods; 93 94 int compare_methods(Method** a, Method** b) { 95 // compiled_invocation_count() returns int64_t, forcing the entire expression 96 // to be evaluated as int64_t. Overflow is not an issue. 97 int64_t diff = (((*b)->invocation_count() + (*b)->compiled_invocation_count()) 98 - ((*a)->invocation_count() + (*a)->compiled_invocation_count())); 99 return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; 100 } 101 102 void collect_profiled_methods(Method* m) { 103 Thread* thread = Thread::current(); 104 methodHandle mh(thread, m); 105 if ((m->method_data() != NULL) && 106 (PrintMethodData || CompilerOracle::should_print(mh))) { 107 collected_profiled_methods->push(m); 108 } 109 } 110 111 void print_method_profiling_data() { 112 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) && 113 (PrintMethodData || CompilerOracle::should_print_methods())) { 114 ResourceMark rm; 115 HandleMark hm; 116 collected_profiled_methods = new GrowableArray<Method*>(1024); 117 SystemDictionary::methods_do(collect_profiled_methods); 118 collected_profiled_methods->sort(&compare_methods); 119 132 tty->fill_to(2); 133 m->method_data()->parameters_type_data()->print_data_on(tty); 134 } 135 m->print_codes(); 136 total_size += m->method_data()->size_in_bytes(); 137 } 138 tty->print_cr("------------------------------------------------------------------------"); 139 tty->print_cr("Total MDO size: %d bytes", total_size); 140 } 141 } 142 } 143 144 145 #ifndef PRODUCT 146 147 // Statistics printing (method invocation histogram) 148 149 GrowableArray<Method*>* collected_invoked_methods; 150 151 void collect_invoked_methods(Method* m) { 152 if (m->invocation_count() + m->compiled_invocation_count() >= 1) { 153 collected_invoked_methods->push(m); 154 } 155 } 156 157 158 // Invocation count accumulators should be unsigned long to shift the 159 // overflow border. Longer-running workloads tend to create invocation 160 // counts which already overflow 32-bit counters for individual methods. 161 void print_method_invocation_histogram() { 162 ResourceMark rm; 163 HandleMark hm; 164 collected_invoked_methods = new GrowableArray<Method*>(1024); 165 SystemDictionary::methods_do(collect_invoked_methods); 166 collected_invoked_methods->sort(&compare_methods); 167 // 168 tty->cr(); 169 tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff); 170 tty->cr(); 171 tty->print_cr("____Count_(I+C)____Method________________________Module_________________"); 172 uint64_t total = 0, 173 int_total = 0, 174 comp_total = 0, 175 special_total= 0, 176 static_total = 0, 177 final_total = 0, 178 synch_total = 0, 179 native_total = 0, 180 access_total = 0; 181 for (int index = 0; index < collected_invoked_methods->length(); index++) { 182 // Counter values returned from getter methods are signed int. 183 // To shift the overflow border by a factor of two, we interpret 184 // them here as unsigned long. A counter can't be negative anyway. 185 Method* m = collected_invoked_methods->at(index); 186 uint64_t iic = (uint64_t)m->invocation_count(); 187 uint64_t cic = (uint64_t)m->compiled_invocation_count(); 188 if ((iic + cic) >= (uint64_t)MethodHistogramCutoff) m->print_invocation_count(); 189 int_total += iic; 190 comp_total += cic; 191 if (m->is_final()) final_total += iic + cic; 192 if (m->is_static()) static_total += iic + cic; 193 if (m->is_synchronized()) synch_total += iic + cic; 194 if (m->is_native()) native_total += iic + cic; 195 if (m->is_accessor()) access_total += iic + cic; 196 } 197 tty->cr(); 198 total = int_total + comp_total; 199 special_total = final_total + static_total +synch_total + native_total + access_total; 200 tty->print_cr("Invocations summary for %d methods:", collected_invoked_methods->length()); 201 tty->print_cr("\t" UINT64_FORMAT_W(12) " (100%%) total", total); 202 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- interpreted", int_total, 100.0 * int_total / total); 203 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- compiled", comp_total, 100.0 * comp_total / total); 204 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- special methods (interpreted and compiled)", 205 special_total, 100.0 * special_total/ total); 206 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- synchronized",synch_total, 100.0 * synch_total / total); 207 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- final", final_total, 100.0 * final_total / total); 208 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- static", static_total, 100.0 * static_total / total); 209 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- native", native_total, 100.0 * native_total / total); 210 tty->print_cr("\t" UINT64_FORMAT_W(12) " (%4.1f%%) |- accessor", access_total, 100.0 * access_total / total); 211 tty->cr(); 212 SharedRuntime::print_call_statistics(comp_total); 213 } 214 215 void print_bytecode_count() { 216 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { 217 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value()); 218 } 219 } 220 221 AllocStats alloc_stats; 222 223 224 225 // General statistics printing (profiling ...) 226 void print_statistics() { 227 #ifdef ASSERT 228 229 if (CountRuntimeCalls) { 230 extern Histogram *RuntimeHistogram; |