diff src/share/vm/compiler/compileBroker.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 3eed8712d410 f73af4455d7d
children 2a69cbe850a8
line wrap: on
line diff
--- a/src/share/vm/compiler/compileBroker.cpp	Thu Oct 16 10:21:29 2014 +0200
+++ b/src/share/vm/compiler/compileBroker.cpp	Wed Oct 15 16:02:50 2014 +0200
@@ -139,9 +139,9 @@
 // The installed compiler(s)
 AbstractCompiler* CompileBroker::_compilers[2];
 
-// These counters are used for assigning id's to each compilation
-uint CompileBroker::_compilation_id        = 0;
-uint CompileBroker::_osr_compilation_id    = 0;
+// These counters are used to assign an unique ID to each compilation.
+volatile jint CompileBroker::_compilation_id     = 0;
+volatile jint CompileBroker::_osr_compilation_id = 0;
 
 // Debugging information
 int  CompileBroker::_last_compile_type     = no_compile;
@@ -213,7 +213,7 @@
   void log_nmethod(JavaThread* thread, nmethod* nm) {
     log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]",
         nm->compile_id(), nm->is_osr_method() ? "%" : "",
-        nm, nm->code_begin(), nm->code_end());
+        p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
   }
 
   void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
@@ -1181,7 +1181,7 @@
     // We now know that this compilation is not pending, complete,
     // or prohibited.  Assign a compile_id to this compilation
     // and check to see if it is in our [Start..Stop) range.
-    uint compile_id = assign_compile_id(method, osr_bci);
+    int compile_id = assign_compile_id(method, osr_bci);
     if (compile_id == 0) {
       // The compilation falls outside the allowed range.
       return;
@@ -1353,18 +1353,12 @@
   // do the compilation
   if (method->is_native()) {
     if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
-      // Acquire our lock.
-      int compile_id;
-      {
-        MutexLocker locker(MethodCompileQueue_lock, THREAD);
-        compile_id = assign_compile_id(method, standard_entry_bci);
-      }
       // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
       // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
       //
       // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
       // in this case.  If we can't generate one and use it we can not execute the out-of-line method handle calls.
-      (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id);
+      AdapterHandlerLibrary::create_native_wrapper(method);
     } else {
       return NULL;
     }
@@ -1467,27 +1461,28 @@
   return false;
 }
 
-
-// ------------------------------------------------------------------
-// CompileBroker::assign_compile_id
-//
-// Assign a serialized id number to this compilation request.  If the
-// number falls out of the allowed range, return a 0.  OSR
-// compilations may be numbered separately from regular compilations
-// if certain debugging flags are used.
-uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
-  assert(MethodCompileQueue_lock->owner() == Thread::current(),
-         "must hold the compilation queue lock");
+/**
+ * Generate serialized IDs for compilation requests. If certain debugging flags are used
+ * and the ID is not within the specified range, the method is not compiled and 0 is returned.
+ * The function also allows to generate separate compilation IDs for OSR compilations.
+ */
+int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
+#ifdef ASSERT
   bool is_osr = (osr_bci != standard_entry_bci);
-  uint id;
-  if (CICountOSR && is_osr) {
-    id = ++_osr_compilation_id;
-    if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) {
+  int id;
+  if (method->is_native()) {
+    assert(!is_osr, "can't be osr");
+    // Adapters, native wrappers and method handle intrinsics
+    // should be generated always.
+    return Atomic::add(1, &_compilation_id);
+  } else if (CICountOSR && is_osr) {
+    id = Atomic::add(1, &_osr_compilation_id);
+    if (CIStartOSR <= id && id < CIStopOSR) {
       return id;
     }
   } else {
-    id = ++_compilation_id;
-    if ((uint)CIStart <= id && id < (uint)CIStop) {
+    id = Atomic::add(1, &_compilation_id);
+    if (CIStart <= id && id < CIStop) {
       return id;
     }
   }
@@ -1495,6 +1490,11 @@
   // Method was not in the appropriate compilation range.
   method->set_not_compilable_quietly();
   return 0;
+#else
+  // CICountOSR is a develop flag and set to 'false' by default. In a product built,
+  // only _compilation_id is incremented.
+  return Atomic::add(1, &_compilation_id);
+#endif
 }
 
 
@@ -1849,7 +1849,7 @@
         if (xtty != NULL) {
           ttyLocker ttyl;
           // Record any per thread log files
-          xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file_name);
+          xtty->elem("thread_logfile thread='" INTX_FORMAT "' filename='%s'", thread_id, file_name);
         }
         return;
       }
@@ -1880,7 +1880,7 @@
   if (_should_block) {
 #ifndef PRODUCT
     if (PrintCompilation && (Verbose || WizardMode))
-      tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", Thread::current());
+      tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
 #endif
     ThreadInVMfromNative tivfn(JavaThread::current());
   }
@@ -1897,7 +1897,7 @@
     CodeCache::print_summary(&s, detailed);
   }
   ttyLocker ttyl;
-  tty->print(s.as_string());
+  tty->print("%s", s.as_string());
 }
 
 void CompileBroker::post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env) {
@@ -2125,7 +2125,7 @@
       // Lock to prevent tearing
       ttyLocker ttyl;
       xtty->begin_elem("code_cache_full");
-      xtty->print(s.as_string());
+      xtty->print("%s", s.as_string());
       xtty->stamp();
       xtty->end_elem();
     }