Mon, 14 Jan 2013 13:52:08 -0500
8005204: Code Cache Reduction: command line options implementation
Summary: Adding more detailed output on CodeCache usage
Reviewed-by: kvn, vladidan
Contributed-by: Alexander Harlap <alexander.harlap@oracle.com>
1.1 --- a/src/share/vm/code/codeCache.cpp Mon Jan 14 13:44:49 2013 -0500 1.2 +++ b/src/share/vm/code/codeCache.cpp Mon Jan 14 13:52:08 2013 -0500 1.3 @@ -30,6 +30,7 @@ 1.4 #include "code/icBuffer.hpp" 1.5 #include "code/nmethod.hpp" 1.6 #include "code/pcDesc.hpp" 1.7 +#include "compiler/compileBroker.hpp" 1.8 #include "gc_implementation/shared/markSweep.hpp" 1.9 #include "memory/allocation.inline.hpp" 1.10 #include "memory/gcLocker.hpp" 1.11 @@ -39,6 +40,7 @@ 1.12 #include "oops/objArrayOop.hpp" 1.13 #include "oops/oop.inline.hpp" 1.14 #include "runtime/handles.inline.hpp" 1.15 +#include "runtime/arguments.hpp" 1.16 #include "runtime/icache.hpp" 1.17 #include "runtime/java.hpp" 1.18 #include "runtime/mutexLocker.hpp" 1.19 @@ -168,6 +170,8 @@ 1.20 return (nmethod*)cb; 1.21 } 1.22 1.23 +static size_t maxCodeCacheUsed = 0; 1.24 + 1.25 CodeBlob* CodeCache::allocate(int size) { 1.26 // Do not seize the CodeCache lock here--if the caller has not 1.27 // already done so, we are going to lose bigtime, since the code 1.28 @@ -192,6 +196,8 @@ 1.29 (address)_heap->end() - (address)_heap->begin()); 1.30 } 1.31 } 1.32 + maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() - 1.33 + (address)_heap->low_boundary()) - unallocated_capacity()); 1.34 verify_if_often(); 1.35 print_trace("allocation", cb, size); 1.36 return cb; 1.37 @@ -928,7 +934,14 @@ 1.38 FREE_C_HEAP_ARRAY(int, buckets, mtCode); 1.39 } 1.40 1.41 +#endif // !PRODUCT 1.42 + 1.43 void CodeCache::print() { 1.44 + print_summary(tty); 1.45 + 1.46 +#ifndef PRODUCT 1.47 + if (!Verbose) return; 1.48 + 1.49 CodeBlob_sizes live; 1.50 CodeBlob_sizes dead; 1.51 1.52 @@ -953,7 +966,7 @@ 1.53 } 1.54 1.55 1.56 - if (Verbose) { 1.57 + if (WizardMode) { 1.58 // print the oop_map usage 1.59 int code_size = 0; 1.60 int number_of_blobs = 0; 1.61 @@ -977,20 +990,30 @@ 1.62 tty->print_cr(" map size = %d", map_size); 1.63 } 1.64 1.65 +#endif // !PRODUCT 1.66 } 1.67 1.68 -#endif // PRODUCT 1.69 +void CodeCache::print_summary(outputStream* st, bool detailed) { 1.70 + size_t total = (_heap->high_boundary() - _heap->low_boundary()); 1.71 + st->print_cr("CodeCache: size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT 1.72 + "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT 1.73 + "Kb max_free_chunk=" SIZE_FORMAT "Kb", 1.74 + total/K, (total - unallocated_capacity())/K, 1.75 + maxCodeCacheUsed/K, unallocated_capacity()/K, largest_free_block()/K); 1.76 1.77 -void CodeCache::print_bounds(outputStream* st) { 1.78 - st->print_cr("Code Cache [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", 1.79 - _heap->low_boundary(), 1.80 - _heap->high(), 1.81 - _heap->high_boundary()); 1.82 - st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT 1.83 - " adapters=" UINT32_FORMAT " free_code_cache=" SIZE_FORMAT "Kb" 1.84 - " largest_free_block=" SIZE_FORMAT, 1.85 - nof_blobs(), nof_nmethods(), nof_adapters(), 1.86 - unallocated_capacity()/K, largest_free_block()); 1.87 + if (detailed) { 1.88 + st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]", 1.89 + _heap->low_boundary(), 1.90 + _heap->high(), 1.91 + _heap->high_boundary()); 1.92 + st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT 1.93 + " adapters=" UINT32_FORMAT, 1.94 + nof_blobs(), nof_nmethods(), nof_adapters()); 1.95 + st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ? 1.96 + "enabled" : Arguments::mode() == Arguments::_int ? 1.97 + "disabled (interpreter mode)" : 1.98 + "disabled (not enough contiguous free space left)"); 1.99 + } 1.100 } 1.101 1.102 void CodeCache::log_state(outputStream* st) {
2.1 --- a/src/share/vm/code/codeCache.hpp Mon Jan 14 13:44:49 2013 -0500 2.2 +++ b/src/share/vm/code/codeCache.hpp Mon Jan 14 13:52:08 2013 -0500 2.3 @@ -145,11 +145,11 @@ 2.4 static void prune_scavenge_root_nmethods(); 2.5 2.6 // Printing/debugging 2.7 - static void print() PRODUCT_RETURN; // prints summary 2.8 + static void print(); // prints summary 2.9 static void print_internals(); 2.10 static void verify(); // verifies the code cache 2.11 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN; 2.12 - static void print_bounds(outputStream* st); // Prints a summary of the bounds of the code cache 2.13 + static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage 2.14 static void log_state(outputStream* st); 2.15 2.16 // The full limits of the codeCache
3.1 --- a/src/share/vm/compiler/compileBroker.cpp Mon Jan 14 13:44:49 2013 -0500 3.2 +++ b/src/share/vm/compiler/compileBroker.cpp Mon Jan 14 13:52:08 2013 -0500 3.3 @@ -1714,6 +1714,20 @@ 3.4 } 3.5 } 3.6 3.7 +// wrapper for CodeCache::print_summary() 3.8 +static void codecache_print(bool detailed) 3.9 +{ 3.10 + ResourceMark rm; 3.11 + stringStream s; 3.12 + // Dump code cache into a buffer before locking the tty, 3.13 + { 3.14 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 3.15 + CodeCache::print_summary(&s, detailed); 3.16 + } 3.17 + ttyLocker ttyl; 3.18 + tty->print_cr(s.as_string()); 3.19 +} 3.20 + 3.21 // ------------------------------------------------------------------ 3.22 // CompileBroker::invoke_compiler_on_method 3.23 // 3.24 @@ -1841,6 +1855,9 @@ 3.25 tty->print_cr("size: %d time: %d inlined: %d bytes", code_size, (int)time.milliseconds(), task->num_inlined_bytecodes()); 3.26 } 3.27 3.28 + if (PrintCodeCacheOnCompilation) 3.29 + codecache_print(/* detailed= */ false); 3.30 + 3.31 // Disable compilation, if required. 3.32 switch (compilable) { 3.33 case ciEnv::MethodCompilable_never: 3.34 @@ -1885,6 +1902,7 @@ 3.35 UseInterpreter = true; 3.36 if (UseCompiler || AlwaysCompileLoopMethods ) { 3.37 if (xtty != NULL) { 3.38 + ResourceMark rm; 3.39 stringStream s; 3.40 // Dump code cache state into a buffer before locking the tty, 3.41 // because log_state() will use locks causing lock conflicts. 3.42 @@ -1898,9 +1916,9 @@ 3.43 } 3.44 warning("CodeCache is full. Compiler has been disabled."); 3.45 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize="); 3.46 - CodeCache::print_bounds(tty); 3.47 #ifndef PRODUCT 3.48 if (CompileTheWorld || ExitOnFullCodeCache) { 3.49 + codecache_print(/* detailed= */ true); 3.50 before_exit(JavaThread::current()); 3.51 exit_globals(); // will delete tty 3.52 vm_direct_exit(CompileTheWorld ? 0 : 1); 3.53 @@ -1913,6 +1931,7 @@ 3.54 AlwaysCompileLoopMethods = false; 3.55 } 3.56 } 3.57 + codecache_print(/* detailed= */ true); 3.58 } 3.59 3.60 // ------------------------------------------------------------------
4.1 --- a/src/share/vm/runtime/globals.hpp Mon Jan 14 13:44:49 2013 -0500 4.2 +++ b/src/share/vm/runtime/globals.hpp Mon Jan 14 13:52:08 2013 -0500 4.3 @@ -929,11 +929,14 @@ 4.4 "Starts debugger when an implicit OS (e.g., NULL) " \ 4.5 "exception happens") \ 4.6 \ 4.7 - notproduct(bool, PrintCodeCache, false, \ 4.8 - "Print the compiled_code cache when exiting") \ 4.9 + product(bool, PrintCodeCache, false, \ 4.10 + "Print the code cache memory usage when exiting") \ 4.11 \ 4.12 develop(bool, PrintCodeCache2, false, \ 4.13 - "Print detailed info on the compiled_code cache when exiting") \ 4.14 + "Print detailed usage info on the code cache when exiting") \ 4.15 + \ 4.16 + product(bool, PrintCodeCacheOnCompilation, false, \ 4.17 + "Print the code cache memory usage each time a method is compiled") \ 4.18 \ 4.19 diagnostic(bool, PrintStubCode, false, \ 4.20 "Print generated stub code") \
5.1 --- a/src/share/vm/runtime/java.cpp Mon Jan 14 13:44:49 2013 -0500 5.2 +++ b/src/share/vm/runtime/java.cpp Mon Jan 14 13:52:08 2013 -0500 5.3 @@ -368,6 +368,12 @@ 5.4 if (CITime) { 5.5 CompileBroker::print_times(); 5.6 } 5.7 + 5.8 + if (PrintCodeCache) { 5.9 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 5.10 + CodeCache::print(); 5.11 + } 5.12 + 5.13 #ifdef COMPILER2 5.14 if (PrintPreciseBiasedLockingStatistics) { 5.15 OptoRuntime::print_named_counters();
6.1 --- a/src/share/vm/utilities/vmError.cpp Mon Jan 14 13:44:49 2013 -0500 6.2 +++ b/src/share/vm/utilities/vmError.cpp Mon Jan 14 13:52:08 2013 -0500 6.3 @@ -702,7 +702,7 @@ 6.4 6.5 if (_verbose && Universe::is_fully_initialized()) { 6.6 // print code cache information before vm abort 6.7 - CodeCache::print_bounds(st); 6.8 + CodeCache::print_summary(st); 6.9 st->cr(); 6.10 } 6.11