src/share/vm/code/codeCache.cpp

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"

  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/gcLocker.hpp"
  37 #include "memory/iterator.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/icache.hpp"
  45 #include "runtime/java.hpp"
  46 #include "runtime/mutexLocker.hpp"
  47 #include "services/memoryService.hpp"
  48 #include "trace/tracing.hpp"
  49 #include "utilities/xmlstream.hpp"
  50 
  51 // Helper class for printing in CodeCache
  52 
  53 class CodeBlob_sizes {
  54  private:


  64   int scopes_pcs_size;
  65 
  66  public:
  67   CodeBlob_sizes() {
  68     count            = 0;
  69     total_size       = 0;
  70     header_size      = 0;
  71     code_size        = 0;
  72     stub_size        = 0;
  73     relocation_size  = 0;
  74     scopes_oop_size  = 0;
  75     scopes_metadata_size  = 0;
  76     scopes_data_size = 0;
  77     scopes_pcs_size  = 0;
  78   }
  79 
  80   int total()                                    { return total_size; }
  81   bool is_empty()                                { return count == 0; }
  82 
  83   void print(const char* title) {



  84     tty->print_cr(" #%d %s = %dK (hdr %d%%,  loc %d%%, code %d%%, stub %d%%, [oops %d%%, data %d%%, pcs %d%%])",
  85                   count,
  86                   title,
  87                   total() / K,
  88                   header_size             * 100 / total_size,
  89                   relocation_size         * 100 / total_size,
  90                   code_size               * 100 / total_size,
  91                   stub_size               * 100 / total_size,
  92                   scopes_oop_size         * 100 / total_size,
  93                   scopes_metadata_size    * 100 / total_size,
  94                   scopes_data_size        * 100 / total_size,
  95                   scopes_pcs_size         * 100 / total_size);
  96   }

  97 
  98   void add(CodeBlob* cb) {
  99     count++;
 100     total_size       += cb->size();
 101     header_size      += cb->header_size();
 102     relocation_size  += cb->relocation_size();
 103     if (cb->is_nmethod()) {
 104       nmethod* nm = cb->as_nmethod_or_null();
 105       code_size        += nm->insts_size();
 106       stub_size        += nm->stub_size();
 107 
 108       scopes_oop_size  += nm->oops_size();
 109       scopes_metadata_size  += nm->metadata_size();
 110       scopes_data_size += nm->scopes_data_size();
 111       scopes_pcs_size  += nm->scopes_pcs_size();
 112     } else {
 113       code_size        += cb->code_size();
 114     }
 115   }
 116 };


 953   tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount);
 954   tty->print_cr("\nnmethod size distribution (non-zombie java)");
 955   tty->print_cr("-------------------------------------------------");
 956 
 957   for(int i=0; i<bucketLimit; i++) {
 958     if(buckets[i] != 0) {
 959       tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize);
 960       tty->fill_to(40);
 961       tty->print_cr("%d",buckets[i]);
 962     }
 963   }
 964 
 965   FREE_C_HEAP_ARRAY(int, buckets, mtCode);
 966 }
 967 
 968 #endif // !PRODUCT
 969 
 970 void CodeCache::print() {
 971   print_summary(tty);
 972 
 973 #ifndef PRODUCT
 974   if (!Verbose) return;
 975 
 976   CodeBlob_sizes live;
 977   CodeBlob_sizes dead;















 978 
 979   FOR_ALL_BLOBS(p) {
 980     if (!p->is_alive()) {
 981       dead.add(p);


































 982     } else {
 983       live.add(p);












 984     }
 985   }
 986 
 987   tty->print_cr("CodeCache:");


































 988 

 989   tty->print_cr("nmethod dependency checking time %f", dependentCheckTime.seconds(),
 990                 dependentCheckTime.seconds() / dependentCheckCount);
 991 
 992   if (!live.is_empty()) {
 993     live.print("live");
 994   }
 995   if (!dead.is_empty()) {
 996     dead.print("dead");
 997   }
 998 
 999 
1000   if (WizardMode) {
1001      // print the oop_map usage
1002     int code_size = 0;
1003     int number_of_blobs = 0;
1004     int number_of_oop_maps = 0;
1005     int map_size = 0;
1006     FOR_ALL_BLOBS(p) {
1007       if (p->is_alive()) {
1008         number_of_blobs++;
1009         code_size += p->code_size();
1010         OopMapSet* set = p->oop_maps();
1011         if (set != NULL) {
1012           number_of_oop_maps += set->size();
1013           map_size           += set->heap_size();
1014         }
1015       }
1016     }
1017     tty->print_cr("OopMaps");
1018     tty->print_cr("  #blobs    = %d", number_of_blobs);
1019     tty->print_cr("  code size = %d", code_size);
1020     tty->print_cr("  #oop_maps = %d", number_of_oop_maps);
1021     tty->print_cr("  map size  = %d", map_size);
1022   }
1023 
1024 #endif // !PRODUCT
1025 }
1026 
1027 void CodeCache::print_summary(outputStream* st, bool detailed) {
1028   size_t total = (_heap->high_boundary() - _heap->low_boundary());
1029   st->print_cr("CodeCache: size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
1030                "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
1031                total/K, (total - unallocated_capacity())/K,
1032                maxCodeCacheUsed/K, unallocated_capacity()/K);
1033 
1034   if (detailed) {
1035     st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
1036                  _heap->low_boundary(),
1037                  _heap->high(),
1038                  _heap->high_boundary());
1039     st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
1040                  " adapters=" UINT32_FORMAT,
1041                  nof_blobs(), nof_nmethods(), nof_adapters());
1042     st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
1043                  "enabled" : Arguments::mode() == Arguments::_int ?
1044                  "disabled (interpreter mode)" :


  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"
  35 #include "interpreter/abstractInterpreter.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "memory/gcLocker.hpp"
  38 #include "memory/iterator.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "oops/method.hpp"
  41 #include "oops/objArrayOop.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/icache.hpp"
  46 #include "runtime/java.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "services/memoryService.hpp"
  49 #include "trace/tracing.hpp"
  50 #include "utilities/xmlstream.hpp"
  51 
  52 // Helper class for printing in CodeCache
  53 
  54 class CodeBlob_sizes {
  55  private:


  65   int scopes_pcs_size;
  66 
  67  public:
  68   CodeBlob_sizes() {
  69     count            = 0;
  70     total_size       = 0;
  71     header_size      = 0;
  72     code_size        = 0;
  73     stub_size        = 0;
  74     relocation_size  = 0;
  75     scopes_oop_size  = 0;
  76     scopes_metadata_size  = 0;
  77     scopes_data_size = 0;
  78     scopes_pcs_size  = 0;
  79   }
  80 
  81   int total()                                    { return total_size; }
  82   bool is_empty()                                { return count == 0; }
  83 
  84   void print(const char* title) {
  85     if (count == 0) {
  86       tty->print_cr("  #%d %s", count, title);
  87     } else {
  88       tty->print_cr("  #%d %s = %dK (hdr %d%%,  loc %d%%, code %d%%, stub %d%%, [oops %d%%, data %d%%, pcs %d%%])",
  89                     count,
  90                     title,
  91                     total() / K,
  92                     header_size             * 100 / total_size,
  93                     relocation_size         * 100 / total_size,
  94                     code_size               * 100 / total_size,
  95                     stub_size               * 100 / total_size,
  96                     scopes_oop_size         * 100 / total_size,
  97                     scopes_metadata_size    * 100 / total_size,
  98                     scopes_data_size        * 100 / total_size,
  99                     scopes_pcs_size         * 100 / total_size);
 100         }
 101   }
 102 
 103   void add(CodeBlob* cb) {
 104     count++;
 105     total_size       += cb->size();
 106     header_size      += cb->header_size();
 107     relocation_size  += cb->relocation_size();
 108     if (cb->is_nmethod()) {
 109       nmethod* nm = cb->as_nmethod_or_null();
 110       code_size        += nm->insts_size();
 111       stub_size        += nm->stub_size();
 112 
 113       scopes_oop_size  += nm->oops_size();
 114       scopes_metadata_size  += nm->metadata_size();
 115       scopes_data_size += nm->scopes_data_size();
 116       scopes_pcs_size  += nm->scopes_pcs_size();
 117     } else {
 118       code_size        += cb->code_size();
 119     }
 120   }
 121 };


 958   tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount);
 959   tty->print_cr("\nnmethod size distribution (non-zombie java)");
 960   tty->print_cr("-------------------------------------------------");
 961 
 962   for(int i=0; i<bucketLimit; i++) {
 963     if(buckets[i] != 0) {
 964       tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize);
 965       tty->fill_to(40);
 966       tty->print_cr("%d",buckets[i]);
 967     }
 968   }
 969 
 970   FREE_C_HEAP_ARRAY(int, buckets, mtCode);
 971 }
 972 
 973 #endif // !PRODUCT
 974 
 975 void CodeCache::print() {
 976   print_summary(tty);
 977 
 978   CodeBlob_sizes live_java_methods  [CompLevel_full_optimization + 1];
 979   CodeBlob_sizes live_osr_methods   [CompLevel_full_optimization + 1];
 980   CodeBlob_sizes live_native_methods;
 981 
 982   CodeBlob_sizes dead_java_methods  [CompLevel_full_optimization + 1];
 983   CodeBlob_sizes dead_osr_methods   [CompLevel_full_optimization + 1];
 984   CodeBlob_sizes dead_native_methods;
 985 
 986   CodeBlob_sizes runtime_stubs;
 987   CodeBlob_sizes deoptimization_stubs;
 988   CodeBlob_sizes uncommon_trap_stubs;
 989   CodeBlob_sizes exception_stubs;
 990   CodeBlob_sizes safepoint_stubs;
 991   CodeBlob_sizes adapter_blobs;
 992   CodeBlob_sizes method_handles_adapter_blobs;
 993   CodeBlob_sizes other_stubs;
 994 
 995   size_t total_live_nmethods = 0;
 996   size_t total_dead_nmethods = 0;
 997   size_t total_stubs_size    = 0;
 998 
 999   FOR_ALL_BLOBS(p) {
1000     // live or not-entrant methods
1001     if (p->is_alive()) {
1002       if (p->is_nmethod()) {
1003         total_live_nmethods++;
1004         // Cannot return NULL, since we checked that it is an nmethod
1005         nmethod* nm = p->as_nmethod_or_null();
1006         const int comp_level = nm->comp_level();
1007 
1008         if (nm->is_osr_method()) {
1009           live_osr_methods[comp_level].add(nm);
1010         } else if (nm->is_native_method()) {
1011           live_native_methods.add(nm);
1012         } else if (nm->is_java_method()) {
1013           live_java_methods[comp_level].add(nm);
1014         }
1015       } else {
1016         total_stubs_size++;
1017         if (p->is_runtime_stub()) {
1018           runtime_stubs.add(p);
1019         } else if (p->is_deoptimization_stub()) {
1020           deoptimization_stubs.add(p);
1021         } else if (p->is_uncommon_trap_stub()) {
1022           uncommon_trap_stubs.add(p);
1023         } else if (p->is_exception_stub()) {
1024           exception_stubs.add(p);
1025         } else if (p->is_safepoint_stub()) {
1026           safepoint_stubs.add(p);
1027         } else if (p->is_adapter_blob()) {
1028           adapter_blobs.add(p);
1029         } else if (p->is_method_handles_adapter_blob()) {
1030           method_handles_adapter_blobs.add(p);
1031         } else {
1032           other_stubs.add(p);
1033         }
1034       }
1035     // zombie or unloaded methods
1036     } else {
1037       if (p->is_nmethod()) {
1038         total_dead_nmethods++;
1039         nmethod* nm = p->as_nmethod_or_null();
1040         const int comp_level = nm->comp_level();
1041 
1042         if (nm->is_osr_method()) {
1043           dead_osr_methods[comp_level].add(nm);
1044         } else if (nm->is_native_method()) {
1045           dead_native_methods.add(nm);
1046         } else if (nm->is_java_method()) {
1047           dead_java_methods[comp_level].add(nm);
1048         }
1049       }
1050     }
1051   }
1052 
1053   // Tier 0 (interpreter)
1054   StubQueue* code = AbstractInterpreter::code();
1055   tty->print("\nInterpreter:");
1056   tty->print_cr("  total=%dk, used=%dk", code->total_space() / K, code->used_space() / K);
1057 
1058   // Print live methods
1059   tty->print_cr("\nTotal number of live methods: %u", total_live_nmethods);
1060   for (int i = 1; i < CompLevel_full_optimization + 1; i++) {
1061         tty->print_cr(" Tier %d:", i);
1062     live_java_methods[i].print("Java methods");
1063     live_osr_methods[i].print("OSR methods");
1064   }
1065   tty->print_cr(" Native methods:");
1066   live_native_methods.print("Native methods");
1067 
1068   // Print dead methods
1069   tty->print_cr("\nTotal number of dead methods: %u", total_dead_nmethods);
1070   for (int i = 1; i < CompLevel_full_optimization + 1; i++) {
1071     tty->print_cr(" Tier %d:", i);
1072         dead_java_methods[i].print("Java methods");
1073         dead_osr_methods[i].print("OSR methods");
1074   }
1075   tty->print_cr(" Native methods:");
1076   dead_native_methods.print("Native methods");
1077 
1078   // Print stubs
1079   tty->print_cr("\nTotal number of stubs: %u", total_stubs_size);
1080   runtime_stubs.print("runtime");
1081   deoptimization_stubs.print("deoptimization");
1082   uncommon_trap_stubs.print("uncommon trap");
1083   exception_stubs.print("exception");
1084   safepoint_stubs.print("safepoint");
1085   adapter_blobs.print("C2I/I2C adapter");
1086   method_handles_adapter_blobs.print("method handles adapter");
1087   other_stubs.print("other");
1088 
1089 #ifndef PRODUCT
1090   tty->print_cr("nmethod dependency checking time %f", dependentCheckTime.seconds(),
1091                 dependentCheckTime.seconds() / dependentCheckCount);
1092 #endif







1093 
1094   if (WizardMode) {
1095      // print the oop_map usage
1096     int code_size = 0;
1097     int number_of_blobs = 0;
1098     int number_of_oop_maps = 0;
1099     int map_size = 0;
1100     FOR_ALL_BLOBS(p) {
1101       if (p->is_alive()) {
1102         number_of_blobs++;
1103         code_size += p->code_size();
1104         OopMapSet* set = p->oop_maps();
1105         if (set != NULL) {
1106           number_of_oop_maps += set->size();
1107           map_size           += set->heap_size();
1108         }
1109       }
1110     }
1111     tty->print_cr("OopMaps");
1112     tty->print_cr("  #blobs    = %d", number_of_blobs);
1113     tty->print_cr("  code size = %d", code_size);
1114     tty->print_cr("  #oop_maps = %d", number_of_oop_maps);
1115     tty->print_cr("  map size  = %d", map_size);
1116   }


1117 }
1118 
1119 void CodeCache::print_summary(outputStream* st, bool detailed) {
1120   size_t total = (_heap->high_boundary() - _heap->low_boundary());
1121   st->print_cr("CodeCache: size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
1122                "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
1123                total/K, (total - unallocated_capacity())/K,
1124                maxCodeCacheUsed/K, unallocated_capacity()/K);
1125 
1126   if (detailed) {
1127     st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
1128                  _heap->low_boundary(),
1129                  _heap->high(),
1130                  _heap->high_boundary());
1131     st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
1132                  " adapters=" UINT32_FORMAT,
1133                  nof_blobs(), nof_nmethods(), nof_adapters());
1134     st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
1135                  "enabled" : Arguments::mode() == Arguments::_int ?
1136                  "disabled (interpreter mode)" :