changeset 52350:9e3fd0cc3936

8213086: Compiler thread creation should be bounded by available space in memory and Code Cache Reviewed-by: kvn, thartmann
author mdoerr
date Wed, 31 Oct 2018 14:48:36 +0100
parents f34a2e0069c7
children 0c25fa66b5c5
files src/hotspot/share/compiler/compileBroker.cpp
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/compiler/compileBroker.cpp	Wed Oct 31 13:43:57 2018 +0100
+++ b/src/hotspot/share/compiler/compileBroker.cpp	Wed Oct 31 14:48:36 2018 +0100
@@ -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));
       }
     }
   }