# HG changeset patch # User mdoerr # Date 1540899142 -3600 # Tue Oct 30 12:32:22 2018 +0100 # Node ID c713078ce31a2ddde11405b3296009c64ebe8f61 # Parent 6fe18b0c0e886a250b5cc41d1662785696aa6501 8213086: Compiler thread creation should be bounded by available space in memory and Code Cache Reviewed-by: kvn diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp --- a/src/hotspot/share/compiler/compileBroker.cpp +++ b/src/hotspot/share/compiler/compileBroker.cpp @@ -894,14 +894,19 @@ EXCEPTION_MARK; julong available_memory = os::available_memory(); + // If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All). + size_t available_cc_np = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled), + available_cc_p = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled); + // Only do attempt to start additional threads if the lock is free. if (!CompileThread_lock->try_lock()) return; if (_c2_compile_queue != NULL) { int old_c2_count = _compilers[1]->num_compiler_threads(); - int new_c2_count = MIN3(_c2_count, + int new_c2_count = MIN4(_c2_count, _c2_compile_queue->size() / 2, - (int)(available_memory / 200*M)); + (int)(available_memory / (200*M)), + (int)(available_cc_np / (128*K))); for (int i = old_c2_count; i < new_c2_count; i++) { JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], true, CHECK); @@ -910,17 +915,18 @@ if (TraceCompilerThreads) { ResourceMark rm; MutexLocker mu(Threads_lock); - tty->print_cr("Added compiler thread %s (available memory: %dMB)", - ct->get_thread_name(), (int)(available_memory/M)); + tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)", + ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M)); } } } if (_c1_compile_queue != NULL) { int old_c1_count = _compilers[0]->num_compiler_threads(); - int new_c1_count = MIN3(_c1_count, + int new_c1_count = MIN4(_c1_count, _c1_compile_queue->size() / 4, - (int)(available_memory / 100*M)); + (int)(available_memory / (100*M)), + (int)(available_cc_p / (128*K))); for (int i = old_c1_count; i < new_c1_count; i++) { JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], true, CHECK); @@ -929,8 +935,8 @@ if (TraceCompilerThreads) { ResourceMark rm; MutexLocker mu(Threads_lock); - tty->print_cr("Added compiler thread %s (available memory: %dMB)", - ct->get_thread_name(), (int)(available_memory/M)); + tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)", + ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M)); } } }