< prev index next >

src/hotspot/share/runtime/sharedRuntime.cpp

Print this page




 121 #ifdef COMPILER2
 122   generate_uncommon_trap_blob();
 123 #endif // COMPILER2
 124 }
 125 
 126 #include <math.h>
 127 
 128 // Implementation of SharedRuntime
 129 
 130 #ifndef PRODUCT
 131 // For statistics
 132 int SharedRuntime::_ic_miss_ctr = 0;
 133 int SharedRuntime::_wrong_method_ctr = 0;
 134 int SharedRuntime::_resolve_static_ctr = 0;
 135 int SharedRuntime::_resolve_virtual_ctr = 0;
 136 int SharedRuntime::_resolve_opt_virtual_ctr = 0;
 137 int SharedRuntime::_implicit_null_throws = 0;
 138 int SharedRuntime::_implicit_div0_throws = 0;
 139 int SharedRuntime::_throw_null_ctr = 0;
 140 
 141 int SharedRuntime::_nof_normal_calls = 0;
 142 int SharedRuntime::_nof_optimized_calls = 0;
 143 int SharedRuntime::_nof_inlined_calls = 0;
 144 int SharedRuntime::_nof_megamorphic_calls = 0;
 145 int SharedRuntime::_nof_static_calls = 0;
 146 int SharedRuntime::_nof_inlined_static_calls = 0;
 147 int SharedRuntime::_nof_interface_calls = 0;
 148 int SharedRuntime::_nof_optimized_interface_calls = 0;
 149 int SharedRuntime::_nof_inlined_interface_calls = 0;
 150 int SharedRuntime::_nof_megamorphic_interface_calls = 0;
 151 int SharedRuntime::_nof_removable_exceptions = 0;
 152 
 153 int SharedRuntime::_new_instance_ctr=0;
 154 int SharedRuntime::_new_array_ctr=0;
 155 int SharedRuntime::_multi1_ctr=0;
 156 int SharedRuntime::_multi2_ctr=0;
 157 int SharedRuntime::_multi3_ctr=0;
 158 int SharedRuntime::_multi4_ctr=0;
 159 int SharedRuntime::_multi5_ctr=0;
 160 int SharedRuntime::_mon_enter_stub_ctr=0;
 161 int SharedRuntime::_mon_exit_stub_ctr=0;
 162 int SharedRuntime::_mon_enter_ctr=0;
 163 int SharedRuntime::_mon_exit_ctr=0;
 164 int SharedRuntime::_partial_subtype_ctr=0;
 165 int SharedRuntime::_jbyte_array_copy_ctr=0;
 166 int SharedRuntime::_jshort_array_copy_ctr=0;
 167 int SharedRuntime::_jint_array_copy_ctr=0;
 168 int SharedRuntime::_jlong_array_copy_ctr=0;
 169 int SharedRuntime::_oop_array_copy_ctr=0;
 170 int SharedRuntime::_checkcast_array_copy_ctr=0;


2128   if (_jshort_array_copy_ctr) tty->print_cr("%5d short array copies", _jshort_array_copy_ctr);
2129   if (_jint_array_copy_ctr) tty->print_cr("%5d int array copies", _jint_array_copy_ctr);
2130   if (_jlong_array_copy_ctr) tty->print_cr("%5d long array copies", _jlong_array_copy_ctr);
2131   if (_oop_array_copy_ctr) tty->print_cr("%5d oop array copies", _oop_array_copy_ctr);
2132   if (_checkcast_array_copy_ctr) tty->print_cr("%5d checkcast array copies", _checkcast_array_copy_ctr);
2133   if (_unsafe_array_copy_ctr) tty->print_cr("%5d unsafe array copies", _unsafe_array_copy_ctr);
2134   if (_generic_array_copy_ctr) tty->print_cr("%5d generic array copies", _generic_array_copy_ctr);
2135   if (_slow_array_copy_ctr) tty->print_cr("%5d slow array copies", _slow_array_copy_ctr);
2136   if (_find_handler_ctr) tty->print_cr("%5d find exception handler", _find_handler_ctr);
2137   if (_rethrow_ctr) tty->print_cr("%5d rethrow handler", _rethrow_ctr);
2138 
2139   AdapterHandlerLibrary::print_statistics();
2140 
2141   if (xtty != NULL)  xtty->tail("statistics");
2142 }
2143 
2144 inline double percent(int x, int y) {
2145   return 100.0 * x / MAX2(y, 1);
2146 }
2147 




2148 class MethodArityHistogram {
2149  public:
2150   enum { MAX_ARITY = 256 };
2151  private:
2152   static int _arity_histogram[MAX_ARITY];     // histogram of #args
2153   static int _size_histogram[MAX_ARITY];      // histogram of arg size in words


2154   static int _max_arity;                      // max. arity seen
2155   static int _max_size;                       // max. arg size seen
2156 
2157   static void add_method_to_histogram(nmethod* nm) {
2158     if (CompiledMethod::nmethod_access_is_safe(nm)) {
2159       Method* method = nm->method();
2160       ArgumentCount args(method->signature());
2161       int arity   = args.size() + (method->is_static() ? 0 : 1);
2162       int argsize = method->size_of_parameters();
2163       arity   = MIN2(arity, MAX_ARITY-1);
2164       argsize = MIN2(argsize, MAX_ARITY-1);
2165       int count = method->compiled_invocation_count();


2166       _arity_histogram[arity]  += count;
2167       _size_histogram[argsize] += count;
2168       _max_arity = MAX2(_max_arity, arity);
2169       _max_size  = MAX2(_max_size, argsize);
2170     }
2171   }
2172 
2173   void print_histogram_helper(int n, int* histo, const char* name) {
2174     const int N = MIN2(5, n);
2175     tty->print_cr("\nHistogram of call arity (incl. rcvr, calls to compiled methods only):");
2176     double sum = 0;
2177     double weighted_sum = 0;
2178     int i;
2179     for (i = 0; i <= n; i++) { sum += histo[i]; weighted_sum += i*histo[i]; }
2180     double rest = sum;
2181     double percent = sum / 100;
2182     for (i = 0; i <= N; i++) {
2183       rest -= histo[i];
2184       tty->print_cr("%4d: %7d (%5.1f%%)", i, histo[i], histo[i] / percent);
2185     }
2186     tty->print_cr("rest: %7d (%5.1f%%))", (int)rest, rest / percent);
2187     tty->print_cr("(avg. %s = %3.1f, max = %d)", name, weighted_sum / sum, n);





2188   }
2189 
2190   void print_histogram() {
2191     tty->print_cr("\nHistogram of call arity (incl. rcvr, calls to compiled methods only):");
2192     print_histogram_helper(_max_arity, _arity_histogram, "arity");
2193     tty->print_cr("\nSame for parameter size (in words):");
2194     print_histogram_helper(_max_size, _size_histogram, "size");
2195     tty->cr();
2196   }
2197 
2198  public:
2199   MethodArityHistogram() {
2200     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2201     _max_arity = _max_size = 0;


2202     for (int i = 0; i < MAX_ARITY; i++) _arity_histogram[i] = _size_histogram[i] = 0;
2203     CodeCache::nmethods_do(add_method_to_histogram);
2204     print_histogram();
2205   }
2206 };
2207 
2208 int MethodArityHistogram::_arity_histogram[MethodArityHistogram::MAX_ARITY];
2209 int MethodArityHistogram::_size_histogram[MethodArityHistogram::MAX_ARITY];


2210 int MethodArityHistogram::_max_arity;
2211 int MethodArityHistogram::_max_size;
2212 
2213 void SharedRuntime::print_call_statistics(int comp_total) {
2214   tty->print_cr("Calls from compiled code:");
2215   int total  = _nof_normal_calls + _nof_interface_calls + _nof_static_calls;
2216   int mono_c = _nof_normal_calls - _nof_optimized_calls - _nof_megamorphic_calls;
2217   int mono_i = _nof_interface_calls - _nof_optimized_interface_calls - _nof_megamorphic_interface_calls;
2218   tty->print_cr("\t%9d   (%4.1f%%) total non-inlined   ", total, percent(total, total));
2219   tty->print_cr("\t%9d   (%4.1f%%) virtual calls       ", _nof_normal_calls, percent(_nof_normal_calls, total));
2220   tty->print_cr("\t  %9d  (%3.0f%%)   inlined          ", _nof_inlined_calls, percent(_nof_inlined_calls, _nof_normal_calls));
2221   tty->print_cr("\t  %9d  (%3.0f%%)   optimized        ", _nof_optimized_calls, percent(_nof_optimized_calls, _nof_normal_calls));
2222   tty->print_cr("\t  %9d  (%3.0f%%)   monomorphic      ", mono_c, percent(mono_c, _nof_normal_calls));
2223   tty->print_cr("\t  %9d  (%3.0f%%)   megamorphic      ", _nof_megamorphic_calls, percent(_nof_megamorphic_calls, _nof_normal_calls));
2224   tty->print_cr("\t%9d   (%4.1f%%) interface calls     ", _nof_interface_calls, percent(_nof_interface_calls, total));
2225   tty->print_cr("\t  %9d  (%3.0f%%)   inlined          ", _nof_inlined_interface_calls, percent(_nof_inlined_interface_calls, _nof_interface_calls));
2226   tty->print_cr("\t  %9d  (%3.0f%%)   optimized        ", _nof_optimized_interface_calls, percent(_nof_optimized_interface_calls, _nof_interface_calls));
2227   tty->print_cr("\t  %9d  (%3.0f%%)   monomorphic      ", mono_i, percent(mono_i, _nof_interface_calls));
2228   tty->print_cr("\t  %9d  (%3.0f%%)   megamorphic      ", _nof_megamorphic_interface_calls, percent(_nof_megamorphic_interface_calls, _nof_interface_calls));
2229   tty->print_cr("\t%9d   (%4.1f%%) static/special calls", _nof_static_calls, percent(_nof_static_calls, total));
2230   tty->print_cr("\t  %9d  (%3.0f%%)   inlined          ", _nof_inlined_static_calls, percent(_nof_inlined_static_calls, _nof_static_calls));
2231   tty->cr();
2232   tty->print_cr("Note 1: counter updates are not MT-safe.");
2233   tty->print_cr("Note 2: %% in major categories are relative to total non-inlined calls;");
2234   tty->print_cr("        %% in nested categories are relative to their category");
2235   tty->print_cr("        (and thus add up to more than 100%% with inlining)");
2236   tty->cr();
2237 
2238   MethodArityHistogram h;
2239 }
2240 #endif
2241 
2242 
2243 // A simple wrapper class around the calling convention information
2244 // that allows sharing of adapters for the same calling convention.
2245 class AdapterFingerPrint : public CHeapObj<mtCode> {
2246  private:
2247   enum {
2248     _basic_type_bits = 4,
2249     _basic_type_mask = right_n_bits(_basic_type_bits),
2250     _basic_types_per_int = BitsPerInt / _basic_type_bits,




 121 #ifdef COMPILER2
 122   generate_uncommon_trap_blob();
 123 #endif // COMPILER2
 124 }
 125 
 126 #include <math.h>
 127 
 128 // Implementation of SharedRuntime
 129 
 130 #ifndef PRODUCT
 131 // For statistics
 132 int SharedRuntime::_ic_miss_ctr = 0;
 133 int SharedRuntime::_wrong_method_ctr = 0;
 134 int SharedRuntime::_resolve_static_ctr = 0;
 135 int SharedRuntime::_resolve_virtual_ctr = 0;
 136 int SharedRuntime::_resolve_opt_virtual_ctr = 0;
 137 int SharedRuntime::_implicit_null_throws = 0;
 138 int SharedRuntime::_implicit_div0_throws = 0;
 139 int SharedRuntime::_throw_null_ctr = 0;
 140 
 141 int64_t SharedRuntime::_nof_normal_calls = 0;
 142 int64_t SharedRuntime::_nof_optimized_calls = 0;
 143 int64_t SharedRuntime::_nof_inlined_calls = 0;
 144 int64_t SharedRuntime::_nof_megamorphic_calls = 0;
 145 int64_t SharedRuntime::_nof_static_calls = 0;
 146 int64_t SharedRuntime::_nof_inlined_static_calls = 0;
 147 int64_t SharedRuntime::_nof_interface_calls = 0;
 148 int64_t SharedRuntime::_nof_optimized_interface_calls = 0;
 149 int64_t SharedRuntime::_nof_inlined_interface_calls = 0;
 150 int64_t SharedRuntime::_nof_megamorphic_interface_calls = 0;
 151 int     SharedRuntime::_nof_removable_exceptions = 0;
 152 
 153 int SharedRuntime::_new_instance_ctr=0;
 154 int SharedRuntime::_new_array_ctr=0;
 155 int SharedRuntime::_multi1_ctr=0;
 156 int SharedRuntime::_multi2_ctr=0;
 157 int SharedRuntime::_multi3_ctr=0;
 158 int SharedRuntime::_multi4_ctr=0;
 159 int SharedRuntime::_multi5_ctr=0;
 160 int SharedRuntime::_mon_enter_stub_ctr=0;
 161 int SharedRuntime::_mon_exit_stub_ctr=0;
 162 int SharedRuntime::_mon_enter_ctr=0;
 163 int SharedRuntime::_mon_exit_ctr=0;
 164 int SharedRuntime::_partial_subtype_ctr=0;
 165 int SharedRuntime::_jbyte_array_copy_ctr=0;
 166 int SharedRuntime::_jshort_array_copy_ctr=0;
 167 int SharedRuntime::_jint_array_copy_ctr=0;
 168 int SharedRuntime::_jlong_array_copy_ctr=0;
 169 int SharedRuntime::_oop_array_copy_ctr=0;
 170 int SharedRuntime::_checkcast_array_copy_ctr=0;


2128   if (_jshort_array_copy_ctr) tty->print_cr("%5d short array copies", _jshort_array_copy_ctr);
2129   if (_jint_array_copy_ctr) tty->print_cr("%5d int array copies", _jint_array_copy_ctr);
2130   if (_jlong_array_copy_ctr) tty->print_cr("%5d long array copies", _jlong_array_copy_ctr);
2131   if (_oop_array_copy_ctr) tty->print_cr("%5d oop array copies", _oop_array_copy_ctr);
2132   if (_checkcast_array_copy_ctr) tty->print_cr("%5d checkcast array copies", _checkcast_array_copy_ctr);
2133   if (_unsafe_array_copy_ctr) tty->print_cr("%5d unsafe array copies", _unsafe_array_copy_ctr);
2134   if (_generic_array_copy_ctr) tty->print_cr("%5d generic array copies", _generic_array_copy_ctr);
2135   if (_slow_array_copy_ctr) tty->print_cr("%5d slow array copies", _slow_array_copy_ctr);
2136   if (_find_handler_ctr) tty->print_cr("%5d find exception handler", _find_handler_ctr);
2137   if (_rethrow_ctr) tty->print_cr("%5d rethrow handler", _rethrow_ctr);
2138 
2139   AdapterHandlerLibrary::print_statistics();
2140 
2141   if (xtty != NULL)  xtty->tail("statistics");
2142 }
2143 
2144 inline double percent(int x, int y) {
2145   return 100.0 * x / MAX2(y, 1);
2146 }
2147 
2148 inline double percent(int64_t x, int64_t y) {
2149   return 100.0 * x / MAX2(y, (int64_t)1);
2150 }
2151 
2152 class MethodArityHistogram {
2153  public:
2154   enum { MAX_ARITY = 256 };
2155  private:
2156   static uint64_t _arity_histogram[MAX_ARITY]; // histogram of #args
2157   static uint64_t _size_histogram[MAX_ARITY];  // histogram of arg size in words
2158   static uint64_t _total_compiled_calls;
2159   static uint64_t _max_compiled_calls_per_method;
2160   static int _max_arity;                       // max. arity seen
2161   static int _max_size;                        // max. arg size seen
2162 
2163   static void add_method_to_histogram(nmethod* nm) {
2164     if (CompiledMethod::nmethod_access_is_safe(nm)) {
2165       Method* method = nm->method();
2166       ArgumentCount args(method->signature());
2167       int arity   = args.size() + (method->is_static() ? 0 : 1);
2168       int argsize = method->size_of_parameters();
2169       arity   = MIN2(arity, MAX_ARITY-1);
2170       argsize = MIN2(argsize, MAX_ARITY-1);
2171       uint64_t count = (uint64_t)method->compiled_invocation_count();
2172       _max_compiled_calls_per_method = count > _max_compiled_calls_per_method ? count : _max_compiled_calls_per_method;
2173       _total_compiled_calls    += count;
2174       _arity_histogram[arity]  += count;
2175       _size_histogram[argsize] += count;
2176       _max_arity = MAX2(_max_arity, arity);
2177       _max_size  = MAX2(_max_size, argsize);
2178     }
2179   }
2180 
2181   void print_histogram_helper(int n, uint64_t* histo, const char* name) {
2182     const int N = MIN2(9, n);

2183     double sum = 0;
2184     double weighted_sum = 0;
2185     for (int i = 0; i <= n; i++) { sum += histo[i]; weighted_sum += i*histo[i]; }
2186     if (sum >= 1.0) { // prevent divide by zero or divide overflow
2187       double rest = sum;
2188       double percent = sum / 100;
2189       for (int i = 0; i <= N; i++) {
2190         rest -= histo[i];
2191         tty->print_cr("%4d: " UINT64_FORMAT_W(12) " (%5.1f%%)", i, histo[i], histo[i] / percent);
2192       }
2193       tty->print_cr("rest: " INT64_FORMAT_W(12) " (%5.1f%%)", (int64_t)rest, rest / percent);
2194       tty->print_cr("(avg. %s = %3.1f, max = %d)", name, weighted_sum / sum, n);
2195       tty->print_cr("(total # of compiled calls = " INT64_FORMAT_W(14) ")", _total_compiled_calls);
2196       tty->print_cr("(max # of compiled calls   = " INT64_FORMAT_W(14) ")", _max_compiled_calls_per_method);
2197     } else {
2198       tty->print_cr("Histogram generation failed for %s. n = %d, sum = %7.5f", name, n, sum);
2199     }
2200   }
2201 
2202   void print_histogram() {
2203     tty->print_cr("\nHistogram of call arity (incl. rcvr, calls to compiled methods only):");
2204     print_histogram_helper(_max_arity, _arity_histogram, "arity");
2205     tty->print_cr("\nHistogram of parameter block size (in words, incl. rcvr):");
2206     print_histogram_helper(_max_size, _size_histogram, "size");
2207     tty->cr();
2208   }
2209 
2210  public:
2211   MethodArityHistogram() {
2212     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2213     _max_arity = _max_size = 0;
2214     _total_compiled_calls = 0;
2215     _max_compiled_calls_per_method = 0;
2216     for (int i = 0; i < MAX_ARITY; i++) _arity_histogram[i] = _size_histogram[i] = 0;
2217     CodeCache::nmethods_do(add_method_to_histogram);
2218     print_histogram();
2219   }
2220 };
2221 
2222 uint64_t MethodArityHistogram::_arity_histogram[MethodArityHistogram::MAX_ARITY];
2223 uint64_t MethodArityHistogram::_size_histogram[MethodArityHistogram::MAX_ARITY];
2224 uint64_t MethodArityHistogram::_total_compiled_calls;
2225 uint64_t MethodArityHistogram::_max_compiled_calls_per_method;
2226 int MethodArityHistogram::_max_arity;
2227 int MethodArityHistogram::_max_size;
2228 
2229 void SharedRuntime::print_call_statistics(uint64_t comp_total) {
2230   tty->print_cr("Calls from compiled code:");
2231   int64_t total  = _nof_normal_calls + _nof_interface_calls + _nof_static_calls;
2232   int64_t mono_c = _nof_normal_calls - _nof_optimized_calls - _nof_megamorphic_calls;
2233   int64_t mono_i = _nof_interface_calls - _nof_optimized_interface_calls - _nof_megamorphic_interface_calls;
2234   tty->print_cr("\t" INT64_FORMAT_W(12) " (100%%)  total non-inlined   ", total);
2235   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- virtual calls       ", _nof_normal_calls, percent(_nof_normal_calls, total));
2236   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- inlined          ", _nof_inlined_calls, percent(_nof_inlined_calls, _nof_normal_calls));
2237   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- optimized        ", _nof_optimized_calls, percent(_nof_optimized_calls, _nof_normal_calls));
2238   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- monomorphic      ", mono_c, percent(mono_c, _nof_normal_calls));
2239   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- megamorphic      ", _nof_megamorphic_calls, percent(_nof_megamorphic_calls, _nof_normal_calls));
2240   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- interface calls     ", _nof_interface_calls, percent(_nof_interface_calls, total));
2241   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- inlined          ", _nof_inlined_interface_calls, percent(_nof_inlined_interface_calls, _nof_interface_calls));
2242   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- optimized        ", _nof_optimized_interface_calls, percent(_nof_optimized_interface_calls, _nof_interface_calls));
2243   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- monomorphic      ", mono_i, percent(mono_i, _nof_interface_calls));
2244   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- megamorphic      ", _nof_megamorphic_interface_calls, percent(_nof_megamorphic_interface_calls, _nof_interface_calls));
2245   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- static/special calls", _nof_static_calls, percent(_nof_static_calls, total));
2246   tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) |  |- inlined          ", _nof_inlined_static_calls, percent(_nof_inlined_static_calls, _nof_static_calls));
2247   tty->cr();
2248   tty->print_cr("Note 1: counter updates are not MT-safe.");
2249   tty->print_cr("Note 2: %% in major categories are relative to total non-inlined calls;");
2250   tty->print_cr("        %% in nested categories are relative to their category");
2251   tty->print_cr("        (and thus add up to more than 100%% with inlining)");
2252   tty->cr();
2253 
2254   MethodArityHistogram h;
2255 }
2256 #endif
2257 
2258 
2259 // A simple wrapper class around the calling convention information
2260 // that allows sharing of adapters for the same calling convention.
2261 class AdapterFingerPrint : public CHeapObj<mtCode> {
2262  private:
2263   enum {
2264     _basic_type_bits = 4,
2265     _basic_type_mask = right_n_bits(_basic_type_bits),
2266     _basic_types_per_int = BitsPerInt / _basic_type_bits,


< prev index next >