src/share/vm/code/codeCache.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/code

src/share/vm/code/codeCache.cpp

Print this page




 205 
 206   // Compute initial sizes of CodeHeaps
 207   size_t init_non_method_size   = MIN2(InitialCodeCacheSize, non_method_size);
 208   size_t init_profiled_size     = MIN2(InitialCodeCacheSize, profiled_size);
 209   size_t init_non_profiled_size = MIN2(InitialCodeCacheSize, non_profiled_size);
 210 
 211   // Reserve one continuous chunk of memory for CodeHeaps and split it into
 212   // parts for the individual heaps. The memory layout looks like this:
 213   // ---------- high -----------
 214   //    Non-profiled nmethods
 215   //      Profiled nmethods
 216   //         Non-methods
 217   // ---------- low ------------
 218   ReservedCodeSpace rs = reserve_heap_memory(non_profiled_size + profiled_size + non_method_size);
 219   ReservedSpace non_method_space    = rs.first_part(non_method_size);
 220   ReservedSpace rest                = rs.last_part(non_method_size);
 221   ReservedSpace profiled_space      = rest.first_part(profiled_size);
 222   ReservedSpace non_profiled_space  = rest.last_part(profiled_size);
 223 
 224   // Non-methods (stubs, adapters, ...)
 225   add_heap(non_method_space, "non-methods", init_non_method_size, CodeBlobType::NonMethod);
 226   // Tier 2 and tier 3 (profiled) methods
 227   add_heap(profiled_space, "profiled nmethods", init_profiled_size, CodeBlobType::MethodProfiled);
 228   // Tier 1 and tier 4 (non-profiled) methods and native methods
 229   add_heap(non_profiled_space, "non-profiled nmethods", init_non_profiled_size, CodeBlobType::MethodNonProfiled);
 230 }
 231 
 232 ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size) {
 233   // Determine alignment
 234   const size_t page_size = os::can_execute_large_page_memory() ?
 235           MIN2(os::page_size_for_region(InitialCodeCacheSize, 8),
 236                os::page_size_for_region(size, 8)) :
 237           os::vm_page_size();
 238   const size_t granularity = os::vm_allocation_granularity();
 239   const size_t r_align = MAX2(page_size, granularity);
 240   const size_t r_size = align_size_up(size, r_align);
 241   const size_t rs_align = page_size == (size_t) os::vm_page_size() ? 0 :
 242     MAX2(page_size, granularity);
 243 
 244   ReservedCodeSpace rs(r_size, rs_align, rs_align > 0);
 245 
 246   // Initialize bounds
 247   _low_bound = (address)rs.base();
 248   _high_bound = _low_bound + rs.size();
 249 


 347   CodeBlob* cb = NULL;
 348 
 349   // Get CodeHeap for the given CodeBlobType
 350   CodeHeap* heap = get_code_heap(SegmentedCodeCache ? code_blob_type : CodeBlobType::All);
 351   assert (heap != NULL, "heap is null");
 352 
 353   while (true) {
 354     cb = (CodeBlob*)heap->allocate(size, is_critical);
 355     if (cb != NULL) break;
 356     if (!heap->expand_by(CodeCacheExpansionSize)) {
 357       // Expansion failed
 358       if (SegmentedCodeCache && (code_blob_type == CodeBlobType::NonMethod)) {
 359         // Fallback solution: Store non-method code in the non-profiled code heap
 360         return allocate(size, CodeBlobType::MethodNonProfiled, is_critical);
 361       }
 362       return NULL;
 363     }
 364     if (PrintCodeCacheExtension) {
 365       ResourceMark rm;
 366       if (SegmentedCodeCache) {
 367         tty->print("Code heap '%s'", heap->name());
 368       } else {
 369         tty->print("Code cache");
 370       }
 371       tty->print_cr(" extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
 372                     (intptr_t)heap->low_boundary(), (intptr_t)heap->high(),
 373                     (address)heap->high() - (address)heap->low_boundary());
 374     }
 375   }
 376   print_trace("allocation", cb, size);
 377   _number_of_blobs++;
 378   return cb;
 379 }
 380 
 381 void CodeCache::free(CodeBlob* cb) {
 382   assert_locked_or_safepoint(CodeCache_lock);
 383 
 384   print_trace("free", cb);
 385   if (cb->is_nmethod()) {
 386     _number_of_nmethods--;
 387     if (((nmethod *)cb)->has_dependencies()) {
 388       _number_of_nmethods_with_dependencies--;
 389     }


 803 
 804 void icache_init();
 805 
 806 void CodeCache::initialize() {
 807   assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points");
 808 #ifdef COMPILER2
 809   assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment,  "CodeCacheSegmentSize must be large enough to align inner loops");
 810 #endif
 811   assert(CodeCacheSegmentSize >= sizeof(jdouble),    "CodeCacheSegmentSize must be large enough to align constants");
 812   // This was originally just a check of the alignment, causing failure, instead, round
 813   // the code cache to the page size.  In particular, Solaris is moving to a larger
 814   // default page size.
 815   CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size());
 816 
 817   if (SegmentedCodeCache) {
 818     // Use multiple code heaps
 819     initialize_heaps();
 820   } else {
 821     // Use a single code heap
 822     ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
 823     add_heap(rs, "Code heap", InitialCodeCacheSize, CodeBlobType::All);
 824   }
 825 
 826   // Initialize ICache flush mechanism
 827   // This service is needed for os::register_code_area
 828   icache_init();
 829 
 830   // Give OS a chance to register generated code area.
 831   // This is used on Windows 64 bit platforms to register
 832   // Structured Exception Handlers for our generated code.
 833   os::register_code_area((char*)low_bound(), (char*)high_bound());
 834 }
 835 
 836 void codeCache_init() {
 837   CodeCache::initialize();
 838 }
 839 
 840 //------------------------------------------------------------------------------------------------
 841 
 842 int CodeCache::number_of_nmethods_with_dependencies() {
 843   return _number_of_nmethods_with_dependencies;


 989   assert_locked_or_safepoint(CodeCache_lock);
 990   FOR_ALL_HEAPS(heap) {
 991     (*heap)->verify();
 992     FOR_ALL_BLOBS(cb, *heap) {
 993       if (cb->is_alive()) {
 994         cb->verify();
 995       }
 996     }
 997   }
 998 }
 999 
1000 // A CodeHeap is full. Print out warning and report event.
1001 void CodeCache::report_codemem_full(int code_blob_type, bool print) {
1002   // Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
1003   CodeHeap* heap = get_code_heap(SegmentedCodeCache ? code_blob_type : CodeBlobType::All);
1004 
1005   if (!heap->was_full() || print) {
1006     // Not yet reported for this heap, report
1007     heap->report_full();
1008     if (SegmentedCodeCache) {
1009       warning("CodeHeap for %s is full. Compiler has been disabled.", CodeCache::get_code_heap_name(code_blob_type));
1010       warning("Try increasing the code heap size using -XX:%s=",
1011           (code_blob_type == CodeBlobType::MethodNonProfiled) ? "NonProfiledCodeHeapSize" : "ProfiledCodeHeapSize");
1012     } else {
1013       warning("CodeCache is full. Compiler has been disabled.");
1014       warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1015     }
1016     ResourceMark rm;
1017     stringStream s;
1018     // Dump code cache  into a buffer before locking the tty,
1019     {
1020       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1021       print_summary(&s);
1022     }
1023     ttyLocker ttyl;
1024     tty->print("%s", s.as_string());
1025   }
1026 
1027   _codemem_full_count++;
1028   EventCodeCacheFull event;
1029   if (event.should_commit()) {


1073 void CodeCache::print_internals() {
1074   int nmethodCount = 0;
1075   int runtimeStubCount = 0;
1076   int adapterCount = 0;
1077   int deoptimizationStubCount = 0;
1078   int uncommonTrapStubCount = 0;
1079   int bufferBlobCount = 0;
1080   int total = 0;
1081   int nmethodAlive = 0;
1082   int nmethodNotEntrant = 0;
1083   int nmethodZombie = 0;
1084   int nmethodUnloaded = 0;
1085   int nmethodJava = 0;
1086   int nmethodNative = 0;
1087   int max_nm_size = 0;
1088   ResourceMark rm;
1089 
1090   int i = 0;
1091   FOR_ALL_HEAPS(heap) {
1092     if (SegmentedCodeCache && Verbose) {
1093       tty->print_cr("-- Code heap '%s' --", (*heap)->name());
1094     }
1095     FOR_ALL_BLOBS(cb, *heap) {
1096       total++;
1097       if (cb->is_nmethod()) {
1098         nmethod* nm = (nmethod*)cb;
1099 
1100         if (Verbose && nm->method() != NULL) {
1101           ResourceMark rm;
1102           char *method_name = nm->method()->name_and_sig_as_C_string();
1103           tty->print("%s", method_name);
1104           if(nm->is_alive()) { tty->print_cr(" alive"); }
1105           if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); }
1106           if(nm->is_zombie()) { tty->print_cr(" zombie"); }
1107         }
1108 
1109         nmethodCount++;
1110 
1111         if(nm->is_alive()) { nmethodAlive++; }
1112         if(nm->is_not_entrant()) { nmethodNotEntrant++; }
1113         if(nm->is_zombie()) { nmethodZombie++; }


1222             map_size           += set->heap_size();
1223           }
1224         }
1225       }
1226     }
1227     tty->print_cr("OopMaps");
1228     tty->print_cr("  #blobs    = %d", number_of_blobs);
1229     tty->print_cr("  code size = %d", code_size);
1230     tty->print_cr("  #oop_maps = %d", number_of_oop_maps);
1231     tty->print_cr("  map size  = %d", map_size);
1232   }
1233 
1234 #endif // !PRODUCT
1235 }
1236 
1237 void CodeCache::print_summary(outputStream* st, bool detailed) {
1238   FOR_ALL_HEAPS(heap_iterator) {
1239     CodeHeap* heap = (*heap_iterator);
1240     size_t total = (heap->high_boundary() - heap->low_boundary());
1241     if (SegmentedCodeCache) {
1242       st->print("CodeHeap '%s':", heap->name());
1243     } else {
1244       st->print("CodeCache:");
1245     }
1246     st->print_cr(" size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
1247                  "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
1248                  total/K, (total - heap->unallocated_capacity())/K,
1249                  heap->max_allocated_capacity()/K, heap->unallocated_capacity()/K);
1250 
1251     if (detailed) {
1252       st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
1253                    p2i(heap->low_boundary()),
1254                    p2i(heap->high()),
1255                    p2i(heap->high_boundary()));
1256     }
1257   }
1258 
1259   if (detailed) {
1260     st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
1261                        " adapters=" UINT32_FORMAT,
1262                        nof_blobs(), nof_nmethods(), nof_adapters());
1263     st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
1264                  "enabled" : Arguments::mode() == Arguments::_int ?




 205 
 206   // Compute initial sizes of CodeHeaps
 207   size_t init_non_method_size   = MIN2(InitialCodeCacheSize, non_method_size);
 208   size_t init_profiled_size     = MIN2(InitialCodeCacheSize, profiled_size);
 209   size_t init_non_profiled_size = MIN2(InitialCodeCacheSize, non_profiled_size);
 210 
 211   // Reserve one continuous chunk of memory for CodeHeaps and split it into
 212   // parts for the individual heaps. The memory layout looks like this:
 213   // ---------- high -----------
 214   //    Non-profiled nmethods
 215   //      Profiled nmethods
 216   //         Non-methods
 217   // ---------- low ------------
 218   ReservedCodeSpace rs = reserve_heap_memory(non_profiled_size + profiled_size + non_method_size);
 219   ReservedSpace non_method_space    = rs.first_part(non_method_size);
 220   ReservedSpace rest                = rs.last_part(non_method_size);
 221   ReservedSpace profiled_space      = rest.first_part(profiled_size);
 222   ReservedSpace non_profiled_space  = rest.last_part(profiled_size);
 223 
 224   // Non-methods (stubs, adapters, ...)
 225   add_heap(non_method_space, "Code Heap 'non-methods'", init_non_method_size, CodeBlobType::NonMethod);
 226   // Tier 2 and tier 3 (profiled) methods
 227   add_heap(profiled_space, "Code Heap 'profiled nmethods'", init_profiled_size, CodeBlobType::MethodProfiled);
 228   // Tier 1 and tier 4 (non-profiled) methods and native methods
 229   add_heap(non_profiled_space, "Code Heap 'non-profiled nmethods'", init_non_profiled_size, CodeBlobType::MethodNonProfiled);
 230 }
 231 
 232 ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size) {
 233   // Determine alignment
 234   const size_t page_size = os::can_execute_large_page_memory() ?
 235           MIN2(os::page_size_for_region(InitialCodeCacheSize, 8),
 236                os::page_size_for_region(size, 8)) :
 237           os::vm_page_size();
 238   const size_t granularity = os::vm_allocation_granularity();
 239   const size_t r_align = MAX2(page_size, granularity);
 240   const size_t r_size = align_size_up(size, r_align);
 241   const size_t rs_align = page_size == (size_t) os::vm_page_size() ? 0 :
 242     MAX2(page_size, granularity);
 243 
 244   ReservedCodeSpace rs(r_size, rs_align, rs_align > 0);
 245 
 246   // Initialize bounds
 247   _low_bound = (address)rs.base();
 248   _high_bound = _low_bound + rs.size();
 249 


 347   CodeBlob* cb = NULL;
 348 
 349   // Get CodeHeap for the given CodeBlobType
 350   CodeHeap* heap = get_code_heap(SegmentedCodeCache ? code_blob_type : CodeBlobType::All);
 351   assert (heap != NULL, "heap is null");
 352 
 353   while (true) {
 354     cb = (CodeBlob*)heap->allocate(size, is_critical);
 355     if (cb != NULL) break;
 356     if (!heap->expand_by(CodeCacheExpansionSize)) {
 357       // Expansion failed
 358       if (SegmentedCodeCache && (code_blob_type == CodeBlobType::NonMethod)) {
 359         // Fallback solution: Store non-method code in the non-profiled code heap
 360         return allocate(size, CodeBlobType::MethodNonProfiled, is_critical);
 361       }
 362       return NULL;
 363     }
 364     if (PrintCodeCacheExtension) {
 365       ResourceMark rm;
 366       if (SegmentedCodeCache) {
 367         tty->print("%s", heap->name());
 368       } else {
 369         tty->print("Code Cache");
 370       }
 371       tty->print_cr(" extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
 372                     (intptr_t)heap->low_boundary(), (intptr_t)heap->high(),
 373                     (address)heap->high() - (address)heap->low_boundary());
 374     }
 375   }
 376   print_trace("allocation", cb, size);
 377   _number_of_blobs++;
 378   return cb;
 379 }
 380 
 381 void CodeCache::free(CodeBlob* cb) {
 382   assert_locked_or_safepoint(CodeCache_lock);
 383 
 384   print_trace("free", cb);
 385   if (cb->is_nmethod()) {
 386     _number_of_nmethods--;
 387     if (((nmethod *)cb)->has_dependencies()) {
 388       _number_of_nmethods_with_dependencies--;
 389     }


 803 
 804 void icache_init();
 805 
 806 void CodeCache::initialize() {
 807   assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points");
 808 #ifdef COMPILER2
 809   assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment,  "CodeCacheSegmentSize must be large enough to align inner loops");
 810 #endif
 811   assert(CodeCacheSegmentSize >= sizeof(jdouble),    "CodeCacheSegmentSize must be large enough to align constants");
 812   // This was originally just a check of the alignment, causing failure, instead, round
 813   // the code cache to the page size.  In particular, Solaris is moving to a larger
 814   // default page size.
 815   CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size());
 816 
 817   if (SegmentedCodeCache) {
 818     // Use multiple code heaps
 819     initialize_heaps();
 820   } else {
 821     // Use a single code heap
 822     ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
 823     add_heap(rs, "Code Cache", InitialCodeCacheSize, CodeBlobType::All);
 824   }
 825 
 826   // Initialize ICache flush mechanism
 827   // This service is needed for os::register_code_area
 828   icache_init();
 829 
 830   // Give OS a chance to register generated code area.
 831   // This is used on Windows 64 bit platforms to register
 832   // Structured Exception Handlers for our generated code.
 833   os::register_code_area((char*)low_bound(), (char*)high_bound());
 834 }
 835 
 836 void codeCache_init() {
 837   CodeCache::initialize();
 838 }
 839 
 840 //------------------------------------------------------------------------------------------------
 841 
 842 int CodeCache::number_of_nmethods_with_dependencies() {
 843   return _number_of_nmethods_with_dependencies;


 989   assert_locked_or_safepoint(CodeCache_lock);
 990   FOR_ALL_HEAPS(heap) {
 991     (*heap)->verify();
 992     FOR_ALL_BLOBS(cb, *heap) {
 993       if (cb->is_alive()) {
 994         cb->verify();
 995       }
 996     }
 997   }
 998 }
 999 
1000 // A CodeHeap is full. Print out warning and report event.
1001 void CodeCache::report_codemem_full(int code_blob_type, bool print) {
1002   // Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
1003   CodeHeap* heap = get_code_heap(SegmentedCodeCache ? code_blob_type : CodeBlobType::All);
1004 
1005   if (!heap->was_full() || print) {
1006     // Not yet reported for this heap, report
1007     heap->report_full();
1008     if (SegmentedCodeCache) {
1009       warning("%s is full. Compiler has been disabled.", CodeCache::get_code_heap_name(code_blob_type));
1010       warning("Try increasing the code heap size using -XX:%s=",
1011           (code_blob_type == CodeBlobType::MethodNonProfiled) ? "NonProfiledCodeHeapSize" : "ProfiledCodeHeapSize");
1012     } else {
1013       warning("CodeCache is full. Compiler has been disabled.");
1014       warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1015     }
1016     ResourceMark rm;
1017     stringStream s;
1018     // Dump code cache  into a buffer before locking the tty,
1019     {
1020       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1021       print_summary(&s);
1022     }
1023     ttyLocker ttyl;
1024     tty->print("%s", s.as_string());
1025   }
1026 
1027   _codemem_full_count++;
1028   EventCodeCacheFull event;
1029   if (event.should_commit()) {


1073 void CodeCache::print_internals() {
1074   int nmethodCount = 0;
1075   int runtimeStubCount = 0;
1076   int adapterCount = 0;
1077   int deoptimizationStubCount = 0;
1078   int uncommonTrapStubCount = 0;
1079   int bufferBlobCount = 0;
1080   int total = 0;
1081   int nmethodAlive = 0;
1082   int nmethodNotEntrant = 0;
1083   int nmethodZombie = 0;
1084   int nmethodUnloaded = 0;
1085   int nmethodJava = 0;
1086   int nmethodNative = 0;
1087   int max_nm_size = 0;
1088   ResourceMark rm;
1089 
1090   int i = 0;
1091   FOR_ALL_HEAPS(heap) {
1092     if (SegmentedCodeCache && Verbose) {
1093       tty->print_cr("-- %s --", (*heap)->name());
1094     }
1095     FOR_ALL_BLOBS(cb, *heap) {
1096       total++;
1097       if (cb->is_nmethod()) {
1098         nmethod* nm = (nmethod*)cb;
1099 
1100         if (Verbose && nm->method() != NULL) {
1101           ResourceMark rm;
1102           char *method_name = nm->method()->name_and_sig_as_C_string();
1103           tty->print("%s", method_name);
1104           if(nm->is_alive()) { tty->print_cr(" alive"); }
1105           if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); }
1106           if(nm->is_zombie()) { tty->print_cr(" zombie"); }
1107         }
1108 
1109         nmethodCount++;
1110 
1111         if(nm->is_alive()) { nmethodAlive++; }
1112         if(nm->is_not_entrant()) { nmethodNotEntrant++; }
1113         if(nm->is_zombie()) { nmethodZombie++; }


1222             map_size           += set->heap_size();
1223           }
1224         }
1225       }
1226     }
1227     tty->print_cr("OopMaps");
1228     tty->print_cr("  #blobs    = %d", number_of_blobs);
1229     tty->print_cr("  code size = %d", code_size);
1230     tty->print_cr("  #oop_maps = %d", number_of_oop_maps);
1231     tty->print_cr("  map size  = %d", map_size);
1232   }
1233 
1234 #endif // !PRODUCT
1235 }
1236 
1237 void CodeCache::print_summary(outputStream* st, bool detailed) {
1238   FOR_ALL_HEAPS(heap_iterator) {
1239     CodeHeap* heap = (*heap_iterator);
1240     size_t total = (heap->high_boundary() - heap->low_boundary());
1241     if (SegmentedCodeCache) {
1242       st->print("%s:", heap->name());
1243     } else {
1244       st->print("Code Cache:");
1245     }
1246     st->print_cr(" size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
1247                  "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
1248                  total/K, (total - heap->unallocated_capacity())/K,
1249                  heap->max_allocated_capacity()/K, heap->unallocated_capacity()/K);
1250 
1251     if (detailed) {
1252       st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
1253                    p2i(heap->low_boundary()),
1254                    p2i(heap->high()),
1255                    p2i(heap->high_boundary()));
1256     }
1257   }
1258 
1259   if (detailed) {
1260     st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
1261                        " adapters=" UINT32_FORMAT,
1262                        nof_blobs(), nof_nmethods(), nof_adapters());
1263     st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
1264                  "enabled" : Arguments::mode() == Arguments::_int ?


src/share/vm/code/codeCache.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File